13static void test_sleep (
int thread_cnt,
int iterations);
62 msg (
"Creating %d threads to sleep %d times each.", thread_cnt,
iterations);
63 msg (
"Thread 0 sleeps 10 ticks each time,");
64 msg (
"thread 1 sleeps 20 ticks each time, and so on.");
65 msg (
"If successful, product of iteration count and");
66 msg (
"sleep duration will appear in nondescending order.");
69 threads =
malloc (
sizeof *threads * thread_cnt);
71 if (threads ==
NULL || output ==
NULL)
72 PANIC (
"couldn't allocate memory for test");
78 test.output_pos = output;
82 for (i = 0; i < thread_cnt; i++)
105 for (op = output; op <
test.output_pos; op++)
110 ASSERT (*op >= 0 && *op < thread_cnt);
115 msg (
"thread %d: duration=%d, iteration=%d, product=%d",
118 if (new_prod >= product)
121 fail (
"thread %d woke up out of order (%d > %d)!",
122 t->
id, product, new_prod);
126 for (i = 0; i < thread_cnt; i++)
128 fail (
"thread %d woke up %d times instead of %d",
144 for (i = 1; i <=
test->iterations; i++)
149 *
test->output_pos++ = t->
id;
void test_alarm_multiple(void)
static void sleeper(void *)
Sleeper thread.
static void test_sleep(int thread_cnt, int iterations)
Creates N threads, each of which sleeps a different, fixed duration, M times.
void test_alarm_single(void)
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
void fail(const char *format,...)
void msg(const char *format,...)
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
void free(void *p)
Frees block P, which must have been previously allocated with malloc(), calloc(), or realloc().
signed long long int int64_t
Information about the test.
struct lock output_lock
Lock protecting output buffer.
int * output_pos
Current position in output buffer.
int iterations
Number of iterations per thread.
int64_t start
Current time at start of test.
Information about an individual thread in the test.
int iterations
Iterations counted so far.
int duration
Number of ticks to sleep.
struct sleep_test * test
Info shared between all threads.
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
void lock_init(struct lock *lock)
Initializes LOCK.
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
void test(void)
Test the linked list implementation.
bool thread_mlfqs
If false (default), use round-robin scheduler.
tid_t thread_create(const char *name, int priority, thread_func *function, void *aux)
Creates a new kernel thread named NAME with the given initial PRIORITY, which executes FUNCTION passi...
#define PRI_DEFAULT
Default priority.
int64_t timer_ticks(void)
Returns the number of timer ticks since the OS booted.
void timer_sleep(int64_t ticks)
Sleeps for approximately TICKS timer ticks.