summaryrefslogtreecommitdiff
path: root/cts/common
diff options
context:
space:
mode:
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