Commit a891d68b authored by Curd Becker's avatar Curd Becker
Browse files

replaced provided threads tests with the tests for our assignment description

parent f6a2989f
......@@ -2,5 +2,4 @@
# tests.
20.0% tests/threads/Rubric.alarm
40.0% tests/threads/Rubric.priority
40.0% tests/threads/Rubric.mlfqs
80.0% tests/threads/Rubric.synchronization
......@@ -2,51 +2,20 @@
# Test names.
tests/threads_TESTS = $(addprefix tests/threads/,alarm-single \
alarm-multiple alarm-simultaneous alarm-priority alarm-zero \
alarm-negative priority-change priority-donate-one \
priority-donate-multiple priority-donate-multiple2 \
priority-donate-nest priority-donate-sema priority-donate-lower \
priority-fifo priority-preempt priority-sema priority-condvar \
priority-donate-chain \
mlfqs-load-1 mlfqs-load-60 mlfqs-load-avg mlfqs-recent-1 mlfqs-fair-2 \
mlfqs-fair-20 mlfqs-nice-2 mlfqs-nice-10 mlfqs-block)
alarm-multiple alarm-simultaneous alarm-zero \
alarm-negative \
producer-consumer narrow-bridge)
# Sources for tests.
tests/threads_SRC = tests/threads/tests.c
tests/threads_SRC += tests/threads/alarm-wait.c
tests/threads_SRC += tests/threads/alarm-simultaneous.c
tests/threads_SRC += tests/threads/alarm-priority.c
tests/threads_SRC += tests/threads/alarm-zero.c
tests/threads_SRC += tests/threads/alarm-negative.c
tests/threads_SRC += tests/threads/priority-change.c
tests/threads_SRC += tests/threads/priority-donate-one.c
tests/threads_SRC += tests/threads/priority-donate-multiple.c
tests/threads_SRC += tests/threads/priority-donate-multiple2.c
tests/threads_SRC += tests/threads/priority-donate-nest.c
tests/threads_SRC += tests/threads/priority-donate-sema.c
tests/threads_SRC += tests/threads/priority-donate-lower.c
tests/threads_SRC += tests/threads/priority-fifo.c
tests/threads_SRC += tests/threads/priority-preempt.c
tests/threads_SRC += tests/threads/priority-sema.c
tests/threads_SRC += tests/threads/priority-condvar.c
tests/threads_SRC += tests/threads/priority-donate-chain.c
tests/threads_SRC += tests/threads/mlfqs-load-1.c
tests/threads_SRC += tests/threads/mlfqs-load-60.c
tests/threads_SRC += tests/threads/mlfqs-load-avg.c
tests/threads_SRC += tests/threads/mlfqs-recent-1.c
tests/threads_SRC += tests/threads/mlfqs-fair.c
tests/threads_SRC += tests/threads/mlfqs-block.c
tests/threads_SRC += tests/threads/producer-consumer.c
tests/threads_SRC += tests/threads/narrow-bridge.c
MLFQS_OUTPUTS = \
tests/threads/mlfqs-load-1.output \
tests/threads/mlfqs-load-60.output \
tests/threads/mlfqs-load-avg.output \
tests/threads/mlfqs-recent-1.output \
tests/threads/mlfqs-fair-2.output \
tests/threads/mlfqs-fair-20.output \
tests/threads/mlfqs-nice-2.output \
tests/threads/mlfqs-nice-10.output \
tests/threads/mlfqs-block.output
MLFQS_OUTPUTS =
$(MLFQS_OUTPUTS): KERNELFLAGS += -mlfqs
$(MLFQS_OUTPUTS): TIMEOUT = 480
......
File mode changed from 100644 to 100755
Functionality of advanced scheduler:
5 mlfqs-load-1
5 mlfqs-load-60
3 mlfqs-load-avg
5 mlfqs-recent-1
5 mlfqs-fair-2
3 mlfqs-fair-20
4 mlfqs-nice-2
2 mlfqs-nice-10
5 mlfqs-block
Functionality of priority scheduler:
3 priority-change
3 priority-preempt
3 priority-fifo
3 priority-sema
3 priority-condvar
3 priority-donate-one
3 priority-donate-multiple
3 priority-donate-multiple2
3 priority-donate-nest
5 priority-donate-chain
3 priority-donate-sema
3 priority-donate-lower
Synchronization problems:
35 producer-consumer
40 narrow-bridge
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
/* Checks that when the alarm clock wakes up threads, the
higher-priority threads run first. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/malloc.h"
#include "threads/synch.h"
#include "threads/thread.h"
#include "devices/timer.h"
static thread_func alarm_priority_thread;
static int64_t wake_time;
static struct semaphore wait_sema;
void
test_alarm_priority (void)
{
int i;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
wake_time = timer_ticks () + 5 * TIMER_FREQ;
sema_init (&wait_sema, 0);
for (i = 0; i < 10; i++)
{
int priority = PRI_DEFAULT - (i + 5) % 10 - 1;
char name[16];
snprintf (name, sizeof name, "priority %d", priority);
thread_create (name, priority, alarm_priority_thread, NULL);
}
thread_set_priority (PRI_MIN);
for (i = 0; i < 10; i++)
sema_down (&wait_sema);
}
static void
alarm_priority_thread (void *aux UNUSED)
{
/* Busy-wait until the current time changes. */
int64_t start_time = timer_ticks ();
while (timer_elapsed (start_time) == 0)
continue;
/* Now we know we're at the very beginning of a timer tick, so
we can call timer_sleep() without worrying about races
between checking the time and a timer interrupt. */
timer_sleep (wake_time - timer_ticks ());
/* Print a message on wake-up. */
msg ("Thread %s woke up.", thread_name ());
sema_up (&wait_sema);
}
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-priority) begin
(alarm-priority) Thread priority 30 woke up.
(alarm-priority) Thread priority 29 woke up.
(alarm-priority) Thread priority 28 woke up.
(alarm-priority) Thread priority 27 woke up.
(alarm-priority) Thread priority 26 woke up.
(alarm-priority) Thread priority 25 woke up.
(alarm-priority) Thread priority 24 woke up.
(alarm-priority) Thread priority 23 woke up.
(alarm-priority) Thread priority 22 woke up.
(alarm-priority) Thread priority 21 woke up.
(alarm-priority) end
EOF
pass;
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
/* Checks that recent_cpu and priorities are updated for blocked
threads.
The main thread sleeps for 25 seconds, spins for 5 seconds,
then releases a lock. The "block" thread spins for 20 seconds
then attempts to acquire the lock, which will block for 10
seconds (until the main thread releases it). If recent_cpu
decays properly while the "block" thread sleeps, then the
block thread should be immediately scheduled when the main
thread releases the lock. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/malloc.h"
#include "threads/synch.h"
#include "threads/thread.h"
#include "devices/timer.h"
static void block_thread (void *lock_);
void
test_mlfqs_block (void)
{
int64_t start_time;
struct lock lock;
ASSERT (thread_mlfqs);
msg ("Main thread acquiring lock.");
lock_init (&lock);
lock_acquire (&lock);
msg ("Main thread creating block thread, sleeping 25 seconds...");
thread_create ("block", PRI_DEFAULT, block_thread, &lock);
timer_sleep (25 * TIMER_FREQ);
msg ("Main thread spinning for 5 seconds...");
start_time = timer_ticks ();
while (timer_elapsed (start_time) < 5 * TIMER_FREQ)
continue;
msg ("Main thread releasing lock.");
lock_release (&lock);
msg ("Block thread should have already acquired lock.");
}
static void
block_thread (void *lock_)
{
struct lock *lock = lock_;
int64_t start_time;
msg ("Block thread spinning for 20 seconds...");
start_time = timer_ticks ();
while (timer_elapsed (start_time) < 20 * TIMER_FREQ)
continue;
msg ("Block thread acquiring lock...");
lock_acquire (lock);
msg ("...got it.");
}
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(mlfqs-block) begin
(mlfqs-block) Main thread acquiring lock.
(mlfqs-block) Main thread creating block thread, sleeping 25 seconds...
(mlfqs-block) Block thread spinning for 20 seconds...
(mlfqs-block) Block thread acquiring lock...
(mlfqs-block) Main thread spinning for 5 seconds...
(mlfqs-block) Main thread releasing lock.
(mlfqs-block) ...got it.
(mlfqs-block) Block thread should have already acquired lock.
(mlfqs-block) end
EOF
pass;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment