blob: 0e002bb40a1b1a000decc15ae8fe7e4e5afd2e4c [file] [log] [blame]
Avi Drissmandb497b32022-09-15 19:47:281// Copyright 2013 The Chromium Authors
[email protected]825b7ab32013-06-26 18:21:542// 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
avie029c4132015-12-23 06:45:227#include <stdint.h>
8
[email protected]825b7ab32013-06-26 18:21:549#include "ppapi/cpp/module.h"
10#include "ppapi/tests/testing_instance.h"
11
12REGISTER_TEST_CASE(TraceEvent);
13
14TestTraceEvent::TestTraceEvent(TestingInstance* instance)
15 : TestCase(instance),
16 interface_(NULL) {
17}
18
19bool 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
25void TestTraceEvent::RunTests(const std::string& filter) {
26 RUN_TEST(Smoke, filter);
27 RUN_TEST(SmokeWithTimestamps, filter);
28 RUN_TEST(Clock, filter);
29}
30
31std::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 Khokhlov7dad5b22022-09-05 09:21:2535 const void* cat_enabled = interface_->GetCategoryEnabled("ppapi");
[email protected]825b7ab32013-06-26 18:21:5436 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
41std::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 Khokhlov7dad5b22022-09-05 09:21:2545 const void* cat_enabled = interface_->GetCategoryEnabled("ppapi");
[email protected]825b7ab32013-06-26 18:21:5446 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
57std::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]d5b04b832013-09-12 19:48:1567}