File: trace_logging_helpers.h

package info (click to toggle)
android-platform-tools 34.0.5-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 150,900 kB
  • sloc: cpp: 805,786; java: 293,500; ansic: 128,288; xml: 127,491; python: 41,481; sh: 14,245; javascript: 9,665; cs: 3,846; asm: 2,049; makefile: 1,917; yacc: 440; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (125 lines) | stat: -rw-r--r-- 4,270 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "platform/api/trace_logging_platform.h"

#ifndef PLATFORM_TEST_TRACE_LOGGING_HELPERS_H_
#define PLATFORM_TEST_TRACE_LOGGING_HELPERS_H_

#include <chrono>

#include "gmock/gmock.h"
#include "platform/base/trace_logging_activation.h"
#include "util/chrono_helpers.h"
#include "util/osp_logging.h"

namespace openscreen {

enum TraceHierarchyParts { kRoot = 0x1, kParent = 0x2, kCurrent = 0x4 };

enum ArgumentId { kFirst, kSecond };

class MockLoggingPlatform : public TraceLoggingPlatform {
 public:
  MockLoggingPlatform() {
    StartTracing(this);

    ON_CALL(*this, IsTraceLoggingEnabled(::testing::_))
        .WillByDefault(::testing::Return(true));
  }

  ~MockLoggingPlatform() override { StopTracing(); }

  MOCK_METHOD1(IsTraceLoggingEnabled, bool(TraceCategory::Value category));
  MOCK_METHOD7(LogTrace,
               void(const char*,
                    const uint32_t,
                    const char* file,
                    Clock::time_point,
                    Clock::time_point,
                    TraceIdHierarchy ids,
                    Error::Code));
  MOCK_METHOD5(LogAsyncStart,
               void(const char*,
                    const uint32_t,
                    const char* file,
                    Clock::time_point,
                    TraceIdHierarchy));
  MOCK_METHOD5(LogAsyncEnd,
               void(const uint32_t,
                    const char* file,
                    Clock::time_point,
                    TraceId,
                    Error::Code));
};

// Methods to validate the results of platform-layer calls.
template <uint64_t milliseconds>
void ValidateTraceTimestampDiff(const char* name,
                                const uint32_t line,
                                const char* file,
                                Clock::time_point start_time,
                                Clock::time_point end_time,
                                TraceIdHierarchy ids,
                                Error error) {
  const auto elapsed = to_milliseconds(end_time - start_time);
  ASSERT_GE(static_cast<uint64_t>(elapsed.count()), milliseconds);
}

template <Error::Code result>
void ValidateTraceErrorCode(const char* name,
                            const uint32_t line,
                            const char* file,
                            Clock::time_point start_time,
                            Clock::time_point end_time,
                            TraceIdHierarchy ids,
                            Error error) {
  ASSERT_EQ(error.code(), result);
}

template <TraceId Current,
          TraceId Parent,
          TraceId Root,
          TraceHierarchyParts parts>
void ValidateTraceIdHierarchyOnSyncTrace(const char* name,
                                         const uint32_t line,
                                         const char* file,
                                         Clock::time_point start_time,
                                         Clock::time_point end_time,
                                         TraceIdHierarchy ids,
                                         Error error) {
  if (parts & TraceHierarchyParts::kCurrent) {
    ASSERT_EQ(ids.current, Current);
  }
  if (parts & TraceHierarchyParts::kParent) {
    ASSERT_EQ(ids.parent, Parent);
  }
  if (parts & TraceHierarchyParts::kRoot) {
    ASSERT_EQ(ids.root, Root);
  }
}

template <TraceId Current,
          TraceId Parent,
          TraceId Root,
          TraceHierarchyParts parts>
void ValidateTraceIdHierarchyOnAsyncTrace(const char* name,
                                          const uint32_t line,
                                          const char* file,
                                          Clock::time_point timestamp,
                                          TraceIdHierarchy ids) {
  if (parts & TraceHierarchyParts::kCurrent) {
    EXPECT_EQ(ids.current, Current);
  }
  if (parts & TraceHierarchyParts::kParent) {
    EXPECT_EQ(ids.parent, Parent);
  }
  if (parts & TraceHierarchyParts::kRoot) {
    EXPECT_EQ(ids.root, Root);
  }
}

}  // namespace openscreen

#endif  // PLATFORM_TEST_TRACE_LOGGING_HELPERS_H_