Add decoded BOM to HWID event log in hwid_v3 test.
BUG=chrome-os-partner:20070
TEST=make lint test
TEST=Manually test on my DUT.
Change-Id: I28cf672046e729d7038d7fbe2886307f9c9b7d12
Reviewed-on: https://gerrit.chromium.org/gerrit/58169
Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org>
Commit-Queue: Ricky Liang <jcliang@chromium.org>
Tested-by: Ricky Liang <jcliang@chromium.org>
diff --git a/py/gooftool/gooftool.py b/py/gooftool/gooftool.py
index 9bd2dbf..53d9b8e 100755
--- a/py/gooftool/gooftool.py
+++ b/py/gooftool/gooftool.py
@@ -903,6 +903,34 @@
print 'Verification SUCCESS!'
+def ParseDecodedHWID(hwid):
+ """Parse the HWID object into a more compact dict.
+
+ Args:
+ hwid: A decoded HWID object.
+
+ Returns:
+ A dict containing the board name, the binary string, and the list of
+ components.
+ """
+ results = {}
+ results['board'] = hwid.database.board
+ results['binary_string'] = hwid.binary_string
+ results['components'] = collections.defaultdict(list)
+ components = hwid.bom.components
+ for comp_cls in sorted(components):
+ for (comp_name, probed_values, _) in sorted(components[comp_cls]):
+ if not probed_values:
+ db_components = hwid.database.components
+ probed_values = db_components.GetComponentAttributes(
+ comp_cls, comp_name).get('values')
+ results['components'][comp_cls].append(
+ {comp_name: probed_values if probed_values else None})
+ # Convert defaultdict to dict.
+ results['components'] = dict(results['components'])
+ return results
+
+
@Command('decode_hwid_v3',
_board_cmd_arg,
_hwdb_path_cmd_arg,
@@ -916,23 +944,8 @@
decoded_hwid_context = Gooftool(hwid_version=3, board=options.board,
hwdb_path=options.hwdb_path).DecodeHwidV3(
options.hwid)
-
- results = {}
- results['board'] = decoded_hwid_context.database.board
- results['binary_string'] = decoded_hwid_context.binary_string
- results['components'] = collections.defaultdict(list)
- components = decoded_hwid_context.bom.components
- for comp_cls in sorted(components):
- for (comp_name, probed_values, _) in sorted(components[comp_cls]):
- if not probed_values:
- db_components = decoded_hwid_context.database.components
- probed_values = db_components.GetComponentAttributes(
- comp_cls, comp_name).get('values')
- results['components'][comp_cls].append(
- {comp_name: probed_values if probed_values else None})
- # Convert defaultdict to dict.
- results['components'] = dict(results['components'])
- print yaml.dump(results, default_flow_style=False)
+ print yaml.dump(ParseDecodedHWID(decoded_hwid_context),
+ default_flow_style=False)
def Main():
diff --git a/py/hwid/common.py b/py/hwid/common.py
index eab3f91..299e36b 100644
--- a/py/hwid/common.py
+++ b/py/hwid/common.py
@@ -301,6 +301,8 @@
return copy.deepcopy(self)
def __eq__(self, op2):
+ if not isinstance(op2, BOM):
+ return False
return self.__dict__ == op2.__dict__
def __ne__(self, op2):
diff --git a/py/hwid/valid_hwid_db_unittest.py b/py/hwid/valid_hwid_db_unittest.py
index 74e87a5..0a60a06 100755
--- a/py/hwid/valid_hwid_db_unittest.py
+++ b/py/hwid/valid_hwid_db_unittest.py
@@ -76,7 +76,7 @@
vpd[match.group(1)][match.group(2)] = v
device_info = sample_dict.get('device_info')
- def _EncodeFunctions():
+ def _Encode():
gt = Gooftool(hwid_version=3, board=board_name,
hwdb_path=os.path.dirname(db_path))
# Test HWID Generation.
@@ -89,9 +89,9 @@
if error:
self.assertRaisesRegexp(Exception, re.compile(error, re.S),
- _EncodeFunctions)
+ _Encode)
else:
- hwid = _EncodeFunctions()
+ hwid = _Encode()
self.assertEquals(binary_string, hwid.binary_string)
self.assertEquals(encoded_string, hwid.encoded_string)
@@ -111,7 +111,7 @@
encoded_fields = sample_dict['encoded_fields']
logging.info('Testing decoding of %r to BOM', encoded_string)
- def _DecodeFunctions():
+ def _Decode():
gt = Gooftool(hwid_version=3, board=board_name,
hwdb_path=os.path.dirname(db_path))
# Test HWID decoding.
@@ -119,9 +119,9 @@
if error:
self.assertRaisesRegexp(Exception, re.compile(error, re.S),
- _DecodeFunctions)
+ _Decode)
else:
- hwid = _DecodeFunctions()
+ hwid = _Decode()
self.assertEquals(binary_string, hwid.binary_string)
self.assertEquals(encoded_fields, hwid.bom.encoded_fields)
diff --git a/py/test/pytests/hwid_v3.py b/py/test/pytests/hwid_v3.py
index 3863dbb..e94629a 100644
--- a/py/test/pytests/hwid_v3.py
+++ b/py/test/pytests/hwid_v3.py
@@ -9,8 +9,8 @@
import unittest
import factory_common # pylint: disable=W0611
-from cros.factory import gooftool
from cros.factory.event_log import Log
+from cros.factory.gooftool import probe, gooftool
from cros.factory.gooftool import Gooftool
from cros.factory.hwdb.hwid_tool import ProbeResults # pylint: disable=E0611
from cros.factory.hwid import common
@@ -55,7 +55,7 @@
with open(OVERRIDE_PROBE_RESULTS_PATH) as f:
probe_results = ProbeResults.Decode(f.read())
else:
- probe_results = gooftool.probe.Probe()
+ probe_results = probe.Probe()
Log('probe', probe_results=probe_results)
gt = Gooftool(hwid_version=3, board=board,
@@ -68,23 +68,24 @@
'Generating HWID (v3)...',
'正在产生 HWID (v3)...'))
generated_hwid = gt.GenerateHwidV3(device_info=device_data)
- encoded_hwid = generated_hwid.encoded_string
- factory.console.info('Generated HWID: %s', encoded_hwid)
- Log('hwid', hwid=encoded_hwid)
- shopfloor.UpdateDeviceData({'hwid': encoded_hwid})
+ hwid = generated_hwid.encoded_string
+ factory.console.info('Generated HWID: %s', hwid)
+ decoded_hwid = gt.DecodeHwidV3(hwid)
+ Log('hwid', hwid=hwid, components=gooftool.ParseDecodedHWID(decoded_hwid))
+ shopfloor.UpdateDeviceData({'hwid': hwid})
else:
- encoded_hwid = None
+ hwid = None
template.SetState(test_ui.MakeLabel(
'Verifying HWID (v3): %s...' % (
- encoded_hwid or '(unchanged)'),
+ hwid or '(unchanged)'),
'正在验证 HWID (v3): %s...' % (
- encoded_hwid or '(不变)')))
- gt.VerifyHwidV3(encoded_hwid, probe_results)
+ hwid or '(不变)')))
+ gt.VerifyHwidV3(hwid, probe_results)
if self.args.generate:
template.SetState(test_ui.MakeLabel(
- 'Setting HWID (v3): %s...' % encoded_hwid,
- '正在写入 HWID (v3): %s...' % encoded_hwid))
- gt.WriteHWID(encoded_hwid)
+ 'Setting HWID (v3): %s...' % hwid,
+ '正在写入 HWID (v3): %s...' % hwid))
+ gt.WriteHWID(hwid)