OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Unit tests for event trace provider. | 5 // Unit tests for event trace provider. |
6 #include "base/win/event_trace_provider.h" | 6 #include "base/win/event_trace_provider.h" |
7 #include <new> | 7 #include <new> |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include <initguid.h> // NOLINT - has to be last | 9 #include <initguid.h> // NOLINT - has to be last |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 TEST(EtwTraceProviderTest, ToleratesPreCreateInvocations) { | 26 TEST(EtwTraceProviderTest, ToleratesPreCreateInvocations) { |
27 // Because the trace provider is used in logging, it's important that | 27 // Because the trace provider is used in logging, it's important that |
28 // it be possible to use static provider instances without regard to | 28 // it be possible to use static provider instances without regard to |
29 // whether they've been constructed or destructed. | 29 // whether they've been constructed or destructed. |
30 // The interface of the class is designed to tolerate this usage. | 30 // The interface of the class is designed to tolerate this usage. |
31 char buf[sizeof(EtwTraceProvider)] = {0}; | 31 char buf[sizeof(EtwTraceProvider)] = {0}; |
32 EtwTraceProvider& provider = reinterpret_cast<EtwTraceProvider&>(buf); | 32 EtwTraceProvider& provider = reinterpret_cast<EtwTraceProvider&>(buf); |
33 | 33 |
34 EXPECT_EQ(NULL, provider.registration_handle()); | 34 EXPECT_EQ(0u, provider.registration_handle()); |
35 EXPECT_EQ(NULL, provider.session_handle()); | 35 EXPECT_EQ(0u, provider.session_handle()); |
36 EXPECT_EQ(0, provider.enable_flags()); | 36 EXPECT_EQ(0u, provider.enable_flags()); |
37 EXPECT_EQ(0, provider.enable_level()); | 37 EXPECT_EQ(0u, provider.enable_level()); |
38 | 38 |
39 EXPECT_FALSE(provider.ShouldLog(TRACE_LEVEL_FATAL, 0xfffffff)); | 39 EXPECT_FALSE(provider.ShouldLog(TRACE_LEVEL_FATAL, 0xfffffff)); |
40 | 40 |
41 // We expect these not to crash. | 41 // We expect these not to crash. |
42 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, "foo"); | 42 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, "foo"); |
43 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, L"foo"); | 43 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, L"foo"); |
44 | 44 |
45 EtwMofEvent<1> dummy(kTestEventClass, 0, TRACE_LEVEL_FATAL); | 45 EtwMofEvent<1> dummy(kTestEventClass, 0, TRACE_LEVEL_FATAL); |
46 DWORD data = 0; | 46 DWORD data = 0; |
47 dummy.SetField(0, sizeof(data), &data); | 47 dummy.SetField(0, sizeof(data), &data); |
48 provider.Log(dummy.get()); | 48 provider.Log(dummy.get()); |
49 | 49 |
50 // Placement-new the provider into our buffer. | 50 // Placement-new the provider into our buffer. |
51 new (buf) EtwTraceProvider(kTestProvider); | 51 new (buf) EtwTraceProvider(kTestProvider); |
52 | 52 |
53 // Registration is now safe. | 53 // Registration is now safe. |
54 EXPECT_EQ(ERROR_SUCCESS, provider.Register()); | 54 EXPECT_EQ(static_cast<ULONG>(ERROR_SUCCESS), provider.Register()); |
55 | 55 |
56 // Destruct the instance, this should unregister it. | 56 // Destruct the instance, this should unregister it. |
57 provider.EtwTraceProvider::~EtwTraceProvider(); | 57 provider.EtwTraceProvider::~EtwTraceProvider(); |
58 | 58 |
59 // And post-destruction, all of the above should still be safe. | 59 // And post-destruction, all of the above should still be safe. |
60 EXPECT_EQ(NULL, provider.registration_handle()); | 60 EXPECT_EQ(0u, provider.registration_handle()); |
61 EXPECT_EQ(NULL, provider.session_handle()); | 61 EXPECT_EQ(0u, provider.session_handle()); |
62 EXPECT_EQ(0, provider.enable_flags()); | 62 EXPECT_EQ(0u, provider.enable_flags()); |
63 EXPECT_EQ(0, provider.enable_level()); | 63 EXPECT_EQ(0u, provider.enable_level()); |
64 | 64 |
65 EXPECT_FALSE(provider.ShouldLog(TRACE_LEVEL_FATAL, 0xfffffff)); | 65 EXPECT_FALSE(provider.ShouldLog(TRACE_LEVEL_FATAL, 0xfffffff)); |
66 | 66 |
67 // We expect these not to crash. | 67 // We expect these not to crash. |
68 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, "foo"); | 68 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, "foo"); |
69 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, L"foo"); | 69 provider.Log(kTestEventClass, 0, TRACE_LEVEL_FATAL, L"foo"); |
70 provider.Log(dummy.get()); | 70 provider.Log(dummy.get()); |
71 } | 71 } |
72 | 72 |
73 TEST(EtwTraceProviderTest, Initialize) { | 73 TEST(EtwTraceProviderTest, Initialize) { |
74 EtwTraceProvider provider(kTestProvider); | 74 EtwTraceProvider provider(kTestProvider); |
75 | 75 |
76 EXPECT_EQ(NULL, provider.registration_handle()); | 76 EXPECT_EQ(0u, provider.registration_handle()); |
77 EXPECT_EQ(NULL, provider.session_handle()); | 77 EXPECT_EQ(0u, provider.session_handle()); |
78 EXPECT_EQ(0, provider.enable_flags()); | 78 EXPECT_EQ(0u, provider.enable_flags()); |
79 EXPECT_EQ(0, provider.enable_level()); | 79 EXPECT_EQ(0u, provider.enable_level()); |
80 } | 80 } |
81 | 81 |
82 TEST(EtwTraceProviderTest, Register) { | 82 TEST(EtwTraceProviderTest, Register) { |
83 EtwTraceProvider provider(kTestProvider); | 83 EtwTraceProvider provider(kTestProvider); |
84 | 84 |
85 ASSERT_EQ(ERROR_SUCCESS, provider.Register()); | 85 ASSERT_EQ(static_cast<ULONG>(ERROR_SUCCESS), provider.Register()); |
86 EXPECT_NE(NULL, provider.registration_handle()); | 86 EXPECT_NE(0u, provider.registration_handle()); |
87 ASSERT_EQ(ERROR_SUCCESS, provider.Unregister()); | 87 ASSERT_EQ(static_cast<ULONG>(ERROR_SUCCESS), provider.Unregister()); |
88 EXPECT_EQ(NULL, provider.registration_handle()); | 88 EXPECT_EQ(0u, provider.registration_handle()); |
89 } | 89 } |
90 | 90 |
91 TEST(EtwTraceProviderTest, RegisterWithNoNameFails) { | 91 TEST(EtwTraceProviderTest, RegisterWithNoNameFails) { |
92 EtwTraceProvider provider; | 92 EtwTraceProvider provider; |
93 | 93 |
94 EXPECT_TRUE(provider.Register() != ERROR_SUCCESS); | 94 EXPECT_TRUE(provider.Register() != ERROR_SUCCESS); |
95 } | 95 } |
96 | 96 |
97 TEST(EtwTraceProviderTest, Enable) { | 97 TEST(EtwTraceProviderTest, Enable) { |
98 EtwTraceProvider provider(kTestProvider); | 98 EtwTraceProvider provider(kTestProvider); |
99 | 99 |
100 ASSERT_EQ(ERROR_SUCCESS, provider.Register()); | 100 ASSERT_EQ(static_cast<ULONG>(ERROR_SUCCESS), provider.Register()); |
101 EXPECT_NE(NULL, provider.registration_handle()); | 101 EXPECT_NE(0u, provider.registration_handle()); |
102 | 102 |
103 // No session so far. | 103 // No session so far. |
104 EXPECT_EQ(NULL, provider.session_handle()); | 104 EXPECT_EQ(0u, provider.session_handle()); |
105 EXPECT_EQ(0, provider.enable_flags()); | 105 EXPECT_EQ(0u, provider.enable_flags()); |
106 EXPECT_EQ(0, provider.enable_level()); | 106 EXPECT_EQ(0u, provider.enable_level()); |
107 | 107 |
108 ASSERT_EQ(ERROR_SUCCESS, provider.Unregister()); | 108 ASSERT_EQ(static_cast<ULONG>(ERROR_SUCCESS), provider.Unregister()); |
109 EXPECT_EQ(NULL, provider.registration_handle()); | 109 EXPECT_EQ(0u, provider.registration_handle()); |
110 } | 110 } |
OLD | NEW |