varch/test/test_vstd.c

126 lines
2.8 KiB
C

#if defined(TEST_TARGET_vstd)
#include <varch/vstdlib.h>
#include <varch/unitt.h>
#include <varch/vmem.h>
#else
#include "init.h"
#include "command.h"
#include "unitt.h"
#include "kern.h"
#include "vstdlib.h"
#include "vmem.h"
#endif
/************************************************************************************/
/************************************* Unit Test ************************************/
/************************************************************************************/
// #define EXIT_TEST
extern uint64_t unitt_clock(void);
static int test_0(void)
{
for (int i = 0; i < 100; i++)
{
if (0)
{
#if defined (EXIT_TEST)
exit(0);
#endif
return UNITT_E_FAIL;
}
}
return UNITT_E_OK;
}
static void unitt_task(void)
{
static UNITT_TCASE rand_tests[] = {
UNITT_TCASE(test_0),
// UNITT_TCASE(test_1),
// UNITT_TCASE(test_2),
};
static UNITT suites[] = {
{ "xxx suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock },
};
UNITT_EXE(suites);
}
/************************************************************************************/
/************************************* Base Test ************************************/
/************************************************************************************/
extern int printf (const char *__format, ...);
static int test(int argc, char *argv[])
{
uint8_t *p;
printf("used %d\r\n", vmem_used());
p = v_malloc(2048);
if (!p)
{
printf("malloc fail!\r\n");
return 0;
}
else
{
printf("malloc success!\r\n");
}
printf("used %d\r\n", vmem_used());
v_free(p);
printf("used %d\r\n", vmem_used());
if (execute)
{
if (!strcmp(execute, "base"))
{
test_base();
}
else if (!strcmp(execute, "ut"))
{
srand((unsigned int)time(NULL));
#if defined(TEST_TARGET_vstd)
while (1)
{
unitt_task();
usleep(1000 * ut_period);
}
#else
printf("create task %d\r\n", task_create(ut_period, unitt_task));
#endif
}
}
else
{
test_base();
}
return 0;
}
/************************************************************************************/
/************************************ Test entry ************************************/
/************************************************************************************/
#if defined(TEST_TARGET_vstd)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_vstd(void)
{
command_export("vstd", test);
}
init_export_app(test_vstd);
#endif