blob: 9e6d9a8c27de511a1bf0dd2d6e36f2c55b30c025 [file] [log] [blame]
John Reckdc87c522016-02-29 13:31:18 -08001/*
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
sergeyv8bd5edf2016-05-13 15:03:35 -070017#include "gmock/gmock.h"
John Reck1bcacfd2017-11-03 10:12:19 -070018#include "gtest/gtest.h"
John Reckdc87c522016-02-29 13:31:18 -080019
20#include "Caches.h"
sergeyv8bd5edf2016-05-13 15:03:35 -070021#include "debug/GlesDriver.h"
22#include "debug/NullGlesDriver.h"
Seigo Nonakab6e20132016-11-14 14:07:41 +090023#include "hwui/Typeface.h"
John Reck56428472018-03-16 17:27:17 -070024#include "Properties.h"
sergeyv7dc370b2016-06-17 11:21:11 -070025#include "tests/common/LeakChecker.h"
John Reck1bcacfd2017-11-03 10:12:19 -070026#include "thread/TaskManager.h"
John Reckdc87c522016-02-29 13:31:18 -080027
John Reckdc87c522016-02-29 13:31:18 -080028#include <signal.h>
John Reckdc87c522016-02-29 13:31:18 -080029
30using namespace std;
31using namespace android;
32using namespace android::uirenderer;
33
34static auto CRASH_SIGNALS = {
John Reck1bcacfd2017-11-03 10:12:19 -070035 SIGABRT, SIGSEGV, SIGBUS,
John Reckdc87c522016-02-29 13:31:18 -080036};
37
38static map<int, struct sigaction> gSigChain;
39
40static void gtestSigHandler(int sig, siginfo_t* siginfo, void* context) {
41 auto testinfo = ::testing::UnitTest::GetInstance()->current_test_info();
John Reck1bcacfd2017-11-03 10:12:19 -070042 printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(), testinfo->name());
John Reckdc87c522016-02-29 13:31:18 -080043 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 Nonakab6e20132016-11-14 14:07:41 +090052class TypefaceEnvironment : public testing::Environment {
53public:
John Reck1bcacfd2017-11-03 10:12:19 -070054 virtual void SetUp() { Typeface::setRobotoTypefaceForTest(); }
Seigo Nonakab6e20132016-11-14 14:07:41 +090055};
56
John Reckdc87c522016-02-29 13:31:18 -080057int main(int argc, char* argv[]) {
58 // Register a crash handler
59 struct sigaction sa;
60 memset(&sa, 0, sizeof(sa));
61 sa.sa_sigaction = &gtestSigHandler;
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
sergeyv8bd5edf2016-05-13 15:03:35 -070069 // Replace the default GLES driver
70 debug::GlesDriver::replace(std::make_unique<debug::NullGlesDriver>());
John Reck56428472018-03-16 17:27:17 -070071 Properties::isolatedProcess = true;
sergeyv8bd5edf2016-05-13 15:03:35 -070072
John Reckdc87c522016-02-29 13:31:18 -080073 // Run the tests
74 testing::InitGoogleTest(&argc, argv);
sergeyv8bd5edf2016-05-13 15:03:35 -070075 testing::InitGoogleMock(&argc, argv);
76
Seigo Nonakab6e20132016-11-14 14:07:41 +090077 testing::AddGlobalTestEnvironment(new TypefaceEnvironment());
78
John Reckdc87c522016-02-29 13:31:18 -080079 int ret = RUN_ALL_TESTS();
sergeyv7dc370b2016-06-17 11:21:11 -070080 test::LeakChecker::checkForLeaks();
John Reckdc87c522016-02-29 13:31:18 -080081 return ret;
82}