1# 2# Copyright (C) 2017 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 17import re 18from vts.utils.python.android import api 19from vts.testcases.kernel.api.proc import KernelProcFileTestBase 20 21 22class ProcModulesTest(KernelProcFileTestBase.KernelProcFileTestBase): 23 '''/proc/modules contains information about loaded kernel modules.''' 24 25 def prepare_test(self, shell, dut): 26 api_level = dut.getLaunchApiLevel(strict=False) 27 self.require_module = False 28 return True 29 30 def parse_contents(self, contents): 31 module_present = False 32 # MODULE_NAME SIZE REFERENCE_COUNT USER1,USER2, STATE BASE_ADDRESS TAINT_FLAG 33 # MODULE_NAME is a string 34 # SIZE is an integer 35 # REFERENCE_COUNT is an integer or - 36 # USER1,USER2, is a list of modules using this module with a trailing comma. 37 # If no modules are using this module or if modules cannot be unloaded then 38 # - will appear. If this mdoule cannot be unloaded then [permanent] will be 39 # the last entry. 40 # STATE is either Unloading, Loading, or Live 41 # BASE_ADDRESS is a memory address 42 # TAINT_FLAG is optional and if present, has characters between ( and ) 43 test_re = re.compile(r"^\w+ \d+ (\d+|-) (((\w+,)*(\[permanent\],)?)|-) (Unloading|Loading|Live) 0x[0-9a-f]+( \(\w+\))?") 44 for line in contents.splitlines(): 45 if not re.match(test_re, line): 46 raise SyntaxError("Malformed entry in /proc/modules: %s" % line) 47 else: 48 module_present = True 49 if self.require_module and not module_present: 50 raise SyntaxError("There must be at least one entry in /proc/modules") 51 52 return '' 53 54 def result_correct(self, parse_result): 55 return True 56 57 def get_path(self): 58 return "/proc/modules" 59