2016-12-14 15:03:03 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-27 14:46:24 +02:00
|
|
|
#include "test/testsupport/test_artifacts.h"
|
2016-12-14 15:03:03 -08:00
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2019-07-18 13:44:12 +02:00
|
|
|
#include "absl/flags/flag.h"
|
|
|
|
|
#include "absl/flags/parse.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2019-02-08 16:40:53 +01:00
|
|
|
#include "rtc_base/system/file_wrapper.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "test/testsupport/file_utils.h"
|
2016-12-14 15:03:03 -08:00
|
|
|
|
2017-08-29 05:51:57 -07:00
|
|
|
namespace {
|
2017-09-27 14:46:24 +02:00
|
|
|
const std::string& DefaultArtifactPath() {
|
2017-08-29 05:51:57 -07:00
|
|
|
static const std::string path = webrtc::test::OutputPath();
|
|
|
|
|
return path;
|
|
|
|
|
}
|
2018-06-19 15:03:05 +02:00
|
|
|
} // namespace
|
2017-08-29 05:51:57 -07:00
|
|
|
|
2019-07-18 13:44:12 +02:00
|
|
|
ABSL_FLAG(std::string,
|
|
|
|
|
test_artifacts_dir,
|
|
|
|
|
DefaultArtifactPath().c_str(),
|
|
|
|
|
"The output folder where test output should be saved.");
|
2016-12-14 15:03:03 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2017-09-27 14:46:24 +02:00
|
|
|
bool GetTestArtifactsDir(std::string* out_dir) {
|
2019-07-18 13:44:12 +02:00
|
|
|
if (absl::GetFlag(FLAGS_test_artifacts_dir).empty()) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING) << "No test_out_dir defined.";
|
2017-07-25 07:31:18 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-07-18 13:44:12 +02:00
|
|
|
*out_dir = absl::GetFlag(FLAGS_test_artifacts_dir);
|
2017-07-25 07:31:18 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 14:46:24 +02:00
|
|
|
bool WriteToTestArtifactsDir(const char* filename,
|
|
|
|
|
const uint8_t* buffer,
|
|
|
|
|
size_t length) {
|
2019-07-18 13:44:12 +02:00
|
|
|
if (absl::GetFlag(FLAGS_test_artifacts_dir).empty()) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING) << "No test_out_dir defined.";
|
2016-12-14 15:03:03 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filename == nullptr || strlen(filename) == 0) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING) << "filename must be provided.";
|
2016-12-14 15:03:03 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 16:40:53 +01:00
|
|
|
FileWrapper output = FileWrapper::OpenWriteOnly(
|
2019-07-18 13:44:12 +02:00
|
|
|
JoinFilename(absl::GetFlag(FLAGS_test_artifacts_dir), filename));
|
2016-12-14 15:03:03 -08:00
|
|
|
|
2019-02-08 16:40:53 +01:00
|
|
|
return output.is_open() && output.Write(buffer, length);
|
2016-12-14 15:03:03 -08:00
|
|
|
}
|
|
|
|
|
|
2017-09-27 14:46:24 +02:00
|
|
|
bool WriteToTestArtifactsDir(const char* filename, const std::string& content) {
|
|
|
|
|
return WriteToTestArtifactsDir(
|
|
|
|
|
filename, reinterpret_cast<const uint8_t*>(content.c_str()),
|
|
|
|
|
content.length());
|
2016-12-14 15:03:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|