+#if CONFIG_KERN_SIGNALS & CONFIG_KERN_PRI
+
+// Define params to test priority
+#define PROC_PRI_TEST(num) static void proc_pri_test##num(void) \
+{ \
+ struct Process *main_proc = (struct Process *) proc_currentUserData(); \
+ kputs("> Process: " #num "\n"); \
+ sig_send(main_proc, SIG_USER##num); \
+}
+
+// Default priority is 0
+#define PROC_PRI_TEST_INIT(num, proc) \
+do { \
+ struct Process *p = proc_new(proc_pri_test##num, (proc), \
+ WORKER_STACK_SIZE, \
+ WORKER_STACK(num)); \
+ proc_setPri(p, num + 1); \
+} while (0)
+
+PROC_PRI_TEST(0)
+PROC_PRI_TEST(1)
+PROC_PRI_TEST(2)
+
+static int prio_worker_test(void)
+{
+ struct Process *curr = proc_current();
+ int orig_pri = curr->link.pri;
+ int ret = 0;
+
+ // test process priority
+ // main process must have the higher priority to check signals received
+ proc_setPri(proc_current(), 10);
+
+ kputs("Run Priority test..\n");
+ // the order in which the processes are created is important!
+ PROC_PRI_TEST_INIT(0, curr);
+ PROC_PRI_TEST_INIT(1, curr);
+ PROC_PRI_TEST_INIT(2, curr);
+
+ // signals must be: USER2, 1, 0 in order
+ sigmask_t signals = sig_wait(SIG_USER0 | SIG_USER1 | SIG_USER2);
+ if (!(signals & SIG_USER2))
+ {
+ ret = -1;
+ goto out;
+ }
+ signals = sig_wait(SIG_USER0 | SIG_USER1 | SIG_USER2);
+ if (!(signals & SIG_USER1))
+ {
+ ret = -1;
+ goto out;
+ }
+ signals = sig_wait(SIG_USER0 | SIG_USER1 | SIG_USER2);
+ if (!(signals & SIG_USER0))
+ {
+ ret = -1;
+ goto out;
+ }
+ // All processes must have quit by now, but just in case...
+ signals = sig_waitTimeout(SIG_USER0 | SIG_USER1 | SIG_USER2, 200);
+ if (signals & (SIG_USER0 | SIG_USER1 | SIG_USER2))
+ {
+ ret = -1;
+ goto out;
+ }
+ if (signals & SIG_TIMEOUT)
+ {
+ kputs("Priority test successfull.\n");
+ }
+out:
+ proc_setPri(proc_current(), orig_pri);
+ if (ret != 0)
+ kputs("Priority test failed.\n");
+ return ret;
+}
+#endif /* CONFIG_KERN_SIGNALS & CONFIG_KERN_PRI */
+
+/**
+ * Process scheduling test
+ */
+int proc_testRun(void)
+{
+ /* Start tests */
+ worker_test();
+#if CONFIG_KERN_PREEMPT
+ preempt_worker_test();
+#endif /* CONFIG_KERN_PREEMPT */
+#if CONFIG_KERN_SIGNALS & CONFIG_KERN_PRI
+ prio_worker_test();
+#endif /* CONFIG_KERN_SIGNALS & CONFIG_KERN_PRI */
+ return 0;
+}