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 import logging 19 20 from vts.runners.host import asserts 21 from vts.runners.host import base_test 22 from vts.runners.host import const 23 from vts.runners.host import test_runner 24 from vts.utils.python.controllers import android_device 25 import re 26 27 28 class MemorySystemStressTest(base_test.BaseTestClass): 29 """Userspace Memory Stress Test.""" 30 _mem = 64 31 _DURATION_SEC = 300 32 _STRESSAPPTEST = '/data/local/tmp/32/stressapptest' 33 34 def setUpClass(self): 35 self.dut = self.android_devices[0] 36 37 # Set executable bit on stressapptest binary 38 self.shell = self.dut.shell 39 cmd = ['chmod +x', str(self._STRESSAPPTEST)] 40 self.shell.Execute(' '.join(cmd)) 41 42 # Read /proc/meminfo to read MemFree; use MemFree as total memory under 43 # test 44 meminfo_results = self.shell.Execute("cat /proc/meminfo") 45 matched = re.search(r'MemFree:\s+(\d+)', str(meminfo_results[const.STDOUT])) 46 if matched: 47 self._mem = int(matched.groups()[0]) / 1024 48 self._mem = max(self._mem, 64) # Minimum 64M memory under test 49 self._mem = min(self._mem, 1280) # Maximum 1280M memory under test 50 51 def testMemory32bit(self): 52 """Memory Test using stressapptest.""" 53 54 # Compose stressapptest command to execute for memory test 55 cmd = [str(self._STRESSAPPTEST), '-W ' '-M', str(self._mem), '-s', str(self._DURATION_SEC)] 56 logging.info(cmd) 57 results = self.shell.Execute(' '.join(cmd)) 58 logging.info(str(results[const.STDOUT])) 59 60 # Check for 'PASS' and exit code 61 asserts.assertTrue('Status: PASS' in results[const.STDOUT][0].strip(), "Memory test failed.") 62 63 if __name__ == "__main__": 64 test_runner.main() 65