1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <stdlib.h> 20 #include <iostream> 21 22 #ifdef BINDER_IPC_32BIT 23 static constexpr bool kBuild32Abi = true; 24 #else 25 static constexpr bool kBuild32Abi = false; 26 #endif 27 28 // TODO: remove when CONFIG_ANDROID_BINDER_IPC_32BIT is no longer supported ReadKernelConfigIs32BitAbi()29static inline bool ReadKernelConfigIs32BitAbi() { 30 // failure case implies we run with standard ABI 31 return 0 == system("zcat /proc/config.gz | grep -E \"^CONFIG_ANDROID_BINDER_IPC_32BIT=y$\""); 32 } 33 ExitIfWrongAbi()34static inline void ExitIfWrongAbi() { 35 bool runtime32Abi = ReadKernelConfigIs32BitAbi(); 36 37 if (kBuild32Abi != runtime32Abi) { 38 std::cout << "[==========] Running 1 test from 1 test suite." << std::endl; 39 std::cout << "[----------] Global test environment set-up." << std::endl; 40 std::cout << "[----------] 1 tests from BinderLibTest" << std::endl; 41 std::cout << "[ RUN ] BinderTest.AbortForWrongAbi" << std::endl; 42 std::cout << "[ INFO ] test build abi 32: " << kBuild32Abi << " runtime abi 32: " << runtime32Abi << " so, skipping tests " << std::endl; 43 std::cout << "[ OK ] BinderTest.AbortForWrongAbi (0 ms) " << std::endl; 44 std::cout << "[----------] 1 tests from BinderTest (0 ms total)" << std::endl; 45 std::cout << "" << std::endl; 46 std::cout << "[----------] Global test environment tear-down" << std::endl; 47 std::cout << "[==========] 1 test from 1 test suite ran. (0 ms total)" << std::endl; 48 std::cout << "[ PASSED ] 1 tests." << std::endl; 49 exit(0); 50 } 51 } 52 53