mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 10:45:22 +00:00
Add shared memory test
Also changes utils test to use EC_SUCCESS to indicate test success. BUG=chrome-os-partner:18598 TEST=Run on Spring BRANCH=None Change-Id: I4a9b08550c15f09cd467706b6a3c0142dd06a558 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/48751 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
test-list=pingpong timer_calib timer_dos timer_jump mutex thermal
|
||||
test-list+=power_button kb_scan scancode typematic charging flash
|
||||
test-list+=stress
|
||||
test-list+=stress utils
|
||||
#disable: powerdemo
|
||||
|
||||
flash-y=flash.o
|
||||
|
||||
70
test/utils.c
70
test/utils.c
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "shared_mem.h"
|
||||
#include "timer.h"
|
||||
#include "util.h"
|
||||
|
||||
static int error_count;
|
||||
@@ -15,7 +17,7 @@ static int error_count;
|
||||
do { \
|
||||
ccprintf("Running %s...", #n); \
|
||||
cflush(); \
|
||||
if (n()) { \
|
||||
if (n() == EC_SUCCESS) { \
|
||||
ccputs("OK\n"); \
|
||||
} else { \
|
||||
ccputs("Fail\n"); \
|
||||
@@ -23,33 +25,47 @@ static int 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)
|
||||
{
|
||||
return strlen("this is a string") == 16;
|
||||
TEST_CHECK(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);
|
||||
TEST_CHECK((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);
|
||||
TEST_CHECK((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);
|
||||
TEST_CHECK((atoi(" 901") == 901) &&
|
||||
(atoi("-12c") == -12) &&
|
||||
(atoi(" 0 ") == 0) &&
|
||||
(atoi("\t111") == 111));
|
||||
}
|
||||
|
||||
static int test_uint64divmod(void)
|
||||
@@ -58,7 +74,30 @@ static int test_uint64divmod(void)
|
||||
int d = 54870071;
|
||||
int r = uint64divmod(&n, d);
|
||||
|
||||
return (r == 5991285 && n == 156134415ULL);
|
||||
TEST_CHECK(r == 5991285 && n == 156134415ULL);
|
||||
}
|
||||
|
||||
static int test_shared_mem(void)
|
||||
{
|
||||
int i, j;
|
||||
int sz = shared_mem_size();
|
||||
char *mem;
|
||||
|
||||
TEST_ASSERT(shared_mem_acquire(sz, &mem) == EC_SUCCESS);
|
||||
TEST_ASSERT(shared_mem_acquire(sz, &mem) == EC_ERROR_BUSY);
|
||||
|
||||
for (i = 0; i < 256; ++i) {
|
||||
memset(mem, i, sz);
|
||||
for (j = 0; j < sz; ++j)
|
||||
TEST_ASSERT(mem[j] == i);
|
||||
|
||||
if ((i & 0xf) == 0)
|
||||
msleep(20); /* Yield to other tasks */
|
||||
}
|
||||
|
||||
shared_mem_release(mem);
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int command_run_test(int argc, char **argv)
|
||||
@@ -70,6 +109,7 @@ static int command_run_test(int argc, char **argv)
|
||||
RUN_TEST(test_strncasecmp);
|
||||
RUN_TEST(test_atoi);
|
||||
RUN_TEST(test_uint64divmod);
|
||||
RUN_TEST(test_shared_mem);
|
||||
|
||||
if (error_count) {
|
||||
ccprintf("Failed %d tests!\n", error_count);
|
||||
|
||||
Reference in New Issue
Block a user