1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #define PW_LOG_LEVEL PW_LOG_LEVEL_INFO
15
16 #include "pw_perf_test/logging_event_handler.h"
17
18 #include "pw_log/log.h"
19 #include "pw_perf_test/event_handler.h"
20 #include "pw_perf_test/googletest_style_event_handler.h"
21 #include "pw_perf_test/internal/timer.h"
22
23 namespace pw::perf_test {
24
RunAllTestsStart(const TestRunInfo & summary)25 void LoggingEventHandler::RunAllTestsStart(const TestRunInfo& summary) {
26 PW_LOG_INFO(PW_PERF_TEST_GOOGLETEST_RUN_ALL_TESTS_START);
27 PW_LOG_INFO(PW_PERF_TEST_GOOGLETEST_BEGINNING_SUMMARY,
28 summary.total_tests,
29 summary.default_iterations);
30 }
31
RunAllTestsEnd()32 void LoggingEventHandler::RunAllTestsEnd() {
33 PW_LOG_INFO(PW_PERF_TEST_GOOGLETEST_RUN_ALL_TESTS_END);
34 }
35
TestCaseStart(const TestCase & info)36 void LoggingEventHandler::TestCaseStart(const TestCase& info) {
37 PW_LOG_INFO(PW_PERF_TEST_GOOGLETEST_CASE_START, info.name);
38 }
39
TestCaseIteration(const TestIteration & iteration)40 void LoggingEventHandler::TestCaseIteration(const TestIteration& iteration) {
41 PW_LOG_DEBUG(PW_PERF_TEST_GOOGLETEST_CASE_ITERATION,
42 static_cast<unsigned>(iteration.number),
43 static_cast<unsigned long>(iteration.result),
44 internal::GetDurationUnitStr());
45 }
46
TestCaseMeasure(const TestMeasurement & measurement)47 void LoggingEventHandler::TestCaseMeasure(const TestMeasurement& measurement) {
48 PW_LOG_INFO(PW_PERF_TEST_GOOGLETEST_CASE_MEASUREMENT,
49 static_cast<unsigned long>(measurement.mean),
50 internal::GetDurationUnitStr(),
51 static_cast<unsigned long>(measurement.min),
52 internal::GetDurationUnitStr(),
53 static_cast<unsigned long>(measurement.max),
54 internal::GetDurationUnitStr());
55 }
56
TestCaseEnd(const TestCase & info)57 void LoggingEventHandler::TestCaseEnd(const TestCase& info) {
58 PW_LOG_INFO(PW_PERF_TEST_GOOGLETEST_CASE_END, info.name);
59 }
60
61 } // namespace pw::perf_test
62