From 2f28370e65f6b2954c2ba1f994f52419dfaba82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20H=C3=B6glund?= Date: Mon, 14 Oct 2019 10:12:18 +0200 Subject: [PATCH] Move --resources_dir to its right place. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We needed a hack in test_main_lib.cc to ensure fileutils were always linked with test binaries downstream. When I removed the hack, it broke the binaries that were _not_ using fileutils because a certain bazel rule expects to be able to pass the flag to all test binaries. The solution is to move the flag to test_main_lib.cc. This is the right place for it since it's apparently in the contract of a WebRTC test binary to support this flag. We then have to pass the value down to the override, which is why I add a new function for that. I leave the flag unimplemented in OSS because no one is using it here anyway. It will be implemented downstream. Bug: webrtc:9792 Change-Id: I21b3deb43bf0cd56d6aa2622dc5519370a0307a9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156568 Reviewed-by: Mirko Bonadei Commit-Queue: Patrik Höglund Cr-Commit-Position: refs/heads/master@{#29474} --- test/BUILD.gn | 1 + test/test_main_lib.cc | 13 +++++++++++++ test/testsupport/file_utils_override.cc | 6 ++++++ test/testsupport/file_utils_override.h | 12 ++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) 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