component_UpdateFlash: Check for clean shutdown.

This updates the component_UpdateFlash check to test for clean
shutdown. The bug causing the dangling reference counts on unmount only
occurs if the UI actually loads and uses the flash library, so this case
needs to be checked in the actual component flash test.

BUG=chromium:779273
TEST=emerge-${BOARD} autotest-tests

Change-Id: I6d2cafe19e673e4df179a04f609a0b80af51f27d
Reviewed-on: https://chromium-review.googlesource.com/756321
Commit-Ready: Greg Kerr <kerrnel@chromium.org>
Tested-by: Greg Kerr <kerrnel@chromium.org>
Reviewed-by: Ilja H. Friedel <ihf@chromium.org>
(cherry picked from commit cfad09c264a82047e52e0a8a260d6dba8f029ff9)
Reviewed-on: https://chromium-review.googlesource.com/764728
Tested-by: Ilja H. Friedel <ihf@chromium.org>
(cherry picked from commit 6a9e518b3ffafc9b4892d0656b288042f277ce87)
Reviewed-on: https://chromium-review.googlesource.com/764729
diff --git a/client/site_tests/platform_CleanShutdown/control b/client/site_tests/platform_CleanShutdown/control
index 6505f00..60ecc40 100644
--- a/client/site_tests/platform_CleanShutdown/control
+++ b/client/site_tests/platform_CleanShutdown/control
@@ -10,10 +10,7 @@
 NAME = 'platform_CleanShutdown'
 PURPOSE = 'Verify the last shutdown was clean.'
 CRITERiA = """
-Fails if any of the following conditions are present:
-  - unmount failure in cyptohome
-  - unmount failure of the stateful partition
-  - if shutdown had to forcefully kill processes
+Fails if the stateful partition was not cleanly unmounted on the last shutdown.
 """
 TEST_CLASS = 'platform'
 TEST_CATEGORY = 'Functional'
diff --git a/client/site_tests/platform_CleanShutdown/platform_CleanShutdown.py b/client/site_tests/platform_CleanShutdown/platform_CleanShutdown.py
index 1ad8c67..103abc2 100644
--- a/client/site_tests/platform_CleanShutdown/platform_CleanShutdown.py
+++ b/client/site_tests/platform_CleanShutdown/platform_CleanShutdown.py
@@ -1,66 +1,19 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Copyright 2017 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, time
-from autotest_lib.client.bin import test, utils
+import os
+from autotest_lib.client.bin import test
 from autotest_lib.client.common_lib import error
 
-
-PROCESS_WHITELIST = (
-    # TODO(dalecurtis): Remove once http://crosbug.com/15697 is fixed.
-    'cryptohom',
-    'chapsd',
-)
-
-SHUTDOWN_CRYPTOHOME_UMOUNT_FAIL = '/var/log/shutdown_cryptohome_umount_failure'
-SHUTDOWN_STATEFUL_UMOUNT_FAIL = '/var/log/shutdown_stateful_umount_failure'
-SHUTDOWN_KILLED_PROCESSES_LOG = '/var/log/shutdown_force_kill_processes'
-
+SHUTDOWN_STATEFUL_UMOUNT_FAIL = ('/mnt/stateful_partition/'
+                                 'shutdown_stateful_umount_failure')
 
 class platform_CleanShutdown(test.test):
+    """Checks for the presence of an unclean shutdown file."""
     version = 1
 
-
-    def _log_remove_if_exists(self, filename, message):
-        if not os.path.exists(filename):
-            return
-
-        contents = utils.read_file(filename).strip()
-        os.remove(filename)
-
-        if filename == SHUTDOWN_KILLED_PROCESSES_LOG:
-            # Remove all killed processes listed in the white list. An example
-            # log is included below:
-            #
-            #    COMMAND     PID    USER  FD   TYPE DEVICE SIZE/OFF   NODE NAME
-            #    cryptohom  [........]
-            #
-            filtered_contents = filter(
-                lambda line: not line.startswith(PROCESS_WHITELIST),
-                contents.splitlines())
-
-            # If there are no lines left but the header, return nothing.
-            if len(filtered_contents) <= 1:
-                return
-            else:
-                contents = '\n'.join(filtered_contents)
-
-        logging.error('Last shutdown problem: %s. Detailed output was:\n%s' %
-                      (message, contents))
-        self._errors.append(message)
-
-
     def run_once(self):
-        self._errors = []
-        # Problems during shutdown are brought out in /var/log files
-        # which we show here.
-        self._log_remove_if_exists(SHUTDOWN_CRYPTOHOME_UMOUNT_FAIL,
-                                   'cryptohome unmount failed')
-        self._log_remove_if_exists(SHUTDOWN_STATEFUL_UMOUNT_FAIL,
-                                   'stateful unmount failed')
-        self._log_remove_if_exists(SHUTDOWN_KILLED_PROCESSES_LOG,
-                                   'force killed processes')
-        if self._errors:
+        if os.path.exists(SHUTDOWN_STATEFUL_UMOUNT_FAIL):
             raise error.TestFail(
-                'Last shutdown problems: %s' % ' and '.join(self._errors))
+                '{} exists!'.format(SHUTDOWN_STATEFUL_UMOUNT_FAIL))
diff --git a/server/site_tests/component_UpdateFlash/component_UpdateFlash.py b/server/site_tests/component_UpdateFlash/component_UpdateFlash.py
index a845c63..5f6e378 100644
--- a/server/site_tests/component_UpdateFlash/component_UpdateFlash.py
+++ b/server/site_tests/component_UpdateFlash/component_UpdateFlash.py
@@ -10,6 +10,7 @@
 
 
 class component_UpdateFlash(test.test):
+    """Downloads, installs, and verifies component updated flash."""
     version = 1
 
     def _run_client_test(self, name, CU_action):
@@ -51,6 +52,14 @@
         self._run_client_test(
             'desktopui_FlashSanityCheck', CU_action='verify-system-flash')
 
+    def _verify_clean_shutdown(self):
+        """Verifies that the stateful partition was cleaned up on shutdown."""
+        try:
+            self.autotest_client.run_test('platform_CleanShutdown',
+                                          check_client_result=True)
+        except:
+            raise error.TestError('Failed: platform_CleanShutdown')
+
     def _reboot(self):
         """Reboot the DUT."""
         self.host.reboot()
@@ -78,3 +87,6 @@
         # Currently mounting the component binaries requires a reboot.
         self._reboot()
         self._verify_component_flash()
+        # Reboot again to see if a clean unmount happens.
+        self._reboot()
+        self._verify_clean_shutdown()