Add variant handling to performance tests.

BUG=chromium:454915
TEST=Unit test for perf_uploader, ran network_WiFi_Perf

Change-Id: I9718b340fced30756d6b7f015e3a7945b1aa4f45
Reviewed-on: https://chromium-review.googlesource.com/246310
Tested-by: Kris Rambish <krisr@chromium.org>
Reviewed-by: Bindu Mahadev <bmahadev@chromium.org>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Commit-Queue: Kris Rambish <krisr@chromium.org>
diff --git a/client/cros/constants.py b/client/cros/constants.py
index 979c13f..ac025a7 100644
--- a/client/cros/constants.py
+++ b/client/cros/constants.py
@@ -184,3 +184,6 @@
 
 # Moblab Environment Constants.
 MOBLAB_USER = 'moblab'
+
+# Variant test keyval
+VARIANT_KEY = 'variant_key'
diff --git a/server/cros/network/wifi_cell_test_base.py b/server/cros/network/wifi_cell_test_base.py
index 92843f9..9c9d4c9 100644
--- a/server/cros/network/wifi_cell_test_base.py
+++ b/server/cros/network/wifi_cell_test_base.py
@@ -5,6 +5,9 @@
 import logging
 
 from autotest_lib.client.common_lib import utils
+from autotest_lib.client.cros import constants
+from autotest_lib.server import frontend
+from autotest_lib.server import site_utils
 from autotest_lib.server import test
 from autotest_lib.server.cros.network import wifi_test_context_manager
 
@@ -26,6 +29,16 @@
 
     """
 
+    def initialize(self, host):
+        # Add the variant key if there is one
+        afe = frontend.AFE(debug=True)
+        variant_name = site_utils.get_label_from_afe(host.hostname,
+                                                     'variant:',
+                                                     afe)
+        if variant_name:
+            self.write_test_keyval({constants.VARIANT_KEY: variant_name})
+
+
     @property
     def context(self):
         """@return the WiFi context for this test."""
diff --git a/tko/perf_upload/perf_uploader.py b/tko/perf_upload/perf_uploader.py
index cf0fc7a..e26bd45 100644
--- a/tko/perf_upload/perf_uploader.py
+++ b/tko/perf_upload/perf_uploader.py
@@ -16,6 +16,7 @@
 import httplib, json, math, os, urllib, urllib2
 
 import common
+from autotest_lib.client.cros import constants
 from autotest_lib.tko import utils as tko_utils
 
 _ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -156,8 +157,8 @@
 
 
 def _format_for_upload(platform_name, cros_version, chrome_version,
-                       hardware_id, hardware_hostname, perf_data,
-                       presentation_info):
+                       hardware_id, variant_name, hardware_hostname,
+                       perf_data, presentation_info):
     """Formats perf data suitably to upload to the perf dashboard.
 
     The perf dashboard expects perf data to be uploaded as a
@@ -172,6 +173,7 @@
     @param chrome_version: The string chrome version number.
     @param hardware_id: String that identifies the type of hardware the test was
         executed on.
+    @param variant_name: String that identifies the variant name of the board.
     @param hardware_hostname: String that identifies the name of the device the
         test was executed on.
     @param perf_data: A dictionary of measured perf data as computed by
@@ -184,6 +186,8 @@
 
     """
     dash_entries = []
+    if variant_name:
+        platform_name += '-' + variant_name
     for (desc, graph), data in perf_data.iteritems():
         # Each perf metric is named by a path that encodes the test name,
         # a graph name (if specified), and a description.  This must be defined
@@ -274,6 +278,7 @@
     chrome_version = test.attributes.get('CHROME_VERSION', '')
     hardware_id = test.attributes.get('hwid', '')
     hardware_hostname = test.machine
+    variant_name = test.attributes.get(constants.VARIANT_KEY, None)
     # Prefix the chromeOS version number with the chrome milestone.
     # TODO(dennisjeffrey): Modify the dashboard to accept the chromeOS version
     # number *without* the milestone attached.
@@ -283,7 +288,7 @@
         presentation_info = _gather_presentation_info(config_data, test_name)
         formatted_data = _format_for_upload(
                 platform_name, cros_version, chrome_version, hardware_id,
-                hardware_hostname, perf_data, presentation_info)
+                variant_name, hardware_hostname, perf_data, presentation_info)
         _send_to_dashboard(formatted_data)
     except PerfUploadingError as e:
         tko_utils.dprint('Error when uploading perf data to the perf '
diff --git a/tko/perf_upload/perf_uploader_unittest.py b/tko/perf_upload/perf_uploader_unittest.py
index 1e5f111..555b8df 100644
--- a/tko/perf_upload/perf_uploader_unittest.py
+++ b/tko/perf_upload/perf_uploader_unittest.py
@@ -333,22 +333,23 @@
         """Verifies format_for_upload generates correct json data."""
         result = perf_uploader._format_for_upload(
                 'platform', '1200.0.0', '25.10.0.0', 'WINKY E2A-F2K-Q35',
-                'test_machine', self._perf_data, self._PRESENT_INFO)
+                'i7', 'test_machine', self._perf_data, self._PRESENT_INFO)
         expected_result_string = (
                 '[{"supplemental_columns": {"r_cros_version": "1200.0.0", '
                 '"a_hardware_identifier" : "WINKY E2A-F2K-Q35",'
                 '"a_hardware_hostname" : "test_machine",'
-                '"r_chrome_version": "25.10.0.0"}, "bot": "cros-platform", '
+                '"r_chrome_version": "25.10.0.0"}, "bot": "cros-platform-i7", '
                 '"higher_is_better": false, "value": 2.7, '
                 '"units": "msec", "master": "new_master_name", '
                 '"error": 0.2, "test": "new_test_name/graph_name/metric1"}, '
                 '{"supplemental_columns": {"r_cros_version": "1200.0.0", '
                 '"a_hardware_identifier" : "WINKY E2A-F2K-Q35",'
                 '"a_hardware_hostname" : "test_machine",'
-                '"r_chrome_version": "25.10.0.0"}, "bot": "cros-platform", '
+                '"r_chrome_version": "25.10.0.0"}, "bot": "cros-platform-i7", '
                 '"higher_is_better": true, "value": 101.35, '
                 '"units": "frames_per_sec", "master": "new_master_name", '
                 '"error": 5.78, "test": "new_test_name/metric2"}]')
+
         self._verify_result_string(result['data'], expected_result_string)