ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 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 | |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 11 | #include "test/testsupport/test_artifacts.h" |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/file.h" |
| 16 | #include "rtc_base/flags.h" |
| 17 | #include "rtc_base/logging.h" |
| 18 | #include "rtc_base/pathutils.h" |
| 19 | #include "test/testsupport/fileutils.h" |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 20 | |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 21 | namespace { |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 22 | const std::string& DefaultArtifactPath() { |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 23 | static const std::string path = webrtc::test::OutputPath(); |
| 24 | return path; |
| 25 | } |
| 26 | } |
| 27 | |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 28 | DEFINE_string(test_artifacts_dir, |
| 29 | DefaultArtifactPath().c_str(), |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 30 | "The output folder where test output should be saved."); |
| 31 | |
| 32 | namespace webrtc { |
| 33 | namespace test { |
| 34 | |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 35 | bool GetTestArtifactsDir(std::string* out_dir) { |
| 36 | if (strlen(FLAG_test_artifacts_dir) == 0) { |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 37 | LOG(LS_WARNING) << "No test_out_dir defined."; |
| 38 | return false; |
| 39 | } |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 40 | *out_dir = FLAG_test_artifacts_dir; |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 44 | bool WriteToTestArtifactsDir(const char* filename, |
| 45 | const uint8_t* buffer, |
| 46 | size_t length) { |
| 47 | if (strlen(FLAG_test_artifacts_dir) == 0) { |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 48 | LOG(LS_WARNING) << "No test_out_dir defined."; |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | if (filename == nullptr || strlen(filename) == 0) { |
| 53 | LOG(LS_WARNING) << "filename must be provided."; |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | rtc::File output = |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 58 | rtc::File::Create(rtc::Pathname(FLAG_test_artifacts_dir, filename)); |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 59 | |
| 60 | return output.IsOpen() && output.Write(buffer, length) == length; |
| 61 | } |
| 62 | |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 63 | bool WriteToTestArtifactsDir(const char* filename, const std::string& content) { |
| 64 | return WriteToTestArtifactsDir( |
| 65 | filename, reinterpret_cast<const uint8_t*>(content.c_str()), |
| 66 | content.length()); |
ilnik | e264a9e | 2017-07-25 07:31:18 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } // namespace test |
| 70 | } // namespace webrtc |