From 93f1e7c21364b36fd0ec7e97a20e0f1bb14c7add Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Tue, 28 Apr 2020 10:26:33 +0800 Subject: Remove vts_vndk_open_libraries_test The test requires LLNDK dependency list that the build system doesn't automatically generate. The list needs to be updated with LLNDK changes, but is only used by this test. We decided to remove the test in order to reduce maintenance cost. Test: vts-tradefed run vts --include-filter vts_vndk_open_libraries_test Bug: 154335335 Change-Id: I9df27a886e38fcad7b2e6187d43314b5c9eaf522 Merged-In: I9df27a886e38fcad7b2e6187d43314b5c9eaf522 (cherry picked from commit 180b978ccaae8a9ebb3e2f357a3e7883d7d92403) --- Android.bp | 13 -- golden/vndk_data.py | 4 - open_libraries/Android.bp | 19 --- open_libraries/AndroidTest.xml | 27 ---- open_libraries/VtsVndkOpenLibrariesTest.py | 143 --------------------- open_libraries/__init__.py | 0 open_libraries/vts_vndk_open_libraries_test.py | 164 ------------------------ open_libraries/vts_vndk_open_libraries_test.xml | 23 ---- 8 files changed, 393 deletions(-) delete mode 100644 open_libraries/Android.bp delete mode 100644 open_libraries/AndroidTest.xml delete mode 100644 open_libraries/VtsVndkOpenLibrariesTest.py delete mode 100644 open_libraries/__init__.py delete mode 100644 open_libraries/vts_vndk_open_libraries_test.py delete mode 100644 open_libraries/vts_vndk_open_libraries_test.xml diff --git a/Android.bp b/Android.bp index 3d8ab5a..dd7852f 100644 --- a/Android.bp +++ b/Android.bp @@ -91,16 +91,3 @@ python_test_host { ], test_config: "files/vts_vndk_files_test.xml", } - -python_test_host { - name: "vts_vndk_open_libraries_test", - defaults: ["vts_vndk_default"], - main: "open_libraries/vts_vndk_open_libraries_test.py", - srcs: [ - "open_libraries/vts_vndk_open_libraries_test.py", - ], - test_suites: [ - "vts", - ], - test_config: "open_libraries/vts_vndk_open_libraries_test.xml", -} diff --git a/golden/vndk_data.py b/golden/vndk_data.py index ffa1527..5e971aa 100644 --- a/golden/vndk_data.py +++ b/golden/vndk_data.py @@ -30,9 +30,6 @@ except ImportError: # Low-level NDK libraries that can be used by framework and vendor modules. LL_NDK = "LLNDK" -# LL-NDK dependencies that vendor modules cannot directly access. -LL_NDK_PRIVATE = "LLNDK-private" - # Same-process HAL implementation in vendor partition. SP_HAL = "SP-HAL" @@ -220,7 +217,6 @@ def _LoadVndkLibraryListsFile(vndk_lists, tags, vndk_lib_list_file): # Compute VNDK-core-private and VNDK-SP-private. private = lib_sets.get('VNDK-private', set()) - lib_sets[LL_NDK_PRIVATE].update(lib_sets[LL_NDK] & private) lib_sets[VNDK_PRIVATE].update(lib_sets[VNDK] & private) lib_sets[VNDK_SP_PRIVATE].update(lib_sets[VNDK_SP] & private) diff --git a/open_libraries/Android.bp b/open_libraries/Android.bp deleted file mode 100644 index 8fd540f..0000000 --- a/open_libraries/Android.bp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (C) 2017 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. -// - -vts_config { - name: "VtsVndkOpenLibraries", -} diff --git a/open_libraries/AndroidTest.xml b/open_libraries/AndroidTest.xml deleted file mode 100644 index 0aee080..0000000 --- a/open_libraries/AndroidTest.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - diff --git a/open_libraries/VtsVndkOpenLibrariesTest.py b/open_libraries/VtsVndkOpenLibrariesTest.py deleted file mode 100644 index a6b066d..0000000 --- a/open_libraries/VtsVndkOpenLibrariesTest.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2017 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. -# - -import logging - -from vts.runners.host import asserts -from vts.runners.host import base_test -from vts.runners.host import const -from vts.runners.host import keys -from vts.runners.host import test_runner -from vts.testcases.vndk.golden import vndk_data -from vts.utils.python.os import path_utils -from vts.utils.python.vndk import vndk_utils - - -class VtsVndkOpenLibrariesTest(base_test.BaseTestClass): - """A test module to verify libraries opened by running processes. - - Attributes: - data_file_path: The path to VTS data directory. - _dut: The AndroidDevice under test. - _shell: The ShellMirrorObject to execute commands - """ - - def setUpClass(self): - """Initializes the data file path and shell.""" - required_params = [keys.ConfigKeys.IKEY_DATA_FILE_PATH] - self.getUserParams(required_params) - self._dut = self.android_devices[0] - self._shell = self._dut.shell - - def _ListProcessCommands(self, cmd_filter): - """Finds current processes whose commands match the filter. - - Args: - cmd_filter: A function that takes a binary file path as argument and - returns whether the path matches the condition. - - Returns: - A dict of {pid: command} where pid and command are strings. - """ - result = self._shell.Execute("ps -Aw -o PID,COMMAND") - asserts.assertEqual(result[const.EXIT_CODE][0], 0) - lines = result[const.STDOUT][0].split("\n") - pid_end = lines[0].index("PID") + len("PID") - cmd_begin = lines[0].index("COMMAND", pid_end) - cmds = {} - for line in lines[1:]: - cmd = line[cmd_begin:] - if not cmd_filter(cmd): - continue - pid = line[:pid_end].lstrip() - cmds[pid] = cmd - return cmds - - def _ListOpenFiles(self, pids, file_filter): - """Finds open files whose names match the filter. - - Args: - pids: A collection of strings, the PIDs to list open files. - file_filter: A function that takes a file path as argument and - returns whether the path matches the condition. - - Returns: - A dict of {pid: [file, ...]} where pid and file are strings. - """ - lsof_cmd = "lsof -p " + ",".join(pids) - result = self._shell.Execute(lsof_cmd) - asserts.assertEqual(result[const.EXIT_CODE][0], 0) - lines = result[const.STDOUT][0].split("\n") - pid_end = lines[0].index("PID") + len("PID") - name_begin = lines[0].index("NAME") - files = {} - for line in lines[1:]: - name = line[name_begin:] - if not file_filter(name): - continue - pid_begin = line.rindex(" ", 0, pid_end) + 1 - pid = line[pid_begin:pid_end] - if pid in files: - files[pid].append(name) - else: - files[pid] = [name] - return files - - def testVendorProcessOpenLibraries(self): - """Checks if vendor processes load shared libraries on system.""" - asserts.skipIf(not vndk_utils.IsVndkRuntimeEnforced(self._dut), - "VNDK runtime is not enforced on the device.") - vndk_lists = vndk_data.LoadVndkLibraryLists( - self.data_file_path, - self._dut.vndk_version, - vndk_data.LL_NDK, - vndk_data.LL_NDK_PRIVATE, - vndk_data.VNDK, - vndk_data.VNDK_PRIVATE, - vndk_data.VNDK_SP, - vndk_data.VNDK_SP_PRIVATE) - asserts.assertTrue(vndk_lists, "Cannot load VNDK library lists.") - allowed_libs = set().union(*vndk_lists) - logging.debug("Allowed system libraries: %s", allowed_libs) - - asserts.assertTrue(self._dut.isAdbRoot, - "Must be root to find all libraries in use.") - cmds = self._ListProcessCommands(lambda x: (x.startswith("/odm/") or - x.startswith("/vendor/"))) - - def _IsDisallowedSystemLib(lib_path): - return ((lib_path.startswith("/system/") or - lib_path.startswith("/apex/")) and - lib_path.endswith(".so") and - path_utils.TargetBaseName(lib_path) not in allowed_libs) - - deps = self._ListOpenFiles(cmds.keys(), _IsDisallowedSystemLib) - if deps: - error_lines = ["%s %s %s" % (pid, cmds[pid], libs) - for pid, libs in deps.iteritems()] - logging.error("pid command libraries\n%s", "\n".join(error_lines)) - - assert_lines = ["pid command libraries"] + error_lines[:20] - if len(deps) > 20: - assert_lines.append("...") - assert_lines.append("Number of vendor processes using system " - "libraries: " + str(len(deps))) - asserts.fail("\n".join(assert_lines)) - - -if __name__ == "__main__": - test_runner.main() diff --git a/open_libraries/__init__.py b/open_libraries/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/open_libraries/vts_vndk_open_libraries_test.py b/open_libraries/vts_vndk_open_libraries_test.py deleted file mode 100644 index b238142..0000000 --- a/open_libraries/vts_vndk_open_libraries_test.py +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env python3 -# -# 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. -# - -import logging -import os -import posixpath as target_path_module -import re -import unittest - -from vts.testcases.vndk import utils -from vts.testcases.vndk.golden import vndk_data -from vts.utils.python.vndk import vndk_utils - - -class VtsVndkOpenLibrariesTest(unittest.TestCase): - """A test module to verify libraries opened by running processes. - - Attributes: - _dut: The AndroidDevice under test. - """ - - def setUp(self): - """Initializes attributes.""" - serial_number = os.environ.get("ANDROID_SERIAL") - self.assertTrue(serial_number, "$ANDROID_SERIAL is empty.") - self._dut = utils.AndroidDevice(serial_number) - - def _ListProcessCommands(self, cmd_filter): - """Finds current processes whose commands match the filter. - - Args: - cmd_filter: A function that takes a binary file path as argument - and returns whether the path matches the condition. - - Returns: - A dict of {pid: command} where pid and command are strings. - """ - ps_cmd = ["ps", "-Aw", "-o", "PID,COMMAND"] - out, err, return_code = self._dut.Execute(*ps_cmd) - if err.strip(): - logging.info("`%s` stderr: %s", " ".join(ps_cmd), err) - self.assertEqual(return_code, 0) - - lines = out.split("\n") - pid_end = lines[0].index("PID") + len("PID") - cmd_begin = lines[0].index("COMMAND", pid_end) - cmds = {} - for line in lines[1:]: - cmd = line[cmd_begin:] - if not cmd_filter(cmd): - continue - pid = line[:pid_end].lstrip() - cmds[pid] = cmd - return cmds - - def _ListOpenFiles(self, pids, file_filter): - """Finds open files whose names match the filter. - - Args: - pids: A collection of strings, the PIDs to list open files. - file_filter: A function that takes a file path as argument and - returns whether the path matches the condition. - - Returns: - A dict of {pid: [file, ...]} where pid and file are strings. - """ - lsof_cmd = ["lsof", "-p", ",".join(pids)] - out, err, return_code = self._dut.Execute(*lsof_cmd) - if err.strip(): - logging.info("`%s` stderr: %s", " ".join(lsof), err) - self.assertEqual(return_code, 0) - # The first line consists of the column names: - # COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME - # PID is right-justified. NAME is left-justified. - lines = out.split("\n") - pid_end = lines[0].index("PID") + len("PID") - name_begin = lines[0].index("NAME") - files = {} - for line in lines[1:]: - if not line.strip(): - continue - # On Android, COMMAND may exceed the column and causes the right - # columns to be misaligned. This program looks for digits in the - # PID column or on the right of the column. - try: - match_pid = next(match for match in - re.finditer(r"\s(\d+)\s", line) if - match.end(1) >= pid_end) - except StopIteration: - self.fail("Cannot parse PID from lsof output: " + line) - offset = match_pid.end(1) - pid_end - self.assertEqual(line[name_begin + offset - 1], " ", - "Cannot parse NAME from lsof output: " + line) - name = line[name_begin + offset:] - if not file_filter(name): - continue - pid = match_pid.group(1) - if pid in files: - files[pid].append(name) - else: - files[pid] = [name] - return files - - def testVendorProcessOpenLibraries(self): - """Checks if vendor processes load shared libraries on system.""" - if not vndk_utils.IsVndkRuntimeEnforced(self._dut): - logging.info("Skip the test as VNDK runtime is not enforced on " - "the device.") - return - vndk_lists = vndk_data.LoadVndkLibraryListsFromResources( - self._dut.GetVndkVersion(), - vndk_data.LL_NDK, - vndk_data.LL_NDK_PRIVATE, - vndk_data.VNDK, - vndk_data.VNDK_PRIVATE, - vndk_data.VNDK_SP, - vndk_data.VNDK_SP_PRIVATE) - self.assertTrue(vndk_lists, "Cannot load VNDK library lists.") - allowed_libs = set().union(*vndk_lists) - logging.debug("Allowed system libraries: %s", allowed_libs) - - self.assertTrue(self._dut.IsRoot(), - "Must be root to find all libraries in use.") - cmds = self._ListProcessCommands(lambda x: (x.startswith("/odm/") or - x.startswith("/vendor/"))) - - def _IsDisallowedSystemLib(lib_path): - return ((lib_path.startswith("/system/") or - lib_path.startswith("/apex/")) and - lib_path.endswith(".so") and - target_path_module.basename(lib_path) not in allowed_libs) - - deps = self._ListOpenFiles(cmds.keys(), _IsDisallowedSystemLib) - if deps: - error_lines = ["%s %s %s" % (pid, cmds[pid], libs) - for pid, libs in deps.items()] - logging.error("pid command libraries\n%s", "\n".join(error_lines)) - - assert_lines = ["pid command libraries"] + error_lines[:20] - if len(deps) > 20: - assert_lines.append("...") - assert_lines.append("Number of vendor processes using system " - "libraries: " + str(len(deps))) - self.fail("\n".join(assert_lines)) - - -if __name__ == "__main__": - # Setting verbosity is required to generate output that the TradeFed test - # runner can parse. - unittest.main(verbosity=3) diff --git a/open_libraries/vts_vndk_open_libraries_test.xml b/open_libraries/vts_vndk_open_libraries_test.xml deleted file mode 100644 index 664f60e..0000000 --- a/open_libraries/vts_vndk_open_libraries_test.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - -- cgit v1.2.3