Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 825b7ab3 | 2013-06-26 18:21:54 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/tests/test_trace_event.h" |
| 6 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
[email protected] | 825b7ab3 | 2013-06-26 18:21:54 | [diff] [blame] | 9 | #include "ppapi/cpp/module.h" |
| 10 | #include "ppapi/tests/testing_instance.h" |
| 11 | |
| 12 | REGISTER_TEST_CASE(TraceEvent); |
| 13 | |
| 14 | TestTraceEvent::TestTraceEvent(TestingInstance* instance) |
| 15 | : TestCase(instance), |
| 16 | interface_(NULL) { |
| 17 | } |
| 18 | |
| 19 | bool TestTraceEvent::Init() { |
| 20 | interface_ = static_cast<const PPB_Trace_Event_Dev*>( |
| 21 | pp::Module::Get()->GetBrowserInterface(PPB_TRACE_EVENT_DEV_INTERFACE)); |
| 22 | return !!interface_; |
| 23 | } |
| 24 | |
| 25 | void TestTraceEvent::RunTests(const std::string& filter) { |
| 26 | RUN_TEST(Smoke, filter); |
| 27 | RUN_TEST(SmokeWithTimestamps, filter); |
| 28 | RUN_TEST(Clock, filter); |
| 29 | } |
| 30 | |
| 31 | std::string TestTraceEvent::TestSmoke() { |
| 32 | // This test does not verify the log message actually reaches dev tracing, but |
| 33 | // it does test that the interface exists and that it can be called without |
| 34 | // crashing. |
Mikhail Khokhlov | 7dad5b2 | 2022-09-05 09:21:25 | [diff] [blame] | 35 | const void* cat_enabled = interface_->GetCategoryEnabled("ppapi"); |
[email protected] | 825b7ab3 | 2013-06-26 18:21:54 | [diff] [blame] | 36 | interface_->AddTraceEvent('B', cat_enabled, "foo", 0, 0, NULL, NULL, NULL, 0); |
| 37 | interface_->AddTraceEvent('E', cat_enabled, "foo", 0, 0, NULL, NULL, NULL, 0); |
| 38 | PASS(); |
| 39 | } |
| 40 | |
| 41 | std::string TestTraceEvent::TestSmokeWithTimestamps() { |
| 42 | // This test does not verify the log message actually reaches dev tracing, but |
| 43 | // it does test that the interface exists and that it can be called without |
| 44 | // crashing. |
Mikhail Khokhlov | 7dad5b2 | 2022-09-05 09:21:25 | [diff] [blame] | 45 | const void* cat_enabled = interface_->GetCategoryEnabled("ppapi"); |
[email protected] | 825b7ab3 | 2013-06-26 18:21:54 | [diff] [blame] | 46 | interface_->AddTraceEventWithThreadIdAndTimestamp( |
| 47 | 'B', cat_enabled, "foo", 0, 0, 42, 0, NULL, NULL, NULL, 0); |
| 48 | interface_->AddTraceEventWithThreadIdAndTimestamp( |
| 49 | 'B', cat_enabled, "foo", 0, 1, 43, 0, NULL, NULL, NULL, 0); |
| 50 | interface_->AddTraceEventWithThreadIdAndTimestamp( |
| 51 | 'E', cat_enabled, "foo", 0, 0, 44, 0, NULL, NULL, NULL, 0); |
| 52 | interface_->AddTraceEventWithThreadIdAndTimestamp( |
| 53 | 'E', cat_enabled, "foo", 0, 1, 45, 0, NULL, NULL, NULL, 0); |
| 54 | PASS(); |
| 55 | } |
| 56 | |
| 57 | std::string TestTraceEvent::TestClock() { |
| 58 | int64_t last = interface_->Now(); |
| 59 | |
| 60 | for(int i=0; i<5; ++i){ |
| 61 | int64_t next = interface_->Now(); |
| 62 | ASSERT_LE(last, next); |
| 63 | last = next; |
| 64 | } |
| 65 | |
| 66 | PASS(); |
[email protected] | d5b04b83 | 2013-09-12 19:48:15 | [diff] [blame] | 67 | } |