X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fmsg_test.c;h=bcb20ea288ef89e94da0569664108d4421915346;hb=32d1445272120a254d77ce8d1af1f527da7a2c17;hp=638eeddd2ede6aea9cf6c1473144bb7e982591a1;hpb=60bc240688870da108a4265d5d28f351995a025c;p=bertos.git diff --git a/bertos/kern/msg_test.c b/bertos/kern/msg_test.c index 638eeddd..bcb20ea2 100644 --- a/bertos/kern/msg_test.c +++ b/bertos/kern/msg_test.c @@ -51,13 +51,24 @@ #include #include -#include +#include + +#include #include +/* + * In the nightly build test, signals are disables, so this + * code won't compile. + * Since this code is used when we run "make check" it will be + * compiled and therefor tested there. + */ +#if CONFIG_KERN_SIGNALS + + // Global settings for the test. #define MAX_GLOBAL_COUNT 11040 -#define TEST_TIME_OUT_MS 10 +#define TEST_TIME_OUT_MS 5000 #define DELAY 5 // Settings for the test message. @@ -83,21 +94,23 @@ /* * These macros generate the code needed to create the test process functions. */ -#define RECV_PROC(num, sig) static void receiver_proc##num(void) \ - { \ - TestMsg *rec_msg; \ - for (;;) \ - { \ - sig_wait(sig); \ - kprintf("Proc[%d]..get message\n", num); \ - rec_msg = containerof(msg_get(&test_port##num), TestMsg, msg); \ - timer_delay(rec_msg->delay); \ - rec_msg->result += rec_msg->val; \ - kprintf("Proc[%d]..process message val[%d],delay[%d],res[%d]\n", num, rec_msg->val, rec_msg->delay, rec_msg->result); \ - msg_reply(&rec_msg->msg); \ - kprintf("Proc[%d] reply\n", num); \ - } \ - } +#define RECV_PROC(num, sig) \ +static NORETURN void receiver_proc##num(void) \ +{ \ + TestMsg *rec_msg; \ + for(;;) \ + { \ + sig_wait(sig); \ + kprintf("Proc[%d]..get message\n", num); \ + rec_msg = containerof(msg_get(&test_port##num), TestMsg, msg); \ + timer_delay(rec_msg->delay); \ + rec_msg->result += rec_msg->val; \ + kprintf("Proc[%d]..process message val[%d],delay[%d],res[%d]\n", num, rec_msg->val, rec_msg->delay, rec_msg->result); \ + msg_reply(&rec_msg->msg); \ + process_num++; \ + kprintf("Proc[%d] reply\n", num); \ + } \ +} #define SEND_MSG(num) \ do { \ @@ -106,9 +119,9 @@ msg_put(&test_port##num, &msg##num.msg); \ } while(0) -#define RECV_STACK(num) static cpu_stack_t receiver_stack##num[CONFIG_KERN_MINSTACKSIZE / sizeof(cpu_stack_t)] +#define RECV_STACK(num) PROC_DEFINE_STACK(receiver_stack##num, KERN_MINSTACKSIZE * 2) #define RECV_INIT_PROC(num) proc_new(receiver_proc##num, NULL, sizeof(receiver_stack##num), receiver_stack##num) -#define RECV_INIT_MSG(num, proc,sig) msg_initPort(&test_port##num, event_createSignal(proc, sig)) +#define RECV_INIT_MSG(num, proc, sig) msg_initPort(&test_port##num, event_createSignal(proc, sig)) // A test message with the parameters and a result. typedef struct @@ -122,6 +135,7 @@ typedef struct // Global count to check if the test is going ok. static int count = 0; +static int process_num; // Our message port. static MsgPort test_port0; @@ -211,6 +225,7 @@ int msg_testRun(void) // Send and wait the message for (int i = 0; i < 23; ++i) { + process_num = 0; SEND_MSG(0); SEND_MSG(1); SEND_MSG(2); @@ -219,14 +234,24 @@ int msg_testRun(void) SEND_MSG(5); while(1) { - if(sig_waitTimeout(SIG_SINGLE, TEST_TIME_OUT_MS) && SIG_SINGLE) + sigmask_t sigs = sig_waitTimeout(SIG_SINGLE, ms_to_ticks(TEST_TIME_OUT_MS)); + if (sigs & SIG_SINGLE) { // Wait for a reply... - reply = containerof(msg_get(&test_portMain), TestMsg, msg); - if(reply == NULL) - break; - count += reply->result; - kprintf("Main recv[%d] count[%d]\n", reply->result, count); + while ((reply = (TestMsg *)msg_get(&test_portMain))) + { + count += reply->result; + kprintf("Main recv[%d] count[%d]\n", reply->result, count); + } + } + + if (process_num == 6) + break; + + if (sigs & SIG_TIMEOUT) + { + kputs("Main: sig timeout\n"); + goto error; } } } @@ -236,7 +261,8 @@ int msg_testRun(void) kprintf("Message test finished..ok!\n"); return 0; } - + +error: kprintf("Message test finished..fail!\n"); return -1; } @@ -245,12 +271,6 @@ int msg_testSetup(void) { kdbg_init(); - #if CONFIG_KERN_PREEMPT - kprintf("Init Interrupt (preempt mode).."); - irq_init(); - kprintf("Done.\n"); - #endif - kprintf("Init Timer.."); timer_init(); kprintf("Done.\n"); @@ -268,3 +288,5 @@ int msg_testTearDown(void) } TEST_MAIN(msg); + +#endif /* CONFIG_KERN_SIGNALS */