update it

This commit is contained in:
Sukchan Lee 2017-03-22 13:41:21 +09:00
parent 6cc5e486d1
commit f2c865f133
1 changed files with 64 additions and 119 deletions

View File

@ -32,8 +32,6 @@ static void msgq_test1(abts_case *tc, void *data)
{ {
int i, n; int i, n;
msgq_init();
/* Basic test */ /* Basic test */
md = msgq_create(5, 8, 0); md = msgq_create(5, 8, 0);
ABTS_INT_NEQUAL(tc, 0, md); ABTS_INT_NEQUAL(tc, 0, md);
@ -96,8 +94,6 @@ static void msgq_test2(abts_case *tc, void *data)
{ {
int i, n; int i, n;
msgq_init();
md = msgq_create(5, 8, MSGQ_O_NONBLOCK); md = msgq_create(5, 8, MSGQ_O_NONBLOCK);
ABTS_INT_NEQUAL(tc, 0, md); ABTS_INT_NEQUAL(tc, 0, md);
@ -135,8 +131,6 @@ static void msgq_test3(abts_case *tc, void *data)
{ {
int i, j, n; int i, j, n;
msgq_init();
md = msgq_create(16, 24, MSGQ_O_BLOCK); md = msgq_create(16, 24, MSGQ_O_BLOCK);
ABTS_INT_NEQUAL(tc, 0, md); ABTS_INT_NEQUAL(tc, 0, md);
@ -169,45 +163,43 @@ typedef struct {
char c[30]; char c[30];
} test_event_t; } test_event_t;
typedef struct {
abts_case *tc;
int opt;
int cancelled;
int timed;
} test_param_t;
static thread_id thr_producer; static thread_id thr_producer;
static thread_id thr_consumer; static thread_id thr_consumer;
static int max = 1000000; static int max = 100000;
static int exit_ret_val = 123; static int exit_ret_val = 123;
static void *THREAD_FUNC producer_main(thread_id id, void *data) static void *THREAD_FUNC producer_main(thread_id id, void *data)
{ {
test_param_t *param = (test_param_t *)data;
abts_case *tc = param->tc;
int r; int r;
int i = 0; int i = 0;
//time_t i_time = time(NULL);
unsigned int full = 0; unsigned int full = 0;
while (i++ < max) while (i++ < max)
{ {
test_event_t t; test_event_t te;
t.a = i; te.a = i;
t.b = i+2; te.b = i+2;
t.c[28] = 'X'; te.c[28] = 'X';
t.c[29] = 'Y'; te.c[29] = 'Y';
///printf("P: a = %d b = %d\n",t.a,t.b); r = msgq_send(md, (char*)&te, TEST_EVT_SIZE);
r = msgq_send(md, (char*)&t, TEST_EVT_SIZE);
if (r == CORE_EAGAIN) if (r == CORE_EAGAIN)
{ {
full++; full++;
thread_yield(); thread_yield();
continue; continue;
} }
else if (r != TEST_EVT_SIZE) ABTS_ASSERT(tc, "producer error", r == TEST_EVT_SIZE);
{
printf("Producer Error\n");
}
} }
#if 0
printf("Total Send:%u Drop = %u , elapsed time: %u\n",
i,
full,
(unsigned int)time(NULL)-(unsigned int)i_time);
#endif
thread_exit(id, exit_ret_val); thread_exit(id, exit_ret_val);
return NULL; return NULL;
@ -215,60 +207,29 @@ static void *THREAD_FUNC producer_main(thread_id id, void *data)
static void *THREAD_FUNC consumer_main(thread_id id, void *data) static void *THREAD_FUNC consumer_main(thread_id id, void *data)
{ {
abts_case *tc = data; test_param_t *param = (test_param_t *)data;
abts_case *tc = param->tc;
int r; int r;
///int prev = -1;
int i = 0;
///char str[256];
while (!thread_should_stop())
{
test_event_t t;
#if HAVE_PTHREAD_H == 1
pthread_testcancel();
#endif
r = msgq_recv(md, (char*)&t, TEST_EVT_SIZE);
if (r == CORE_EAGAIN)
{
thread_yield();
continue;
}
ABTS_ASSERT(tc, "consumer error", r == TEST_EVT_SIZE);
ABTS_ASSERT(tc, "consumer error", t.c[28] == 'X' && t.c[29] == 'Y');
///sprintf(str, "consumer error - prev:%d, t.a:%d", prev, t.a);
///ABTS_ASSERT(tc, str, (prev+1) == t.a);
///prev = t.a;
///printf("C: a = %d b = %d\n",t.a,t.b);
i++;
}
return NULL;
}
static void *THREAD_FUNC timedconsumer_main(thread_id id, void *data)
{
abts_case *tc = data;
int r;
///int prev = -1;
int i = 0; int i = 0;
while (!thread_should_stop()) while (!thread_should_stop())
{ {
test_event_t t; test_event_t te;
#if HAVE_PTHREAD_H == 1 if (param->cancelled)
pthread_testcancel(); pthread_testcancel();
#endif
r = msgq_timedrecv(md, (char*)&t, TEST_EVT_SIZE, 10000); if (param->timed)
r = msgq_timedrecv(md, (char*)&te, TEST_EVT_SIZE, 10000);
else
r = msgq_recv(md, (char*)&te, TEST_EVT_SIZE);
if (r == CORE_EAGAIN || r == CORE_TIMEUP) if (r == CORE_EAGAIN || r == CORE_TIMEUP)
{ {
thread_yield(); thread_yield();
continue; continue;
} }
ABTS_ASSERT(tc, "consumer error", r == TEST_EVT_SIZE); ABTS_ASSERT(tc, "consumer error", r == TEST_EVT_SIZE);
ABTS_ASSERT(tc, "consumer error", t.c[28] == 'X' && t.c[29] == 'Y'); ABTS_ASSERT(tc, "consumer error", te.c[28] == 'X' && te.c[29] == 'Y');
///prev = t.a;
i++; i++;
} }
@ -278,66 +239,38 @@ static void *THREAD_FUNC timedconsumer_main(thread_id id, void *data)
static void msgq_test4(abts_case *tc, void *data) static void msgq_test4(abts_case *tc, void *data)
{ {
status_t rv; status_t rv;
int opt = (int)data; test_param_t *param = (test_param_t *)data;
#if HAVE_PTHREAD_H == 1 param->tc = tc;
os_thread_t *thread;
#endif
md = msgq_create(TEST_QUEUE_SIZE, TEST_EVT_SIZE, opt); md = msgq_create(TEST_QUEUE_SIZE, TEST_EVT_SIZE, param->opt);
ABTS_INT_NEQUAL(tc, 0, md); ABTS_INT_NEQUAL(tc, 0, md);
rv = thread_create(&thr_producer, NULL, producer_main, NULL); rv = thread_create(&thr_producer, NULL, producer_main, param);
ABTS_INT_EQUAL(tc, CORE_OK, rv); ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = thread_create(&thr_consumer, NULL, consumer_main, tc); rv = thread_create(&thr_consumer, NULL, consumer_main, param);
ABTS_INT_EQUAL(tc, CORE_OK, rv); ABTS_INT_EQUAL(tc, CORE_OK, rv);
thread_join(&rv, thr_producer); thread_join(&rv, thr_producer);
ABTS_INT_EQUAL(tc, exit_ret_val, rv); ABTS_INT_EQUAL(tc, exit_ret_val, rv);
#if HAVE_PTHREAD_H == 1 if (param->cancelled)
os_thread_get(&thread, thr_consumer); {
pthread_cancel(*thread); os_thread_t *thread;
thread_join(&rv, thr_consumer);
#else os_thread_get(&thread, thr_consumer);
thread_delete(thr_consumer); pthread_cancel(*thread);
#endif thread_join(&rv, thr_consumer);
}
else
{
thread_delete(thr_consumer);
}
msgq_delete(md); msgq_delete(md);
} }
static void msgq_test5(abts_case *tc, void *data) #define STRESS_TEST 0
{
status_t rv;
int opt = (int)data;
#if HAVE_PTHREAD_H == 1
os_thread_t *thread;
#endif
md = msgq_create(TEST_QUEUE_SIZE, TEST_EVT_SIZE, opt);
ABTS_INT_NEQUAL(tc, 0, md);
rv = thread_create(&thr_producer, NULL, producer_main, NULL);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = thread_create(&thr_consumer, NULL, timedconsumer_main, tc);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
thread_join(&rv, thr_producer);
ABTS_INT_EQUAL(tc, exit_ret_val, rv);
#if HAVE_PTHREAD_H == 1
os_thread_get(&thread, thr_consumer);
pthread_cancel(*thread);
thread_join(&rv, thr_consumer);
#else
thread_delete(thr_consumer);
#endif
msgq_delete(md);
}
#define STRESS_TEST 1
abts_suite *testmsgq(abts_suite *suite) abts_suite *testmsgq(abts_suite *suite)
{ {
@ -353,13 +286,25 @@ abts_suite *testmsgq(abts_suite *suite)
while(1) while(1)
{ {
#endif #endif
abts_run_test(suite, msgq_test4, (void *)MSGQ_O_NONBLOCK); test_param_t param;
abts_run_test(suite, msgq_test4, (void *)MSGQ_O_BLOCK); memset(&param, 0, sizeof(test_param_t));
abts_run_test(suite, msgq_test5, (void *)MSGQ_O_NONBLOCK);
abts_run_test(suite, msgq_test5, (void *)MSGQ_O_BLOCK); param.opt = MSGQ_O_NONBLOCK;
abts_run_test(suite, msgq_test4, (void *)&param);
#if HAVE_PTHREAD_H == 1
param.opt = MSGQ_O_BLOCK;
param.cancelled = 1;
abts_run_test(suite, msgq_test4, (void *)&param);
#endif
param.opt = MSGQ_O_NONBLOCK;
param.timed = 1;
abts_run_test(suite, msgq_test4, (void *)&param);
param.opt = MSGQ_O_BLOCK;
param.timed = 1;
abts_run_test(suite, msgq_test4, (void *)&param);
#if STRESS_TEST == 1 #if STRESS_TEST == 1
printf("Test again = %u\n", (unsigned int)time(NULL)); printf("Test again = %"C_UINT64_T_FMT "\n", time_now());
sleep(5); sleep(3);
} }
#endif #endif