Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: client/site_tests/logging_LogVolume/logging_LogVolume.py

Issue 1213005: Add test to check stateful partition contents (Closed)
Patch Set: use site_ui_test, add a few files, rename wait_for_login, and remove trailing spaces Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/site_tests/logging_LogVolume/logging_LogVolume.py
diff --git a/client/site_tests/logging_LogVolume/logging_LogVolume.py b/client/site_tests/logging_LogVolume/logging_LogVolume.py
new file mode 100644
index 0000000000000000000000000000000000000000..6d66538dc6c5fab678446d782b2bc7801bdd74a7
--- /dev/null
+++ b/client/site_tests/logging_LogVolume/logging_LogVolume.py
@@ -0,0 +1,79 @@
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging, os, re, subprocess, utils
+from autotest_lib.client.bin import site_login, site_ui_test, test
+from autotest_lib.client.common_lib import error
+
+
+class logging_LogVolume(site_ui_test.UITest):
+ version = 1
+
+
+ def log_stateful_used(self):
+ output = utils.system_output('df /mnt/stateful_partition/')
+ matches = re.search('(\d+)%', output)
+ if matches is None:
+ error.TestError('df failed')
+ self._perf['percent_stateful_used'] = int(matches.group(1))
+
+
+ def run_once(self):
+ if not site_login.wait_for_cryptohome():
+ raise error.TestFail('Could not wait for crytohome')
+
+ self._perf = {}
+ self.log_stateful_used()
+ whitelist = open(os.path.join(self.bindir,
+ 'stateful_whitelist.txt'))
+ patterns = {}
+ for pattern in whitelist.readlines():
+ pattern = pattern.strip()
+ if pattern == '' or pattern[0] == '#':
+ continue
+ if pattern in patterns:
+ logging.error('Duplicate pattern in file: %s' % pattern)
+ patterns[pattern] = {
+ 'regexp': re.compile(pattern + '$'),
+ 'count': 0
+ }
+
+ find_handle = subprocess.Popen(['find',
+ '/mnt/stateful_partition'],
+ stdout=subprocess.PIPE)
+ stateful_files = 0
+ # Count number of files that were found but were not whitelisted.
+ unexpected_files = 0
+ for filename in find_handle.stdout.readlines():
+ filename = filename.strip()[len('/mnt/stateful_partition'):]
+ if filename == '':
+ continue
+ stateful_files += 1
+ match = False
+ for pattern in patterns:
+ regexp = patterns[pattern]['regexp']
+ if regexp.match(filename):
+ match = True
+ patterns[pattern]['count'] += 1
+ break
+ if not match:
+ logging.error('Unexpected file %s' % filename)
+ unexpected_files += 1
+
+ unmatched_patterns = 0
+ for pattern in patterns:
+ if patterns[pattern]['count'] == 0:
+ logging.warn('No files matched: %s' % pattern)
+ unmatched_patterns += 1
+
+ self._perf['percent_unused_patterns'] = \
+ int(100 * unmatched_patterns / len(patterns))
+
+ self._perf['files_in_stateful_partition'] = stateful_files
+
+ self.write_perf_keyval(self._perf)
+
+ if unexpected_files > 0:
+ raise error.TestError('There were %d unexpected files' %
+ unexpected_files)
« no previous file with comments | « client/site_tests/logging_LogVolume/control ('k') | client/site_tests/logging_LogVolume/stateful_whitelist.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698