Skip to content

Commit

Permalink
Cherry pick PR #1488: Use SbThreadSleep for cval_stats_test. (#1496)
Browse files Browse the repository at this point in the history
Refer to the original PR: #1488

This should fix test on Evergreen.

b/292030213

Change-Id: I4514aa08729fa814f58a3f2cf1b7b0339e59574d

Co-authored-by: thorsten sideb0ard <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and sideb0ard authored Sep 20, 2023
1 parent eb925e4 commit 8c3b813
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cobalt/build/cobalt_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
29 changes: 8 additions & 21 deletions cobalt/media/base/cval_stats_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
#include "cobalt/media/base/cval_stats.h"

#include <set>
#include <string>

#include "cobalt/media/base/cval_stats.h"
#include "starboard/thread.h"
#include "testing/gtest/include/gtest/gtest.h"


Expand All @@ -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);
Expand All @@ -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<std::string> result =
Expand All @@ -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<std::string> result =
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 8c3b813

Please sign in to comment.