OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging, os, re, subprocess, utils |
| 6 from autotest_lib.client.bin import site_login, site_ui_test, test |
| 7 from autotest_lib.client.common_lib import error |
| 8 |
| 9 |
| 10 class logging_LogVolume(site_ui_test.UITest): |
| 11 version = 1 |
| 12 |
| 13 |
| 14 def log_stateful_used(self): |
| 15 output = utils.system_output('df /mnt/stateful_partition/') |
| 16 matches = re.search('(\d+)%', output) |
| 17 if matches is None: |
| 18 error.TestError('df failed') |
| 19 self._perf['percent_stateful_used'] = int(matches.group(1)) |
| 20 |
| 21 |
| 22 def run_once(self): |
| 23 if not site_login.wait_for_cryptohome(): |
| 24 raise error.TestFail('Could not wait for crytohome') |
| 25 |
| 26 self._perf = {} |
| 27 self.log_stateful_used() |
| 28 whitelist = open(os.path.join(self.bindir, |
| 29 'stateful_whitelist.txt')) |
| 30 patterns = {} |
| 31 for pattern in whitelist.readlines(): |
| 32 pattern = pattern.strip() |
| 33 if pattern == '' or pattern[0] == '#': |
| 34 continue |
| 35 if pattern in patterns: |
| 36 logging.error('Duplicate pattern in file: %s' % pattern) |
| 37 patterns[pattern] = { |
| 38 'regexp': re.compile(pattern + '$'), |
| 39 'count': 0 |
| 40 } |
| 41 |
| 42 find_handle = subprocess.Popen(['find', |
| 43 '/mnt/stateful_partition'], |
| 44 stdout=subprocess.PIPE) |
| 45 stateful_files = 0 |
| 46 # Count number of files that were found but were not whitelisted. |
| 47 unexpected_files = 0 |
| 48 for filename in find_handle.stdout.readlines(): |
| 49 filename = filename.strip()[len('/mnt/stateful_partition'):] |
| 50 if filename == '': |
| 51 continue |
| 52 stateful_files += 1 |
| 53 match = False |
| 54 for pattern in patterns: |
| 55 regexp = patterns[pattern]['regexp'] |
| 56 if regexp.match(filename): |
| 57 match = True |
| 58 patterns[pattern]['count'] += 1 |
| 59 break |
| 60 if not match: |
| 61 logging.error('Unexpected file %s' % filename) |
| 62 unexpected_files += 1 |
| 63 |
| 64 unmatched_patterns = 0 |
| 65 for pattern in patterns: |
| 66 if patterns[pattern]['count'] == 0: |
| 67 logging.warn('No files matched: %s' % pattern) |
| 68 unmatched_patterns += 1 |
| 69 |
| 70 self._perf['percent_unused_patterns'] = \ |
| 71 int(100 * unmatched_patterns / len(patterns)) |
| 72 |
| 73 self._perf['files_in_stateful_partition'] = stateful_files |
| 74 |
| 75 self.write_perf_keyval(self._perf) |
| 76 |
| 77 if unexpected_files > 0: |
| 78 raise error.TestError('There were %d unexpected files' % |
| 79 unexpected_files) |
OLD | NEW |