graphics_Drm: refactor test status.

1) Check failures in more ways and try to provide a good string to wmatrix.
2) Run all tests as part of bvt-perbuild.
3) Tag all tests after all. This will make it easier to diff across boards
   on wmatrix.

BUG=chromium:654131
TEST=test_that $DUT graphics_Drm.atomictest

Change-Id: I203e49d0a1765fe2bc77169c38191f2d3be23bef
Reviewed-on: https://chromium-review.googlesource.com/409036
Commit-Ready: Ilja H. Friedel <ihf@chromium.org>
Tested-by: Ilja H. Friedel <ihf@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
diff --git a/client/site_tests/graphics_Drm/control.atomictest b/client/site_tests/graphics_Drm/control.atomictest
index f5f9a20..20b09c9 100644
--- a/client/site_tests/graphics_Drm/control.atomictest
+++ b/client/site_tests/graphics_Drm/control.atomictest
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs atomictest.
 """
 
-job.run_test('graphics_Drm', cmd='atomictest')
+job.run_test('graphics_Drm', tag='atomictest', cmd='atomictest')
diff --git a/client/site_tests/graphics_Drm/control.drm_cursor_test b/client/site_tests/graphics_Drm/control.drm_cursor_test
index d454e8f..0557c48 100644
--- a/client/site_tests/graphics_Drm/control.drm_cursor_test
+++ b/client/site_tests/graphics_Drm/control.drm_cursor_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs drm_cursor_test.
 """
 
-job.run_test('graphics_Drm', cmd='drm_cursor_test')
+job.run_test('graphics_Drm', tag='drm_cursor_test', cmd='drm_cursor_test')
diff --git a/client/site_tests/graphics_Drm/control.gamma_test b/client/site_tests/graphics_Drm/control.gamma_test
index 0e3a27f..d122845 100644
--- a/client/site_tests/graphics_Drm/control.gamma_test
+++ b/client/site_tests/graphics_Drm/control.gamma_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs gamma_test.
 """
 
-job.run_test('graphics_Drm', cmd='gamma_test')
+job.run_test('graphics_Drm', tag='gamma_test', cmd='gamma_test')
diff --git a/client/site_tests/graphics_Drm/control.linear_bo_test b/client/site_tests/graphics_Drm/control.linear_bo_test
index 523e7e4..f5c0fc0 100644
--- a/client/site_tests/graphics_Drm/control.linear_bo_test
+++ b/client/site_tests/graphics_Drm/control.linear_bo_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs linear_bo_test.
 """
 
-job.run_test('graphics_Drm', cmd='linear_bo_test')
+job.run_test('graphics_Drm', tag='linear_bo_test', cmd='linear_bo_test')
diff --git a/client/site_tests/graphics_Drm/control.null_platform_test b/client/site_tests/graphics_Drm/control.null_platform_test
index a17af32..319bf7a 100644
--- a/client/site_tests/graphics_Drm/control.null_platform_test
+++ b/client/site_tests/graphics_Drm/control.null_platform_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs null_platform_test.
 """
 
-job.run_test('graphics_Drm', cmd='null_platform_test')
+job.run_test('graphics_Drm', tag='null_platform_test', cmd='null_platform_test')
diff --git a/client/site_tests/graphics_Drm/control.swrast_test b/client/site_tests/graphics_Drm/control.swrast_test
index 622f45a..0aeee6a 100644
--- a/client/site_tests/graphics_Drm/control.swrast_test
+++ b/client/site_tests/graphics_Drm/control.swrast_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs swrast_test.
 """
 
-job.run_test('graphics_Drm', cmd='swrast_test')
+job.run_test('graphics_Drm', tag='swrast_test', cmd='swrast_test')
diff --git a/client/site_tests/graphics_Drm/control.vgem_fb_test b/client/site_tests/graphics_Drm/control.vgem_fb_test
index 8c2f4a5..7826fe6 100644
--- a/client/site_tests/graphics_Drm/control.vgem_fb_test
+++ b/client/site_tests/graphics_Drm/control.vgem_fb_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs vgem_fb_test.
 """
 
-job.run_test('graphics_Drm', cmd='vgem_fb_test')
+job.run_test('graphics_Drm', tag='vgem_fb_test', cmd='vgem_fb_test')
diff --git a/client/site_tests/graphics_Drm/control.vgem_test b/client/site_tests/graphics_Drm/control.vgem_test
index bbd160d..9821c9b 100644
--- a/client/site_tests/graphics_Drm/control.vgem_test
+++ b/client/site_tests/graphics_Drm/control.vgem_test
@@ -8,7 +8,7 @@
 CRITERIA = """
 Runs drm-tests. All tests must run without error.
 """
-ATTRIBUTES = 'suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
+ATTRIBUTES = 'suite:bvt-perbuild, suite:graphics_per-day, suite:drm, suite:graphics, suite:graphics_system'
 TIME='FAST'
 TEST_CATEGORY = 'Functional'
 TEST_CLASS = "gl"
@@ -21,4 +21,4 @@
 Runs vgem_test.
 """
 
-job.run_test('graphics_Drm', cmd='vgem_test')
+job.run_test('graphics_Drm', tag='vgem_test', cmd='vgem_test')
diff --git a/client/site_tests/graphics_Drm/graphics_Drm.py b/client/site_tests/graphics_Drm/graphics_Drm.py
index fadbb27..2e7ee76 100644
--- a/client/site_tests/graphics_Drm/graphics_Drm.py
+++ b/client/site_tests/graphics_Drm/graphics_Drm.py
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 from autotest_lib.client.bin import test
+from autotest_lib.client.common_lib import error
 from autotest_lib.client.common_lib import utils
 from autotest_lib.client.cros import service_stopper
 from autotest_lib.client.cros.graphics import graphics_utils
@@ -14,6 +15,7 @@
     version = 1
     GSC = None
     _services = None
+    _timeout = 120
 
     def initialize(self):
         self.GSC = graphics_utils.GraphicsStateChecker()
@@ -28,7 +30,31 @@
     def run_once(self, cmd, stop_ui=True):
         if stop_ui:
             self._services.stop_services()
-        utils.run(cmd,
-                  stderr_is_expected=False,
-                  stdout_tee=utils.TEE_TO_LOGS,
-                  stderr_tee=utils.TEE_TO_LOGS)
+        try:
+            result = utils.run(cmd,
+                               timeout=self._timeout,
+                               ignore_status=True,
+                               stderr_is_expected=True,
+                               verbose=True,
+                               stdout_tee=utils.TEE_TO_LOGS,
+                               stderr_tee=utils.TEE_TO_LOGS)
+        except Exception:
+            # Fail on exceptions.
+            raise error.TestFail('Failed: Exception running %s' % cmd)
+
+        # Fail on any stderr with first line of stderr for triage.
+        if result.stderr:
+            raise error.TestFail('Failed: %s (%s)' %
+                                    (cmd, result.stderr.splitlines()[0]))
+
+        # Fail on fishy output with said output for triage.
+        stdout = result.stdout.lower()
+        if 'fail' in stdout or 'error' in stdout:
+            for line in result.stdout.splitlines():
+                if 'fail' in line.lower() or 'error' in line.lower():
+                    raise error.TestFail('Failed: %s (%s)' % (cmd, line))
+
+        # Last but not least check return code and use it for triage.
+        if result.exit_status != 0:
+            raise error.TestFail('Failed: %s (exit=%d)' %
+                                    (cmd, result.exit_status))