You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "test/testsupport/test_artifacts.h"
  11. #include <string.h>
  12. #include "absl/flags/flag.h"
  13. #include "absl/flags/parse.h"
  14. #include "rtc_base/logging.h"
  15. #include "rtc_base/system/file_wrapper.h"
  16. #include "test/testsupport/file_utils.h"
  17. namespace {
  18. const std::string& DefaultArtifactPath() {
  19. static const std::string path = webrtc::test::OutputPath();
  20. return path;
  21. }
  22. } // namespace
  23. ABSL_FLAG(std::string,
  24. test_artifacts_dir,
  25. DefaultArtifactPath().c_str(),
  26. "The output folder where test output should be saved.");
  27. namespace webrtc {
  28. namespace test {
  29. bool GetTestArtifactsDir(std::string* out_dir) {
  30. if (absl::GetFlag(FLAGS_test_artifacts_dir).empty()) {
  31. RTC_LOG(LS_WARNING) << "No test_out_dir defined.";
  32. return false;
  33. }
  34. *out_dir = absl::GetFlag(FLAGS_test_artifacts_dir);
  35. return true;
  36. }
  37. bool WriteToTestArtifactsDir(const char* filename,
  38. const uint8_t* buffer,
  39. size_t length) {
  40. if (absl::GetFlag(FLAGS_test_artifacts_dir).empty()) {
  41. RTC_LOG(LS_WARNING) << "No test_out_dir defined.";
  42. return false;
  43. }
  44. if (filename == nullptr || strlen(filename) == 0) {
  45. RTC_LOG(LS_WARNING) << "filename must be provided.";
  46. return false;
  47. }
  48. FileWrapper output = FileWrapper::OpenWriteOnly(
  49. JoinFilename(absl::GetFlag(FLAGS_test_artifacts_dir), filename));
  50. return output.is_open() && output.Write(buffer, length);
  51. }
  52. bool WriteToTestArtifactsDir(const char* filename, const std::string& content) {
  53. return WriteToTestArtifactsDir(
  54. filename, reinterpret_cast<const uint8_t*>(content.c_str()),
  55. content.length());
  56. }
  57. } // namespace test
  58. } // namespace webrtc