blob: d05bdbf1709ecb7a363a178c04e7cf9617a3ae19 [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
17#include "gtest/gtest.h"
sergeyv8bd5edf2016-05-13 15:03:35 -070018#include "gmock/gmock.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"
John Reckdc87c522016-02-29 13:31:18 -080023#include "thread/TaskManager.h"
sergeyv7dc370b2016-06-17 11:21:11 -070024#include "tests/common/LeakChecker.h"
John Reckdc87c522016-02-29 13:31:18 -080025
John Reckdc87c522016-02-29 13:31:18 -080026#include <signal.h>
John Reckdc87c522016-02-29 13:31:18 -080027
28using namespace std;
29using namespace android;
30using namespace android::uirenderer;
31
32static auto CRASH_SIGNALS = {
33 SIGABRT,
34 SIGSEGV,
35 SIGBUS,
36};
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();
42 printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(),
43 testinfo->name());
44 printf("[ FATAL! ] Process crashed, aborting tests!\n");
45 fflush(stdout);
46
47 // restore the default sighandler and re-raise
48 struct sigaction sa = gSigChain[sig];
49 sigaction(sig, &sa, nullptr);
50 raise(sig);
51}
52
John Reckdc87c522016-02-29 13:31:18 -080053int main(int argc, char* argv[]) {
54 // Register a crash handler
55 struct sigaction sa;
56 memset(&sa, 0, sizeof(sa));
57 sa.sa_sigaction = &gtestSigHandler;
58 sa.sa_flags = SA_SIGINFO;
59 for (auto sig : CRASH_SIGNALS) {
60 struct sigaction old_sa;
61 sigaction(sig, &sa, &old_sa);
62 gSigChain.insert(pair<int, struct sigaction>(sig, old_sa));
63 }
64
sergeyv8bd5edf2016-05-13 15:03:35 -070065 // Replace the default GLES driver
66 debug::GlesDriver::replace(std::make_unique<debug::NullGlesDriver>());
67
John Reckdc87c522016-02-29 13:31:18 -080068 // Run the tests
69 testing::InitGoogleTest(&argc, argv);
sergeyv8bd5edf2016-05-13 15:03:35 -070070 testing::InitGoogleMock(&argc, argv);
71
John Reckdc87c522016-02-29 13:31:18 -080072 int ret = RUN_ALL_TESTS();
sergeyv7dc370b2016-06-17 11:21:11 -070073 test::LeakChecker::checkForLeaks();
John Reckdc87c522016-02-29 13:31:18 -080074 return ret;
75}
76