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 vts.testcases.kernel.api.proc import KernelProcFileTestBase 18 19from vts.utils.python.file import file_utils 20 21 22class ProcKptrRestrictTest(KernelProcFileTestBase.KernelProcFileTestBase): 23 '''/proc/sys/kernel/kptr_restrict determines whether kernel pointers are printed 24 in proc files. 25 ''' 26 27 def parse_contents(self, contents): 28 return self.parse_line("{:d}\n", contents)[0] 29 30 def result_correct(self, result): 31 return result >= 0 and result <= 4 32 33 def get_path(self): 34 return "/proc/sys/kernel/kptr_restrict" 35 36 def get_permission_checker(self): 37 """Get r/w file permission checker. 38 """ 39 return file_utils.IsReadWrite 40 41 42class ProcRandomizeVaSpaceTest(KernelProcFileTestBase.KernelProcFileTestBase): 43 '''/proc/sys/kernel/randomize_va_space determines the address layout randomization 44 policy for the system. 45 ''' 46 47 def parse_contents(self, contents): 48 return self.parse_line("{:d}\n", contents)[0] 49 50 def result_correct(self, result): 51 return result >= 0 and result <= 2 52 53 def get_path(self): 54 return "/proc/sys/kernel/randomize_va_space" 55 56 def get_permission_checker(self): 57 """Get r/w file permission checker. 58 """ 59 return file_utils.IsReadWrite 60 61 62class ProcOverCommitMemoryTest(KernelProcFileTestBase.KernelProcFileTestBase): 63 '''/proc/sys/vm/overcommit_memory determines the kernel virtual memory accounting mode. 64 ''' 65 66 def parse_contents(self, contents): 67 return self.parse_line("{:d}\n", contents)[0] 68 69 def result_correct(self, result): 70 return result >= 0 and result <= 2 71 72 def get_path(self): 73 return "/proc/sys/vm/overcommit_memory" 74 75 def get_permission_checker(self): 76 """Get r/w file permission checker. 77 """ 78 return file_utils.IsReadWrite 79 80 81class ProcMmapMinAddrTest(KernelProcFileTestBase.KernelProcFileTestBase): 82 '''/proc/sys/vm/mmap_min_addr specifies the minimum address that can be mmap'd. 83 ''' 84 85 def parse_contents(self, contents): 86 return self.parse_line("{:d}\n", contents)[0] 87 88 def get_path(self): 89 return "/proc/sys/vm/mmap_min_addr" 90 91 def get_permission_checker(self): 92 """Get r/w file permission checker. 93 """ 94 return file_utils.IsReadWrite 95 96 97class ProcMmapRndBitsTest(KernelProcFileTestBase.KernelProcFileTestBase): 98 '''/proc/sys/vm/mmap_rnd_(compat_)bits specifies the amount of randomness in mmap'd 99 addresses. Must be >= 8. 100 ''' 101 102 def parse_contents(self, contents): 103 return self.parse_line("{:d}\n", contents)[0] 104 105 def result_correct(self, result): 106 return result >= 8 107 108 def get_path(self): 109 return "/proc/sys/vm/mmap_rnd_bits" 110 111 def get_permission_checker(self): 112 """Get r/w file permission checker. 113 """ 114 return file_utils.IsReadWrite 115 116 117class ProcMmapRndCompatBitsTest(ProcMmapRndBitsTest): 118 def get_path(self): 119 return "/proc/sys/vm/mmap_rnd_compat_bits" 120