Add a test for testing common utilities

BUG=chrome-os-partner:18598
TEST=Run on Spring
BRANCH=None

Change-Id: Ie10f81783a0c22a10b9535350dc29b972bffd87e
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47962
This commit is contained in:
Vic Yang
2013-04-12 10:20:25 +08:00
committed by ChromeBot
parent 6f2ec76a25
commit 1cc01fdcbc
3 changed files with 102 additions and 1 deletions

View File

@@ -8,7 +8,7 @@
test-list=hello pingpong timer_calib timer_dos timer_jump mutex thermal
test-list+=power_button kb_deghost kb_debounce scancode typematic charging
test-list+=flash_overwrite flash_rw_erase
test-list+=flash_overwrite flash_rw_erase utils
#disable: powerdemo
kb_deghost-y=kb_deghost.o
@@ -19,6 +19,7 @@ timer_dos-y=timer_dos.o
mutex-y=mutex.o
flash_overwrite-y=flash.o
flash_rw_erase-y=flash.o
utils-y=utils.o
# Mock modules for 'thermal'
chip-mock-thermal-lpc.o=mock_lpc.o

83
test/utils.c Normal file
View File

@@ -0,0 +1,83 @@
/* Copyright (c) 2013 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 common utilities.
*/
#include "common.h"
#include "console.h"
#include "util.h"
static int error_count;
#define RUN_TEST(n) \
do { \
ccprintf("Running %s...", #n); \
cflush(); \
if (n()) { \
ccputs("OK\n"); \
} else { \
ccputs("Fail\n"); \
error_count++; \
} \
} while (0)
static int test_strlen(void)
{
return strlen("this is a string") == 16;
}
static int test_strcasecmp(void)
{
return (strcasecmp("test string", "TEST strIng") == 0) &&
(strcasecmp("test123!@#", "TesT123!@#") == 0) &&
(strcasecmp("lower", "UPPER") != 0);
}
static int test_strncasecmp(void)
{
return (strncasecmp("test string", "TEST str", 4) == 0) &&
(strncasecmp("test string", "TEST str", 8) == 0) &&
(strncasecmp("test123!@#", "TesT321!@#", 5) != 0) &&
(strncasecmp("test123!@#", "TesT321!@#", 4) == 0) &&
(strncasecmp("1test123!@#", "1TesT321!@#", 5) == 0);
}
static int test_atoi(void)
{
return (atoi(" 901") == 901) &&
(atoi("-12c") == -12) &&
(atoi(" 0 ") == 0) &&
(atoi("\t111") == 111);
}
static int test_uint64divmod(void)
{
uint64_t n = 8567106442584750ULL;
int d = 54870071;
int r = uint64divmod(&n, d);
return (r == 5991285 && n == 156134415ULL);
}
static int command_run_test(int argc, char **argv)
{
error_count = 0;
RUN_TEST(test_strlen);
RUN_TEST(test_strcasecmp);
RUN_TEST(test_strncasecmp);
RUN_TEST(test_atoi);
RUN_TEST(test_uint64divmod);
if (error_count) {
ccprintf("Failed %d tests!\n", error_count);
return EC_ERROR_UNKNOWN;
} else {
ccprintf("Pass!\n");
return EC_SUCCESS;
}
}
DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
NULL, NULL, NULL);

17
test/utils.tasklist Normal file
View File

@@ -0,0 +1,17 @@
/* Copyright (c) 2013 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.
*/
/**
* List of enabled tasks in the priority order
*
* The first one has the lowest priority.
*
* For each task, use the macro TASK_TEST(n, r, d, s) where :
* 'n' in the name of the task
* 'r' in the main routine of the task
* 'd' in an opaque parameter passed to the routine at startup
* 's' is the stack size in bytes; must be a multiple of 8
*/
#define CONFIG_TEST_TASK_LIST /* No test task */