-+ //test_preempt ();
-+ //test_fifo ();
-+ test_donate_return ();
- }
- \f
--/* Based on a test originally submitted for Stanford's CS 140 in
-- winter 1998 by Rob Baesman <rbaesman@cs.stanford.edu>, Ben
-- Taskar <btaskar@cs.stanford.edu>, and Toli Kuznets
-- <tolik@cs.stanford.edu>. */
--struct sleep_thread_data
-- {
-- int64_t start; /* Start time. */
-- int duration; /* Number of ticks to sleep. */
-- int iterations; /* Number of iterations to run. */
-- int *product; /* Largest product so far. */
-- struct lock *lock; /* Lock on access to `product'. */
-- struct semaphore done; /* Completion semaphore. */
-- tid_t tid; /* Thread ID. */
-- };
-+static thread_func simple_thread_func;
-+static thread_func acquire_thread_func;
-
--static void sleeper (void *);
-+static void
-+test_preempt (void)
-+{
-+ printf ("\n"
-+ "Testing priority preemption.\n");
-+ thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL);
-+ printf ("The high-priority thread should have already completed.\n"
-+ "Priority preemption test done.\n");
-+}
-
- static void
--test_sleep (int iterations)
-+test_fifo (void)
- {
-- struct sleep_thread_data threads[5];
-- const int thread_cnt = sizeof threads / sizeof *threads;
-- struct lock lock;
-- int64_t start;
-- int product;
- int i;
--
-+
- printf ("\n"
-- "Testing %d sleeps per thread.\n"
-- "If successful, product of iteration count and\n"
-- "sleep duration will appear in nondescending order.\n",
-- iterations);
--
-- /* Start all the threads. */
-- product = 0;
-- lock_init (&lock, "product");
-- start = timer_ticks ();
-- for (i = 0; i < thread_cnt; i++)
-+ "Testing FIFO preemption.\n"
-+ "5 threads will iterate 10 times in the same order each time.\n"
-+ "If the order varies then there is a bug.\n");
-+
-+ thread_set_priority (PRI_DEFAULT + 2);
-+ for (i = 0; i < 5; i++)
- {
-- struct sleep_thread_data *t;
- char name[16];
--
-- snprintf (name, sizeof name, "thread %d", i);
-- t = threads + i;
-- t->start = start;
-- t->duration = (i + 1) * 10;
-- t->iterations = iterations;
-- t->product = &product;
-- t->lock = &lock;
-- sema_init (&t->done, 0, name);
-- t->tid = thread_create (name, PRI_DEFAULT, sleeper, t);
-- }
--
-- /* Wait for all the threads to finish. */
-- for (i = 0; i < thread_cnt; i++)
-- {
--#ifdef THREAD_JOIN_IMPLEMENTED
-- thread_join (threads[i].tid);
--#else
-- sema_down (&threads[i].done);
--#endif
-+ snprintf (name, sizeof name, "%d", i);
-+ thread_create (name, PRI_DEFAULT + 1, simple_thread_func, NULL);
- }
-+ thread_set_priority (PRI_DEFAULT);
-
-- printf ("...done\n");
-+ printf ("FIFO preemption test done.\n");