diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2016-07-12 14:32:38 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-15 21:39:18 -0700 |
commit | b783f0b991c43310675ab542c95902b65fffdbc4 (patch) | |
tree | e83e2500311225a1524dce9ba019bcfd41e00c47 /cts | |
parent | 846741eddbb28e6770532ab09fb64dc619c2f6e6 (diff) | |
download | chrome-ec-b783f0b991c43310675ab542c95902b65fffdbc4.tar.gz |
cts: Use pointers for test functions
Test functions are listed in cts.testlist and shared by th.c and dut.c.
This way, we can gurantee the two files are in sync. Also, cts.testlist
is used to count the number of tests automatically.
This allows us to use a for loop to execute each test.
BUG=none
BRANCH=none
TEST=build buildall
Change-Id: I0c811405134fad04f5c6914b1ac38835e212cbd2
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/359619
Diffstat (limited to 'cts')
-rw-r--r-- | cts/common/cts_common.h | 2 | ||||
-rw-r--r-- | cts/common/cts_testlist.h | 21 | ||||
-rw-r--r-- | cts/gpio/cts.testlist | 18 | ||||
-rw-r--r-- | cts/gpio/dut.c | 34 | ||||
-rw-r--r-- | cts/gpio/gpio_common.h | 21 | ||||
-rw-r--r-- | cts/gpio/th.c | 38 |
6 files changed, 69 insertions, 65 deletions
diff --git a/cts/common/cts_common.h b/cts/common/cts_common.h index eed93dccea..4f0036039f 100644 --- a/cts/common/cts_common.h +++ b/cts/common/cts_common.h @@ -13,6 +13,8 @@ #define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) #define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) +#define READ_WAIT_TIME_MS 100 + /* In a single test, only one board can return unknown, the other must * return a useful result (i.e. success, failure, etc) */ diff --git a/cts/common/cts_testlist.h b/cts/common/cts_testlist.h new file mode 100644 index 0000000000..8f560d674d --- /dev/null +++ b/cts/common/cts_testlist.h @@ -0,0 +1,21 @@ +/* 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. + */ + +struct cts_test { + enum cts_error_code (*run)(void); + char *name; +}; + +#define CTS_TEST(test) {test, STRINGIFY(test)}, +struct cts_test tests[] = { +#include "cts.testlist" +}; + +#undef CTS_TEST +#define CTS_TEST(test) CTS_TEST_ID_##test, +enum { +#include "cts.testlist" + CTS_TEST_ID_COUNT, +}; diff --git a/cts/gpio/cts.testlist b/cts/gpio/cts.testlist new file mode 100644 index 0000000000..8a6656db1d --- /dev/null +++ b/cts/gpio/cts.testlist @@ -0,0 +1,18 @@ +/* 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. + */ + +/* Test whether sync completes successfully */ +CTS_TEST(sync_test) +/* Check if the dut can set a line low */ +CTS_TEST(set_low_test) +/* Check if the dut can set a line high */ +CTS_TEST(set_high_test) +/* Check if the dut can read a line that is low */ +CTS_TEST(read_high_test) +/* Check if the dut can read a line that is high */ +CTS_TEST(read_low_test) +/* Check if the dut reads its true pin level (success) + or its register level when configured as a low open drain output pin */ +CTS_TEST(od_read_high_test) diff --git a/cts/gpio/dut.c b/cts/gpio/dut.c index c1b32ef0de..20248f2642 100644 --- a/cts/gpio/dut.c +++ b/cts/gpio/dut.c @@ -10,7 +10,6 @@ #include "watchdog.h" #include "dut_common.h" #include "cts_common.h" -#include "gpio_common.h" enum cts_error_code sync_test(void) { @@ -72,43 +71,38 @@ enum cts_error_code od_read_high_test(void) return FAILURE; } +#include "cts_testlist.h" + void cts_task(void) { - enum cts_error_code results[GPIO_CTS_TEST_COUNT]; + enum cts_error_code results[CTS_TEST_ID_COUNT]; int i; - sync(); - results[0] = sync_test(); - sync(); - results[1] = set_low_test(); - sync(); - results[2] = set_high_test(); - sync(); - results[3] = read_high_test(); - sync(); - results[4] = read_low_test(); - sync(); - results[5] = od_read_high_test(); + for (i = 0; i < CTS_TEST_ID_COUNT; i++) { + sync(); + results[i] = tests[i].run(); + } CPRINTS("GPIO test suite finished"); uart_flush_output(); CPRINTS("Results:"); - for (i = 0; i < GPIO_CTS_TEST_COUNT; i++) { + for (i = 0; i < CTS_TEST_ID_COUNT; i++) { switch (results[i]) { case SUCCESS: - CPRINTS("%d) Passed", i); + CPRINTS("%s) Passed", tests[i].name); break; case FAILURE: - CPRINTS("%d) Failed", i); + CPRINTS("%s) Failed", tests[i].name); break; case BAD_SYNC: - CPRINTS("%d) Bad sync", i); + CPRINTS("%s) Bad sync", tests[i].name); break; case UNKNOWN: - CPRINTS("%d) Test result unknown", i); + CPRINTS("%s) Test result unknown", tests[i].name); break; default: - CPRINTS("%d) ErrorCode not recognized", i); + CPRINTS("%s) ErrorCode (%d) not recognized", + tests[i].name, results[i]); break; } } diff --git a/cts/gpio/gpio_common.h b/cts/gpio/gpio_common.h deleted file mode 100644 index b19d23165a..0000000000 --- a/cts/gpio/gpio_common.h +++ /dev/null @@ -1,21 +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 __GPIO_COMMON_H -#define __GPIO_COMMON_H - -/* sync_test tests whether sync completes successfully - * set_low_test checks if the dut can set a line low - * set_high test checks if the dut can set a line high - * read_low_test checks if the dut can read a line that is low - * read_high_test checks if the dut can read a line that is high - * od_read_high_test checks if the dut reads its true pin level (success) - * or its register level when configured as a low open drain output pin - */ - -#define READ_WAIT_TIME_MS 100 -#define GPIO_CTS_TEST_COUNT 6 - -#endif diff --git a/cts/gpio/th.c b/cts/gpio/th.c index ddc46f6602..ed1d582a75 100644 --- a/cts/gpio/th.c +++ b/cts/gpio/th.c @@ -10,7 +10,6 @@ #include "watchdog.h" #include "dut_common.h" #include "cts_common.h" -#include "gpio_common.h" enum cts_error_code sync_test(void) { @@ -66,47 +65,38 @@ enum cts_error_code od_read_high_test(void) return UNKNOWN; } +#include "cts_testlist.h" + void cts_task(void) { - enum cts_error_code results[GPIO_CTS_TEST_COUNT]; + enum cts_error_code results[CTS_TEST_ID_COUNT]; int i; - /* Don't bother checking sync's return value now because - * host will deal with hanging syncs/tests as well as - * interpreting test results later - */ - sync(); - results[0] = sync_test(); - sync(); - results[1] = set_low_test(); - sync(); - results[2] = set_high_test(); - sync(); - results[3] = read_high_test(); - sync(); - results[4] = read_low_test(); - sync(); - results[5] = od_read_high_test(); + for (i = 0; i < CTS_TEST_ID_COUNT; i++) { + sync(); + results[i] = tests[i].run(); + } CPRINTS("GPIO test suite finished"); uart_flush_output(); CPRINTS("Results:"); - for (i = 0; i < GPIO_CTS_TEST_COUNT; i++) { + for (i = 0; i < CTS_TEST_ID_COUNT; i++) { switch (results[i]) { case SUCCESS: - CPRINTS("%d) Passed", i); + CPRINTS("%s) Passed", tests[i].name); break; case FAILURE: - CPRINTS("%d) Failed", i); + CPRINTS("%s) Failed", tests[i].name); break; case BAD_SYNC: - CPRINTS("%d) Bad sync", i); + CPRINTS("%s) Bad sync", tests[i].name); break; case UNKNOWN: - CPRINTS("%d) Test result unknown", i); + CPRINTS("%s) Test result unknown", tests[i].name); break; default: - CPRINTS("%d) ErrorCode not recognized", i); + CPRINTS("%s) ErrorCode (%d) not recognized", + tests[i].name, results[i]); break; } } |