cheets_CTS/GTS: Clean crash logs before running media tests.

~3GB of free disk space is required to push all test assests
for CTS media tests. The requirement is very tight for 16GB
storage devices like Octoups.Fleex. To ensure the room, this
CL cleans up the crash logs (occupying 1GB ~ 2GB of DUTs
storage quite often in the lab) before test execution.

BUG=b:156075084
TEST=cheets_CTS_P.9.0_r12.arm.CtsMediaStressTestCases

Change-Id: Ia8af1688f1649a03e442151b38bc84def364a719
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2280758
Tested-by: Kazuhiro Inaba <kinaba@chromium.org>
Commit-Queue: Kazuhiro Inaba <kinaba@chromium.org>
Auto-Submit: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Shao-Chuan Lee <shaochuan@chromium.org>
diff --git a/server/cros/tradefed/tradefed_test.py b/server/cros/tradefed/tradefed_test.py
index 7201ccb..35f3bf1 100644
--- a/server/cros/tradefed/tradefed_test.py
+++ b/server/cros/tradefed/tradefed_test.py
@@ -913,6 +913,12 @@
             logging.warning('Failed to restore powerd policy, overrided policy '
                             'will persist until device reboot.')
 
+    def _clean_crash_logs(self):
+        try:
+            self._run_commands(['rm -f /home/chronos/crash/*'])
+        except (error.AutoservRunError, error.AutoservSSHTimeout):
+            logging.warning('Failed to clean up crash logs.')
+
     def _run_and_parse_tradefed(self, command):
         """Kick off the tradefed command.
 
@@ -1202,9 +1208,13 @@
                 #              not-excecuted, for instance, by collecting all
                 #              tests on startup (very expensive, may take 30
                 #              minutes).
-                # TODO(b/137917339): Only prevent screen from turning off for
-                # media tests. Remove this check once the GPU issue is fixed.
                 if media_asset and media_asset.uri:
+                    # Clean-up crash logs from previous sessions to ensure
+                    # enough disk space for 16GB storage devices: b/156075084.
+                    if not keep_media:
+                        self._clean_crash_logs()
+                    # TODO(b/137917339): Only prevent screen from turning off for
+                    # media tests. Remove this check once the GPU issue is fixed.
                     self._override_powerd_prefs()
                 try:
                     waived_tests, acc = self._run_and_parse_tradefed(command)