summaryrefslogtreecommitdiffstats
path: root/src/tests/threads/priority-change.c
diff options
context:
space:
mode:
authorFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
committerFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
commitd4522b8e9854178473adcea0fbb84f23f6e744bd (patch)
treefbcf620617c5023154eba3f965b3a982daa64a47 /src/tests/threads/priority-change.c
downloadpintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz
Initial commit
Diffstat (limited to 'src/tests/threads/priority-change.c')
-rw-r--r--src/tests/threads/priority-change.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/tests/threads/priority-change.c b/src/tests/threads/priority-change.c
new file mode 100644
index 0000000..810b05a
--- /dev/null
+++ b/src/tests/threads/priority-change.c
@@ -0,0 +1,31 @@
+/* Verifies that lowering a thread's priority so that it is no
+ longer the highest-priority thread in the system causes it to
+ yield immediately. */
+
+#include <stdio.h>
+#include "tests/threads/tests.h"
+#include "threads/init.h"
+#include "threads/thread.h"
+
+static thread_func changing_thread;
+
+void
+test_priority_change (void)
+{
+ /* This test does not work with the MLFQS. */
+ ASSERT (!thread_mlfqs);
+
+ msg ("Creating a high-priority thread 2.");
+ thread_create ("thread 2", PRI_DEFAULT + 1, changing_thread, NULL);
+ msg ("Thread 2 should have just lowered its priority.");
+ thread_set_priority (PRI_DEFAULT - 2);
+ msg ("Thread 2 should have just exited.");
+}
+
+static void
+changing_thread (void *aux UNUSED)
+{
+ msg ("Thread 2 now lowering priority.");
+ thread_set_priority (PRI_DEFAULT - 1);
+ msg ("Thread 2 exiting.");
+}