summaryrefslogtreecommitdiff
path: root/cts/common
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-06-22 14:36:24 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-06-27 15:52:06 -0700
commita82421df00ac1834d0dc8a93f788c323b1bf1977 (patch)
tree3ce0268be0e05e9b53a6afe5565bbf3cf6e8a06d /cts/common
parent4c23fa01df623438e7d2bfe51dec6eac4f7d9ff2 (diff)
downloadchrome-ec-a82421df00ac1834d0dc8a93f788c323b1bf1977.tar.gz
eCTS: Print start marker before sync
This patch makes each test print start marker before sync. This will allow us to distinguish the failure before even sync is attempted (CTS_RC_DID_NOT_START, thus probably caused by the previous test) and the failure caused by the hanging partner, in which case the one good and alive will be stuck in sync (and should return _DID_NOT_END or even better _BAD_SYNC once we implement timeout in sync). This patch also: * Adds did_not_start_test to and removes debug_test from meta suite * Consolidates test runner loops into common cts_main_loop * Removes dut_common.h and th_common.h * Removes debug print macro and CTS_DEBUG * Replaces all infinite loops after tests with task_wait_event(-1) * Removes meaningless comments and debug printfs * Removes CTS_TEST_ID_* * Adds sync() to task suite BUG=chromium:736104 BRANCH=none TEST=Run run_ects.sh and verify all tests pass Change-Id: I6ccdf26afac6b8e8cb16483c5d75e4e77e7962f4 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/545176
Diffstat (limited to 'cts/common')
-rw-r--r--cts/common/cts_common.c31
-rw-r--r--cts/common/cts_common.h48
-rw-r--r--cts/common/cts_testlist.h30
-rw-r--r--cts/common/dut_common.c8
-rw-r--r--cts/common/dut_common.h13
-rw-r--r--cts/common/th_common.c1
-rw-r--r--cts/common/th_common.h13
7 files changed, 79 insertions, 65 deletions
diff --git a/cts/common/cts_common.c b/cts/common/cts_common.c
new file mode 100644
index 0000000000..8975636655
--- /dev/null
+++ b/cts/common/cts_common.c
@@ -0,0 +1,31 @@
+/* Copyright 2017 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.
+ */
+
+#include "console.h"
+#include "cts_common.h"
+
+__attribute__((weak)) void clean_state(void)
+{
+ /* Each test overrides as needed */
+}
+
+void cts_main_loop(const struct cts_test* tests, const char *name)
+{
+ enum cts_rc rc;
+ int i;
+
+ cflush();
+ for (i = 0; i < cts_test_count; i++) {
+ CPRINTF("\n%s start\n", tests[i].name);
+ cflush();
+ clean_state();
+ sync();
+ rc = tests[i].run();
+ CPRINTF("\n%s end %d\n", tests[i].name, rc);
+ cflush();
+ }
+
+ CPRINTS("%s test suite finished", name);
+}
diff --git a/cts/common/cts_common.h b/cts/common/cts_common.h
index 3c24b815e7..13a435e655 100644
--- a/cts/common/cts_common.h
+++ b/cts/common/cts_common.h
@@ -15,29 +15,41 @@
#define CPRINTL(format, args...) CPRINTS("%s:%d: "format, \
__func__, __LINE__, ## args)
-#ifdef CTS_DEBUG
-/* These debug tags should not be changed */
-#define CTS_DEBUG_START "\n[DEBUG]\n"
-#define CTS_DEBUG_END "\n[DEBUG_END]\n"
-
-#define CTS_DEBUG_PRINTF(format, args...) \
- do { \
- CPRINTF(CTS_DEBUG_START format CTS_DEBUG_END, ## args); \
- cflush(); \
- } while (0)
-#else
-#define CTS_DEBUG_PRINTF(format, args...)
-#endif
-
#define READ_WAIT_TIME_MS 100
#define CTS_INTERRUPT_TRIGGER_DELAY_US (250 * MSEC)
-/* In a single test, only one board can return unknown, the other must
- * return a useful result (i.e. success, failure, etc)
- */
-
enum cts_rc {
#include "cts.rc"
};
+struct cts_test {
+ enum cts_rc (*run)(void);
+ char *name;
+};
+
+extern const int cts_test_count;
+
+/**
+ * Main loop where each test in a suite is executed
+ *
+ * A test suite can implement its custom loop as needed.
+ *
+ * Args:
+ * @test: List of tests to run
+ * @name: Name of the test to be printed on EC console
+ */
+void cts_main_loop(const struct cts_test* tests, const char *name);
+
+/**
+ * Callback function called at the beginning of the main loop
+ */
+void clean_state(void);
+
+/**
+ * Synchronize DUT and TH
+ *
+ * @return CTS_RC_SUCCESS if sync is successful
+ */
+enum cts_rc sync(void);
+
#endif
diff --git a/cts/common/cts_testlist.h b/cts/common/cts_testlist.h
index 9e18c7f8eb..1586c1348e 100644
--- a/cts/common/cts_testlist.h
+++ b/cts/common/cts_testlist.h
@@ -3,26 +3,28 @@
* found in the LICENSE file.
*/
+#include "util.h"
+
/*
- * CTS_TEST macro is used by dut.c, th.c, and cts.py. Currently, the 2nd
- * and 3rd arguments are only used by cts.py. They specify the expected
- * strings output by TH and DUT, respectively.
+ * CTS_TEST macro takes the following arguments:
+ *
+ * @test: Function running the test
+ * @th_rc: Expected CTS_RC_* from TH
+ * @th_string: Expected string printed by TH
+ * @dut_rc: Expected CTR_RC_* from DUT
+ * @dut_string: Expected string printed by DUT
+ *
+ * CTS_TEST macro is processed in multiple places. One is here for creating
+ * an array of test functions. Only @test is used.
+ *
+ * Another is in cts.py for evaluating the test results against expectations.
*/
-struct cts_test {
- enum cts_rc (*run)(void);
- char *name;
-};
-
+#undef CTS_TEST
#define CTS_TEST(test, th_rc, th_string, dut_rc, dut_string) \
{test, STRINGIFY(test)},
struct cts_test tests[] = {
#include "cts.testlist"
};
-#undef CTS_TEST
-#define CTS_TEST(test, th_rc, th_string, dut_rc, dut_string) CTS_TEST_ID_##test,
-enum {
-#include "cts.testlist"
- CTS_TEST_ID_COUNT,
-};
+const int cts_test_count = ARRAY_SIZE(tests);
diff --git a/cts/common/dut_common.c b/cts/common/dut_common.c
index 23315f970f..6e62a280e2 100644
--- a/cts/common/dut_common.c
+++ b/cts/common/dut_common.c
@@ -3,15 +3,10 @@
* found in the LICENSE file.
*/
+#include "cts_common.h"
#include "gpio.h"
-#include "timer.h"
#include "watchdog.h"
-#include "cts_common.h"
-#include "dut_common.h"
-/* Returns unknown because TH could potentially still get stuck
- * even if the DUT completes the sync
- */
enum cts_rc sync(void)
{
int input_level;
@@ -30,3 +25,4 @@ enum cts_rc sync(void)
return CTS_RC_SUCCESS;
}
+
diff --git a/cts/common/dut_common.h b/cts/common/dut_common.h
deleted file mode 100644
index f812631633..0000000000
--- a/cts/common/dut_common.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* Copyright 2016 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.
- */
-
-#ifndef __DUT_COMMON_H
-#define __DUT_COMMON_H
-
-#include "cts_common.h"
-
-enum cts_rc sync(void);
-
-#endif
diff --git a/cts/common/th_common.c b/cts/common/th_common.c
index bcab367658..1d692b7843 100644
--- a/cts/common/th_common.c
+++ b/cts/common/th_common.c
@@ -7,7 +7,6 @@
#include "timer.h"
#include "watchdog.h"
#include "cts_common.h"
-#include "th_common.h"
/* Return SUCCESS if and only if we reach end of function
* Returning success here means sync was successful
diff --git a/cts/common/th_common.h b/cts/common/th_common.h
deleted file mode 100644
index 339375c78c..0000000000
--- a/cts/common/th_common.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* Copyright 2016 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.
- */
-
-#ifndef __TH_COMMON_H
-#define __TH_COMMON_H
-
-#include "cts_common.h"
-
-enum cts_rc sync(void);
-
-#endif