blob: bd8e85f4f3b3a2866b137c2e73f34c9d77896734 [file] [log] [blame]
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "test/testsupport/perf_test.h"
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000012
13#include <string>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "test/gtest.h"
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000016
Edward Lemur936dfb12017-11-30 11:43:42 +010017namespace {
18
19const char* kJsonExpected = R"({
20 "format_version":"1.0",
21 "charts":{
22 "foobar":{
23 "baz_v":{
24 "type":"scalar",
25 "value":7,
26 "units":"widgets"
27 },
28 "baz_me":{
Edward Lemurc492bf12018-01-05 15:06:59 +010029 "type":"list_of_scalar_values",
Edward Lemur936dfb12017-11-30 11:43:42 +010030 "values":[1],
31 "std":2,
32 "units":"lemurs"
33 },
34 "baz_vl":{
Edward Lemurc492bf12018-01-05 15:06:59 +010035 "type":"list_of_scalar_values",
Edward Lemur936dfb12017-11-30 11:43:42 +010036 "values":[1,2,3],
37 "units":"units"
38 }
39 },
40 "measurementmodifier":{
41 "trace":{
42 "type":"scalar",
43 "value":42,
44 "units":"units"
45 }
46 }
47 }
48})";
49
50std::string RemoveSpaces(std::string s) {
51 s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
52 s.erase(std::remove(s.begin(), s.end(), '\n'), s.end());
53 return s;
54}
55
56} // namespace
57
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000058namespace webrtc {
59namespace test {
60
Edward Lemur936dfb12017-11-30 11:43:42 +010061class PerfTest : public ::testing::Test {
62 protected:
63 void TearDown() override {
64 ClearPerfResults();
65 }
66};
67
68
Edward Lemurf49a56b2017-11-29 20:29:30 +010069#if defined(WEBRTC_IOS)
Edward Lemur936dfb12017-11-30 11:43:42 +010070#define MAYBE_TestPrintResult DISABLED_TestPrintResult
Edward Lemurf49a56b2017-11-29 20:29:30 +010071#else
Edward Lemur936dfb12017-11-30 11:43:42 +010072#define MAYBE_TestPrintResult TestPrintResult
Edward Lemurf49a56b2017-11-29 20:29:30 +010073#endif
Edward Lemur936dfb12017-11-30 11:43:42 +010074TEST_F(PerfTest, MAYBE_TestPrintResult) {
Edward Lemurf7ff3e82017-11-22 16:32:01 +010075 testing::internal::CaptureStdout();
Edward Lemur936dfb12017-11-30 11:43:42 +010076 std::string expected;
77
78 expected += "RESULT measurementmodifier: trace= 42 units\n";
Edward Lemurf7ff3e82017-11-22 16:32:01 +010079 PrintResult("measurement", "modifier", "trace", 42, "units", false);
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +000080
Edward Lemurcb666f52017-12-04 13:21:01 +010081 expected += "*RESULT foobar: baz_v= 1423730 widgets\n";
82 PrintResult("foo", "bar", "baz_v", 1423730, "widgets", true);
Edward Lemur2f061682017-11-24 13:40:01 +010083
Edward Lemur936dfb12017-11-30 11:43:42 +010084 expected += "RESULT foobar: baz_me= {1,2} lemurs\n";
85 PrintResultMeanAndError("foo", "bar", "baz_me", 1, 2, "lemurs", false);
Edward Lemur2f061682017-11-24 13:40:01 +010086
Edward Lemur936dfb12017-11-30 11:43:42 +010087 const double kListOfScalars[] = {1, 2, 3};
88 expected += "RESULT foobar: baz_vl= [1,2,3] units\n";
89 PrintResultList("foo", "bar", "baz_vl", kListOfScalars, "units", false);
Edward Lemurf7ff3e82017-11-22 16:32:01 +010090
Edward Lemur936dfb12017-11-30 11:43:42 +010091 EXPECT_EQ(expected, testing::internal::GetCapturedStdout());
92}
93
94TEST_F(PerfTest, TestGetPerfResultsJSON) {
95 PrintResult("measurement", "modifier", "trace", 42, "units", false);
96 PrintResult("foo", "bar", "baz_v", 7, "widgets", true);
97 PrintResultMeanAndError("foo", "bar", "baz_me", 1, 2, "lemurs", false);
98 const double kListOfScalars[] = {1, 2, 3};
99 PrintResultList("foo", "bar", "baz_vl", kListOfScalars, "units", false);
100
101 EXPECT_EQ(RemoveSpaces(kJsonExpected), GetPerfResultsJSON());
102}
103
104TEST_F(PerfTest, TestClearPerfResults) {
105 PrintResult("measurement", "modifier", "trace", 42, "units", false);
106 ClearPerfResults();
107 EXPECT_EQ(R"({"format_version":"1.0","charts":{}})", GetPerfResultsJSON());
andrew@webrtc.org2009f6b2012-11-20 00:20:20 +0000108}
109
110} // namespace test
111} // namespace webrtc