• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
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 
7 #include "ppapi/cpp/module.h"
8 #include "ppapi/tests/testing_instance.h"
9 
10 REGISTER_TEST_CASE(TraceEvent);
11 
TestTraceEvent(TestingInstance * instance)12 TestTraceEvent::TestTraceEvent(TestingInstance* instance)
13     : TestCase(instance),
14       interface_(NULL) {
15 }
16 
Init()17 bool TestTraceEvent::Init() {
18   interface_ = static_cast<const PPB_Trace_Event_Dev*>(
19       pp::Module::Get()->GetBrowserInterface(PPB_TRACE_EVENT_DEV_INTERFACE));
20   return !!interface_;
21 }
22 
RunTests(const std::string & filter)23 void TestTraceEvent::RunTests(const std::string& filter) {
24   RUN_TEST(Smoke, filter);
25   RUN_TEST(SmokeWithTimestamps, filter);
26   RUN_TEST(Clock, filter);
27 }
28 
TestSmoke()29 std::string TestTraceEvent::TestSmoke() {
30   // This test does not verify the log message actually reaches dev tracing, but
31   // it does test that the interface exists and that it can be called without
32   // crashing.
33   const void* cat_enabled = interface_->GetCategoryEnabled("bar");
34   interface_->AddTraceEvent('B', cat_enabled, "foo", 0, 0, NULL, NULL, NULL, 0);
35   interface_->AddTraceEvent('E', cat_enabled, "foo", 0, 0, NULL, NULL, NULL, 0);
36   PASS();
37 }
38 
TestSmokeWithTimestamps()39 std::string TestTraceEvent::TestSmokeWithTimestamps() {
40   // This test does not verify the log message actually reaches dev tracing, but
41   // it does test that the interface exists and that it can be called without
42   // crashing.
43   const void* cat_enabled = interface_->GetCategoryEnabled("bar");
44   interface_->AddTraceEventWithThreadIdAndTimestamp(
45     'B', cat_enabled, "foo", 0, 0, 42, 0, NULL, NULL, NULL, 0);
46   interface_->AddTraceEventWithThreadIdAndTimestamp(
47     'B', cat_enabled, "foo", 0, 1, 43, 0, NULL, NULL, NULL, 0);
48   interface_->AddTraceEventWithThreadIdAndTimestamp(
49     'E', cat_enabled, "foo", 0, 0, 44, 0, NULL, NULL, NULL, 0);
50   interface_->AddTraceEventWithThreadIdAndTimestamp(
51     'E', cat_enabled, "foo", 0, 1, 45, 0, NULL, NULL, NULL, 0);
52   PASS();
53 }
54 
TestClock()55 std::string TestTraceEvent::TestClock() {
56   int64_t last = interface_->Now();
57 
58   for(int i=0; i<5; ++i){
59     int64_t next = interface_->Now();
60     ASSERT_LE(last, next);
61     last = next;
62   }
63 
64   PASS();
65 }
66