Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / threads / priority-sema.c
1 #include <stdio.h>
2 #include "tests/threads/tests.h"
3 #include "threads/init.h"
4 #include "threads/malloc.h"
5 #include "threads/synch.h"
6 #include "threads/thread.h"
7 #include "devices/timer.h"
8
9 static thread_func priority_sema_thread;
10 static struct semaphore sema;
11
12 void
13 test_priority_sema (void) 
14 {
15   int i;
16   
17   /* This test does not work with the MLFQS. */
18   ASSERT (!enable_mlfqs);
19
20   sema_init (&sema, 0);
21   thread_set_priority (PRI_MAX);
22   for (i = 0; i < 10; i++) 
23     {
24       int priority = (i + 3) % 10 + PRI_DEFAULT + 1;
25       char name[16];
26       snprintf (name, sizeof name, "priority %d", priority);
27       thread_create (name, priority, priority_sema_thread, NULL);
28     }
29
30   for (i = 0; i < 10; i++) 
31     {
32       sema_up (&sema);
33       msg ("Back in main thread."); 
34     }
35 }
36
37 static void
38 priority_sema_thread (void *aux UNUSED) 
39 {
40   sema_down (&sema);
41   msg ("Thread %s woke up.", thread_name ());
42 }