(factory-980B) factory: Add "hwid_cfg" to mark test image.

For RMA images.
Reviewed-on: https://gerrit.chromium.org/gerrit/11122

The same factory test image is used for factory/RMA/... (may be more in future),
so we need some mechanism to differentiate the type of test we performed.

The HWID already has configuration names to describe what we are testing for, so
this CL first tries to look up "cfg" from installed HWID folder, and then decide
which test list to use; and in the end add that to "report_tag".

BUG=chromium-os:22460
TEST=manual

Change-Id: Idb09e083920044562e1a256d0a128e50fd4ae869
Reviewed-on: https://gerrit.chromium.org/gerrit/11257
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
diff --git a/client/site_tests/factory_Finalize/factory_Finalize.py b/client/site_tests/factory_Finalize/factory_Finalize.py
index ce42a1e..bf416a9 100644
--- a/client/site_tests/factory_Finalize/factory_Finalize.py
+++ b/client/site_tests/factory_Finalize/factory_Finalize.py
@@ -99,10 +99,14 @@
         # solve upload file names
         upload_method = self.normalize_upload_method(upload_method)
 
+        # get report information
+        hwid_cfg = factory.get_shared_data('hwid_cfg')
+
         args = ['gooftool',
                 '--finalize',
                 '--verbose',
                 '--wipe_method "%s"' % ('secure' if secure_wipe else 'fast'),
+                '--report_tag "%s"' % hwid_cfg,
                 '--upload_method "%s"' % upload_method,
                 ]
         if not check_and_enable_write_protect:
diff --git a/client/site_tests/suite_Factory/control b/client/site_tests/suite_Factory/control
index b9b0442..6236ed2 100644
--- a/client/site_tests/suite_Factory/control
+++ b/client/site_tests/suite_Factory/control
@@ -39,6 +39,7 @@
 FACTORY_STATE_SERVER_PATH = job.autodir + '/bin/factory_state.py'
 STATUS_FILE_PATH = job.autodir + '/results/default/status'
 DEFAULT_TEST_LIST_PATH = job.autodir + '/site_tests/suite_Factory/test_list'
+HWID_CFG_PATH = '/usr/local/share/chromeos-hwid/cfg'
 
 
 # Hack to grab the pid for forked tests.
@@ -76,11 +77,27 @@
 job.bootloader.boot_once = lambda x: None
 
 
+def get_hwid_cfg():
+    if os.path.exists(HWID_CFG_PATH):
+        with open(HWID_CFG_PATH, "rt") as hwid_cfg_handle:
+            return hwid_cfg_handle.read().strip()
+    return ''
+
 def find_test_list():
+    hwid_cfg = get_hwid_cfg()
+
+    # Try in order: test_list, test_list.$hwid_cfg, test_list.all
+    if hwid_cfg:
+        test_list = "%s_%s" % (DEFAULT_TEST_LIST_PATH, hwid_cfg)
+        if os.path.exists(test_list):
+            factory.log('Loaded special test list: %s' % test_list)
+            return test_list
+        factory.log('WARNING: no specific test list for config: %s' % hwid_cfg)
+
     test_list = DEFAULT_TEST_LIST_PATH
     if os.path.exists(test_list):
         return test_list
-    # try default (all) list
+
     test_list = ('%s.all' % DEFAULT_TEST_LIST_PATH)
     if os.path.exists(test_list):
         factory.log('Using default test list: ' + test_list)
@@ -191,6 +208,9 @@
     else:
         factory.log('Continue with existing test list.')
 
+    # Updates HWID configuration tag.
+    factory.set_shared_data('hwid_cfg', get_hwid_cfg())
+
     # any 'active' tests should be fail now.
     for test in test_db.get_all_tests():
         status = status_map.lookup_status(test)