summaryrefslogtreecommitdiff
path: root/cts
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-11-10 14:17:09 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-06-17 01:12:42 -0700
commit0696dd1e68692ca8dae17b737e0d895561f65cd4 (patch)
tree1c34077988da2927d0de9296f3277f9fcbcc1562 /cts
parent12fd77967f9239f462bb66087cf4496f36e16302 (diff)
downloadchrome-ec-0696dd1e68692ca8dae17b737e0d895561f65cd4.tar.gz
eCTS: Refactor return code handling
This patch adds host only return codes to cts.rc and derive names from there. BUG=chromium:664309 BRANCH=none TEST=cts.py -m task, interrupt, gpio test name TH DUT debug_test SUCCESS SUCCESS success_test SUCCESS SUCCESS fail_dut_test SUCCESS FAILURE fail_th_test FAILURE SUCCESS fail_both_test FAILURE FAILURE bad_sync_and_success_test BAD_SYNC BAD_SYNC bad_sync_both_test BAD_SYNC BAD_SYNC bad_sync_failure_test FAILURE BAD_SYNC hang_test SUCCESS NO_RESULT post_corruption_success NO_RESULT NO_RESULT Change-Id: I169b2466646d6236571a8a4c5d3e208d928b9dd2 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/410282 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'cts')
-rw-r--r--cts/common/cts.rc18
-rwxr-xr-xcts/cts.py44
2 files changed, 44 insertions, 18 deletions
diff --git a/cts/common/cts.rc b/cts/common/cts.rc
index 11ae8a8dce..8d66a8af4e 100644
--- a/cts/common/cts.rc
+++ b/cts/common/cts.rc
@@ -5,13 +5,21 @@
/*
* This file is included by cts_common.h as an enumeration of error codes,
- * as well as being processed by cts.py to get error code names.
- * cts.py depends on CTS_RC_SUCCESS being the first error code listed so
- * that its value
- * is 0 when enumerated
+ * as well as being processed by cts.py to get error code names. The format
+ * must be either of the followings:
+ *
+ * CTS_RC_<NAME>,
+ * CTS_RC_<NAME> = X,
+ *
+ * where <NAME> will be printed on the result screen.
*/
-CTS_RC_SUCCESS,
+/* Host only codes. Should not be needed by th.c or dut.c. */
+CTS_RC_DUPLICATE_RUN = -2,
+CTS_RC_NO_RESULT = -1,
+
+/* Regular codes */
+CTS_RC_SUCCESS = 0,
CTS_RC_FAILURE,
CTS_RC_BAD_SYNC,
CTS_RC_TIMEOUT,
diff --git a/cts/cts.py b/cts/cts.py
index 0c6a23cd7c..b046bc4ca5 100755
--- a/cts/cts.py
+++ b/cts/cts.py
@@ -24,11 +24,10 @@ import shutil
import time
-CTS_CORRUPTED_CODE = -2 # The test didn't execute correctly
-CTS_CONFLICTING_CODE = -1 # Error codes should never conflict
-CTS_SUCCESS_CODE = 0
-CTS_COLOR_RED = '#fb7d7d'
-CTS_COLOR_GREEN = '#7dfb9f'
+# Host only return codes. Make sure they match values in cts.rc
+CTS_RC_DUPLICATE_RUN = -2 # The test was run multiple times.
+CTS_RC_NO_RESULT = -1 # The test did not run.
+
DEFAULT_TH = 'stm32l476g-eval'
DEFAULT_DUT = 'nucleo-f072rb'
MAX_SUITE_TIME_SEC = 5
@@ -72,11 +71,7 @@ class Cts(object):
self.test_names = Cts.get_macro_args(testlist_path, 'CTS_TEST')
return_codes_path = os.path.join(cts_dir, 'common', 'cts.rc')
- self.return_codes = dict(enumerate(Cts.get_macro_args(
- return_codes_path, 'CTS_RC_')))
-
- self.return_codes[CTS_CONFLICTING_CODE] = 'RESULTS CONFLICT'
- self.return_codes[CTS_CORRUPTED_CODE] = 'CORRUPTED'
+ self.get_return_codes(return_codes_path, 'CTS_RC_')
def build(self):
"""Build images for DUT and TH"""
@@ -127,8 +122,26 @@ class Cts(object):
args.append(l.strip('()').replace(',', ''))
return args
+ def get_return_codes(self, file, prefix):
+ """Extract return code names from the definition file (cts.rc)"""
+ self.return_codes = {}
+ val = 0
+ with open(file, 'r') as f:
+ for line in f.readlines():
+ line = line.strip()
+ if not line.startswith(prefix):
+ continue
+ line = line[len(prefix):]
+ line = line.split(',')[0]
+ if '=' in line:
+ tokens = line.split('=')
+ line = tokens[0].strip()
+ val = int(tokens[1].strip())
+ self.return_codes[val] = line
+ val += 1
+
def parse_output(self, output):
- results = defaultdict(lambda: CTS_CORRUPTED_CODE)
+ results = defaultdict(lambda: CTS_RC_NO_RESULT)
for ln in [ln.strip() for ln in output.split('\n')]:
tokens = ln.split()
@@ -141,7 +154,10 @@ class Cts(object):
return_code = int(tokens[1])
except ValueError: # Second token is not an int
continue
- results[test_name] = return_code
+ if test_name in results:
+ results[test_name] = CTS_RC_DUPLICATE_RUN
+ else:
+ results[test_name] = return_code
return results
@@ -168,7 +184,7 @@ class Cts(object):
fmt += '{:>' + str(len_code_name) + '} '
fmt += '{:>' + str(len_code_name) + '}\n'
- self.formatted_results = head.format('test name', 'TH result', 'DUT result')
+ self.formatted_results = head.format('test name', 'TH', 'DUT')
for test_name in self.test_names:
th_cn = self.get_return_code_name(th_results[test_name])
dut_cn = self.get_return_code_name(dut_results[test_name])
@@ -246,6 +262,8 @@ class Cts(object):
print self.formatted_results
+ # TODO: Should set exit code for the shell
+
def main():
"""Main entry point for CTS script from command line"""