Skip to content
Snippets Groups Projects
Commit aca12244 authored by Martine Lenders's avatar Martine Lenders
Browse files

tests: port semaphore tests to xtimer

parent 21ea7cc4
No related branches found
No related tags found
No related merge requests found
......@@ -22,13 +22,14 @@
* @}
*/
#include <errno.h>
#include <stdio.h>
#include <semaphore.h>
#include "msg.h"
#include "timex.h"
#include "thread.h"
#include "vtimer.h"
#include "xtimer.h"
#define SEMAPHORE_MSG_QUEUE_SIZE (8)
#define SEMAPHORE_TEST_THREADS (5)
......@@ -236,16 +237,16 @@ void test3(void)
void test4(void)
{
struct timespec abs;
char timestamp[TIMEX_MAX_STR_LEN];
timex_t now, start, stop, exp = { 1, 0 };
vtimer_now(&now);
abs.tv_sec = now.seconds + 1;
abs.tv_nsec = now.microseconds * 1000;
uint64_t now, start, stop;
const uint64_t exp = 1000000;
now = xtimer_now64();
abs.tv_sec = (time_t)((now / SEC_IN_USEC) + 1);
abs.tv_nsec = (long)((now % SEC_IN_USEC) * 1000);
puts("first: sem_init s1");
if (sem_init(&s1, 0, 0) < 0) {
puts("first: sem_init FAILED");
}
vtimer_now(&start);
start = xtimer_now64();
puts("first: wait 1 sec for s1");
if (sem_timedwait(&s1, &abs) != 0) {
if (errno != ETIMEDOUT) {
......@@ -256,18 +257,17 @@ void test4(void)
puts("first: timed out");
}
}
vtimer_now(&stop);
stop = timex_sub(stop, start);
if (timex_cmp(stop, exp) < 0) {
printf("first: waited only %s => FAILED\n",
timex_to_str(stop, timestamp));
stop = xtimer_now64() - start;
if (stop < exp) {
printf("first: waited only %" PRIu64 " usec => FAILED\n", stop);
}
printf("first: waited %s\n", timex_to_str(stop, timestamp));
printf("first: waited %" PRIu64 " usec\n", stop);
}
int main(void)
{
msg_init_queue(main_msg_queue, SEMAPHORE_MSG_QUEUE_SIZE);
xtimer_init();
puts("######################### TEST1:");
test1();
puts("######################### TEST2:");
......
......@@ -32,7 +32,6 @@ def test1(term):
term.expect_exact("first: sem_trywait FAILED")
term.expect_exact("first: sem_trywait done")
term.expect_exact("first: sem_post")
term.expect_exact("second: sem_wait failed")
term.expect_exact("second: sem was posted")
term.expect_exact("second: end")
term.expect_exact("first: sem_post done")
......@@ -90,7 +89,7 @@ def test4(term):
term.expect_exact("first: sem_init s1")
term.expect_exact("first: wait 1 sec for s1")
term.expect_exact("first: timed out")
term.expect(r"first: waited 1\.\d{6} s")
term.expect(r"first: waited 1\d{6} usec")
if __name__ == "__main__":
TERM = init()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment