dut: Add DUT-aware 'DUTHooks' module to replace callback board APIs.
The board APIs for test callback (OnTestStart, OnTestFailure, ...) should have
the reference to DUT and is better to be managed in its own module.
This change moves them to self.dut.hooks so the error can be notified on DUT
more easily.
BUG=chromium:557573
TEST=make test
Change-Id: If7acc6ba5ffb9dca8b20eb4f4213ec3463eb47e3
Reviewed-on: https://chromium-review.googlesource.com/318394
Commit-Ready: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Wei-Han Chen <stimim@chromium.org>
diff --git a/py/goofy/goofy.py b/py/goofy/goofy.py
index 587e9cf..6d588d0 100755
--- a/py/goofy/goofy.py
+++ b/py/goofy/goofy.py
@@ -990,7 +990,7 @@
status_filter: List of available test states. Only run the tests which
states are in the list. Set to None if all test states are available.
"""
- system.GetBoard().OnTestStart()
+ self.dut.hooks.OnTestStart()
if type(subtrees) != list:
subtrees = [subtrees]
@@ -1616,7 +1616,7 @@
self.state_instance.set_shared_data('tests_after_shutdown', None)
self.restore_active_run_state()
- system.GetBoard().OnTestStart()
+ self.dut.hooks.OnTestStart()
self.may_disable_cros_shortcut_keys()
@@ -2074,7 +2074,7 @@
self.reap_completed_tests()
def test_fail(self, test):
- system.GetBoard().OnTestFailure(test)
+ self.dut.hooks.OnTestFailure(test)
if self.link_manager:
self.link_manager.UpdateStatus(False)
diff --git a/py/system/board/__init__.py b/py/system/board/__init__.py
index 8d505b1..eb01ea0 100644
--- a/py/system/board/__init__.py
+++ b/py/system/board/__init__.py
@@ -91,40 +91,3 @@
BoardException if board version cannot be obtained.
"""
raise NotImplementedError
-
- def OnTestStart(self):
- """Callback invoked when factory test starts.
-
- This method is called when goofy starts or when the operator
- starts a test manually. This can be used to light up a green
- LED or send a notification to a remote server.
- """
- pass
-
- def OnTestFailure(self, test):
- """Callback invoked when a test fails.
-
- This method can be used to bring the attention of the operators
- when a display is not available. For example, lightting up a red
- LED may help operators identify failing device on the run-in
- rack easily.
- """
- pass
-
- def OnSummaryGood(self):
- """Callback invoked when the test summary page shows and all test passed.
-
- This method can be used to notify the operator that a device has finished
- a test section, e.g. run-in. For example, lightting up a green LED here
- and the operators may be instructed to move all devices with a green LED
- to FATP testing.
- """
- pass
-
- def OnSummaryBad(self):
- """Callback invoked when the test summary page shows and some test failed.
-
- Similar to OnSummaryGood, but is used to notify the operator of failing
- test(s).
- """
- pass
diff --git a/py/test/dut/board.py b/py/test/dut/board.py
index 83224ce..91f7422 100644
--- a/py/test/dut/board.py
+++ b/py/test/dut/board.py
@@ -20,6 +20,7 @@
from cros.factory.test.dut import display
from cros.factory.test.dut import ec
from cros.factory.test.dut.links import utils as link_utils
+from cros.factory.test.dut import hooks
from cros.factory.test.dut import led
from cros.factory.test.dut import power
from cros.factory.test.dut import temp
@@ -95,6 +96,10 @@
return ec.EmbeddedController(self)
@DUTProperty
+ def hooks(self):
+ return hooks.DUTHooks(self)
+
+ @DUTProperty
def led(self):
return led.LED(self)
diff --git a/py/test/dut/hooks.py b/py/test/dut/hooks.py
new file mode 100644
index 0000000..17a090e
--- /dev/null
+++ b/py/test/dut/hooks.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+#
+# Copyright 2015 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 factory_common # pylint: disable=W0611
+from cros.factory.test.dut import component
+
+
+class DUTHooks(component.DUTComponent):
+ """Utility class managing device-specific callbacks."""
+
+ def OnTestStart(self):
+ """Callback invoked when factory test starts.
+
+ This method is called when goofy starts or when the operator
+ starts a test manually. This can be used to light up a green
+ LED or send a notification to a remote server.
+ """
+ pass
+
+ def OnTestFailure(self, test):
+ """Callback invoked when a test fails.
+
+ This method can be used to bring the attention of the operators
+ when a display is not available. For example, lightting up a red
+ LED may help operators identify failing device on the run-in
+ rack easily.
+ """
+ pass
+
+ def OnSummaryGood(self):
+ """Callback invoked when the test summary page shows and all test passed.
+
+ This method can be used to notify the operator that a device has finished
+ a test section, e.g. run-in. For example, lightting up a green LED here
+ and the operators may be instructed to move all devices with a green LED
+ to FATP testing.
+ """
+ pass
+
+ def OnSummaryBad(self):
+ """Callback invoked when the test summary page shows and some test failed.
+
+ Similar to OnSummaryGood, but is used to notify the operator of failing
+ test(s).
+ """
+ pass
diff --git a/py/test/pytests/summary/summary.py b/py/test/pytests/summary/summary.py
index 5f9b6e2..9732d81 100644
--- a/py/test/pytests/summary/summary.py
+++ b/py/test/pytests/summary/summary.py
@@ -35,7 +35,6 @@
import unittest
import factory_common # pylint: disable=W0611
-from cros.factory import system
from cros.factory.test import factory
from cros.factory.test import test_ui
from cros.factory.test.args import Arg
@@ -111,11 +110,10 @@
all_pass = overall_status in (factory.TestState.PASSED,
factory.TestState.FAILED_AND_WAIVED)
- board = system.GetBoard(self.dut)
if all_pass:
- board.OnSummaryGood()
+ self.dut.hooks.OnSummaryGood()
else:
- board.OnSummaryBad()
+ self.dut.hooks.OnSummaryBad()
"""factory.get_state_instance().UpdateStatus(all_pass) will call
UpdateStatus in goofy_rpc.py, and notify ui to update the color of
dut's tab.