John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 17 | #include "gmock/gmock.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 18 | #include "gtest/gtest.h" |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 19 | |
| 20 | #include "Caches.h" |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 21 | #include "debug/GlesDriver.h" |
| 22 | #include "debug/NullGlesDriver.h" |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 23 | #include "hwui/Typeface.h" |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 24 | #include "Properties.h" |
sergeyv | 7dc370b | 2016-06-17 11:21:11 -0700 | [diff] [blame] | 25 | #include "tests/common/LeakChecker.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 26 | #include "thread/TaskManager.h" |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 27 | |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 28 | #include <signal.h> |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 29 | |
| 30 | using namespace std; |
| 31 | using namespace android; |
| 32 | using namespace android::uirenderer; |
| 33 | |
| 34 | static auto CRASH_SIGNALS = { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 35 | SIGABRT, SIGSEGV, SIGBUS, |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static map<int, struct sigaction> gSigChain; |
| 39 | |
| 40 | static void gtestSigHandler(int sig, siginfo_t* siginfo, void* context) { |
| 41 | auto testinfo = ::testing::UnitTest::GetInstance()->current_test_info(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 42 | printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(), testinfo->name()); |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 43 | printf("[ FATAL! ] Process crashed, aborting tests!\n"); |
| 44 | fflush(stdout); |
| 45 | |
| 46 | // restore the default sighandler and re-raise |
| 47 | struct sigaction sa = gSigChain[sig]; |
| 48 | sigaction(sig, &sa, nullptr); |
| 49 | raise(sig); |
| 50 | } |
| 51 | |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 52 | class TypefaceEnvironment : public testing::Environment { |
| 53 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 54 | virtual void SetUp() { Typeface::setRobotoTypefaceForTest(); } |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 55 | }; |
| 56 | |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 57 | int main(int argc, char* argv[]) { |
| 58 | // Register a crash handler |
| 59 | struct sigaction sa; |
| 60 | memset(&sa, 0, sizeof(sa)); |
| 61 | sa.sa_sigaction = >estSigHandler; |
| 62 | sa.sa_flags = SA_SIGINFO; |
| 63 | for (auto sig : CRASH_SIGNALS) { |
| 64 | struct sigaction old_sa; |
| 65 | sigaction(sig, &sa, &old_sa); |
| 66 | gSigChain.insert(pair<int, struct sigaction>(sig, old_sa)); |
| 67 | } |
| 68 | |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 69 | // Replace the default GLES driver |
| 70 | debug::GlesDriver::replace(std::make_unique<debug::NullGlesDriver>()); |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 71 | Properties::isolatedProcess = true; |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 72 | |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 73 | // Run the tests |
| 74 | testing::InitGoogleTest(&argc, argv); |
sergeyv | 8bd5edf | 2016-05-13 15:03:35 -0700 | [diff] [blame] | 75 | testing::InitGoogleMock(&argc, argv); |
| 76 | |
Seigo Nonaka | b6e2013 | 2016-11-14 14:07:41 +0900 | [diff] [blame] | 77 | testing::AddGlobalTestEnvironment(new TypefaceEnvironment()); |
| 78 | |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 79 | int ret = RUN_ALL_TESTS(); |
sergeyv | 7dc370b | 2016-06-17 11:21:11 -0700 | [diff] [blame] | 80 | test::LeakChecker::checkForLeaks(); |
John Reck | dc87c52 | 2016-02-29 13:31:18 -0800 | [diff] [blame] | 81 | return ret; |
| 82 | } |