summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/threads/priority-preempt.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/threads/priority-preempt.c
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/threads/priority-preempt.c')
-rw-r--r--pintos-progos/tests/threads/priority-preempt.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/pintos-progos/tests/threads/priority-preempt.c b/pintos-progos/tests/threads/priority-preempt.c
new file mode 100644
index 0000000..3c3aacb
--- /dev/null
+++ b/pintos-progos/tests/threads/priority-preempt.c
@@ -0,0 +1,41 @@
1/* Ensures that a high-priority thread really preempts.
2
3 Based on a test originally submitted for Stanford's CS 140 in
4 winter 1999 by by Matt Franklin
5 <startled@leland.stanford.edu>, Greg Hutchins
6 <gmh@leland.stanford.edu>, Yu Ping Hu <yph@cs.stanford.edu>.
7 Modified by arens. */
8
9#include <stdio.h>
10#include "tests/threads/tests.h"
11#include "threads/init.h"
12#include "threads/synch.h"
13#include "threads/thread.h"
14
15static thread_func simple_thread_func;
16
17void
18test_priority_preempt (void)
19{
20 /* This test does not work with the MLFQS. */
21 ASSERT (!thread_mlfqs);
22
23 /* Make sure our priority is the default. */
24 ASSERT (thread_get_priority () == PRI_DEFAULT);
25
26 thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL);
27 msg ("The high-priority thread should have already completed.");
28}
29
30static void
31simple_thread_func (void *aux UNUSED)
32{
33 int i;
34
35 for (i = 0; i < 5; i++)
36 {
37 msg ("Thread %s iteration %d", thread_name (), i);
38 thread_yield ();
39 }
40 msg ("Thread %s done!", thread_name ());
41}