blob: 10c874ec3f123f63cdb65126f568b0f7e4d4c422 [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
John Reck283bb462018-12-13 16:40:14 -080020#include "Properties.h"
Seigo Nonakab6e20132016-11-14 14:07:41 +090021#include "hwui/Typeface.h"
sergeyv7dc370b2016-06-17 11:21:11 -070022#include "tests/common/LeakChecker.h"
John Reckdc87c522016-02-29 13:31:18 -080023
John Reckdc87c522016-02-29 13:31:18 -080024#include <signal.h>
John Reckdc87c522016-02-29 13:31:18 -080025
26using namespace std;
27using namespace android;
28using namespace android::uirenderer;
29
30static auto CRASH_SIGNALS = {
John Reck1bcacfd2017-11-03 10:12:19 -070031 SIGABRT, SIGSEGV, SIGBUS,
John Reckdc87c522016-02-29 13:31:18 -080032};
33
34static map<int, struct sigaction> gSigChain;
35
36static void gtestSigHandler(int sig, siginfo_t* siginfo, void* context) {
37 auto testinfo = ::testing::UnitTest::GetInstance()->current_test_info();
John Reck1bcacfd2017-11-03 10:12:19 -070038 printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(), testinfo->name());
John Reckdc87c522016-02-29 13:31:18 -080039 printf("[ FATAL! ] Process crashed, aborting tests!\n");
40 fflush(stdout);
41
42 // restore the default sighandler and re-raise
43 struct sigaction sa = gSigChain[sig];
44 sigaction(sig, &sa, nullptr);
45 raise(sig);
46}
47
Seigo Nonakab6e20132016-11-14 14:07:41 +090048class TypefaceEnvironment : public testing::Environment {
49public:
John Reck1bcacfd2017-11-03 10:12:19 -070050 virtual void SetUp() { Typeface::setRobotoTypefaceForTest(); }
Seigo Nonakab6e20132016-11-14 14:07:41 +090051};
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
John Reckfaa1b0a2021-05-13 10:28:38 -040065 // Avoid talking to SF
John Reck56428472018-03-16 17:27:17 -070066 Properties::isolatedProcess = true;
John Reckfaa1b0a2021-05-13 10:28:38 -040067 // Default to GLES (Vulkan-aware tests will override this)
68 Properties::overrideRenderPipelineType(RenderPipelineType::SkiaGL);
sergeyv8bd5edf2016-05-13 15:03:35 -070069
John Reckdc87c522016-02-29 13:31:18 -080070 // Run the tests
71 testing::InitGoogleTest(&argc, argv);
sergeyv8bd5edf2016-05-13 15:03:35 -070072 testing::InitGoogleMock(&argc, argv);
73
Seigo Nonakab6e20132016-11-14 14:07:41 +090074 testing::AddGlobalTestEnvironment(new TypefaceEnvironment());
75
John Reckdc87c522016-02-29 13:31:18 -080076 int ret = RUN_ALL_TESTS();
sergeyv7dc370b2016-06-17 11:21:11 -070077 test::LeakChecker::checkForLeaks();
John Reckdc87c522016-02-29 13:31:18 -080078 return ret;
79}