1#!/usr/bin/env python 2# 3# Copyright (C) 2017 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18# TODO(hsinyichen): delete this file when BINDER_IPC_32BIT is unsupported 19import gzip 20import logging 21import os 22import tempfile 23 24from vts.runners.host import asserts 25from vts.runners.host import test_runner 26from vts.testcases.template.gtest_binary_test import gtest_binary_test 27from vts.utils.python.controllers import adb 28from vts.utils.python.os import path_utils 29 30 31class VtsKernelBinderTest(gtest_binary_test.GtestBinaryTest): 32 """Tests to verify kernel binder. 33 34 Attributes: 35 _dut: AndroidDevice, the device under test. 36 _is_32: boolean, whether CONFIG_ANDROID_BINDER_IPC_32BIT=y. 37 _BINDER_IPC_32BIT_LINE: the line enabling 32-bit binder interface in 38 kernel config. 39 _TAG_IPC32: the tag on 32-bit binder interface tests. 40 _TAG_IPC64: the tag on 64-bit binder interface tests. 41 """ 42 _BINDER_IPC_32BIT_LINE = "CONFIG_ANDROID_BINDER_IPC_32BIT=y\n" 43 _TAG_IPC32 = "_IPC32_" 44 _TAG_IPC64 = "_IPC64_" 45 46 # @Override 47 def setUpClass(self): 48 """Checks if binder interface is 32-bit.""" 49 super(VtsKernelBinderTest, self).setUpClass() 50 self._is_32 = None 51 with tempfile.NamedTemporaryFile(delete=False) as temp_file: 52 config_path = temp_file.name 53 try: 54 logging.info("Pull config.gz to %s", config_path) 55 self._dut.adb.pull("/proc/config.gz", config_path) 56 with gzip.GzipFile(config_path) as config_file: 57 self._is_32 = (self._BINDER_IPC_32BIT_LINE in config_file) 58 except (adb.AdbError, IOError) as e: 59 logging.exception("Cannot read kernel config. Both 32 and 64-bit " 60 "binder interface tests will be executed: %s", e) 61 finally: 62 os.remove(config_path) 63 logging.info("BINDER_IPC_32BIT = %s", self._is_32) 64 65 # @Override 66 def RunTestCase(self, test_case): 67 """Runs the test case corresponding to binder bitness. 68 69 Args: 70 test_case: GtestTestCase object 71 """ 72 asserts.skipIf((self._TAG_IPC32 in test_case.tag and 73 self._is_32 == False), 74 "Skip tests for 32-bit binder interface.") 75 asserts.skipIf(self._TAG_IPC64 in test_case.tag and self._is_32, 76 "Skip tests for 64-bit binder interface.") 77 super(VtsKernelBinderTest, self).RunTestCase(test_case) 78 79 80if __name__ == "__main__": 81 test_runner.main() 82