1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <gmock/gmock.h>
16 
17 #include "host-common/GfxstreamFatalError.h"
18 
19 #include "aemu/base/testing/TestUtils.h"
20 
21 namespace emugl {
22 namespace {
23 
TEST(GFXSTREAM_ABORT,MessageIsWellFormatted)24 TEST(GFXSTREAM_ABORT, MessageIsWellFormatted) {
25     EXPECT_DEATH(
26         { GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) << "I'm dying!"; },
27         MatchesStdRegex(R"re(F\d\d\d\d .*\] FATAL in \S+, err code: 4300000000: I'm dying!\n)re"));
28 }
29 
TEST(GFXSTREAM_ABORT,WithVkResult)30 TEST(GFXSTREAM_ABORT, WithVkResult) {
31     VkResult VK_ERROR_FRAGMENTATION = -1000161000;
32     EXPECT_DEATH({ GFXSTREAM_ABORT(FatalError(VK_ERROR_FRAGMENTATION)) << "so fragmented"; },
33                  "err code: -1000161000: so fragmented");
34 }
35 
TEST(GFXSTREAM_ABORT,WithCustomizedDeathFunction)36 TEST(GFXSTREAM_ABORT, WithCustomizedDeathFunction) {
37     emugl::setDieFunction([] { exit(42); });
38     EXPECT_EXIT(GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER));, testing::ExitedWithCode(42), "");
39     setDieFunction(std::nullopt);
40 }
41 }  // namespace
42 }  // namespace emugl
43