diff --git a/webrtc/test/BUILD.gn b/webrtc/test/BUILD.gn index 8f50c1189a..799642d1e1 100644 --- a/webrtc/test/BUILD.gn +++ b/webrtc/test/BUILD.gn @@ -235,11 +235,11 @@ if (!build_with_chromium) { } } - rtc_source_set("test_support_isolated_output") { + rtc_source_set("test_support_test_output") { testonly = true sources = [ - "testsupport/isolated_output.cc", - "testsupport/isolated_output.h", + "testsupport/test_output.cc", + "testsupport/test_output.h", ] deps = [ ":fileutils", @@ -286,10 +286,10 @@ if (!build_with_chromium) { "rtp_file_reader_unittest.cc", "rtp_file_writer_unittest.cc", "testsupport/always_passing_unittest.cc", - "testsupport/isolated_output_unittest.cc", "testsupport/metrics/video_metrics_unittest.cc", "testsupport/packet_reader_unittest.cc", "testsupport/perf_test_unittest.cc", + "testsupport/test_output_unittest.cc", "testsupport/y4m_frame_writer_unittest.cc", "testsupport/yuv_frame_reader_unittest.cc", "testsupport/yuv_frame_writer_unittest.cc", @@ -323,7 +323,7 @@ if (!build_with_chromium) { ":fileutils_unittests", ":test_common", ":test_main", - ":test_support_isolated_output", + ":test_support_test_output", ":video_test_common", ":video_test_support", "../modules/video_capture", diff --git a/webrtc/test/testsupport/isolated_output.cc b/webrtc/test/testsupport/test_output.cc similarity index 50% rename from webrtc/test/testsupport/isolated_output.cc rename to webrtc/test/testsupport/test_output.cc index 5324900efc..aea5110d97 100644 --- a/webrtc/test/testsupport/isolated_output.cc +++ b/webrtc/test/testsupport/test_output.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/test/testsupport/isolated_output.h" +#include "webrtc/test/testsupport/test_output.h" #include @@ -18,17 +18,27 @@ #include "webrtc/rtc_base/pathutils.h" #include "webrtc/test/testsupport/fileutils.h" -DEFINE_string(isolated_out_dir, webrtc::test::OutputPath(), - "The isolated output folder provided by swarming test framework."); +DEFINE_string(test_output_dir, + webrtc::test::OutputPath(), + "The output folder where test output should be saved."); namespace webrtc { namespace test { -bool WriteIsolatedOutput(const char* filename, - const uint8_t* buffer, - size_t length) { - if (FLAGS_isolated_out_dir.empty()) { - LOG(LS_WARNING) << "No isolated_out_dir defined."; +bool GetTestOutputDir(std::string* out_dir) { + if (FLAGS_test_output_dir.empty()) { + LOG(LS_WARNING) << "No test_out_dir defined."; + return false; + } + *out_dir = FLAGS_test_output_dir; + return true; +} + +bool WriteToTestOutput(const char* filename, + const uint8_t* buffer, + size_t length) { + if (FLAGS_test_output_dir.empty()) { + LOG(LS_WARNING) << "No test_out_dir defined."; return false; } @@ -38,15 +48,15 @@ bool WriteIsolatedOutput(const char* filename, } rtc::File output = - rtc::File::Create(rtc::Pathname(FLAGS_isolated_out_dir, filename)); + rtc::File::Create(rtc::Pathname(FLAGS_test_output_dir, filename)); return output.IsOpen() && output.Write(buffer, length) == length; } -bool WriteIsolatedOutput(const char* filename, const std::string& content) { - return WriteIsolatedOutput(filename, - reinterpret_cast(content.c_str()), - content.length()); +bool WriteToTestOutput(const char* filename, const std::string& content) { + return WriteToTestOutput(filename, + reinterpret_cast(content.c_str()), + content.length()); } } // namespace test diff --git a/webrtc/test/testsupport/isolated_output.h b/webrtc/test/testsupport/test_output.h similarity index 63% rename from webrtc/test/testsupport/isolated_output.h rename to webrtc/test/testsupport/test_output.h index f4e9695157..c502ea38d9 100644 --- a/webrtc/test/testsupport/isolated_output.h +++ b/webrtc/test/testsupport/test_output.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_TEST_TESTSUPPORT_ISOLATED_OUTPUT_H_ -#define WEBRTC_TEST_TESTSUPPORT_ISOLATED_OUTPUT_H_ +#ifndef WEBRTC_TEST_TESTSUPPORT_TEST_OUTPUT_H_ +#define WEBRTC_TEST_TESTSUPPORT_TEST_OUTPUT_H_ #include @@ -18,18 +18,22 @@ namespace webrtc { namespace test { +// If the test_output_dir flag is set, returns true and copies the location of +// the dir to |out_dir|. Otherwise, return false. +bool GetTestOutputDir(std::string* out_dir); + // Writes a |length| bytes array |buffer| to |filename| in isolated output // directory defined by swarming. If the file is existing, content will be // appended. Otherwise a new file will be created. This function returns false // if isolated output directory has not been defined, or |filename| indicates an // invalid or non-writable file, or underlying file system errors. -bool WriteIsolatedOutput(const char* filename, - const uint8_t* buffer, - size_t length); +bool WriteToTestOutput(const char* filename, + const uint8_t* buffer, + size_t length); -bool WriteIsolatedOutput(const char* filename, const std::string& content); +bool WriteToTestOutput(const char* filename, const std::string& content); } // namespace test } // namespace webrtc -#endif // WEBRTC_TEST_TESTSUPPORT_ISOLATED_OUTPUT_H_ +#endif // WEBRTC_TEST_TESTSUPPORT_TEST_OUTPUT_H_ diff --git a/webrtc/test/testsupport/isolated_output_unittest.cc b/webrtc/test/testsupport/test_output_unittest.cc similarity index 74% rename from webrtc/test/testsupport/isolated_output_unittest.cc rename to webrtc/test/testsupport/test_output_unittest.cc index bb75ebfe14..511ce6f750 100644 --- a/webrtc/test/testsupport/isolated_output_unittest.cc +++ b/webrtc/test/testsupport/test_output_unittest.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/test/testsupport/isolated_output.h" +#include "webrtc/test/testsupport/test_output.h" #include @@ -20,29 +20,29 @@ #include "webrtc/rtc_base/platform_file.h" #include "webrtc/test/gtest.h" -DECLARE_string(isolated_out_dir); +DECLARE_string(test_output_dir); namespace webrtc { namespace test { TEST(IsolatedOutputTest, ShouldRejectInvalidIsolatedOutDir) { - std::string backup = FLAGS_isolated_out_dir; - FLAGS_isolated_out_dir = ""; - ASSERT_FALSE(WriteIsolatedOutput("a-file", "some-contents")); - FLAGS_isolated_out_dir = backup; + std::string backup = FLAGS_test_output_dir; + FLAGS_test_output_dir = ""; + ASSERT_FALSE(WriteToTestOutput("a-file", "some-contents")); + FLAGS_test_output_dir = backup; } TEST(IsolatedOutputTest, ShouldRejectInvalidFileName) { - ASSERT_FALSE(WriteIsolatedOutput(nullptr, "some-contents")); - ASSERT_FALSE(WriteIsolatedOutput("", "some-contents")); + ASSERT_FALSE(WriteToTestOutput(nullptr, "some-contents")); + ASSERT_FALSE(WriteToTestOutput("", "some-contents")); } // Sets isolated_out_dir= to execute this test. TEST(IsolatedOutputTest, ShouldBeAbleToWriteContent) { const char* filename = "a-file"; const char* content = "some-contents"; - if (WriteIsolatedOutput(filename, content)) { - rtc::Pathname out_file(FLAGS_isolated_out_dir, filename); + if (WriteToTestOutput(filename, content)) { + rtc::Pathname out_file(FLAGS_test_output_dir, filename); rtc::File input = rtc::File::Open(out_file); EXPECT_TRUE(input.IsOpen()); EXPECT_TRUE(input.Seek(0));