diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/libwebrtc/test/testsupport | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/test/testsupport')
4 files changed, 62 insertions, 7 deletions
diff --git a/third_party/libwebrtc/test/testsupport/file_utils.cc b/third_party/libwebrtc/test/testsupport/file_utils.cc index 47fed9ac05..afabbaad3f 100644 --- a/third_party/libwebrtc/test/testsupport/file_utils.cc +++ b/third_party/libwebrtc/test/testsupport/file_utils.cc @@ -36,7 +36,7 @@ #include <sys/stat.h> // To check for directory existence. #ifndef S_ISDIR // Not defined in stat.h on Windows. -#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) #endif #include <stdio.h> @@ -54,6 +54,7 @@ #include "absl/strings/string_view.h" #include "rtc_base/checks.h" +#include "rtc_base/helpers.h" #include "rtc_base/string_utils.h" #include "rtc_base/strings/string_builder.h" #include "test/testsupport/file_utils_override.h" @@ -94,6 +95,13 @@ std::string OutputPath() { return webrtc::test::internal::OutputPath(); } +std::string OutputPathWithRandomDirectory() { + std::string path = webrtc::test::internal::OutputPath(); + std::string rand_dir = path + rtc::CreateRandomUuid(); + + return CreateDir(rand_dir) ? rand_dir + std::string(kPathDelimiter) : path; +} + std::string WorkingDir() { return webrtc::test::internal::WorkingDir(); } @@ -229,7 +237,12 @@ std::string ResourcePath(absl::string_view name, absl::string_view extension) { std::string JoinFilename(absl::string_view dir, absl::string_view name) { RTC_CHECK(!dir.empty()) << "Special cases not implemented."; rtc::StringBuilder os; - os << dir << kPathDelimiter << name; + os << dir; + // If the directory path already ends with a path delimiter don't append it + if (dir.back() != kPathDelimiter.back()) { + os << kPathDelimiter; + } + os << name; return os.Release(); } diff --git a/third_party/libwebrtc/test/testsupport/file_utils.h b/third_party/libwebrtc/test/testsupport/file_utils.h index ab80ca4454..120c6cb279 100644 --- a/third_party/libwebrtc/test/testsupport/file_utils.h +++ b/third_party/libwebrtc/test/testsupport/file_utils.h @@ -42,6 +42,11 @@ ABSL_CONST_INIT extern const absl::string_view kPathDelimiter; // found, the current working directory ("./") is returned as a fallback. std::string OutputPath(); +// Same as the above but appends a randomly named folder at the end of the path +// Primerly used to provide a solution for stress testing environments to +// prevent colission of files and folders. +std::string OutputPathWithRandomDirectory(); + // Generates an empty file with a unique name in the specified directory and // returns the file name and path. // TODO(titovartem) rename to TempFile and next method to TempFilename diff --git a/third_party/libwebrtc/test/testsupport/file_utils_unittest.cc b/third_party/libwebrtc/test/testsupport/file_utils_unittest.cc index b9de01d09d..1101a63352 100644 --- a/third_party/libwebrtc/test/testsupport/file_utils_unittest.cc +++ b/third_party/libwebrtc/test/testsupport/file_utils_unittest.cc @@ -19,6 +19,7 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "rtc_base/checks.h" +#include "rtc_base/helpers.h" #include "test/gmock.h" #include "test/gtest.h" @@ -119,6 +120,28 @@ TEST_F(FileUtilsTest, OutputPathFromRootWorkingDir) { ASSERT_THAT(result, EndsWith(expected_end)); } +TEST_F(FileUtilsTest, RandomOutputPathFromUnchangedWorkingDir) { + rtc::SetRandomTestMode(true); + std::string fixed_first_uuid = "def01482-f829-429a-bfd4-841706e92cdd"; + std::string expected_end = ExpectedRootDirByPlatform() + fixed_first_uuid + + std::string(kPathDelimiter); + std::string result = webrtc::test::OutputPathWithRandomDirectory(); + + ASSERT_THAT(result, EndsWith(expected_end)); +} + +TEST_F(FileUtilsTest, RandomOutputPathFromRootWorkingDir) { + ASSERT_EQ(0, chdir(kPathDelimiter.data())); + + rtc::SetRandomTestMode(true); + std::string fixed_first_uuid = "def01482-f829-429a-bfd4-841706e92cdd"; + std::string expected_end = ExpectedRootDirByPlatform() + fixed_first_uuid + + std::string(kPathDelimiter); + std::string result = webrtc::test::OutputPathWithRandomDirectory(); + + ASSERT_THAT(result, EndsWith(expected_end)); +} + TEST_F(FileUtilsTest, TempFilename) { std::string temp_filename = webrtc::test::TempFilename( webrtc::test::OutputPath(), "TempFilenameTest"); @@ -147,7 +170,8 @@ TEST_F(FileUtilsTest, GenerateTempFilename) { #define MAYBE_CreateDir CreateDir #endif TEST_F(FileUtilsTest, MAYBE_CreateDir) { - std::string directory = "fileutils-unittest-empty-dir"; + std::string directory = + test::OutputPathWithRandomDirectory() + "fileutils-unittest-empty-dir"; // Make sure it's removed if a previous test has failed: remove(directory.c_str()); ASSERT_TRUE(webrtc::test::CreateDir(directory)); @@ -231,7 +255,7 @@ TEST_F(FileUtilsTest, WriteReadDeleteFilesAndDirs) { // Create an empty temporary directory for this test. const std::string temp_directory = - OutputPath() + Path("TempFileUtilsTestReadDirectory/"); + OutputPathWithRandomDirectory() + Path("TempFileUtilsTestReadDirectory/"); CreateDir(temp_directory); EXPECT_NO_FATAL_FAILURE(CleanDir(temp_directory, &num_deleted_entries)); EXPECT_TRUE(DirExists(temp_directory)); @@ -273,5 +297,15 @@ TEST_F(FileUtilsTest, DirNameStopsAtRoot) { EXPECT_EQ(Path("/"), DirName(Path("/"))); } +TEST_F(FileUtilsTest, JoinFilenameDoesNotAppendExtraPathDelimiterIfExists) { + EXPECT_EQ(JoinFilename(Path("/some/path/"), "file.txt"), + Path("/some/path/file.txt")); +} + +TEST_F(FileUtilsTest, JoinFilenameAppendsPathDelimiterIfMissing) { + EXPECT_EQ(JoinFilename(Path("/some/path"), "file.txt"), + Path("/some/path/file.txt")); +} + } // namespace test } // namespace webrtc diff --git a/third_party/libwebrtc/test/testsupport/test_artifacts.cc b/third_party/libwebrtc/test/testsupport/test_artifacts.cc index 6f062e5fe4..b0ab046e63 100644 --- a/third_party/libwebrtc/test/testsupport/test_artifacts.cc +++ b/third_party/libwebrtc/test/testsupport/test_artifacts.cc @@ -20,7 +20,7 @@ namespace { const std::string& DefaultArtifactPath() { - static const std::string path = webrtc::test::OutputPath(); + static const std::string path = webrtc::test::OutputPathWithRandomDirectory(); return path; } } // namespace @@ -55,8 +55,11 @@ bool WriteToTestArtifactsDir(const char* filename, return false; } - FileWrapper output = FileWrapper::OpenWriteOnly( - JoinFilename(absl::GetFlag(FLAGS_test_artifacts_dir), filename)); + std::string full_path = + JoinFilename(absl::GetFlag(FLAGS_test_artifacts_dir), filename); + FileWrapper output = FileWrapper::OpenWriteOnly(full_path); + + RTC_LOG(LS_INFO) << "Writing test artifacts in: " << full_path; return output.is_open() && output.Write(buffer, length); } |