blob: aecceb3609f5c24e2f7f9bfeb1ebdb6108b85b6f [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
sergeyv8bd5edf2016-05-13 15:03:35 -070020#include "debug/GlesDriver.h"
21#include "debug/NullGlesDriver.h"
Seigo Nonakab6e20132016-11-14 14:07:41 +090022#include "hwui/Typeface.h"
John Reck56428472018-03-16 17:27:17 -070023#include "Properties.h"
sergeyv7dc370b2016-06-17 11:21:11 -070024#include "tests/common/LeakChecker.h"
Stan Iliev85f90962018-08-31 18:35:06 +000025#include "thread/TaskProcessor.h"
26#include "thread/Task.h"
John Reck1bcacfd2017-11-03 10:12:19 -070027#include "thread/TaskManager.h"
John Reckdc87c522016-02-29 13:31:18 -080028
John Reckdc87c522016-02-29 13:31:18 -080029#include <signal.h>
John Reckdc87c522016-02-29 13:31:18 -080030
31using namespace std;
32using namespace android;
33using namespace android::uirenderer;
34
35static auto CRASH_SIGNALS = {
John Reck1bcacfd2017-11-03 10:12:19 -070036 SIGABRT, SIGSEGV, SIGBUS,
John Reckdc87c522016-02-29 13:31:18 -080037};
38
39static map<int, struct sigaction> gSigChain;
40
41static void gtestSigHandler(int sig, siginfo_t* siginfo, void* context) {
42 auto testinfo = ::testing::UnitTest::GetInstance()->current_test_info();
John Reck1bcacfd2017-11-03 10:12:19 -070043 printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(), testinfo->name());
John Reckdc87c522016-02-29 13:31:18 -080044 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
Seigo Nonakab6e20132016-11-14 14:07:41 +090053class TypefaceEnvironment : public testing::Environment {
54public:
John Reck1bcacfd2017-11-03 10:12:19 -070055 virtual void SetUp() { Typeface::setRobotoTypefaceForTest(); }
Seigo Nonakab6e20132016-11-14 14:07:41 +090056};
57
John Reckdc87c522016-02-29 13:31:18 -080058int main(int argc, char* argv[]) {
59 // Register a crash handler
60 struct sigaction sa;
61 memset(&sa, 0, sizeof(sa));
62 sa.sa_sigaction = &gtestSigHandler;
63 sa.sa_flags = SA_SIGINFO;
64 for (auto sig : CRASH_SIGNALS) {
65 struct sigaction old_sa;
66 sigaction(sig, &sa, &old_sa);
67 gSigChain.insert(pair<int, struct sigaction>(sig, old_sa));
68 }
69
sergeyv8bd5edf2016-05-13 15:03:35 -070070 // Replace the default GLES driver
71 debug::GlesDriver::replace(std::make_unique<debug::NullGlesDriver>());
John Reck56428472018-03-16 17:27:17 -070072 Properties::isolatedProcess = true;
sergeyv8bd5edf2016-05-13 15:03:35 -070073
John Reckdc87c522016-02-29 13:31:18 -080074 // Run the tests
75 testing::InitGoogleTest(&argc, argv);
sergeyv8bd5edf2016-05-13 15:03:35 -070076 testing::InitGoogleMock(&argc, argv);
77
Seigo Nonakab6e20132016-11-14 14:07:41 +090078 testing::AddGlobalTestEnvironment(new TypefaceEnvironment());
79
John Reckdc87c522016-02-29 13:31:18 -080080 int ret = RUN_ALL_TESTS();
sergeyv7dc370b2016-06-17 11:21:11 -070081 test::LeakChecker::checkForLeaks();
John Reckdc87c522016-02-29 13:31:18 -080082 return ret;
83}