From 8b91cd790b73ac0d9da358ec47a78393630c8aa4 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 2 Nov 2010 13:46:25 +0100 Subject: [PATCH] * test_suite: added thread_sleep test & expect script' --- projects/test_suite/tests/04-thread_sleep | 70 +++++++++++++++++++++++ projects/test_suite/thread_sleep.c | 6 +- 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100755 projects/test_suite/tests/04-thread_sleep diff --git a/projects/test_suite/tests/04-thread_sleep b/projects/test_suite/tests/04-thread_sleep new file mode 100755 index 0000000000..1734706b7a --- /dev/null +++ b/projects/test_suite/tests/04-thread_sleep @@ -0,0 +1,70 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + ">$" {} + timeout { exit 1 } +} + +send "start_test\n" +expect { + "\[TEST_START\]" {} + timeout { exit 1 } +} + +expect { + ">$" {} + timeout { exit 1 } +} + +send "thread_sleep\n" +expect { +" main: running. integer=0, i=1." {} +" main: running. integer=0, i=2." {} +"Waking up sleeper." {} +"sleeper: running. integer=1, i=2." {} +"sleeper: running. integer=2, i=2." {} +"Going to sleep." {} +" main: running. integer=2, i=3." {} +" main: running. integer=2, i=4." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=3, i=4." {} +"sleeper: running. integer=4, i=4." {} +"Going to sleep." {} +" main: running. integer=4, i=5." {} +" main: running. integer=4, i=6." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=5, i=6." {} +"sleeper: running. integer=6, i=6." {} +"Going to sleep." {} +" main: running. integer=6, i=7." {} +" main: running. integer=6, i=8." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=7, i=8." {} +"sleeper: running. integer=8, i=8." {} +"Going to sleep." {} +" main: running. integer=8, i=9." {} +" main: running. integer=8, i=10." {} +"Waking up sleeper." {} +"Woke up!" {} +"sleeper: running. integer=9, i=10." {} +"sleeper: running. integer=10, i=10." {} +"Going to sleep." {} + ">$" {} + timeout { exit 1 } +} + +send "end_test\n" + +expect { + "\[TEST_END\]" {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" diff --git a/projects/test_suite/thread_sleep.c b/projects/test_suite/thread_sleep.c index c4bc3294a3..7790a32e0d 100644 --- a/projects/test_suite/thread_sleep.c +++ b/projects/test_suite/thread_sleep.c @@ -9,7 +9,7 @@ static void second_thread(void) { while(1) { integer++; printf("sleeper: running. integer=%i, i=%i.\n", integer, i); - if (integer % 10 == 0) { + if (integer % 2 == 0) { printf("Going to sleep.\n"); thread_sleep(); printf("Woke up!\n"); @@ -29,10 +29,10 @@ void test_thread_sleep(char* line) while(1); } - while(1) { + while(i < 10) { i++; printf(" main: running. integer=%i, i=%i.\n", integer, i); - if (i % 10 == 0) { + if (i % 2 == 0) { printf("Waking up sleeper.\n"); thread_wakeup(pid); }