diff --git a/projects/test_mutex_trylock_fail/Jamfile b/projects/test_mutex_trylock_fail/Jamfile new file mode 100644 index 0000000000000000000000000000000000000000..3f0bfe1dfdcfa027086fa61c7601b8ba25ce0439 --- /dev/null +++ b/projects/test_mutex_trylock_fail/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP projects test_mutex_trylock_fail ; + +Module test_mutex_trylock_fail : main.c ; + +UseModule test_mutex_trylock_fail ; diff --git a/projects/test_mutex_trylock_fail/main.c b/projects/test_mutex_trylock_fail/main.c new file mode 100644 index 0000000000000000000000000000000000000000..de7619adab366b229886b1b5f6be9cf641251a73 --- /dev/null +++ b/projects/test_mutex_trylock_fail/main.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <mutex.h> + +#include <thread.h> +#include <flags.h> +#include <kernel.h> + +mutex_t mutex; + +void second_thread(void) { + puts(" 2nd: trying to lock mutex..."); + mutex_trylock(&mutex); + puts(" 2nd: done."); +} + +tcb second_tcb; +char second_stack[8192]; + +int main(void) +{ + puts("main: locking mutex..."); + mutex_lock(&mutex); + + puts("main: creating thread..."); + int pid = thread_create(&second_tcb, second_stack, 8192, PRIORITY_MAIN-1, CREATE_STACKTEST, second_thread, "nr2"); + + puts("main: thread created. Unlocking mutex..."); + mutex_unlock(&mutex, true); + + puts("main: mutex unlocked."); +} diff --git a/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail b/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail new file mode 100755 index 0000000000000000000000000000000000000000..1795de002a42fd52f636efaeff4621dadacff096 --- /dev/null +++ b/projects/test_mutex_trylock_fail/tests/test_mutex_trylock_fail @@ -0,0 +1,13 @@ +#!/usr/bin/expect + +set timeout 5 + +spawn pseudoterm $env(PORT) + +expect { + "main: mutex unlocked." {} + timeout { exit 1 } +} + +puts "\nTest successful!\n" +