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 17from parse import with_pattern 18from vts.testcases.kernel.api.proc import KernelProcFileTestBase 19 20 21@with_pattern(r'[0-9a-f]{8,}') 22def token_addr(text): 23 return int(text, 16) 24 25@with_pattern(r'[0-9a-f]{2,5}') 26def token_mm(text): 27 return int(text, 16) 28 29@with_pattern(r'[0-9]+') 30def token_lu(text): 31 return int(text) 32 33@with_pattern(r'[^\n^\0]*') 34def token_path(text): 35 return text.strip() 36 37@with_pattern(r'[r-]') 38def token_rbit(text): 39 return text 40 41@with_pattern(r'[w-]') 42def token_wbit(text): 43 return text 44 45@with_pattern(r'[x-]') 46def token_xbit(text): 47 return text 48 49@with_pattern(r'[sp]') 50def token_spbit(text): 51 return text 52 53class ProcMapsTest(KernelProcFileTestBase.KernelProcFileTestBase): 54 '''/proc/self/maps provides currently mapped memory regions and permissions.''' 55 56 def parse_contents(self, contents): 57 result = [] 58 lines = contents.split('\n') 59 if lines[-1] != '': 60 raise SyntaxError("missing final newline") 61 for line in lines[:-1]: 62 parsed = self.parse_line( 63 "{:addr}-{:addr} {:rbit}{:wbit}{:xbit}{:spbit} {:addr} {:mm}:{:mm} {:lu}{:path}", 64 line, dict(mm=token_mm, addr=token_addr, lu=token_lu, path=token_path, 65 rbit=token_rbit, wbit=token_wbit, xbit=token_xbit, spbit=token_spbit)) 66 result.append(parsed) 67 return result 68 69 def get_path(self): 70 return "/proc/self/maps" 71