Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 1 | /* |
| 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 Sehr | 1979c64 | 2018-04-26 14:41:18 -0700 | [diff] [blame] | 22 | #include "bit_utils.h" |
David Sehr | 9c4a015 | 2018-04-05 12:23:54 -0700 | [diff] [blame] | 23 | #include "gtest/gtest.h" |
David Sehr | 1979c64 | 2018-04-26 14:41:18 -0700 | [diff] [blame] | 24 | #include "macros.h" |
Andreas Gampe | dcc528d | 2017-12-07 13:37:10 -0800 | [diff] [blame] | 25 | #include "runtime_debug.h" |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
Martin Stjernholm | 02e3be0 | 2021-10-28 03:24:58 +0100 | [diff] [blame] | 29 | [[noreturn]] |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 30 | static void SimpleAborter(const char* msg) { |
| 31 | LOG(FATAL_WITHOUT_ABORT) << msg; |
| 32 | _exit(1); |
| 33 | } |
| 34 | |
David Sehr | 9c4a015 | 2018-04-05 12:23:54 -0700 | [diff] [blame] | 35 | class LoggingTest : public testing::Test { |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 36 | protected: |
David Sehr | 9c4a015 | 2018-04-05 12:23:54 -0700 | [diff] [blame] | 37 | LoggingTest() { |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 38 | // In our abort tests we really don't want the runtime to create a real dump. |
| 39 | android::base::SetAborter(SimpleAborter); |
| 40 | } |
| 41 | }; |
| 42 | |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 43 | class TestClass { |
| 44 | public: |
| 45 | DECLARE_RUNTIME_DEBUG_FLAG(kFlag); |
| 46 | }; |
| 47 | DEFINE_RUNTIME_DEBUG_FLAG(TestClass, kFlag); |
| 48 | |
| 49 | TEST_F(LoggingTest, DECL_DEF) { |
| 50 | SetRuntimeDebugFlagsEnabled(true); |
Roland Levillain | f040914 | 2021-03-22 15:45:03 +0000 | [diff] [blame] | 51 | if (kIsDebugBuild) { |
| 52 | EXPECT_TRUE(TestClass::kFlag); |
| 53 | } else { |
| 54 | // Runtime debug flags have a constant `false` value on non-debug builds. |
| 55 | EXPECT_FALSE(TestClass::kFlag); |
| 56 | } |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 57 | |
| 58 | SetRuntimeDebugFlagsEnabled(false); |
| 59 | EXPECT_FALSE(TestClass::kFlag); |
| 60 | } |
| 61 | |
| 62 | } // namespace art |