Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SbThreadSleep for cval_stats_test. #1488

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
'net_unittests',
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