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
17 #include "gmock/gmock.h"
18 #include "gtest/gtest.h"
19
20 #include "Properties.h"
21 #include "hwui/Typeface.h"
22 #include "tests/common/LeakChecker.h"
23
24 #include <signal.h>
25
26 using namespace std;
27 using namespace android;
28 using namespace android::uirenderer;
29
30 static auto CRASH_SIGNALS = {
31 SIGABRT, SIGSEGV, SIGBUS,
32 };
33
34 static map<int, struct sigaction> gSigChain;
35
gtestSigHandler(int sig,siginfo_t * siginfo,void * context)36 static void gtestSigHandler(int sig, siginfo_t* siginfo, void* context) {
37 auto testinfo = ::testing::UnitTest::GetInstance()->current_test_info();
38 printf("[ FAILED ] %s.%s\n", testinfo->test_case_name(), testinfo->name());
39 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
48 class TypefaceEnvironment : public testing::Environment {
49 public:
SetUp()50 virtual void SetUp() { Typeface::setRobotoTypefaceForTest(); }
51 };
52
main(int argc,char * argv[])53 int main(int argc, char* argv[]) {
54 // Register a crash handler
55 struct sigaction sa;
56 memset(&sa, 0, sizeof(sa));
57 sa.sa_sigaction = >estSigHandler;
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
65 // Avoid talking to SF
66 Properties::isolatedProcess = true;
67 // Default to GLES (Vulkan-aware tests will override this)
68 Properties::overrideRenderPipelineType(RenderPipelineType::SkiaGL);
69
70 // Run the tests
71 testing::InitGoogleTest(&argc, argv);
72 testing::InitGoogleMock(&argc, argv);
73
74 testing::AddGlobalTestEnvironment(new TypefaceEnvironment());
75
76 int ret = RUN_ALL_TESTS();
77 test::LeakChecker::checkForLeaks();
78 return ret;
79 }
80