Add debug logging in WavWriterTest.LargeFile
Also CHECK in OutputPathWithRandomDirectory. This function is used in tests that need a unique folder to avoid interaction with other tests that may run in parallel. Continuing with a non-unique folder if the creation fails, is likely to cause surprising errors later on.
Bug: webrtc:379973428
Change-Id: I6a30ef9034be8132e2362eff5e46e3b99b30acd2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/368542
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43431}
diff --git a/common_audio/BUILD.gn b/common_audio/BUILD.gn
index a3a2bb5..1342eef 100644
--- a/common_audio/BUILD.gn
+++ b/common_audio/BUILD.gn
@@ -373,6 +373,7 @@
":fir_filter_factory",
":sinc_resampler",
"../rtc_base:checks",
+ "../rtc_base:logging",
"../rtc_base:macromagic",
"../rtc_base:rtc_base_tests_utils",
"../rtc_base:stringutils",
diff --git a/common_audio/wav_file_unittest.cc b/common_audio/wav_file_unittest.cc
index 71e4fedf..9b03c3d 100644
--- a/common_audio/wav_file_unittest.cc
+++ b/common_audio/wav_file_unittest.cc
@@ -17,6 +17,7 @@
#include <limits>
#include "common_audio/wav_header.h"
+#include "rtc_base/logging.h"
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
@@ -31,6 +32,18 @@
namespace webrtc {
+namespace {
+const char* SampleFormatToStr(WavFile::SampleFormat format) {
+ switch (format) {
+ case WavFile::SampleFormat::kInt16:
+ return "int16";
+ case WavFile::SampleFormat::kFloat:
+ return "float";
+ }
+ RTC_CHECK_NOTREACHED();
+}
+} // namespace
+
static const float kSamples[] = {0.0, 10.0, 4e4, -1e9};
// Write a tiny WAV file with the C++ interface and verify the result.
@@ -125,6 +138,9 @@
std::sin(t * kToneHz * 2 * M_PI);
samples[i] = std::pow(std::sin(t * 2 * 2 * M_PI), 10) * x;
samples[i + 1] = std::pow(std::cos(t * 2 * 2 * M_PI), 10) * x;
+ // See https://issues.webrtc.org/issues/379973428
+ RTC_CHECK(isfinite(samples[i]));
+ RTC_CHECK(isfinite(samples[i + 1]));
}
{
WavWriter w(outfile, kSampleRate, kNumChannels, wav_format);
@@ -161,6 +177,14 @@
EXPECT_EQ(kNumSamples, r.ReadSamples(kNumSamples, read_samples));
for (size_t i = 0; i < kNumSamples; ++i) {
EXPECT_NEAR(samples[i], read_samples[i], 1);
+ if (!isfinite(samples[i])) {
+ // See https://issues.webrtc.org/issues/379973428
+ RTC_LOG(LS_ERROR)
+ << "samples[" << i << "] is not finite. "
+ << "wav_format=" << SampleFormatToStr(wav_format)
+ << ", write_format=" << SampleFormatToStr(write_format)
+ << ", read_format=" << SampleFormatToStr(read_format);
+ }
}
EXPECT_EQ(0u, r.ReadSamples(kNumSamples, read_samples));
} else {
@@ -168,6 +192,14 @@
EXPECT_EQ(kNumSamples, r.ReadSamples(kNumSamples, read_samples));
for (size_t i = 0; i < kNumSamples; ++i) {
EXPECT_NEAR(samples[i], static_cast<float>(read_samples[i]), 1);
+ if (!isfinite(samples[i])) {
+ // See https://issues.webrtc.org/issues/379973428
+ RTC_LOG(LS_ERROR)
+ << "samples[" << i << "] is not finite. "
+ << "wav_format=" << SampleFormatToStr(wav_format)
+ << ", write_format=" << SampleFormatToStr(write_format)
+ << ", read_format=" << SampleFormatToStr(read_format);
+ }
}
EXPECT_EQ(0u, r.ReadSamples(kNumSamples, read_samples));
}
diff --git a/test/testsupport/file_utils.cc b/test/testsupport/file_utils.cc
index 9451c20..38d4019 100644
--- a/test/testsupport/file_utils.cc
+++ b/test/testsupport/file_utils.cc
@@ -97,8 +97,8 @@
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;
+ RTC_CHECK(CreateDir(rand_dir)) << "Failed to create dir: " << rand_dir;
+ return rand_dir + std::string(kPathDelimiter);
}
std::string WorkingDir() {