diff options
| author | 2020-05-06 17:14:39 -0700 | |
|---|---|---|
| committer | 2020-05-08 13:36:09 -0700 | |
| commit | f9f3de2434d82942b989621c43490eff46b8512d (patch) | |
| tree | 24423986e58a3c2f0425e7bd314190a64b0f3bed | |
| parent | a7e92558ee6b21be51ec2b47854639c990ec1cc2 (diff) | |
binder tests respect libbinder bitness
Some 32-bit kernels use a binder kernel interface with a different API
controlled by the kernel configuration CONFIG_ANDROID_BINDER_IPC_32BIT.
This changes builds versions of these tests built for this bitness
specially so that they can run and work on these devices.
Test: atest --all binderLibTest{,_IPC_32} binderDriverInterfaceTest{,_IPC_32}
Bug: 154755898
Change-Id: I82b47e8064564a037bf8ed453e9ae7b8901b5667
| -rw-r--r-- | libs/binder/tests/Android.bp | 5 | ||||
| -rw-r--r-- | libs/binder/tests/binderAbiHelper.h | 52 | ||||
| -rw-r--r-- | libs/binder/tests/binderDriverInterfaceTest.cpp | 3 | ||||
| -rw-r--r-- | libs/binder/tests/binderLibTest.cpp | 4 |
4 files changed, 64 insertions, 0 deletions
diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp index 69fdd7c5d8..c0da2cd8d4 100644 --- a/libs/binder/tests/Android.bp +++ b/libs/binder/tests/Android.bp @@ -27,7 +27,9 @@ cc_test { defaults: ["binder_test_defaults"], srcs: ["binderDriverInterfaceTest.cpp"], compile_multilib: "32", + multilib: { lib32: { suffix: "" } }, cflags: ["-DBINDER_IPC_32BIT=1"], + test_suites: ["vts"], } cc_test { @@ -52,7 +54,10 @@ cc_test { "libutils", ], compile_multilib: "32", + multilib: { lib32: { suffix: "" } }, cflags: ["-DBINDER_IPC_32BIT=1"], + test_suites: ["vts"], + require_root: true, } cc_test { diff --git a/libs/binder/tests/binderAbiHelper.h b/libs/binder/tests/binderAbiHelper.h new file mode 100644 index 0000000000..369b55dc22 --- /dev/null +++ b/libs/binder/tests/binderAbiHelper.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <stdlib.h> +#include <iostream> + +#ifdef BINDER_IPC_32BIT +static constexpr bool kBuild32Abi = true; +#else +static constexpr bool kBuild32Abi = false; +#endif + +// TODO: remove when CONFIG_ANDROID_BINDER_IPC_32BIT is no longer supported +static inline bool ReadKernelConfigIs32BitAbi() { + // failure case implies we run with standard ABI + return 0 == system("zcat /proc/config.gz | grep -E \"^CONFIG_ANDROID_BINDER_IPC_32BIT=y$\""); +} + +static inline void ExitIfWrongAbi() { + bool runtime32Abi = ReadKernelConfigIs32BitAbi(); + + if (kBuild32Abi != runtime32Abi) { + std::cout << "[==========] Running 1 test from 1 test suite." << std::endl; + std::cout << "[----------] Global test environment set-up." << std::endl; + std::cout << "[----------] 1 tests from BinderLibTest" << std::endl; + std::cout << "[ RUN ] BinderTest.AbortForWrongAbi" << std::endl; + std::cout << "[ INFO ] test build abi 32: " << kBuild32Abi << " runtime abi 32: " << runtime32Abi << " so, skipping tests " << std::endl; + std::cout << "[ OK ] BinderTest.AbortForWrongAbi (0 ms) " << std::endl; + std::cout << "[----------] 1 tests from BinderTest (0 ms total)" << std::endl; + std::cout << "" << std::endl; + std::cout << "[----------] Global test environment tear-down" << std::endl; + std::cout << "[==========] 1 test from 1 test suite ran. (0 ms total)" << std::endl; + std::cout << "[ PASSED ] 1 tests." << std::endl; + exit(0); + } +} + diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp index f3ed6a613c..8cc3054f80 100644 --- a/libs/binder/tests/binderDriverInterfaceTest.cpp +++ b/libs/binder/tests/binderDriverInterfaceTest.cpp @@ -25,6 +25,8 @@ #include <sys/mman.h> #include <poll.h> +#include "binderAbiHelper.h" + #define BINDER_DEV_NAME "/dev/binder" testing::Environment* binder_env; @@ -361,6 +363,7 @@ TEST_F(BinderDriverInterfaceTest, RequestDeathNotification) { } int main(int argc, char **argv) { + ExitIfWrongAbi(); ::testing::InitGoogleTest(&argc, argv); binder_env = AddGlobalTestEnvironment(new BinderDriverInterfaceTestEnv()); diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index e343df7e50..40de2db2cb 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -32,6 +32,8 @@ #include <sys/epoll.h> #include <sys/prctl.h> +#include "binderAbiHelper.h" + #define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) using namespace android; @@ -1451,6 +1453,8 @@ int run_server(int index, int readypipefd, bool usePoll) } int main(int argc, char **argv) { + ExitIfWrongAbi(); + if (argc == 4 && !strcmp(argv[1], "--servername")) { binderservername = argv[2]; } else { |