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
This commit is contained in:
Daisuke Nojiri
2016-07-12 14:32:38 -07:00
committed by chrome-bot
parent 846741eddb
commit b783f0b991
6 changed files with 69 additions and 65 deletions

View File

@@ -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)
*/

21
cts/common/cts_testlist.h Normal file
View File

@@ -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,
};

18
cts/gpio/cts.testlist Normal file
View File

@@ -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)

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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;
}
}