From 04a65a5ce1cd3c253a0eaa43fb32dcba1f59f7f6 Mon Sep 17 00:00:00 2001 From: thorsten sideb0ard Date: Wed, 6 Sep 2023 12:12:19 -0700 Subject: [PATCH] Use SbThreadSleep for cval_stats_test. (#1488) This should fix test on Evergreen. b/292030213 Change-Id: I4514aa08729fa814f58a3f2cf1b7b0339e59574d (cherry picked from commit e9b7f499fa79968aac272ba88ea7c05e3eac0dd9) --- cobalt/build/cobalt_configuration.py | 3 +-- cobalt/media/base/cval_stats_test.cc | 29 ++++++++-------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/cobalt/build/cobalt_configuration.py b/cobalt/build/cobalt_configuration.py index e1320ab077c1..ca1c943ea270 100644 --- a/cobalt/build/cobalt_configuration.py +++ b/cobalt/build/cobalt_configuration.py @@ -133,8 +133,7 @@ def GetTestTargets(self): 'media_capture_test', 'media_session_test', 'media_stream_test', - # TODO(b/292030213): Crashes on evergreen - # 'media_test', + 'media_test', 'memory_store_test', 'metrics_test', 'nb_test', diff --git a/cobalt/media/base/cval_stats_test.cc b/cobalt/media/base/cval_stats_test.cc index 673e20cc477f..ceba32024d9a 100644 --- a/cobalt/media/base/cval_stats_test.cc +++ b/cobalt/media/base/cval_stats_test.cc @@ -12,16 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifdef _WIN32 -#include -#else -#include -#endif +#include "cobalt/media/base/cval_stats.h" #include #include -#include "cobalt/media/base/cval_stats.h" +#include "starboard/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -33,21 +29,11 @@ const char kCValnameMinimum[] = "Media.SbPlayerCreateTime.Minimum"; const char kPipelineIdentifier[] = "test_pipeline"; -constexpr int kSleepTimeMs = 50; +constexpr SbTime kSleepTime = 50; // 50 microseconds namespace cobalt { namespace media { -namespace { -void sleep_ms(int ms) { -#ifdef _WIN32 - Sleep(ms); -#else - usleep(ms); -#endif -} -} // namespace - TEST(MediaCValStatsTest, InitiallyEmpty) { base::CValManager* cvm = base::CValManager::GetInstance(); EXPECT_TRUE(cvm); @@ -71,7 +57,8 @@ TEST(MediaCValStatsTest, NothingRecorded) { CValStats cval_stats_; cval_stats_.StartTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); - sleep_ms(kSleepTimeMs); + SbThreadSleep(kSleepTime); + cval_stats_.StopTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); base::Optional result = @@ -88,7 +75,7 @@ TEST(MediaCValStatsTest, EnableRecording) { cval_stats_.Enable(true); cval_stats_.StartTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); - sleep_ms(kSleepTimeMs); + SbThreadSleep(kSleepTime); cval_stats_.StopTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); base::Optional result = @@ -114,7 +101,7 @@ TEST(MediaCValStatsTest, DontGenerateHistoricalData) { for (int i = 0; i < kMediaDefaultMaxSamplesBeforeCalculation - 1; i++) { cval_stats_.StartTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); - sleep_ms(kSleepTimeMs); + SbThreadSleep(kSleepTime); cval_stats_.StopTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); } @@ -141,7 +128,7 @@ TEST(MediaCValStatsTest, GenerateHistoricalData) { for (int i = 0; i < kMediaDefaultMaxSamplesBeforeCalculation; i++) { cval_stats_.StartTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); - sleep_ms(kSleepTimeMs); + SbThreadSleep(kSleepTime); cval_stats_.StopTimer(MediaTiming::SbPlayerCreate, kPipelineIdentifier); }