summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-09 07:16:01 +0800
committerChromeBot <chrome-bot@google.com>2013-05-08 18:11:01 -0700
commite71f008388b3c69cf01a534c5084d7e3a441149b (patch)
treec68a0ba7443eef434ca3799ae85b4207ccfbc68c /test
parent4f463ebc46463d397e8a4c5296ad2168ce881bde (diff)
downloadchrome-ec-e71f008388b3c69cf01a534c5084d7e3a441149b.tar.gz
Put test utility macros in header
Several test utility macros have been duplicated across tests. Let's put them in a single place. BUG=chrome-os-partner:19236 TEST='make runtests', 'BOARD=spring make tests' BRANCH=None Change-Id: Ib0c9f829715425cc23e33b8ef456b17dfadab13c Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50513 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/flash.c25
-rw-r--r--test/kb_mkbp.c36
-rw-r--r--test/kb_scan.c73
-rw-r--r--test/lid_sw.c36
-rw-r--r--test/mutex.c8
-rw-r--r--test/pingpong.c8
-rw-r--r--test/stress.c15
-rw-r--r--test/timer_calib.c5
-rw-r--r--test/timer_dos.c8
-rw-r--r--test/utils.c44
10 files changed, 38 insertions, 220 deletions
diff --git a/test/flash.c b/test/flash.c
index 67ee61ec27..02144e756c 100644
--- a/test/flash.c
+++ b/test/flash.c
@@ -13,6 +13,7 @@
#include "hooks.h"
#include "host_command.h"
#include "system.h"
+#include "test_util.h"
#include "timer.h"
#include "util.h"
@@ -78,17 +79,6 @@ int gpio_get_level(enum gpio_signal signal)
/*****************************************************************************/
/* Test utilities */
-#define RUN_TEST(n) \
- do { \
- ccprintf("Running %s...", #n); \
- cflush(); \
- if (n() == EC_SUCCESS) { \
- ccputs("OK\n"); \
- } else { \
- ccputs("Fail\n"); \
- error_count++; \
- } \
- } while (0)
static void begin_verify(void)
{
@@ -113,12 +103,6 @@ static int verify_write(int offset, int size, const char *data)
}
-#define TEST_ASSERT(x) \
- do { \
- if (!(x)) \
- return EC_ERROR_UNKNOWN; \
- } while (0)
-
#define VERIFY_NO_WRITE(off, sz, d) \
do { \
begin_verify(); \
@@ -418,10 +402,7 @@ int TaskTest(void *data)
return EC_SUCCESS;
}
-static int command_run_test(int argc, char **argv)
+void run_test(void)
{
- run_test_step1(); /* Never returns */
- return EC_ERROR_UNKNOWN;
+ run_test_step1();
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/kb_mkbp.c b/test/kb_mkbp.c
index a8e57bfe57..fc7a9255de 100644
--- a/test/kb_mkbp.c
+++ b/test/kb_mkbp.c
@@ -13,10 +13,9 @@
#include "keyboard_mkbp.h"
#include "keyboard_protocol.h"
#include "keyboard_scan.h"
+#include "test_util.h"
#include "util.h"
-static int error_count;
-
static uint8_t state[KEYBOARD_COLS];
static int ec_int_level;
@@ -44,24 +43,6 @@ int lid_is_open(void)
/*****************************************************************************/
/* Test utilities */
-#define RUN_TEST(n) \
- do { \
- ccprintf("Running %s...", #n); \
- cflush(); \
- if (n() == EC_SUCCESS) { \
- ccputs("OK\n"); \
- } else { \
- ccputs("Fail\n"); \
- error_count++; \
- } \
- } while (0)
-
-#define TEST_ASSERT(n) \
- do { \
- if (!(n)) \
- return EC_ERROR_UNKNOWN; \
- } while (0)
-
#define FIFO_EMPTY() (ec_int_level == 1)
#define FIFO_NOT_EMPTY() (ec_int_level == 0)
@@ -227,24 +208,13 @@ int fifo_underrun(void)
void run_test(void)
{
- error_count = 0;
ec_int_level = 1;
+ test_reset();
RUN_TEST(single_key_press);
RUN_TEST(test_fifo_size);
RUN_TEST(test_enable);
RUN_TEST(fifo_underrun);
- if (error_count == 0)
- ccprintf("Pass!\n");
- else
- ccprintf("Fail!\n");
-}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
+ test_print_result();
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/kb_scan.c b/test/kb_scan.c
index 756d87b8ee..3822e155ae 100644
--- a/test/kb_scan.c
+++ b/test/kb_scan.c
@@ -13,6 +13,7 @@
#include "keyboard_scan.h"
#include "lid_switch.h"
#include "task.h"
+#include "test_util.h"
#include "timer.h"
#include "util.h"
@@ -20,26 +21,6 @@
#define KEYDOWN_RETRY 10
#define NO_KEYDOWN_DELAY_MS 100
-#define TEST_ASSERT(n) \
- do { \
- if (n() != EC_SUCCESS) { \
- ccprintf("%s failed.\n", #n); \
- return EC_ERROR_UNKNOWN; \
- } \
- } while (0)
-
-#define RUN_TEST(n) \
- do { \
- ccprintf("Running %s...", #n); \
- cflush(); \
- if (n() == EC_SUCCESS) { \
- ccputs("OK\n"); \
- } else { \
- ccputs("Fail\n"); \
- error_count++; \
- } \
- } while (0)
-
#define CHECK_KEY_COUNT(old, expected) \
do { \
if (verify_key_presses(old, expected) != EC_SUCCESS) \
@@ -50,7 +31,6 @@
static uint8_t mock_state[KEYBOARD_COLS];
static int column_driven;
static int fifo_add_count;
-static int error_count;
static int lid_open;
#ifdef CONFIG_LID_SWITCH
@@ -138,41 +118,41 @@ int deghost_test(void)
{
/* Test we can detect a keypress */
mock_key(1, 1, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 1, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
/* (1, 1) (1, 2) (2, 1) (2, 2) form ghosting keys */
mock_key(1, 1, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(2, 2, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 2, 1);
mock_key(2, 1, 1);
- TEST_ASSERT(expect_no_keychange);
+ TEST_ASSERT(expect_no_keychange() == EC_SUCCESS);
mock_key(2, 1, 0);
mock_key(1, 2, 0);
- TEST_ASSERT(expect_no_keychange);
+ TEST_ASSERT(expect_no_keychange() == EC_SUCCESS);
mock_key(2, 2, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 1, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
/* (1, 1) (2, 0) (2, 1) don't form ghosting keys */
mock_key(1, 1, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(2, 0, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 0, 1);
mock_key(2, 1, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 0, 0);
mock_key(2, 1, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(2, 0, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 1, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
return EC_SUCCESS;
}
@@ -242,15 +222,15 @@ int lid_test(void)
{
lid_open = 0;
mock_key(1, 1, 1);
- TEST_ASSERT(expect_no_keychange);
+ TEST_ASSERT(expect_no_keychange() == EC_SUCCESS);
mock_key(1, 1, 0);
- TEST_ASSERT(expect_no_keychange);
+ TEST_ASSERT(expect_no_keychange() == EC_SUCCESS);
lid_open = 1;
mock_key(1, 1, 1);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
mock_key(1, 1, 0);
- TEST_ASSERT(expect_keychange);
+ TEST_ASSERT(expect_keychange() == EC_SUCCESS);
return EC_SUCCESS;
}
@@ -258,8 +238,8 @@ int lid_test(void)
void run_test(void)
{
- error_count = 0;
lid_open = 1;
+ test_reset();
RUN_TEST(deghost_test);
RUN_TEST(debounce_test);
@@ -267,16 +247,5 @@ void run_test(void)
RUN_TEST(lid_test);
#endif
- if (error_count == 0)
- ccprintf("Pass!\n");
- else
- ccprintf("Fail!\n");
-}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
+ test_print_result();
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/lid_sw.c b/test/lid_sw.c
index 4993147dcb..cf04d91efb 100644
--- a/test/lid_sw.c
+++ b/test/lid_sw.c
@@ -10,32 +10,13 @@
#include "hooks.h"
#include "host_command.h"
#include "lid_switch.h"
+#include "test_util.h"
#include "timer.h"
#include "util.h"
-static int error_count;
-
static int mock_lid;
static int lid_hook_count;
-#define RUN_TEST(n) \
- do { \
- ccprintf("Running %s...", #n); \
- cflush(); \
- if (n() == EC_SUCCESS) { \
- ccputs("OK\n"); \
- } else { \
- ccputs("Fail\n"); \
- error_count++; \
- } \
- } while (0)
-
-#define TEST_ASSERT(n) \
- do { \
- if (!(n)) \
- return EC_ERROR_UNKNOWN; \
- } while (0)
-
int gpio_get_level(enum gpio_signal signal)
{
if (signal == GPIO_LID_OPEN)
@@ -107,21 +88,10 @@ static int test_debounce(void)
void run_test(void)
{
- error_count = 0;
+ test_reset();
RUN_TEST(test_hook);
RUN_TEST(test_debounce);
- if (error_count)
- ccprintf("Fail!\n", error_count);
- else
- ccprintf("Pass!\n");
-}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
+ test_print_result();
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/mutex.c b/test/mutex.c
index e795fa15b7..cc4202378c 100644
--- a/test/mutex.c
+++ b/test/mutex.c
@@ -118,11 +118,3 @@ void run_test(void)
{
task_wake(TASK_ID_MTX1);
}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/pingpong.c b/test/pingpong.c
index 4cf5d53ced..202dc8be38 100644
--- a/test/pingpong.c
+++ b/test/pingpong.c
@@ -63,11 +63,3 @@ void run_test(void)
task_wake(TASK_ID_TICK);
task_wake(TASK_ID_TESTA);
}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/stress.c b/test/stress.c
index 8a69d84b19..e62212e69f 100644
--- a/test/stress.c
+++ b/test/stress.c
@@ -9,6 +9,7 @@
#include "console.h"
#include "ec_commands.h"
#include "i2c.h"
+#include "test_util.h"
#include "timer.h"
#include "util.h"
@@ -147,9 +148,9 @@ static int test_adc(void)
}
#endif
-static int command_run_test(int argc, char **argv)
+void run_test(void)
{
- error_count = 0;
+ test_reset();
#ifdef CONFIG_I2C
RUN_STRESS_TEST("I2C Stress Test", test_i2c, I2C_TEST_ITERATION);
@@ -158,13 +159,5 @@ static int command_run_test(int argc, char **argv)
RUN_STRESS_TEST("ADC Stress Test", test_adc, ADC_TEST_ITERATION);
#endif
- if (error_count) {
- ccprintf("Failed %d tests!\n", error_count);
- return EC_ERROR_UNKNOWN;
- } else {
- ccprintf("Pass!\n");
- return EC_SUCCESS;
- }
+ test_print_result();
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/timer_calib.c b/test/timer_calib.c
index e64cc6a769..65dab2900f 100644
--- a/test/timer_calib.c
+++ b/test/timer_calib.c
@@ -56,10 +56,7 @@ int timer_calib_task(void *data)
return EC_SUCCESS;
}
-static int command_run_test(int argc, char **argv)
+void run_test(void)
{
task_wake(TASK_ID_TESTTMR);
- return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/timer_dos.c b/test/timer_dos.c
index 327206e6df..73b06d681e 100644
--- a/test/timer_dos.c
+++ b/test/timer_dos.c
@@ -53,11 +53,3 @@ void run_test(void)
task_wake(TASK_ID_TMRB);
task_wake(TASK_ID_TMRA);
}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/utils.c b/test/utils.c
index 81fe2ef072..1aabbb81d7 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -9,37 +9,10 @@
#include "console.h"
#include "shared_mem.h"
#include "system.h"
+#include "test_util.h"
#include "timer.h"
#include "util.h"
-static int error_count;
-
-#define RUN_TEST(n) \
- do { \
- ccprintf("Running %s...", #n); \
- cflush(); \
- if (n() == EC_SUCCESS) { \
- ccputs("OK\n"); \
- } else { \
- ccputs("Fail\n"); \
- error_count++; \
- } \
- } while (0)
-
-#define TEST_ASSERT(n) \
- do { \
- if (!(n)) \
- return EC_ERROR_UNKNOWN; \
- } while (0)
-
-#define TEST_CHECK(n) \
- do { \
- if (n) \
- return EC_SUCCESS; \
- else \
- return EC_ERROR_UNKNOWN; \
- } while (0)
-
static int test_strlen(void)
{
TEST_CHECK(strlen("this is a string") == 16);
@@ -111,7 +84,7 @@ static int test_scratchpad(void)
void run_test(void)
{
- error_count = 0;
+ test_reset();
RUN_TEST(test_strlen);
RUN_TEST(test_strcasecmp);
@@ -121,16 +94,5 @@ void run_test(void)
RUN_TEST(test_shared_mem);
RUN_TEST(test_scratchpad);
- if (error_count)
- ccprintf("Failed %d tests!\n", error_count);
- else
- ccprintf("Pass!\n");
-}
-
-static int command_run_test(int argc, char **argv)
-{
- run_test();
- return EC_SUCCESS;
+ test_print_result();
}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);