mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Provide test output path with OutputPathWithRandomDirectory
1/n
First commit in a series of commits to wire up the test output path utility that adds a random directory in the path, for problematic tests that run in concurrent execution environments. Bug: webrtc:15833 Change-Id: I5e5b3940007be773d77dbbfc953efa810e4e3ea9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/339522 Reviewed-by: Artem Titov <titovartem@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41738}
This commit is contained in:
parent
3e9e4e7c9c
commit
4efc830e53
9 changed files with 45 additions and 28 deletions
|
@ -34,7 +34,8 @@ class RtcEventLogOutputFileTest : public ::testing::Test {
|
|||
protected:
|
||||
std::string GetOutputFilePath() const {
|
||||
auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||
return test::OutputPath() + test_info->test_case_name() + test_info->name();
|
||||
return test::OutputPathWithRandomDirectory() + test_info->test_case_name() +
|
||||
test_info->name();
|
||||
}
|
||||
|
||||
std::string GetOutputFileContents() const {
|
||||
|
|
|
@ -375,7 +375,6 @@ if (rtc_include_tests && !build_with_chromium) {
|
|||
"../rtc_base:checks",
|
||||
"../rtc_base:macromagic",
|
||||
"../rtc_base:rtc_base_tests_utils",
|
||||
"../rtc_base:ssl",
|
||||
"../rtc_base:stringutils",
|
||||
"../rtc_base:timeutils",
|
||||
"../rtc_base/system:arch",
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <limits>
|
||||
|
||||
#include "common_audio/wav_header.h"
|
||||
#include "rtc_base/helpers.h"
|
||||
#include "test/gtest.h"
|
||||
#include "test/testsupport/file_utils.h"
|
||||
|
||||
|
@ -37,7 +36,7 @@ static const float kSamples[] = {0.0, 10.0, 4e4, -1e9};
|
|||
// Write a tiny WAV file with the C++ interface and verify the result.
|
||||
TEST(WavWriterTest, MAYBE_CPP) {
|
||||
const std::string outfile =
|
||||
test::OutputPath() + "wavtest1-" + rtc::CreateRandomUuid() + ".wav";
|
||||
test::OutputPathWithRandomDirectory() + "wavtest1.wav";
|
||||
static const size_t kNumSamples = 3;
|
||||
{
|
||||
WavWriter w(outfile, 14099, 1);
|
||||
|
@ -114,7 +113,8 @@ TEST(WavWriterTest, LargeFile) {
|
|||
{WavFile::SampleFormat::kInt16, WavFile::SampleFormat::kFloat}) {
|
||||
for (WavFile::SampleFormat read_format :
|
||||
{WavFile::SampleFormat::kInt16, WavFile::SampleFormat::kFloat}) {
|
||||
std::string outfile = test::OutputPath() + "wavtest3.wav";
|
||||
std::string outfile =
|
||||
test::OutputPathWithRandomDirectory() + "wavtest3.wav";
|
||||
float samples[kNumSamples];
|
||||
for (size_t i = 0; i < kNumSamples; i += kNumChannels) {
|
||||
// A nice periodic beeping sound.
|
||||
|
@ -179,7 +179,8 @@ TEST(WavWriterTest, LargeFile) {
|
|||
|
||||
// Write a tiny WAV file with the C++ interface then read-reset-read.
|
||||
TEST(WavReaderTest, MAYBE_CPPReset) {
|
||||
const std::string outfile = test::OutputPath() + "wavtest4.wav";
|
||||
const std::string outfile =
|
||||
test::OutputPathWithRandomDirectory() + "wavtest4.wav";
|
||||
static const size_t kNumSamples = 3;
|
||||
{
|
||||
WavWriter w(outfile, 14099, 1);
|
||||
|
|
|
@ -488,7 +488,6 @@ if (rtc_include_tests && !build_with_chromium) {
|
|||
"../../rtc_base:race_checker",
|
||||
"../../rtc_base:rtc_event",
|
||||
"../../rtc_base:safe_conversions",
|
||||
"../../rtc_base:ssl",
|
||||
"../../rtc_base:timeutils",
|
||||
"../../rtc_base/synchronization:mutex",
|
||||
"../../system_wrappers",
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "common_audio/wav_header.h"
|
||||
#include "modules/audio_device/include/audio_device_defines.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/helpers.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "test/gmock.h"
|
||||
|
@ -40,9 +39,9 @@ void RunWavTest(const std::vector<int16_t>& input_samples,
|
|||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
const std::string output_filename =
|
||||
test::OutputPath() + "BoundedWavFileWriterTest_" + test_info->name() +
|
||||
"_" + rtc::CreateRandomUuid() + ".wav";
|
||||
const std::string output_filename = test::OutputPathWithRandomDirectory() +
|
||||
"BoundedWavFileWriterTest_" +
|
||||
test_info->name() + ".wav";
|
||||
|
||||
static const size_t kSamplesPerFrame = 8;
|
||||
static const int kSampleRate = kSamplesPerFrame * 100;
|
||||
|
@ -137,9 +136,9 @@ TEST(WavFileReaderTest, RepeatedTrueWithSingleFrameFileReadTwice) {
|
|||
static const rtc::BufferT<int16_t> kExpectedSamples(kInputSamples.data(),
|
||||
kInputSamples.size());
|
||||
|
||||
const std::string output_filename = test::OutputPath() +
|
||||
const std::string output_filename = test::OutputPathWithRandomDirectory() +
|
||||
"WavFileReaderTest_RepeatedTrue_" +
|
||||
std::to_string(std::rand()) + ".wav";
|
||||
".wav";
|
||||
|
||||
static const size_t kSamplesPerFrame = 8;
|
||||
static const int kSampleRate = kSamplesPerFrame * 100;
|
||||
|
@ -176,9 +175,9 @@ void RunRawTestNoRepeat(const std::vector<int16_t>& input_samples,
|
|||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
const std::string output_filename = test::OutputPath() + "RawFileTest_" +
|
||||
test_info->name() + "_" +
|
||||
std::to_string(std::rand()) + ".raw";
|
||||
const std::string output_filename = test::OutputPathWithRandomDirectory() +
|
||||
"RawFileTest_" + test_info->name() +
|
||||
".raw";
|
||||
|
||||
static const size_t kSamplesPerFrame = 8;
|
||||
static const int kSampleRate = kSamplesPerFrame * 100;
|
||||
|
@ -282,8 +281,8 @@ TEST(RawFileWriterTest, Repeat) {
|
|||
const ::testing::TestInfo* const test_info =
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
const std::string output_filename = test::OutputPath() + "RawFileTest_" +
|
||||
test_info->name() + "_" +
|
||||
const std::string output_filename = test::OutputPathWithRandomDirectory() +
|
||||
"RawFileTest_" + test_info->name() + "_" +
|
||||
std::to_string(std::rand()) + ".raw";
|
||||
|
||||
static const size_t kSamplesPerFrame = 8;
|
||||
|
|
|
@ -21,7 +21,8 @@ TEST(FileWrapper, FileSize) {
|
|||
std::string test_name =
|
||||
std::string(test_info->test_case_name()) + "_" + test_info->name();
|
||||
std::replace(test_name.begin(), test_name.end(), '/', '_');
|
||||
const std::string temp_filename = test::OutputPath() + test_name;
|
||||
const std::string temp_filename =
|
||||
test::OutputPathWithRandomDirectory() + test_name;
|
||||
|
||||
// Write
|
||||
{
|
||||
|
|
|
@ -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>
|
||||
|
@ -237,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();
|
||||
}
|
||||
|
||||
|
|
|
@ -170,8 +170,8 @@ TEST_F(FileUtilsTest, GenerateTempFilename) {
|
|||
#define MAYBE_CreateDir CreateDir
|
||||
#endif
|
||||
TEST_F(FileUtilsTest, MAYBE_CreateDir) {
|
||||
std::string directory = test::OutputPath() + "fileutils-unittest-empty-dir" +
|
||||
rtc::CreateRandomUuid();
|
||||
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));
|
||||
|
@ -255,8 +255,7 @@ TEST_F(FileUtilsTest, WriteReadDeleteFilesAndDirs) {
|
|||
|
||||
// Create an empty temporary directory for this test.
|
||||
const std::string temp_directory =
|
||||
OutputPath() +
|
||||
Path("TempFileUtilsTestReadDirectory" + rtc::CreateRandomUuid() + "/");
|
||||
OutputPathWithRandomDirectory() + Path("TempFileUtilsTestReadDirectory/");
|
||||
CreateDir(temp_directory);
|
||||
EXPECT_NO_FATAL_FAILURE(CleanDir(temp_directory, &num_deleted_entries));
|
||||
EXPECT_TRUE(DirExists(temp_directory));
|
||||
|
@ -298,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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue