diff --git a/test/BUILD.gn b/test/BUILD.gn index f2632d3f63..ff13621c1e 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -253,6 +253,7 @@ if (rtc_include_tests) { deps = [ ":field_trial", + ":fileutils_override_api", ":perf_test", ":test_support", "../rtc_base", diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc index bb41e6530f..1650d2ac79 100644 --- a/test/test_main_lib.cc +++ b/test/test_main_lib.cc @@ -28,6 +28,7 @@ #include "test/gmock.h" #include "test/gtest.h" #include "test/testsupport/file_utils.h" +#include "test/testsupport/file_utils_override.h" #include "test/testsupport/perf_test.h" #if defined(WEBRTC_WIN) @@ -80,6 +81,14 @@ ABSL_FLAG(std::vector, #endif +ABSL_FLAG(std::string, + resources_dir, + "", + "Where to look for the runtime dependencies. If not specified, we " + "will use a reasonable default depending on where we are running. " + "This flag is useful if we copy over test resources to a phone and " + "need to tell the tests where their resources are."); + ABSL_FLAG(bool, logs, true, "print logs to stderr"); ABSL_FLAG(bool, verbose, false, "verbose logs to stderr"); @@ -106,6 +115,10 @@ class TestMainImpl : public TestMain { ::testing::InitGoogleMock(argc, argv); absl::ParseCommandLine(*argc, argv); + std::string resources_dir = absl::GetFlag(FLAGS_resources_dir); + if (!resources_dir.empty()) + test::internal::OverrideResourcesDir(resources_dir); + // Default to LS_INFO, even for release builds to provide better test // logging. if (rtc::LogMessage::GetLogToDebug() > rtc::LS_INFO) diff --git a/test/testsupport/file_utils_override.cc b/test/testsupport/file_utils_override.cc index 09806913a5..3106d0fe0e 100644 --- a/test/testsupport/file_utils_override.cc +++ b/test/testsupport/file_utils_override.cc @@ -150,6 +150,12 @@ std::string ResourcePath(const std::string& name, #endif } +void OverrideResourcesDir(const std::string& resources_dir) { + RTC_CHECK(false) + << "Setting the resource dir is not supported in open-source " + "tests."; +} + } // namespace internal } // namespace test } // namespace webrtc diff --git a/test/testsupport/file_utils_override.h b/test/testsupport/file_utils_override.h index a72cd805cf..235c83994b 100644 --- a/test/testsupport/file_utils_override.h +++ b/test/testsupport/file_utils_override.h @@ -38,8 +38,7 @@ std::string OutputPath(); // directory. std::string WorkingDir(); -// Returns a path to a resource file in [project-root]/resources/ dir. -// Returns an absolute path +// Returns a full path to a resource file in the resources_dir dir. // // Arguments: // name - Name of the resource file. If a plain filename (no directory path) @@ -49,6 +48,15 @@ std::string WorkingDir(); // extension - File extension, without the dot, i.e. "bmp" or "yuv". std::string ResourcePath(const std::string& name, const std::string& extension); +// Overrides the root resource dir. See ResourcePath for more information. +// +// This is not necessary in most cases, but it can be if we're running on +// phones and copy over resources to some custom location. +// +// Arguments: +// resources_dir - Where resources are located. +void OverrideResourcesDir(const std::string& resources_dir); + } // namespace internal } // namespace test } // namespace webrtc