blob: 46ba41bb1f184d7565e7b0726d1355b9c234033e [file] [log] [blame]
Andreas Gampe1c5b42f2017-06-15 18:20:45 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "logging.h"
18
19#include <type_traits>
20
21#include "android-base/logging.h"
David Sehr1979c642018-04-26 14:41:18 -070022#include "bit_utils.h"
David Sehr9c4a0152018-04-05 12:23:54 -070023#include "gtest/gtest.h"
David Sehr1979c642018-04-26 14:41:18 -070024#include "macros.h"
Andreas Gampedcc528d2017-12-07 13:37:10 -080025#include "runtime_debug.h"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070026
27namespace art {
28
29static void SimpleAborter(const char* msg) {
30 LOG(FATAL_WITHOUT_ABORT) << msg;
31 _exit(1);
32}
33
David Sehr9c4a0152018-04-05 12:23:54 -070034class LoggingTest : public testing::Test {
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070035 protected:
David Sehr9c4a0152018-04-05 12:23:54 -070036 LoggingTest() {
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070037 // In our abort tests we really don't want the runtime to create a real dump.
38 android::base::SetAborter(SimpleAborter);
39 }
40};
41
42#ifdef NDEBUG
43#error Unexpected NDEBUG
44#endif
45
46class TestClass {
47 public:
48 DECLARE_RUNTIME_DEBUG_FLAG(kFlag);
49};
50DEFINE_RUNTIME_DEBUG_FLAG(TestClass, kFlag);
51
52TEST_F(LoggingTest, DECL_DEF) {
53 SetRuntimeDebugFlagsEnabled(true);
54 EXPECT_TRUE(TestClass::kFlag);
55
56 SetRuntimeDebugFlagsEnabled(false);
57 EXPECT_FALSE(TestClass::kFlag);
58}
59
60} // namespace art