code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231
values | license stringclasses 13
values | size int64 1 2.01M |
|---|---|---|---|---|---|
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-close) begin
(mmap-close) open "sample.txt"
(mmap-close) mmap "sample.txt"
(mmap-close) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-close.ck | Perl | oos | 219 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-remove) begin
(mmap-remove) open "sample.txt"
(mmap-remove) mmap "sample.txt"
(mmap-remove) remove "sample.txt"
(mmap-remove) try to open "sample.txt"
(mmap-remove) create "another"
(mmap-remove) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-remove.ck | Perl | oos | 327 |
# -*- makefile -*-
tests/vm_TESTS = $(addprefix tests/vm/,pt-grow-stack pt-grow-pusha \
pt-grow-bad pt-big-stk-obj pt-bad-addr pt-bad-read pt-write-code \
pt-write-code2 pt-grow-stk-sc page-linear page-parallel page-merge-seq \
page-merge-par page-merge-stk page-merge-mm page-shuffle mmap-read \
mmap-close mmap-unmap mmap-overlap mmap-twice mmap-write mmap-exit \
mmap-shuffle mmap-bad-fd mmap-clean mmap-inherit mmap-misalign \
mmap-null mmap-over-code mmap-over-data mmap-over-stk mmap-remove \
mmap-zero lru_10cm)
tests/vm_PROGS = $(tests/vm_TESTS) $(addprefix tests/vm/,child-linear \
child-sort child-qsort child-qsort-mm child-mm-wrt child-inherit)
tests/vm/pt-grow-stack_SRC = tests/vm/pt-grow-stack.c tests/arc4.c \
tests/cksum.c tests/lib.c tests/main.c
tests/vm/pt-grow-pusha_SRC = tests/vm/pt-grow-pusha.c tests/lib.c \
tests/main.c
tests/vm/pt-grow-bad_SRC = tests/vm/pt-grow-bad.c tests/lib.c tests/main.c
tests/vm/pt-big-stk-obj_SRC = tests/vm/pt-big-stk-obj.c tests/arc4.c \
tests/cksum.c tests/lib.c tests/main.c
tests/vm/pt-bad-addr_SRC = tests/vm/pt-bad-addr.c tests/lib.c tests/main.c
tests/vm/pt-bad-read_SRC = tests/vm/pt-bad-read.c tests/lib.c tests/main.c
tests/vm/pt-write-code_SRC = tests/vm/pt-write-code.c tests/lib.c tests/main.c
tests/vm/pt-write-code2_SRC = tests/vm/pt-write-code-2.c tests/lib.c tests/main.c
tests/vm/pt-grow-stk-sc_SRC = tests/vm/pt-grow-stk-sc.c tests/lib.c tests/main.c
tests/vm/page-linear_SRC = tests/vm/page-linear.c tests/arc4.c \
tests/lib.c tests/main.c
tests/vm/page-parallel_SRC = tests/vm/page-parallel.c tests/lib.c tests/main.c
tests/vm/page-merge-seq_SRC = tests/vm/page-merge-seq.c tests/arc4.c \
tests/lib.c tests/main.c
tests/vm/page-merge-par_SRC = tests/vm/page-merge-par.c \
tests/vm/parallel-merge.c tests/arc4.c tests/lib.c tests/main.c
tests/vm/page-merge-stk_SRC = tests/vm/page-merge-stk.c \
tests/vm/parallel-merge.c tests/arc4.c tests/lib.c tests/main.c
tests/vm/page-merge-mm_SRC = tests/vm/page-merge-mm.c \
tests/vm/parallel-merge.c tests/arc4.c tests/lib.c tests/main.c
tests/vm/page-shuffle_SRC = tests/vm/page-shuffle.c tests/arc4.c \
tests/cksum.c tests/lib.c tests/main.c
tests/vm/mmap-read_SRC = tests/vm/mmap-read.c tests/lib.c tests/main.c
tests/vm/mmap-close_SRC = tests/vm/mmap-close.c tests/lib.c tests/main.c
tests/vm/mmap-unmap_SRC = tests/vm/mmap-unmap.c tests/lib.c tests/main.c
tests/vm/mmap-overlap_SRC = tests/vm/mmap-overlap.c tests/lib.c tests/main.c
tests/vm/mmap-twice_SRC = tests/vm/mmap-twice.c tests/lib.c tests/main.c
tests/vm/mmap-write_SRC = tests/vm/mmap-write.c tests/lib.c tests/main.c
tests/vm/mmap-exit_SRC = tests/vm/mmap-exit.c tests/lib.c tests/main.c
tests/vm/mmap-shuffle_SRC = tests/vm/mmap-shuffle.c tests/arc4.c \
tests/cksum.c tests/lib.c tests/main.c
tests/vm/mmap-bad-fd_SRC = tests/vm/mmap-bad-fd.c tests/lib.c tests/main.c
tests/vm/mmap-clean_SRC = tests/vm/mmap-clean.c tests/lib.c tests/main.c
tests/vm/mmap-inherit_SRC = tests/vm/mmap-inherit.c tests/lib.c tests/main.c
tests/vm/mmap-misalign_SRC = tests/vm/mmap-misalign.c tests/lib.c \
tests/main.c
tests/vm/mmap-null_SRC = tests/vm/mmap-null.c tests/lib.c tests/main.c
tests/vm/mmap-over-code_SRC = tests/vm/mmap-over-code.c tests/lib.c \
tests/main.c
tests/vm/mmap-over-data_SRC = tests/vm/mmap-over-data.c tests/lib.c \
tests/main.c
tests/vm/mmap-over-stk_SRC = tests/vm/mmap-over-stk.c tests/lib.c tests/main.c
tests/vm/mmap-remove_SRC = tests/vm/mmap-remove.c tests/lib.c tests/main.c
tests/vm/mmap-zero_SRC = tests/vm/mmap-zero.c tests/lib.c tests/main.c
tests/vm/child-linear_SRC = tests/vm/child-linear.c tests/arc4.c tests/lib.c
tests/vm/child-qsort_SRC = tests/vm/child-qsort.c tests/vm/qsort.c tests/lib.c
tests/vm/child-qsort-mm_SRC = tests/vm/child-qsort-mm.c tests/vm/qsort.c \
tests/lib.c
tests/vm/child-sort_SRC = tests/vm/child-sort.c tests/lib.c
tests/vm/child-mm-wrt_SRC = tests/vm/child-mm-wrt.c tests/lib.c tests/main.c
tests/vm/child-inherit_SRC = tests/vm/child-inherit.c tests/lib.c tests/main.c
tests/vm/lru_10cm_SRC = tests/vm/lru_10cm.c tests/lib.c tests/main.c
tests/vm/pt-bad-read_PUTFILES = tests/vm/sample.txt
tests/vm/pt-write-code2_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-close_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-read_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-unmap_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-twice_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-overlap_PUTFILES = tests/vm/zeros
tests/vm/mmap-exit_PUTFILES = tests/vm/child-mm-wrt
tests/vm/page-parallel_PUTFILES = tests/vm/child-linear
tests/vm/page-merge-seq_PUTFILES = tests/vm/child-sort
tests/vm/page-merge-par_PUTFILES = tests/vm/child-sort
tests/vm/page-merge-stk_PUTFILES = tests/vm/child-qsort
tests/vm/page-merge-mm_PUTFILES = tests/vm/child-qsort-mm
tests/vm/mmap-clean_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-inherit_PUTFILES = tests/vm/sample.txt tests/vm/child-inherit
tests/vm/mmap-misalign_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-null_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-over-code_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-over-data_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-over-stk_PUTFILES = tests/vm/sample.txt
tests/vm/mmap-remove_PUTFILES = tests/vm/sample.txt
tests/vm/page-linear.output: TIMEOUT = 300
tests/vm/page-shuffle.output: TIMEOUT = 600
tests/vm/mmap-shuffle.output: TIMEOUT = 600
tests/vm/page-merge-seq.output: TIMEOUT = 600
tests/vm/page-merge-par.output: TIMEOUT = 600
tests/vm/zeros:
dd if=/dev/zero of=$@ bs=1024 count=6
clean::
rm -f tests/vm/zeros
| 10cm | trunk/10cm/pintos/src/tests/vm/Make.tests | Makefile | oos | 5,526 |
/* Child process of mmap-exit.
Mmaps a file and writes to it via the mmap'ing, then exits
without calling munmap. The data in the mapped region must be
written out at program termination. */
#include <string.h>
#include <syscall.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
#define ACTUAL ((void *) 0x10000000)
void
test_main (void)
{
int handle;
CHECK (create ("sample.txt", sizeof sample), "create \"sample.txt\"");
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
CHECK (mmap (handle, ACTUAL) != MAP_FAILED, "mmap \"sample.txt\"");
memcpy (ACTUAL, sample, sizeof sample);
}
| 10cm | trunk/10cm/pintos/src/tests/vm/child-mm-wrt.c | C | oos | 656 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::cksum;
use tests::lib;
my ($init, @shuffle);
if (1) {
# Use precalculated values.
$init = 3115322833;
@shuffle = (1691062564, 1973575879, 1647619479, 96566261, 3885786467,
3022003332, 3614934266, 2704001777, 735775156, 1864109763);
} else {
# Recalculate values.
my ($buf) = "";
for my $i (0...128 * 1024 - 1) {
$buf .= chr (($i * 257) & 0xff);
}
$init = cksum ($buf);
random_init (0);
for my $i (1...10) {
$buf = shuffle ($buf, length ($buf), 1);
push (@shuffle, cksum ($buf));
}
}
check_expected (IGNORE_EXIT_CODES => 1, [<<EOF]);
(page-shuffle) begin
(page-shuffle) init: cksum=$init
(page-shuffle) shuffle 0: cksum=$shuffle[0]
(page-shuffle) shuffle 1: cksum=$shuffle[1]
(page-shuffle) shuffle 2: cksum=$shuffle[2]
(page-shuffle) shuffle 3: cksum=$shuffle[3]
(page-shuffle) shuffle 4: cksum=$shuffle[4]
(page-shuffle) shuffle 5: cksum=$shuffle[5]
(page-shuffle) shuffle 6: cksum=$shuffle[6]
(page-shuffle) shuffle 7: cksum=$shuffle[7]
(page-shuffle) shuffle 8: cksum=$shuffle[8]
(page-shuffle) shuffle 9: cksum=$shuffle[9]
(page-shuffle) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/page-shuffle.ck | Perl | oos | 1,178 |
/* Verifies that mapping over the data segment is disallowed. */
#include <stdint.h>
#include <round.h>
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
static char x;
void
test_main (void)
{
uintptr_t x_page = ROUND_DOWN ((uintptr_t) &x, 4096);
int handle;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
CHECK (mmap (handle, (void *) x_page) == MAP_FAILED,
"try to mmap over data segment");
}
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-over-data.c | C | oos | 458 |
/* Shuffles a 128 kB data buffer 10 times, printing the checksum
after each time. */
#include <stdbool.h>
#include "tests/arc4.h"
#include "tests/cksum.h"
#include "tests/lib.h"
#include "tests/main.h"
#define SIZE (128 * 1024)
static char buf[SIZE];
void
test_main (void)
{
size_t i;
/* Initialize. */
for (i = 0; i < sizeof buf; i++)
buf[i] = i * 257;
msg ("init: cksum=%lu", cksum (buf, sizeof buf));
/* Shuffle repeatedly. */
for (i = 0; i < 10; i++)
{
shuffle (buf, sizeof buf, 1);
msg ("shuffle %zu: cksum=%lu", i, cksum (buf, sizeof buf));
}
}
| 10cm | trunk/10cm/pintos/src/tests/vm/page-shuffle.c | C | oos | 600 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(page-merge-mm) begin
(page-merge-mm) init
(page-merge-mm) sort chunk 0
(page-merge-mm) sort chunk 1
(page-merge-mm) sort chunk 2
(page-merge-mm) sort chunk 3
(page-merge-mm) sort chunk 4
(page-merge-mm) sort chunk 5
(page-merge-mm) sort chunk 6
(page-merge-mm) sort chunk 7
(page-merge-mm) wait for child 0
(page-merge-mm) wait for child 1
(page-merge-mm) wait for child 2
(page-merge-mm) wait for child 3
(page-merge-mm) wait for child 4
(page-merge-mm) wait for child 5
(page-merge-mm) wait for child 6
(page-merge-mm) wait for child 7
(page-merge-mm) merge
(page-merge-mm) verify
(page-merge-mm) success, buf_idx=1,048,576
(page-merge-mm) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/page-merge-mm.ck | Perl | oos | 768 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-twice) begin
(mmap-twice) open "sample.txt" #0
(mmap-twice) mmap "sample.txt" #0 at 0x10000000
(mmap-twice) open "sample.txt" #1
(mmap-twice) mmap "sample.txt" #1 at 0x20000000
(mmap-twice) compare mmap'd file 0 against data
(mmap-twice) compare mmap'd file 1 against data
(mmap-twice) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-twice.ck | Perl | oos | 417 |
/* Maps a file into memory and runs child-inherit to verify that
mappings are not inherited. */
#include <string.h>
#include <syscall.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
char *actual = (char *) 0x54321000;
int handle;
pid_t child;
/* Open file, map, verify data. */
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
CHECK (mmap (handle, actual) != MAP_FAILED, "mmap \"sample.txt\"");
if (memcmp (actual, sample, strlen (sample)))
fail ("read of mmap'd file reported bad data");
/* Spawn child and wait. */
CHECK ((child = exec ("child-inherit")) != -1, "exec \"child-inherit\"");
quiet = true;
CHECK (wait (child) == -1, "wait for child (should return -1)");
quiet = false;
/* Verify data again. */
CHECK (!memcmp (actual, sample, strlen (sample)),
"checking that mmap'd file still has same data");
}
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-inherit.c | C | oos | 936 |
/* Accesses a bad address.
The process must be terminated with -1 exit code. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
fail ("bad addr read as %d", *(int *) 0x04000000);
}
| 10cm | trunk/10cm/pintos/src/tests/vm/pt-bad-addr.c | C | oos | 211 |
/* Generates about 1 MB of random data that is then divided into
16 chunks. A separate subprocess sorts each chunk; the
subprocesses run in parallel. Then we merge the chunks and
verify that the result is what it should be. */
#include "tests/vm/parallel-merge.h"
#include <stdio.h>
#include <syscall.h>
#include "tests/arc4.h"
#include "tests/lib.h"
#include "tests/main.h"
#define CHUNK_SIZE (128 * 1024)
#define CHUNK_CNT 8 /* Number of chunks. */
#define DATA_SIZE (CHUNK_CNT * CHUNK_SIZE) /* Buffer size. */
unsigned char buf1[DATA_SIZE], buf2[DATA_SIZE];
size_t histogram[256];
/* Initialize buf1 with random data,
then count the number of instances of each value within it. */
static void
init (void)
{
struct arc4 arc4;
size_t i;
msg ("init");
arc4_init (&arc4, "foobar", 6);
arc4_crypt (&arc4, buf1, sizeof buf1);
for (i = 0; i < sizeof buf1; i++)
histogram[buf1[i]]++;
}
/* Sort each chunk of buf1 using SUBPROCESS,
which is expected to return EXIT_STATUS. */
static void
sort_chunks (const char *subprocess, int exit_status)
{
pid_t children[CHUNK_CNT];
size_t i;
for (i = 0; i < CHUNK_CNT; i++)
{
char fn[128];
char cmd[128];
int handle;
msg ("sort chunk %zu", i);
/* Write this chunk to a file. */
snprintf (fn, sizeof fn, "buf%zu", i);
create (fn, CHUNK_SIZE);
quiet = true;
CHECK ((handle = open (fn)) > 1, "open \"%s\"", fn);
write (handle, buf1 + CHUNK_SIZE * i, CHUNK_SIZE);
close (handle);
/* Sort with subprocess. */
snprintf (cmd, sizeof cmd, "%s %s", subprocess, fn);
CHECK ((children[i] = exec (cmd)) != -1, "exec \"%s\"", cmd);
quiet = false;
}
for (i = 0; i < CHUNK_CNT; i++)
{
char fn[128];
int handle;
CHECK (wait (children[i]) == exit_status, "wait for child %zu", i);
/* Read chunk back from file. */
quiet = true;
snprintf (fn, sizeof fn, "buf%zu", i);
CHECK ((handle = open (fn)) > 1, "open \"%s\"", fn);
read (handle, buf1 + CHUNK_SIZE * i, CHUNK_SIZE);
close (handle);
quiet = false;
}
}
/* Merge the sorted chunks in buf1 into a fully sorted buf2. */
static void
merge (void)
{
unsigned char *mp[CHUNK_CNT];
size_t mp_left;
unsigned char *op;
size_t i;
msg ("merge");
/* Initialize merge pointers. */
mp_left = CHUNK_CNT;
for (i = 0; i < CHUNK_CNT; i++)
mp[i] = buf1 + CHUNK_SIZE * i;
/* Merge. */
op = buf2;
while (mp_left > 0)
{
/* Find smallest value. */
size_t min = 0;
for (i = 1; i < mp_left; i++)
if (*mp[i] < *mp[min])
min = i;
/* Append value to buf2. */
*op++ = *mp[min];
/* Advance merge pointer.
Delete this chunk from the set if it's emptied. */
if ((++mp[min] - buf1) % CHUNK_SIZE == 0)
mp[min] = mp[--mp_left];
}
}
static void
verify (void)
{
size_t buf_idx;
size_t hist_idx;
msg ("verify");
buf_idx = 0;
for (hist_idx = 0; hist_idx < sizeof histogram / sizeof *histogram;
hist_idx++)
{
while (histogram[hist_idx]-- > 0)
{
if (buf2[buf_idx] != hist_idx)
fail ("bad value %d in byte %zu", buf2[buf_idx], buf_idx);
buf_idx++;
}
}
msg ("success, buf_idx=%'zu", buf_idx);
}
void
parallel_merge (const char *child_name, int exit_status)
{
init ();
sort_chunks (child_name, exit_status);
merge ();
verify ();
}
| 10cm | trunk/10cm/pintos/src/tests/vm/parallel-merge.c | C | oos | 3,528 |
/* Uses a memory mapping to read a file. */
#include <string.h>
#include <syscall.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
char *actual = (char *) 0x10000000;
int handle;
mapid_t map;
size_t i;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
CHECK ((map = mmap (handle, actual)) != MAP_FAILED, "mmap \"sample.txt\"");
/* Check that data is correct. */
if (memcmp (actual, sample, strlen (sample)))
fail ("read of mmap'd file reported bad data");
/* Verify that data is followed by zeros. */
for (i = strlen (sample); i < 4096; i++)
if (actual[i] != 0)
fail ("byte %zu of mmap'd region has value %02hhx (should be 0)",
i, actual[i]);
munmap (map);
close (handle);
}
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-read.c | C | oos | 804 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(mmap-bad-fd) begin
(mmap-bad-fd) try to mmap invalid fd
(mmap-bad-fd) end
mmap-bad-fd: exit(0)
EOF
(mmap-bad-fd) begin
(mmap-bad-fd) try to mmap invalid fd
mmap-bad-fd: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-bad-fd.ck | Perl | oos | 285 |
#include <string.h>
#include <syscall.h>
#include <stdio.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
#define SIZE 23*1024
int buf2[SIZE];
void test_main(void) {
int i = 0;
printf("program start.... \n");
printf("accsses 13th page %p\n",&buf2[13*1024]);
buf2[13*1024] = 1;
printf("accsses 14th page %p\n",&buf2[14*1024]);
buf2[14*1024] = 1;
for (i = 0; i < SIZE; i++) {
buf2[i] = (i % 991);
}
for (i = 0; i < SIZE; i++) {
if (buf2[i] != (i % 991)){
fail("invalid : %d, %d, %d\n", i, (int)buf2[i], (i%256));
}
}
printf("finished..\n");
}
| 10cm | trunk/10cm/pintos/src/tests/vm/lru_10cm.c | C | oos | 599 |
/* Runs 4 child-linear processes at once. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
#define CHILD_CNT 4
void
test_main (void)
{
pid_t children[CHILD_CNT];
int i;
for (i = 0; i < CHILD_CNT; i++)
CHECK ((children[i] = exec ("child-linear")) != -1,
"exec \"child-linear\"");
for (i = 0; i < CHILD_CNT; i++)
CHECK (wait (children[i]) == 0x42, "wait for child %d", i);
}
| 10cm | trunk/10cm/pintos/src/tests/vm/page-parallel.c | C | oos | 429 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(pt-big-stk-obj) begin
(pt-big-stk-obj) cksum: 3256410166
(pt-big-stk-obj) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/pt-big-stk-obj.ck | Perl | oos | 200 |
/* Verifies that overlapping memory mappings are disallowed. */
#include <syscall.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
char *start = (char *) 0x10000000;
int fd[2];
CHECK ((fd[0] = open ("zeros")) > 1, "open \"zeros\" once");
CHECK (mmap (fd[0], start) != MAP_FAILED, "mmap \"zeros\"");
CHECK ((fd[1] = open ("zeros")) > 1 && fd[0] != fd[1],
"open \"zeros\" again");
CHECK (mmap (fd[1], start + 4096) == MAP_FAILED,
"try to mmap \"zeros\" again");
}
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-overlap.c | C | oos | 551 |
/* Generates about 1 MB of random data that is then divided into
16 chunks. A separate subprocess sorts each chunk in
sequence. Then we merge the chunks and verify that the result
is what it should be. */
#include <syscall.h>
#include "tests/arc4.h"
#include "tests/lib.h"
#include "tests/main.h"
/* This is the max file size for an older version of the Pintos
file system that had 126 direct blocks each pointing to a
single disk sector. We could raise it now. */
#define CHUNK_SIZE (126 * 512)
#define CHUNK_CNT 16 /* Number of chunks. */
#define DATA_SIZE (CHUNK_CNT * CHUNK_SIZE) /* Buffer size. */
unsigned char buf1[DATA_SIZE], buf2[DATA_SIZE];
size_t histogram[256];
/* Initialize buf1 with random data,
then count the number of instances of each value within it. */
static void
init (void)
{
struct arc4 arc4;
size_t i;
msg ("init");
arc4_init (&arc4, "foobar", 6);
arc4_crypt (&arc4, buf1, sizeof buf1);
for (i = 0; i < sizeof buf1; i++)
histogram[buf1[i]]++;
}
/* Sort each chunk of buf1 using a subprocess. */
static void
sort_chunks (void)
{
size_t i;
create ("buffer", CHUNK_SIZE);
for (i = 0; i < CHUNK_CNT; i++)
{
pid_t child;
int handle;
msg ("sort chunk %zu", i);
/* Write this chunk to a file. */
quiet = true;
CHECK ((handle = open ("buffer")) > 1, "open \"buffer\"");
write (handle, buf1 + CHUNK_SIZE * i, CHUNK_SIZE);
close (handle);
/* Sort with subprocess. */
CHECK ((child = exec ("child-sort buffer")) != -1,
"exec \"child-sort buffer\"");
CHECK (wait (child) == 123, "wait for child-sort");
/* Read chunk back from file. */
CHECK ((handle = open ("buffer")) > 1, "open \"buffer\"");
read (handle, buf1 + CHUNK_SIZE * i, CHUNK_SIZE);
close (handle);
quiet = false;
}
}
/* Merge the sorted chunks in buf1 into a fully sorted buf2. */
static void
merge (void)
{
unsigned char *mp[CHUNK_CNT];
size_t mp_left;
unsigned char *op;
size_t i;
msg ("merge");
/* Initialize merge pointers. */
mp_left = CHUNK_CNT;
for (i = 0; i < CHUNK_CNT; i++)
mp[i] = buf1 + CHUNK_SIZE * i;
/* Merge. */
op = buf2;
while (mp_left > 0)
{
/* Find smallest value. */
size_t min = 0;
for (i = 1; i < mp_left; i++)
if (*mp[i] < *mp[min])
min = i;
/* Append value to buf2. */
*op++ = *mp[min];
/* Advance merge pointer.
Delete this chunk from the set if it's emptied. */
if ((++mp[min] - buf1) % CHUNK_SIZE == 0)
mp[min] = mp[--mp_left];
}
}
static void
verify (void)
{
size_t buf_idx;
size_t hist_idx;
msg ("verify");
buf_idx = 0;
for (hist_idx = 0; hist_idx < sizeof histogram / sizeof *histogram;
hist_idx++)
{
while (histogram[hist_idx]-- > 0)
{
if (buf2[buf_idx] != hist_idx)
fail ("bad value %d in byte %zu", buf2[buf_idx], buf_idx);
buf_idx++;
}
}
msg ("success, buf_idx=%'zu", buf_idx);
}
void
test_main (void)
{
init ();
sort_chunks ();
merge ();
verify ();
}
| 10cm | trunk/10cm/pintos/src/tests/vm/page-merge-seq.c | C | oos | 3,189 |
#include "tests/main.h"
#include "tests/vm/parallel-merge.h"
void
test_main (void)
{
parallel_merge ("child-qsort-mm", 80);
}
| 10cm | trunk/10cm/pintos/src/tests/vm/page-merge-mm.c | C | oos | 130 |
/* Child process for mmap-inherit test.
Tries to write to a mapping present in the parent.
The process must be terminated with -1 exit code. */
#include <string.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
memset ((char *) 0x54321000, 0, 4096);
fail ("child can modify parent's memory mappings");
}
| 10cm | trunk/10cm/pintos/src/tests/vm/child-inherit.c | C | oos | 372 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(pt-bad-read) begin
(pt-bad-read) open "sample.txt"
pt-bad-read: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/pt-bad-read.ck | Perl | oos | 171 |
/* Demonstrate that the stack can grow.
This must succeed. */
#include <string.h>
#include "tests/arc4.h"
#include "tests/cksum.h"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
char stack_obj[4096];
struct arc4 arc4;
arc4_init (&arc4, "foobar", 6);
memset (stack_obj, 0, sizeof stack_obj);
arc4_crypt (&arc4, stack_obj, sizeof stack_obj);
msg ("cksum: %lu", cksum (stack_obj, sizeof stack_obj));
}
| 10cm | trunk/10cm/pintos/src/tests/vm/pt-grow-stack.c | C | oos | 441 |
/* Reads a 128 kB file onto the stack and "sorts" the bytes in
it, using quick sort, a multi-pass divide and conquer
algorithm. The sorted data is written back to the same file
in-place. */
#include <debug.h>
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
#include "tests/vm/qsort.h"
const char *test_name = "child-qsort";
int
main (int argc UNUSED, char *argv[])
{
int handle;
unsigned char buf[128 * 1024];
size_t size;
quiet = true;
CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
size = read (handle, buf, sizeof buf);
qsort_bytes (buf, sizeof buf);
seek (handle, 0);
write (handle, buf, size);
close (handle);
return 72;
}
| 10cm | trunk/10cm/pintos/src/tests/vm/child-qsort.c | C | oos | 706 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-null) begin
(mmap-null) open "sample.txt"
(mmap-null) try to mmap at address 0
(mmap-null) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-null.ck | Perl | oos | 222 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(pt-grow-stack) begin
(pt-grow-stack) cksum: 3424492700
(pt-grow-stack) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/pt-grow-stack.ck | Perl | oos | 197 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-write) begin
(mmap-write) create "sample.txt"
(mmap-write) open "sample.txt"
(mmap-write) mmap "sample.txt"
(mmap-write) compare read data against written data
(mmap-write) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-write.ck | Perl | oos | 304 |
/* Writes to a file through a mapping, and unmaps the file,
then reads the data in the file back using the read system
call to verify. */
#include <string.h>
#include <syscall.h>
#include "tests/vm/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
#define ACTUAL ((void *) 0x10000000)
void
test_main (void)
{
int handle;
mapid_t map;
char buf[1024];
/* Write file via mmap. */
CHECK (create ("sample.txt", strlen (sample)), "create \"sample.txt\"");
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
CHECK ((map = mmap (handle, ACTUAL)) != MAP_FAILED, "mmap \"sample.txt\"");
memcpy (ACTUAL, sample, strlen (sample));
munmap (map);
/* Read back via read(). */
read (handle, buf, strlen (sample));
CHECK (!memcmp (buf, sample, strlen (sample)),
"compare read data against written data");
close (handle);
}
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-write.c | C | oos | 877 |
char sample[] = {
"=== ALL USERS PLEASE NOTE ========================\n"
"\n"
"CAR and CDR now return extra values.\n"
"\n"
"The function CAR now returns two values. Since it has to go to the\n"
"trouble to figure out if the object is carcdr-able anyway, we figured\n"
"you might as well get both halves at once. For example, the following\n"
"code shows how to destructure a cons (SOME-CONS) into its two slots\n"
"(THE-CAR and THE-CDR):\n"
"\n"
" (MULTIPLE-VALUE-BIND (THE-CAR THE-CDR) (CAR SOME-CONS) ...)\n"
"\n"
"For symmetry with CAR, CDR returns a second value which is the CAR of\n"
"the object. In a related change, the functions MAKE-ARRAY and CONS\n"
"have been fixed so they don't allocate any storage except on the\n"
"stack. This should hopefully help people who don't like using the\n"
"garbage collector because it cold boots the machine so often.\n"
};
| 10cm | trunk/10cm/pintos/src/tests/vm/sample.inc | C++ | oos | 917 |
/* Reads a 128 kB file into static data and "sorts" the bytes in
it, using counting sort, a single-pass algorithm. The sorted
data is written back to the same file in-place. */
#include <debug.h>
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
const char *test_name = "child-sort";
unsigned char buf[128 * 1024];
size_t histogram[256];
int
main (int argc UNUSED, char *argv[])
{
int handle;
unsigned char *p;
size_t size;
size_t i;
quiet = true;
CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
size = read (handle, buf, sizeof buf);
for (i = 0; i < size; i++)
histogram[buf[i]]++;
p = buf;
for (i = 0; i < sizeof histogram / sizeof *histogram; i++)
{
size_t j = histogram[i];
while (j-- > 0)
*p++ = i;
}
seek (handle, 0);
write (handle, buf, size);
close (handle);
return 123;
}
| 10cm | trunk/10cm/pintos/src/tests/vm/child-sort.c | C | oos | 893 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-clean) begin
(mmap-clean) open "sample.txt"
(mmap-clean) mmap "sample.txt"
(mmap-clean) write "sample.txt"
(mmap-clean) munmap "sample.txt"
(mmap-clean) seek "sample.txt"
(mmap-clean) read "sample.txt"
(mmap-clean) file change was retained after munmap
(mmap-clean) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-clean.ck | Perl | oos | 397 |
#ifndef TESTS_VM_QSORT_H
#define TESTS_VM_QSORT_H 1
#include <stddef.h>
void qsort_bytes (unsigned char *buf, size_t size);
#endif /* tests/vm/qsort.h */
| 10cm | trunk/10cm/pintos/src/tests/vm/qsort.h | C | oos | 157 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
(mmap-over-code) begin
(mmap-over-code) open "sample.txt"
(mmap-over-code) try to mmap over code segment
(mmap-over-code) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/vm/mmap-over-code.ck | Perl | oos | 247 |
#ifndef TESTS_ARC4_H
#define TESTS_ARC4_H
#include <stddef.h>
#include <stdint.h>
/* Alleged RC4 algorithm encryption state. */
struct arc4
{
uint8_t s[256];
uint8_t i, j;
};
void arc4_init (struct arc4 *, const void *, size_t);
void arc4_crypt (struct arc4 *, void *, size_t);
#endif /* tests/arc4.h */
| 10cm | trunk/10cm/pintos/src/tests/arc4.h | C | oos | 320 |
/* Creates several threads all at the same priority and ensures
that they consistently run in the same round-robin order.
Based on a test originally submitted for Stanford's CS 140 in
winter 1999 by by Matt Franklin
<startled@leland.stanford.edu>, Greg Hutchins
<gmh@leland.stanford.edu>, Yu Ping Hu <yph@cs.stanford.edu>.
Modified by arens. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "devices/timer.h"
#include "threads/malloc.h"
#include "threads/synch.h"
#include "threads/thread.h"
struct simple_thread_data
{
int id; /* Sleeper ID. */
int iterations; /* Iterations so far. */
struct lock *lock; /* Lock on output. */
int **op; /* Output buffer position. */
};
#define THREAD_CNT 16
#define ITER_CNT 16
static thread_func simple_thread_func;
void
test_priority_fifo (void)
{
struct simple_thread_data data[THREAD_CNT];
struct lock lock;
int *output, *op;
int i, cnt;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
/* Make sure our priority is the default. */
ASSERT (thread_get_priority () == PRI_DEFAULT);
msg ("%d threads will iterate %d times in the same order each time.",
THREAD_CNT, ITER_CNT);
msg ("If the order varies then there is a bug.");
output = op = malloc (sizeof *output * THREAD_CNT * ITER_CNT * 2);
ASSERT (output != NULL);
lock_init (&lock);
thread_set_priority (PRI_DEFAULT + 2);
for (i = 0; i < THREAD_CNT; i++)
{
char name[16];
struct simple_thread_data *d = data + i;
snprintf (name, sizeof name, "%d", i);
d->id = i;
d->iterations = 0;
d->lock = &lock;
d->op = &op;
thread_create (name, PRI_DEFAULT + 1, simple_thread_func, d);
}
thread_set_priority (PRI_DEFAULT);
/* All the other threads now run to termination here. */
ASSERT (lock.holder == NULL);
cnt = 0;
for (; output < op; output++)
{
struct simple_thread_data *d;
ASSERT (*output >= 0 && *output < THREAD_CNT);
d = data + *output;
if (cnt % THREAD_CNT == 0)
printf ("(priority-fifo) iteration:");
printf (" %d", d->id);
if (++cnt % THREAD_CNT == 0)
printf ("\n");
d->iterations++;
}
}
static void
simple_thread_func (void *data_)
{
struct simple_thread_data *data = data_;
int i;
for (i = 0; i < ITER_CNT; i++)
{
lock_acquire (data->lock);
*(*data->op)++ = data->id;
lock_release (data->lock);
thread_yield ();
}
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-fifo.c | C | oos | 2,601 |
/* Creates N threads, each of which sleeps a different, fixed
duration, M times. Records the wake-up order and verifies
that it is valid. */
#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 test_sleep (int thread_cnt, int iterations);
void
test_alarm_simultaneous (void)
{
test_sleep (3, 5);
}
/* Information about the test. */
struct sleep_test
{
int64_t start; /* Current time at start of test. */
int iterations; /* Number of iterations per thread. */
int *output_pos; /* Current position in output buffer. */
};
static void sleeper (void *);
/* Runs THREAD_CNT threads thread sleep ITERATIONS times each. */
static void
test_sleep (int thread_cnt, int iterations)
{
struct sleep_test test;
int *output;
int i;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
msg ("Creating %d threads to sleep %d times each.", thread_cnt, iterations);
msg ("Each thread sleeps 10 ticks each time.");
msg ("Within an iteration, all threads should wake up on the same tick.");
/* Allocate memory. */
output = malloc (sizeof *output * iterations * thread_cnt * 2);
if (output == NULL)
PANIC ("couldn't allocate memory for test");
/* Initialize test. */
test.start = timer_ticks () + 100;
test.iterations = iterations;
test.output_pos = output;
/* Start threads. */
ASSERT (output != NULL);
for (i = 0; i < thread_cnt; i++)
{
char name[16];
snprintf (name, sizeof name, "thread %d", i);
thread_create (name, PRI_DEFAULT, sleeper, &test);
}
/* Wait long enough for all the threads to finish. */
timer_sleep (100 + iterations * 10 + 100);
/* Print completion order. */
msg ("iteration 0, thread 0: woke up after %d ticks", output[0]);
for (i = 1; i < test.output_pos - output; i++)
msg ("iteration %d, thread %d: woke up %d ticks later",
i / thread_cnt, i % thread_cnt, output[i] - output[i - 1]);
free (output);
}
/* Sleeper thread. */
static void
sleeper (void *test_)
{
struct sleep_test *test = test_;
int i;
/* Make sure we're at the beginning of a timer tick. */
timer_sleep (1);
for (i = 1; i <= test->iterations; i++)
{
int64_t sleep_until = test->start + i * 10;
timer_sleep (sleep_until - timer_ticks ());
*test->output_pos++ = timer_ticks () - test->start;
thread_yield ();
}
}
| 10cm | trunk/10cm/pintos/src/tests/threads/alarm-simultaneous.c | C | oos | 2,564 |
/* The main thread set its priority to PRI_MIN and creates 7 threads
(thread 1..7) with priorities PRI_MIN + 3, 6, 9, 12, ...
The main thread initializes 8 locks: lock 0..7 and acquires lock 0.
When thread[i] starts, it first acquires lock[i] (unless i == 7.)
Subsequently, thread[i] attempts to acquire lock[i-1], which is held by
thread[i-1], except for lock[0], which is held by the main thread.
Because the lock is held, thread[i] donates its priority to thread[i-1],
which donates to thread[i-2], and so on until the main thread
receives the donation.
After threads[1..7] have been created and are blocked on locks[0..7],
the main thread releases lock[0], unblocking thread[1], and being
preempted by it.
Thread[1] then completes acquiring lock[0], then releases lock[0],
then releases lock[1], unblocking thread[2], etc.
Thread[7] finally acquires & releases lock[7] and exits, allowing
thread[6], then thread[5] etc. to run and exit until finally the
main thread exits.
In addition, interloper threads are created at priority levels
p = PRI_MIN + 2, 5, 8, 11, ... which should not be run until the
corresponding thread with priority p + 1 has finished.
Written by Godmar Back <gback@cs.vt.edu> */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
#define NESTING_DEPTH 8
struct lock_pair
{
struct lock *second;
struct lock *first;
};
static thread_func donor_thread_func;
static thread_func interloper_thread_func;
void
test_priority_donate_chain (void)
{
int i;
struct lock locks[NESTING_DEPTH - 1];
struct lock_pair lock_pairs[NESTING_DEPTH];
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
thread_set_priority (PRI_MIN);
for (i = 0; i < NESTING_DEPTH - 1; i++)
lock_init (&locks[i]);
lock_acquire (&locks[0]);
msg ("%s got lock.", thread_name ());
for (i = 1; i < NESTING_DEPTH; i++)
{
char name[16];
int thread_priority;
snprintf (name, sizeof name, "thread %d", i);
thread_priority = PRI_MIN + i * 3;
lock_pairs[i].first = i < NESTING_DEPTH - 1 ? locks + i: NULL;
lock_pairs[i].second = locks + i - 1;
thread_create (name, thread_priority, donor_thread_func, lock_pairs + i);
msg ("%s should have priority %d. Actual priority: %d.",
thread_name (), thread_priority, thread_get_priority ());
snprintf (name, sizeof name, "interloper %d", i);
thread_create (name, thread_priority - 1, interloper_thread_func, NULL);
}
lock_release (&locks[0]);
msg ("%s finishing with priority %d.", thread_name (),
thread_get_priority ());
}
static void
donor_thread_func (void *locks_)
{
struct lock_pair *locks = locks_;
if (locks->first)
lock_acquire (locks->first);
lock_acquire (locks->second);
msg ("%s got lock", thread_name ());
lock_release (locks->second);
msg ("%s should have priority %d. Actual priority: %d",
thread_name (), (NESTING_DEPTH - 1) * 3,
thread_get_priority ());
if (locks->first)
lock_release (locks->first);
msg ("%s finishing with priority %d.", thread_name (),
thread_get_priority ());
}
static void
interloper_thread_func (void *arg_ UNUSED)
{
msg ("%s finished.", thread_name ());
}
// vim: sw=2
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-chain.c | C | oos | 3,468 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-preempt) begin
(priority-preempt) Thread high-priority iteration 0
(priority-preempt) Thread high-priority iteration 1
(priority-preempt) Thread high-priority iteration 2
(priority-preempt) Thread high-priority iteration 3
(priority-preempt) Thread high-priority iteration 4
(priority-preempt) Thread high-priority done!
(priority-preempt) The high-priority thread should have already completed.
(priority-preempt) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-preempt.ck | Perl | oos | 526 |
/* 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.");
}
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-block.c | C | oos | 1,683 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-lower) begin
(priority-donate-lower) Main thread should have priority 41. Actual priority: 41.
(priority-donate-lower) Lowering base priority...
(priority-donate-lower) Main thread should have priority 41. Actual priority: 41.
(priority-donate-lower) acquire: got the lock
(priority-donate-lower) acquire: done
(priority-donate-lower) acquire must already have finished.
(priority-donate-lower) Main thread should have priority 21. Actual priority: 21.
(priority-donate-lower) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-lower.ck | Perl | oos | 598 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([0...9], 25);
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-nice-10.ck | Perl | oos | 119 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-negative) begin
(alarm-negative) PASS
(alarm-negative) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/alarm-negative.ck | Perl | oos | 163 |
# -*- perl -*-
# The expected output looks like this:
#
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# A different permutation of 0...15 is acceptable, but every line must
# be in the same order.
use strict;
use warnings;
use tests::tests;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
my ($thread_cnt) = 16;
my ($iter_cnt) = 16;
my (@order);
my (@t) = (-1) x $thread_cnt;
my (@iterations) = grep (/iteration:/, @output);
fail "No iterations found in output.\n" if !@iterations;
my (@numbering) = $iterations[0] =~ /(\d+)/g;
fail "First iteration does not list exactly $thread_cnt threads.\n"
if @numbering != $thread_cnt;
my (@sorted_numbering) = sort { $a <=> $b } @numbering;
for my $i (0...$#sorted_numbering) {
if ($sorted_numbering[$i] != $i) {
fail "First iteration does not list all threads "
. "0...$#sorted_numbering\n";
}
}
for my $i (1...$#iterations) {
if ($iterations[$i] ne $iterations[0]) {
fail "Iteration $i differs from iteration 0\n";
}
}
fail "$iter_cnt iterations expected but " . scalar (@iterations) . " found\n"
if $iter_cnt != @iterations;
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-fifo.ck | Perl | oos | 2,185 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-simultaneous) begin
(alarm-simultaneous) Creating 3 threads to sleep 5 times each.
(alarm-simultaneous) Each thread sleeps 10 ticks each time.
(alarm-simultaneous) Within an iteration, all threads should wake up on the same tick.
(alarm-simultaneous) iteration 0, thread 0: woke up after 10 ticks
(alarm-simultaneous) iteration 0, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 0, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 1, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 1, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 1, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 2, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 2, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 2, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 3, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 3, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 3, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 4, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 4, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 4, thread 2: woke up 0 ticks later
(alarm-simultaneous) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/alarm-simultaneous.ck | Perl | oos | 1,354 |
/* Tests timer_sleep(0), which should return immediately. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/malloc.h"
#include "threads/synch.h"
#include "threads/thread.h"
#include "devices/timer.h"
void
test_alarm_zero (void)
{
timer_sleep (0);
pass ();
}
| 10cm | trunk/10cm/pintos/src/tests/threads/alarm-zero.c | C | oos | 288 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-zero) begin
(alarm-zero) PASS
(alarm-zero) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/alarm-zero.ck | Perl | oos | 151 |
/* Checks that recent_cpu is calculated properly for the case of
a single ready process.
The expected output is this (some margin of error is allowed):
After 2 seconds, recent_cpu is 6.40, load_avg is 0.03.
After 4 seconds, recent_cpu is 12.60, load_avg is 0.07.
After 6 seconds, recent_cpu is 18.61, load_avg is 0.10.
After 8 seconds, recent_cpu is 24.44, load_avg is 0.13.
After 10 seconds, recent_cpu is 30.08, load_avg is 0.15.
After 12 seconds, recent_cpu is 35.54, load_avg is 0.18.
After 14 seconds, recent_cpu is 40.83, load_avg is 0.21.
After 16 seconds, recent_cpu is 45.96, load_avg is 0.24.
After 18 seconds, recent_cpu is 50.92, load_avg is 0.26.
After 20 seconds, recent_cpu is 55.73, load_avg is 0.29.
After 22 seconds, recent_cpu is 60.39, load_avg is 0.31.
After 24 seconds, recent_cpu is 64.90, load_avg is 0.33.
After 26 seconds, recent_cpu is 69.27, load_avg is 0.35.
After 28 seconds, recent_cpu is 73.50, load_avg is 0.38.
After 30 seconds, recent_cpu is 77.60, load_avg is 0.40.
After 32 seconds, recent_cpu is 81.56, load_avg is 0.42.
After 34 seconds, recent_cpu is 85.40, load_avg is 0.44.
After 36 seconds, recent_cpu is 89.12, load_avg is 0.45.
After 38 seconds, recent_cpu is 92.72, load_avg is 0.47.
After 40 seconds, recent_cpu is 96.20, load_avg is 0.49.
After 42 seconds, recent_cpu is 99.57, load_avg is 0.51.
After 44 seconds, recent_cpu is 102.84, load_avg is 0.52.
After 46 seconds, recent_cpu is 106.00, load_avg is 0.54.
After 48 seconds, recent_cpu is 109.06, load_avg is 0.55.
After 50 seconds, recent_cpu is 112.02, load_avg is 0.57.
After 52 seconds, recent_cpu is 114.89, load_avg is 0.58.
After 54 seconds, recent_cpu is 117.66, load_avg is 0.60.
After 56 seconds, recent_cpu is 120.34, load_avg is 0.61.
After 58 seconds, recent_cpu is 122.94, load_avg is 0.62.
After 60 seconds, recent_cpu is 125.46, load_avg is 0.64.
After 62 seconds, recent_cpu is 127.89, load_avg is 0.65.
After 64 seconds, recent_cpu is 130.25, load_avg is 0.66.
After 66 seconds, recent_cpu is 132.53, load_avg is 0.67.
After 68 seconds, recent_cpu is 134.73, load_avg is 0.68.
After 70 seconds, recent_cpu is 136.86, load_avg is 0.69.
After 72 seconds, recent_cpu is 138.93, load_avg is 0.70.
After 74 seconds, recent_cpu is 140.93, load_avg is 0.71.
After 76 seconds, recent_cpu is 142.86, load_avg is 0.72.
After 78 seconds, recent_cpu is 144.73, load_avg is 0.73.
After 80 seconds, recent_cpu is 146.54, load_avg is 0.74.
After 82 seconds, recent_cpu is 148.29, load_avg is 0.75.
After 84 seconds, recent_cpu is 149.99, load_avg is 0.76.
After 86 seconds, recent_cpu is 151.63, load_avg is 0.76.
After 88 seconds, recent_cpu is 153.21, load_avg is 0.77.
After 90 seconds, recent_cpu is 154.75, load_avg is 0.78.
After 92 seconds, recent_cpu is 156.23, load_avg is 0.79.
After 94 seconds, recent_cpu is 157.67, load_avg is 0.79.
After 96 seconds, recent_cpu is 159.06, load_avg is 0.80.
After 98 seconds, recent_cpu is 160.40, load_avg is 0.81.
After 100 seconds, recent_cpu is 161.70, load_avg is 0.81.
After 102 seconds, recent_cpu is 162.96, load_avg is 0.82.
After 104 seconds, recent_cpu is 164.18, load_avg is 0.83.
After 106 seconds, recent_cpu is 165.35, load_avg is 0.83.
After 108 seconds, recent_cpu is 166.49, load_avg is 0.84.
After 110 seconds, recent_cpu is 167.59, load_avg is 0.84.
After 112 seconds, recent_cpu is 168.66, load_avg is 0.85.
After 114 seconds, recent_cpu is 169.69, load_avg is 0.85.
After 116 seconds, recent_cpu is 170.69, load_avg is 0.86.
After 118 seconds, recent_cpu is 171.65, load_avg is 0.86.
After 120 seconds, recent_cpu is 172.58, load_avg is 0.87.
After 122 seconds, recent_cpu is 173.49, load_avg is 0.87.
After 124 seconds, recent_cpu is 174.36, load_avg is 0.88.
After 126 seconds, recent_cpu is 175.20, load_avg is 0.88.
After 128 seconds, recent_cpu is 176.02, load_avg is 0.88.
After 130 seconds, recent_cpu is 176.81, load_avg is 0.89.
After 132 seconds, recent_cpu is 177.57, load_avg is 0.89.
After 134 seconds, recent_cpu is 178.31, load_avg is 0.89.
After 136 seconds, recent_cpu is 179.02, load_avg is 0.90.
After 138 seconds, recent_cpu is 179.72, load_avg is 0.90.
After 140 seconds, recent_cpu is 180.38, load_avg is 0.90.
After 142 seconds, recent_cpu is 181.03, load_avg is 0.91.
After 144 seconds, recent_cpu is 181.65, load_avg is 0.91.
After 146 seconds, recent_cpu is 182.26, load_avg is 0.91.
After 148 seconds, recent_cpu is 182.84, load_avg is 0.92.
After 150 seconds, recent_cpu is 183.41, load_avg is 0.92.
After 152 seconds, recent_cpu is 183.96, load_avg is 0.92.
After 154 seconds, recent_cpu is 184.49, load_avg is 0.92.
After 156 seconds, recent_cpu is 185.00, load_avg is 0.93.
After 158 seconds, recent_cpu is 185.49, load_avg is 0.93.
After 160 seconds, recent_cpu is 185.97, load_avg is 0.93.
After 162 seconds, recent_cpu is 186.43, load_avg is 0.93.
After 164 seconds, recent_cpu is 186.88, load_avg is 0.94.
After 166 seconds, recent_cpu is 187.31, load_avg is 0.94.
After 168 seconds, recent_cpu is 187.73, load_avg is 0.94.
After 170 seconds, recent_cpu is 188.14, load_avg is 0.94.
After 172 seconds, recent_cpu is 188.53, load_avg is 0.94.
After 174 seconds, recent_cpu is 188.91, load_avg is 0.95.
After 176 seconds, recent_cpu is 189.27, load_avg is 0.95.
After 178 seconds, recent_cpu is 189.63, load_avg is 0.95.
After 180 seconds, recent_cpu is 189.97, load_avg is 0.95.
*/
#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"
/* Sensitive to assumption that recent_cpu updates happen exactly
when timer_ticks() % TIMER_FREQ == 0. */
void
test_mlfqs_recent_1 (void)
{
int64_t start_time;
int last_elapsed = 0;
ASSERT (thread_mlfqs);
do
{
msg ("Sleeping 10 seconds to allow recent_cpu to decay, please wait...");
start_time = timer_ticks ();
timer_sleep (DIV_ROUND_UP (start_time, TIMER_FREQ) - start_time
+ 10 * TIMER_FREQ);
}
while (thread_get_recent_cpu () > 700);
start_time = timer_ticks ();
for (;;)
{
int elapsed = timer_elapsed (start_time);
if (elapsed % (TIMER_FREQ * 2) == 0 && elapsed > last_elapsed)
{
int recent_cpu = thread_get_recent_cpu ();
int load_avg = thread_get_load_avg ();
int elapsed_seconds = elapsed / TIMER_FREQ;
msg ("After %d seconds, recent_cpu is %d.%02d, load_avg is %d.%02d.",
elapsed_seconds,
recent_cpu / 100, recent_cpu % 100,
load_avg / 100, load_avg % 100);
if (elapsed_seconds >= 180)
break;
}
last_elapsed = elapsed;
}
}
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-recent-1.c | C | oos | 7,017 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-sema) begin
(priority-sema) Thread priority 30 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 29 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 28 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 27 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 26 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 25 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 24 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 23 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 22 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 21 woke up.
(priority-sema) Back in main thread.
(priority-sema) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-sema.ck | Perl | oos | 949 |
/* Tests that cond_signal() wakes up the highest-priority thread
waiting in cond_wait(). */
#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 priority_condvar_thread;
static struct lock lock;
static struct condition condition;
void
test_priority_condvar (void)
{
int i;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
lock_init (&lock);
cond_init (&condition);
thread_set_priority (PRI_MIN);
for (i = 0; i < 10; i++)
{
int priority = PRI_DEFAULT - (i + 7) % 10 - 1;
char name[16];
snprintf (name, sizeof name, "priority %d", priority);
thread_create (name, priority, priority_condvar_thread, NULL);
}
for (i = 0; i < 10; i++)
{
lock_acquire (&lock);
msg ("Signaling...");
cond_signal (&condition, &lock);
lock_release (&lock);
}
}
static void
priority_condvar_thread (void *aux UNUSED)
{
msg ("Thread %s starting.", thread_name ());
lock_acquire (&lock);
cond_wait (&condition, &lock);
msg ("Thread %s woke up.", thread_name ());
lock_release (&lock);
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-condvar.c | C | oos | 1,240 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
fail "missing PASS in output"
unless grep ($_ eq '(mlfqs-load-1) PASS', @output);
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-load-1.ck | Perl | oos | 290 |
/* Starts 60 threads that each sleep for 10 seconds, then spin in
a tight loop for 60 seconds, and sleep for another 60 seconds.
Every 2 seconds after the initial sleep, the main thread
prints the load average.
The expected output is this (some margin of error is allowed):
After 0 seconds, load average=1.00.
After 2 seconds, load average=2.95.
After 4 seconds, load average=4.84.
After 6 seconds, load average=6.66.
After 8 seconds, load average=8.42.
After 10 seconds, load average=10.13.
After 12 seconds, load average=11.78.
After 14 seconds, load average=13.37.
After 16 seconds, load average=14.91.
After 18 seconds, load average=16.40.
After 20 seconds, load average=17.84.
After 22 seconds, load average=19.24.
After 24 seconds, load average=20.58.
After 26 seconds, load average=21.89.
After 28 seconds, load average=23.15.
After 30 seconds, load average=24.37.
After 32 seconds, load average=25.54.
After 34 seconds, load average=26.68.
After 36 seconds, load average=27.78.
After 38 seconds, load average=28.85.
After 40 seconds, load average=29.88.
After 42 seconds, load average=30.87.
After 44 seconds, load average=31.84.
After 46 seconds, load average=32.77.
After 48 seconds, load average=33.67.
After 50 seconds, load average=34.54.
After 52 seconds, load average=35.38.
After 54 seconds, load average=36.19.
After 56 seconds, load average=36.98.
After 58 seconds, load average=37.74.
After 60 seconds, load average=37.48.
After 62 seconds, load average=36.24.
After 64 seconds, load average=35.04.
After 66 seconds, load average=33.88.
After 68 seconds, load average=32.76.
After 70 seconds, load average=31.68.
After 72 seconds, load average=30.63.
After 74 seconds, load average=29.62.
After 76 seconds, load average=28.64.
After 78 seconds, load average=27.69.
After 80 seconds, load average=26.78.
After 82 seconds, load average=25.89.
After 84 seconds, load average=25.04.
After 86 seconds, load average=24.21.
After 88 seconds, load average=23.41.
After 90 seconds, load average=22.64.
After 92 seconds, load average=21.89.
After 94 seconds, load average=21.16.
After 96 seconds, load average=20.46.
After 98 seconds, load average=19.79.
After 100 seconds, load average=19.13.
After 102 seconds, load average=18.50.
After 104 seconds, load average=17.89.
After 106 seconds, load average=17.30.
After 108 seconds, load average=16.73.
After 110 seconds, load average=16.17.
After 112 seconds, load average=15.64.
After 114 seconds, load average=15.12.
After 116 seconds, load average=14.62.
After 118 seconds, load average=14.14.
After 120 seconds, load average=13.67.
After 122 seconds, load average=13.22.
After 124 seconds, load average=12.78.
After 126 seconds, load average=12.36.
After 128 seconds, load average=11.95.
After 130 seconds, load average=11.56.
After 132 seconds, load average=11.17.
After 134 seconds, load average=10.80.
After 136 seconds, load average=10.45.
After 138 seconds, load average=10.10.
After 140 seconds, load average=9.77.
After 142 seconds, load average=9.45.
After 144 seconds, load average=9.13.
After 146 seconds, load average=8.83.
After 148 seconds, load average=8.54.
After 150 seconds, load average=8.26.
After 152 seconds, load average=7.98.
After 154 seconds, load average=7.72.
After 156 seconds, load average=7.47.
After 158 seconds, load average=7.22.
After 160 seconds, load average=6.98.
After 162 seconds, load average=6.75.
After 164 seconds, load average=6.53.
After 166 seconds, load average=6.31.
After 168 seconds, load average=6.10.
After 170 seconds, load average=5.90.
After 172 seconds, load average=5.70.
After 174 seconds, load average=5.52.
After 176 seconds, load average=5.33.
After 178 seconds, load average=5.16.
*/
#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 int64_t start_time;
static void load_thread (void *aux);
#define THREAD_CNT 60
void
test_mlfqs_load_60 (void)
{
int i;
ASSERT (thread_mlfqs);
start_time = timer_ticks ();
msg ("Starting %d niced load threads...", THREAD_CNT);
for (i = 0; i < THREAD_CNT; i++)
{
char name[16];
snprintf(name, sizeof name, "load %d", i);
thread_create (name, PRI_DEFAULT, load_thread, NULL);
}
msg ("Starting threads took %d seconds.",
timer_elapsed (start_time) / TIMER_FREQ);
for (i = 0; i < 90; i++)
{
int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10);
int load_avg;
timer_sleep (sleep_until - timer_ticks ());
load_avg = thread_get_load_avg ();
msg ("After %d seconds, load average=%d.%02d.",
i * 2, load_avg / 100, load_avg % 100);
}
}
static void
load_thread (void *aux UNUSED)
{
int64_t sleep_time = 10 * TIMER_FREQ;
int64_t spin_time = sleep_time + 60 * TIMER_FREQ;
int64_t exit_time = spin_time + 60 * TIMER_FREQ;
thread_set_nice (20);
timer_sleep (sleep_time - timer_elapsed (start_time));
while (timer_elapsed (start_time) < spin_time)
continue;
timer_sleep (exit_time - timer_elapsed (start_time));
}
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-load-60.c | C | oos | 5,423 |
/* Low-priority main thread L acquires lock A. Medium-priority
thread M then acquires lock B then blocks on acquiring lock A.
High-priority thread H then blocks on acquiring lock B. Thus,
thread H donates its priority to M, which in turn donates it
to thread L.
Based on a test originally submitted for Stanford's CS 140 in
winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
<yph@cs.stanford.edu>. Modified by arens. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
struct locks
{
struct lock *a;
struct lock *b;
};
static thread_func medium_thread_func;
static thread_func high_thread_func;
void
test_priority_donate_nest (void)
{
struct lock a, b;
struct locks locks;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
/* Make sure our priority is the default. */
ASSERT (thread_get_priority () == PRI_DEFAULT);
lock_init (&a);
lock_init (&b);
lock_acquire (&a);
locks.a = &a;
locks.b = &b;
thread_create ("medium", PRI_DEFAULT + 1, medium_thread_func, &locks);
thread_yield ();
msg ("Low thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT + 1, thread_get_priority ());
thread_create ("high", PRI_DEFAULT + 2, high_thread_func, &b);
thread_yield ();
msg ("Low thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT + 2, thread_get_priority ());
lock_release (&a);
thread_yield ();
msg ("Medium thread should just have finished.");
msg ("Low thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT, thread_get_priority ());
}
static void
medium_thread_func (void *locks_)
{
struct locks *locks = locks_;
lock_acquire (locks->b);
lock_acquire (locks->a);
msg ("Medium thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT + 2, thread_get_priority ());
msg ("Medium thread got the lock.");
lock_release (locks->a);
thread_yield ();
lock_release (locks->b);
thread_yield ();
msg ("High thread should have just finished.");
msg ("Middle thread finished.");
}
static void
high_thread_func (void *lock_)
{
struct lock *lock = lock_;
lock_acquire (lock);
msg ("High thread got the lock.");
lock_release (lock);
msg ("High thread finished.");
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-nest.c | C | oos | 2,430 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-multiple) begin
(priority-donate-multiple) Main thread should have priority 32. Actual priority: 32.
(priority-donate-multiple) Main thread should have priority 33. Actual priority: 33.
(priority-donate-multiple) Thread b acquired lock b.
(priority-donate-multiple) Thread b finished.
(priority-donate-multiple) Thread b should have just finished.
(priority-donate-multiple) Main thread should have priority 32. Actual priority: 32.
(priority-donate-multiple) Thread a acquired lock a.
(priority-donate-multiple) Thread a finished.
(priority-donate-multiple) Thread a should have just finished.
(priority-donate-multiple) Main thread should have priority 31. Actual priority: 31.
(priority-donate-multiple) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-multiple.ck | Perl | oos | 829 |
/* Low priority thread L acquires a lock, then blocks downing a
semaphore. Medium priority thread M then blocks waiting on
the same semaphore. Next, high priority thread H attempts to
acquire the lock, donating its priority to L.
Next, the main thread ups the semaphore, waking up L. L
releases the lock, which wakes up H. H "up"s the semaphore,
waking up M. H terminates, then M, then L, and finally the
main thread.
Written by Godmar Back <gback@cs.vt.edu>. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
struct lock_and_sema
{
struct lock lock;
struct semaphore sema;
};
static thread_func l_thread_func;
static thread_func m_thread_func;
static thread_func h_thread_func;
void
test_priority_donate_sema (void)
{
struct lock_and_sema ls;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
/* Make sure our priority is the default. */
ASSERT (thread_get_priority () == PRI_DEFAULT);
lock_init (&ls.lock);
sema_init (&ls.sema, 0);
thread_create ("low", PRI_DEFAULT + 1, l_thread_func, &ls);
thread_create ("med", PRI_DEFAULT + 3, m_thread_func, &ls);
thread_create ("high", PRI_DEFAULT + 5, h_thread_func, &ls);
sema_up (&ls.sema);
msg ("Main thread finished.");
}
static void
l_thread_func (void *ls_)
{
struct lock_and_sema *ls = ls_;
lock_acquire (&ls->lock);
msg ("Thread L acquired lock.");
sema_down (&ls->sema);
msg ("Thread L downed semaphore.");
lock_release (&ls->lock);
msg ("Thread L finished.");
}
static void
m_thread_func (void *ls_)
{
struct lock_and_sema *ls = ls_;
sema_down (&ls->sema);
msg ("Thread M finished.");
}
static void
h_thread_func (void *ls_)
{
struct lock_and_sema *ls = ls_;
lock_acquire (&ls->lock);
msg ("Thread H acquired lock.");
sema_up (&ls->sema);
lock_release (&ls->lock);
msg ("Thread H finished.");
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-sema.c | C | oos | 1,971 |
/* Ensures that a high-priority thread really preempts.
Based on a test originally submitted for Stanford's CS 140 in
winter 1999 by by Matt Franklin
<startled@leland.stanford.edu>, Greg Hutchins
<gmh@leland.stanford.edu>, Yu Ping Hu <yph@cs.stanford.edu>.
Modified by arens. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
static thread_func simple_thread_func;
void
test_priority_preempt (void)
{
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
/* Make sure our priority is the default. */
ASSERT (thread_get_priority () == PRI_DEFAULT);
thread_create ("high-priority", PRI_DEFAULT + 1, simple_thread_func, NULL);
msg ("The high-priority thread should have already completed.");
}
static void
simple_thread_func (void *aux UNUSED)
{
int i;
for (i = 0; i < 5; i++)
{
msg ("Thread %s iteration %d", thread_name (), i);
thread_yield ();
}
msg ("Thread %s done!", thread_name ());
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-preempt.c | C | oos | 1,058 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([(0) x 20], 20);
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-fair-20.ck | Perl | oos | 122 |
/* The main thread acquires locks A and B, then it creates two
higher-priority threads. Each of these threads blocks
acquiring one of the locks and thus donate their priority to
the main thread. The main thread releases the locks in turn
and relinquishes its donated priorities.
Based on a test originally submitted for Stanford's CS 140 in
winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
<yph@cs.stanford.edu>. Modified by arens. */
#include <stdio.h>
#include "tests/threads/tests.h"
#include "threads/init.h"
#include "threads/synch.h"
#include "threads/thread.h"
static thread_func a_thread_func;
static thread_func b_thread_func;
void
test_priority_donate_multiple (void)
{
struct lock a, b;
/* This test does not work with the MLFQS. */
ASSERT (!thread_mlfqs);
/* Make sure our priority is the default. */
ASSERT (thread_get_priority () == PRI_DEFAULT);
lock_init (&a);
lock_init (&b);
lock_acquire (&a);
lock_acquire (&b);
thread_create ("a", PRI_DEFAULT + 1, a_thread_func, &a);
msg ("Main thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT + 1, thread_get_priority ());
thread_create ("b", PRI_DEFAULT + 2, b_thread_func, &b);
msg ("Main thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT + 2, thread_get_priority ());
lock_release (&b);
msg ("Thread b should have just finished.");
msg ("Main thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT + 1, thread_get_priority ());
lock_release (&a);
msg ("Thread a should have just finished.");
msg ("Main thread should have priority %d. Actual priority: %d.",
PRI_DEFAULT, thread_get_priority ());
}
static void
a_thread_func (void *lock_)
{
struct lock *lock = lock_;
lock_acquire (lock);
msg ("Thread a acquired lock a.");
lock_release (lock);
msg ("Thread a finished.");
}
static void
b_thread_func (void *lock_)
{
struct lock *lock = lock_;
lock_acquire (lock);
msg ("Thread b acquired lock b.");
lock_release (lock);
msg ("Thread b finished.");
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-multiple.c | C | oos | 2,158 |
# -*- 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;
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-block.ck | Perl | oos | 529 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([0, 0], 50);
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-fair-2.ck | Perl | oos | 118 |
/* Starts 60 threads numbered 0 through 59. Thread #i sleeps for
(10+i) seconds, then spins in a loop for 60 seconds, then
sleeps until a total of 120 seconds have passed. Every 2
seconds, starting 10 seconds in, the main thread prints the
load average.
The expected output is listed below. Some margin of error is
allowed.
If your implementation fails this test but passes most other
tests, then consider whether you are doing too much work in
the timer interrupt. If the timer interrupt handler takes too
long, then the test's main thread will not have enough time to
do its own work (printing a message) and go back to sleep
before the next tick arrives. Then the main thread will be
ready, instead of sleeping, when the tick arrives,
artificially driving up the load average.
After 0 seconds, load average=0.00.
After 2 seconds, load average=0.05.
After 4 seconds, load average=0.16.
After 6 seconds, load average=0.34.
After 8 seconds, load average=0.58.
After 10 seconds, load average=0.87.
After 12 seconds, load average=1.22.
After 14 seconds, load average=1.63.
After 16 seconds, load average=2.09.
After 18 seconds, load average=2.60.
After 20 seconds, load average=3.16.
After 22 seconds, load average=3.76.
After 24 seconds, load average=4.42.
After 26 seconds, load average=5.11.
After 28 seconds, load average=5.85.
After 30 seconds, load average=6.63.
After 32 seconds, load average=7.46.
After 34 seconds, load average=8.32.
After 36 seconds, load average=9.22.
After 38 seconds, load average=10.15.
After 40 seconds, load average=11.12.
After 42 seconds, load average=12.13.
After 44 seconds, load average=13.16.
After 46 seconds, load average=14.23.
After 48 seconds, load average=15.33.
After 50 seconds, load average=16.46.
After 52 seconds, load average=17.62.
After 54 seconds, load average=18.81.
After 56 seconds, load average=20.02.
After 58 seconds, load average=21.26.
After 60 seconds, load average=22.52.
After 62 seconds, load average=23.71.
After 64 seconds, load average=24.80.
After 66 seconds, load average=25.78.
After 68 seconds, load average=26.66.
After 70 seconds, load average=27.45.
After 72 seconds, load average=28.14.
After 74 seconds, load average=28.75.
After 76 seconds, load average=29.27.
After 78 seconds, load average=29.71.
After 80 seconds, load average=30.06.
After 82 seconds, load average=30.34.
After 84 seconds, load average=30.55.
After 86 seconds, load average=30.68.
After 88 seconds, load average=30.74.
After 90 seconds, load average=30.73.
After 92 seconds, load average=30.66.
After 94 seconds, load average=30.52.
After 96 seconds, load average=30.32.
After 98 seconds, load average=30.06.
After 100 seconds, load average=29.74.
After 102 seconds, load average=29.37.
After 104 seconds, load average=28.95.
After 106 seconds, load average=28.47.
After 108 seconds, load average=27.94.
After 110 seconds, load average=27.36.
After 112 seconds, load average=26.74.
After 114 seconds, load average=26.07.
After 116 seconds, load average=25.36.
After 118 seconds, load average=24.60.
After 120 seconds, load average=23.81.
After 122 seconds, load average=23.02.
After 124 seconds, load average=22.26.
After 126 seconds, load average=21.52.
After 128 seconds, load average=20.81.
After 130 seconds, load average=20.12.
After 132 seconds, load average=19.46.
After 134 seconds, load average=18.81.
After 136 seconds, load average=18.19.
After 138 seconds, load average=17.59.
After 140 seconds, load average=17.01.
After 142 seconds, load average=16.45.
After 144 seconds, load average=15.90.
After 146 seconds, load average=15.38.
After 148 seconds, load average=14.87.
After 150 seconds, load average=14.38.
After 152 seconds, load average=13.90.
After 154 seconds, load average=13.44.
After 156 seconds, load average=13.00.
After 158 seconds, load average=12.57.
After 160 seconds, load average=12.15.
After 162 seconds, load average=11.75.
After 164 seconds, load average=11.36.
After 166 seconds, load average=10.99.
After 168 seconds, load average=10.62.
After 170 seconds, load average=10.27.
After 172 seconds, load average=9.93.
After 174 seconds, load average=9.61.
After 176 seconds, load average=9.29.
After 178 seconds, load average=8.98.
*/
#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 int64_t start_time;
static void load_thread (void *seq_no);
#define THREAD_CNT 60
void
test_mlfqs_load_avg (void)
{
int i;
ASSERT (thread_mlfqs);
start_time = timer_ticks ();
msg ("Starting %d load threads...", THREAD_CNT);
for (i = 0; i < THREAD_CNT; i++)
{
char name[16];
snprintf(name, sizeof name, "load %d", i);
thread_create (name, PRI_DEFAULT, load_thread, (void *) i);
}
msg ("Starting threads took %d seconds.",
timer_elapsed (start_time) / TIMER_FREQ);
thread_set_nice (-20);
for (i = 0; i < 90; i++)
{
int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10);
int load_avg;
timer_sleep (sleep_until - timer_ticks ());
load_avg = thread_get_load_avg ();
msg ("After %d seconds, load average=%d.%02d.",
i * 2, load_avg / 100, load_avg % 100);
}
}
static void
load_thread (void *seq_no_)
{
int seq_no = (int) seq_no_;
int sleep_time = TIMER_FREQ * (10 + seq_no);
int spin_time = sleep_time + TIMER_FREQ * THREAD_CNT;
int exit_time = TIMER_FREQ * (THREAD_CNT * 2);
timer_sleep (sleep_time - timer_elapsed (start_time));
while (timer_elapsed (start_time) < spin_time)
continue;
timer_sleep (exit_time - timer_elapsed (start_time));
}
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-load-avg.c | C | oos | 6,006 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-one) begin
(priority-donate-one) This thread should have priority 32. Actual priority: 32.
(priority-donate-one) This thread should have priority 33. Actual priority: 33.
(priority-donate-one) acquire2: got the lock
(priority-donate-one) acquire2: done
(priority-donate-one) acquire1: got the lock
(priority-donate-one) acquire1: done
(priority-donate-one) acquire2, acquire1 must already have finished, in that order.
(priority-donate-one) This should be the last line before finishing this test.
(priority-donate-one) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-one.ck | Perl | oos | 640 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-condvar) begin
(priority-condvar) Thread priority 23 starting.
(priority-condvar) Thread priority 22 starting.
(priority-condvar) Thread priority 21 starting.
(priority-condvar) Thread priority 30 starting.
(priority-condvar) Thread priority 29 starting.
(priority-condvar) Thread priority 28 starting.
(priority-condvar) Thread priority 27 starting.
(priority-condvar) Thread priority 26 starting.
(priority-condvar) Thread priority 25 starting.
(priority-condvar) Thread priority 24 starting.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 30 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 29 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 28 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 27 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 26 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 25 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 24 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 23 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 22 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 21 woke up.
(priority-condvar) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-condvar.ck | Perl | oos | 1,415 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-multiple) begin
(priority-donate-multiple) Main thread should have priority 32. Actual priority: 32.
(priority-donate-multiple) Main thread should have priority 33. Actual priority: 33.
(priority-donate-multiple) Thread b acquired lock b.
(priority-donate-multiple) Thread b finished.
(priority-donate-multiple) Thread b should have just finished.
(priority-donate-multiple) Main thread should have priority 32. Actual priority: 32.
(priority-donate-multiple) Thread a acquired lock a.
(priority-donate-multiple) Thread a finished.
(priority-donate-multiple) Thread a should have just finished.
(priority-donate-multiple) Main thread should have priority 31. Actual priority: 31.
(priority-donate-multiple) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-multiple.ck.svn-base | Perl | oos | 829 |
# -*- perl -*-
use tests::tests;
use tests::threads::alarm;
check_alarm (7);
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/alarm-multiple.ck.svn-base | Perl | oos | 77 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([0...9], 25);
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-nice-10.ck.svn-base | Perl | oos | 119 |
# -*- perl -*-
use tests::tests;
use tests::threads::alarm;
check_alarm (1);
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/alarm-single.ck.svn-base | Perl | oos | 77 |
# -*- perl -*-
# The expected output looks like this:
#
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# (priority-fifo) iteration: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# A different permutation of 0...15 is acceptable, but every line must
# be in the same order.
use strict;
use warnings;
use tests::tests;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
my ($thread_cnt) = 16;
my ($iter_cnt) = 16;
my (@order);
my (@t) = (-1) x $thread_cnt;
my (@iterations) = grep (/iteration:/, @output);
fail "No iterations found in output.\n" if !@iterations;
my (@numbering) = $iterations[0] =~ /(\d+)/g;
fail "First iteration does not list exactly $thread_cnt threads.\n"
if @numbering != $thread_cnt;
my (@sorted_numbering) = sort { $a <=> $b } @numbering;
for my $i (0...$#sorted_numbering) {
if ($sorted_numbering[$i] != $i) {
fail "First iteration does not list all threads "
. "0...$#sorted_numbering\n";
}
}
for my $i (1...$#iterations) {
if ($iterations[$i] ne $iterations[0]) {
fail "Iteration $i differs from iteration 0\n";
}
}
fail "$iter_cnt iterations expected but " . scalar (@iterations) . " found\n"
if $iter_cnt != @iterations;
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-fifo.ck.svn-base | Perl | oos | 2,185 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-multiple2) begin
(priority-donate-multiple2) Main thread should have priority 34. Actual priority: 34.
(priority-donate-multiple2) Main thread should have priority 36. Actual priority: 36.
(priority-donate-multiple2) Main thread should have priority 36. Actual priority: 36.
(priority-donate-multiple2) Thread b acquired lock b.
(priority-donate-multiple2) Thread b finished.
(priority-donate-multiple2) Thread a acquired lock a.
(priority-donate-multiple2) Thread a finished.
(priority-donate-multiple2) Thread c finished.
(priority-donate-multiple2) Threads b, a, c should have just finished, in that order.
(priority-donate-multiple2) Main thread should have priority 31. Actual priority: 31.
(priority-donate-multiple2) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-multiple2.ck.svn-base | Perl | oos | 846 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-condvar) begin
(priority-condvar) Thread priority 23 starting.
(priority-condvar) Thread priority 22 starting.
(priority-condvar) Thread priority 21 starting.
(priority-condvar) Thread priority 30 starting.
(priority-condvar) Thread priority 29 starting.
(priority-condvar) Thread priority 28 starting.
(priority-condvar) Thread priority 27 starting.
(priority-condvar) Thread priority 26 starting.
(priority-condvar) Thread priority 25 starting.
(priority-condvar) Thread priority 24 starting.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 30 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 29 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 28 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 27 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 26 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 25 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 24 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 23 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 22 woke up.
(priority-condvar) Signaling...
(priority-condvar) Thread priority 21 woke up.
(priority-condvar) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-condvar.ck.svn-base | Perl | oos | 1,415 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
# Get actual values.
local ($_);
my (@actual);
foreach (@output) {
my ($t, $load_avg) = /After (\d+) seconds, load average=(\d+\.\d+)\./
or next;
$actual[$t] = $load_avg;
}
# Calculate expected values.
my ($load_avg) = 0;
my ($recent) = 0;
my (@expected);
for (my ($t) = 0; $t < 180; $t++) {
my ($ready) = $t < 60 ? $t : $t < 120 ? 120 - $t : 0;
$load_avg = (59/60) * $load_avg + (1/60) * $ready;
$expected[$t] = $load_avg;
}
mlfqs_compare ("time", "%.2f", \@actual, \@expected, 2.5, [2, 178, 2],
"Some load average values were missing or "
. "differed from those expected "
. "by more than 2.5.");
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-load-avg.ck.svn-base | Perl | oos | 883 |
# -*- makefile -*-
# 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)
# 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
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): KERNELFLAGS += -mlfqs
$(MLFQS_OUTPUTS): TIMEOUT = 480
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/Make.tests.svn-base | Makefile | oos | 2,339 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([0, 0], 50);
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-fair-2.ck.svn-base | Perl | oos | 118 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-sema) begin
(priority-donate-sema) Thread L acquired lock.
(priority-donate-sema) Thread L downed semaphore.
(priority-donate-sema) Thread H acquired lock.
(priority-donate-sema) Thread H finished.
(priority-donate-sema) Thread M finished.
(priority-donate-sema) Thread L finished.
(priority-donate-sema) Main thread finished.
(priority-donate-sema) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-sema.ck.svn-base | Perl | oos | 468 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-preempt) begin
(priority-preempt) Thread high-priority iteration 0
(priority-preempt) Thread high-priority iteration 1
(priority-preempt) Thread high-priority iteration 2
(priority-preempt) Thread high-priority iteration 3
(priority-preempt) Thread high-priority iteration 4
(priority-preempt) Thread high-priority done!
(priority-preempt) The high-priority thread should have already completed.
(priority-preempt) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-preempt.ck.svn-base | Perl | oos | 526 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-negative) begin
(alarm-negative) PASS
(alarm-negative) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/alarm-negative.ck.svn-base | Perl | oos | 163 |
# -*- 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;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/alarm-priority.ck.svn-base | Perl | oos | 591 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([(0) x 20], 20);
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-fair-20.ck.svn-base | Perl | oos | 122 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-lower) begin
(priority-donate-lower) Main thread should have priority 41. Actual priority: 41.
(priority-donate-lower) Lowering base priority...
(priority-donate-lower) Main thread should have priority 41. Actual priority: 41.
(priority-donate-lower) acquire: got the lock
(priority-donate-lower) acquire: done
(priority-donate-lower) acquire must already have finished.
(priority-donate-lower) Main thread should have priority 21. Actual priority: 21.
(priority-donate-lower) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-lower.ck.svn-base | Perl | oos | 598 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
fail "missing PASS in output"
unless grep ($_ eq '(mlfqs-load-1) PASS', @output);
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-load-1.ck.svn-base | Perl | oos | 290 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-change) begin
(priority-change) Creating a high-priority thread 2.
(priority-change) Thread 2 now lowering priority.
(priority-change) Thread 2 should have just lowered its priority.
(priority-change) Thread 2 exiting.
(priority-change) Thread 2 should have just exited.
(priority-change) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-change.ck.svn-base | Perl | oos | 400 |
# -*- 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;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-block.ck.svn-base | Perl | oos | 529 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-one) begin
(priority-donate-one) This thread should have priority 32. Actual priority: 32.
(priority-donate-one) This thread should have priority 33. Actual priority: 33.
(priority-donate-one) acquire2: got the lock
(priority-donate-one) acquire2: done
(priority-donate-one) acquire1: got the lock
(priority-donate-one) acquire1: done
(priority-donate-one) acquire2, acquire1 must already have finished, in that order.
(priority-donate-one) This should be the last line before finishing this test.
(priority-donate-one) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-one.ck.svn-base | Perl | oos | 640 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
# Get actual values.
local ($_);
my (@actual);
foreach (@output) {
my ($t, $load_avg) = /After (\d+) seconds, load average=(\d+\.\d+)\./
or next;
$actual[$t] = $load_avg;
}
# Calculate expected values.
my ($load_avg) = 0;
my ($recent) = 0;
my (@expected);
for (my ($t) = 0; $t < 180; $t++) {
my ($ready) = $t < 60 ? 60 : 0;
$load_avg = (59/60) * $load_avg + (1/60) * $ready;
$expected[$t] = $load_avg;
}
mlfqs_compare ("time", "%.2f", \@actual, \@expected, 3.5, [2, 178, 2],
"Some load average values were missing or "
. "differed from those expected "
. "by more than 3.5.");
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-load-60.ck.svn-base | Perl | oos | 861 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
check_mlfqs_fair ([0, 5], 50);
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-nice-2.ck.svn-base | Perl | oos | 118 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-simultaneous) begin
(alarm-simultaneous) Creating 3 threads to sleep 5 times each.
(alarm-simultaneous) Each thread sleeps 10 ticks each time.
(alarm-simultaneous) Within an iteration, all threads should wake up on the same tick.
(alarm-simultaneous) iteration 0, thread 0: woke up after 10 ticks
(alarm-simultaneous) iteration 0, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 0, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 1, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 1, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 1, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 2, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 2, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 2, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 3, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 3, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 3, thread 2: woke up 0 ticks later
(alarm-simultaneous) iteration 4, thread 0: woke up 10 ticks later
(alarm-simultaneous) iteration 4, thread 1: woke up 0 ticks later
(alarm-simultaneous) iteration 4, thread 2: woke up 0 ticks later
(alarm-simultaneous) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/alarm-simultaneous.ck.svn-base | Perl | oos | 1,354 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-nest) begin
(priority-donate-nest) Low thread should have priority 32. Actual priority: 32.
(priority-donate-nest) Low thread should have priority 33. Actual priority: 33.
(priority-donate-nest) Medium thread should have priority 33. Actual priority: 33.
(priority-donate-nest) Medium thread got the lock.
(priority-donate-nest) High thread got the lock.
(priority-donate-nest) High thread finished.
(priority-donate-nest) High thread should have just finished.
(priority-donate-nest) Middle thread finished.
(priority-donate-nest) Medium thread should just have finished.
(priority-donate-nest) Low thread should have priority 31. Actual priority: 31.
(priority-donate-nest) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-nest.ck.svn-base | Perl | oos | 798 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-sema) begin
(priority-sema) Thread priority 30 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 29 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 28 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 27 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 26 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 25 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 24 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 23 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 22 woke up.
(priority-sema) Back in main thread.
(priority-sema) Thread priority 21 woke up.
(priority-sema) Back in main thread.
(priority-sema) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-sema.ck.svn-base | Perl | oos | 949 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
# Get actual values.
local ($_);
my (@actual);
foreach (@output) {
my ($t, $recent_cpu) = /After (\d+) seconds, recent_cpu is (\d+\.\d+),/
or next;
$actual[$t] = $recent_cpu;
}
# Calculate expected values.
my ($expected_load_avg, $expected_recent_cpu)
= mlfqs_expected_load ([(1) x 180], [(100) x 180]);
my (@expected) = @$expected_recent_cpu;
# Compare actual and expected values.
mlfqs_compare ("time", "%.2f", \@actual, \@expected, 2.5, [2, 178, 2],
"Some recent_cpu values were missing or "
. "differed from those expected "
. "by more than 2.5.");
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs-recent-1.ck.svn-base | Perl | oos | 826 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-chain) begin
(priority-donate-chain) main got lock.
(priority-donate-chain) main should have priority 3. Actual priority: 3.
(priority-donate-chain) main should have priority 6. Actual priority: 6.
(priority-donate-chain) main should have priority 9. Actual priority: 9.
(priority-donate-chain) main should have priority 12. Actual priority: 12.
(priority-donate-chain) main should have priority 15. Actual priority: 15.
(priority-donate-chain) main should have priority 18. Actual priority: 18.
(priority-donate-chain) main should have priority 21. Actual priority: 21.
(priority-donate-chain) thread 1 got lock
(priority-donate-chain) thread 1 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 2 got lock
(priority-donate-chain) thread 2 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 3 got lock
(priority-donate-chain) thread 3 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 4 got lock
(priority-donate-chain) thread 4 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 5 got lock
(priority-donate-chain) thread 5 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 6 got lock
(priority-donate-chain) thread 6 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 7 got lock
(priority-donate-chain) thread 7 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 7 finishing with priority 21.
(priority-donate-chain) interloper 7 finished.
(priority-donate-chain) thread 6 finishing with priority 18.
(priority-donate-chain) interloper 6 finished.
(priority-donate-chain) thread 5 finishing with priority 15.
(priority-donate-chain) interloper 5 finished.
(priority-donate-chain) thread 4 finishing with priority 12.
(priority-donate-chain) interloper 4 finished.
(priority-donate-chain) thread 3 finishing with priority 9.
(priority-donate-chain) interloper 3 finished.
(priority-donate-chain) thread 2 finishing with priority 6.
(priority-donate-chain) interloper 2 finished.
(priority-donate-chain) thread 1 finishing with priority 3.
(priority-donate-chain) interloper 1 finished.
(priority-donate-chain) main finishing with priority 0.
(priority-donate-chain) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/priority-donate-chain.ck.svn-base | Perl | oos | 2,369 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(alarm-zero) begin
(alarm-zero) PASS
(alarm-zero) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/alarm-zero.ck.svn-base | Perl | oos | 151 |
# -*- perl -*-
use strict;
use warnings;
sub mlfqs_expected_load {
my ($ready, $recent_delta) = @_;
my (@load_avg) = 0;
my (@recent_cpu) = 0;
my ($load_avg) = 0;
my ($recent_cpu) = 0;
for my $i (0...$#$ready) {
$load_avg = (59/60) * $load_avg + (1/60) * $ready->[$i];
push (@load_avg, $load_avg);
if (defined $recent_delta->[$i]) {
my ($twice_load) = $load_avg * 2;
my ($load_factor) = $twice_load / ($twice_load + 1);
$recent_cpu = ($recent_cpu + $recent_delta->[$i]) * $load_factor;
push (@recent_cpu, $recent_cpu);
}
}
return (\@load_avg, \@recent_cpu);
}
sub mlfqs_expected_ticks {
my (@nice) = @_;
my ($thread_cnt) = scalar (@nice);
my (@recent_cpu) = (0) x $thread_cnt;
my (@slices) = (0) x $thread_cnt;
my (@fifo) = (0) x $thread_cnt;
my ($next_fifo) = 1;
my ($load_avg) = 0;
for my $i (1...750) {
if ($i % 25 == 0) {
# Update load average.
$load_avg = (59/60) * $load_avg + (1/60) * $thread_cnt;
# Update recent_cpu.
my ($twice_load) = $load_avg * 2;
my ($load_factor) = $twice_load / ($twice_load + 1);
$recent_cpu[$_] = $recent_cpu[$_] * $load_factor + $nice[$_]
foreach 0...($thread_cnt - 1);
}
# Update priorities.
my (@priority);
foreach my $j (0...($thread_cnt - 1)) {
my ($priority) = int ($recent_cpu[$j] / 4 + $nice[$j] * 2);
$priority = 0 if $priority < 0;
$priority = 63 if $priority > 63;
push (@priority, $priority);
}
# Choose thread to run.
my $max = 0;
for my $j (1...$#priority) {
if ($priority[$j] < $priority[$max]
|| ($priority[$j] == $priority[$max]
&& $fifo[$j] < $fifo[$max])) {
$max = $j;
}
}
$fifo[$max] = $next_fifo++;
# Run thread.
$recent_cpu[$max] += 4;
$slices[$max] += 4;
}
return @slices;
}
sub check_mlfqs_fair {
my ($nice, $maxdiff) = @_;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
my (@actual);
local ($_);
foreach (@output) {
my ($id, $count) = /Thread (\d+) received (\d+) ticks\./ or next;
$actual[$id] = $count;
}
my (@expected) = mlfqs_expected_ticks (@$nice);
mlfqs_compare ("thread", "%d",
\@actual, \@expected, $maxdiff, [0, $#$nice, 1],
"Some tick counts were missing or differed from those "
. "expected by more than $maxdiff.");
pass;
}
sub mlfqs_compare {
my ($indep_var, $format,
$actual_ref, $expected_ref, $maxdiff, $t_range, $message) = @_;
my ($t_min, $t_max, $t_step) = @$t_range;
my ($ok) = 1;
for (my ($t) = $t_min; $t <= $t_max; $t += $t_step) {
my ($actual) = $actual_ref->[$t];
my ($expected) = $expected_ref->[$t];
$ok = 0, last
if !defined ($actual) || abs ($actual - $expected) > $maxdiff + .01;
}
return if $ok;
print "$message\n";
mlfqs_row ($indep_var, "actual", "<->", "expected", "explanation");
mlfqs_row ("------", "--------", "---", "--------", '-' x 40);
for (my ($t) = $t_min; $t <= $t_max; $t += $t_step) {
my ($actual) = $actual_ref->[$t];
my ($expected) = $expected_ref->[$t];
my ($diff, $rationale);
if (!defined $actual) {
$actual = 'undef' ;
$diff = '';
$rationale = 'Missing value.';
} else {
my ($delta) = abs ($actual - $expected);
if ($delta > $maxdiff + .01) {
my ($excess) = $delta - $maxdiff;
if ($actual > $expected) {
$diff = '>>>';
$rationale = sprintf "Too big, by $format.", $excess;
} else {
$diff = '<<<';
$rationale = sprintf "Too small, by $format.", $excess;
}
} else {
$diff = ' = ';
$rationale = '';
}
$actual = sprintf ($format, $actual);
}
$expected = sprintf ($format, $expected);
mlfqs_row ($t, $actual, $diff, $expected, $rationale);
}
fail;
}
sub mlfqs_row {
printf "%6s %8s %3s %-8s %s\n", @_;
}
1;
| 10cm | trunk/10cm/pintos/src/tests/threads/.svn/text-base/mlfqs.pm.svn-base | Perl | oos | 3,921 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-chain) begin
(priority-donate-chain) main got lock.
(priority-donate-chain) main should have priority 3. Actual priority: 3.
(priority-donate-chain) main should have priority 6. Actual priority: 6.
(priority-donate-chain) main should have priority 9. Actual priority: 9.
(priority-donate-chain) main should have priority 12. Actual priority: 12.
(priority-donate-chain) main should have priority 15. Actual priority: 15.
(priority-donate-chain) main should have priority 18. Actual priority: 18.
(priority-donate-chain) main should have priority 21. Actual priority: 21.
(priority-donate-chain) thread 1 got lock
(priority-donate-chain) thread 1 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 2 got lock
(priority-donate-chain) thread 2 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 3 got lock
(priority-donate-chain) thread 3 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 4 got lock
(priority-donate-chain) thread 4 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 5 got lock
(priority-donate-chain) thread 5 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 6 got lock
(priority-donate-chain) thread 6 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 7 got lock
(priority-donate-chain) thread 7 should have priority 21. Actual priority: 21
(priority-donate-chain) thread 7 finishing with priority 21.
(priority-donate-chain) interloper 7 finished.
(priority-donate-chain) thread 6 finishing with priority 18.
(priority-donate-chain) interloper 6 finished.
(priority-donate-chain) thread 5 finishing with priority 15.
(priority-donate-chain) interloper 5 finished.
(priority-donate-chain) thread 4 finishing with priority 12.
(priority-donate-chain) interloper 4 finished.
(priority-donate-chain) thread 3 finishing with priority 9.
(priority-donate-chain) interloper 3 finished.
(priority-donate-chain) thread 2 finishing with priority 6.
(priority-donate-chain) interloper 2 finished.
(priority-donate-chain) thread 1 finishing with priority 3.
(priority-donate-chain) interloper 1 finished.
(priority-donate-chain) main finishing with priority 0.
(priority-donate-chain) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-chain.ck | Perl | oos | 2,369 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-change) begin
(priority-change) Creating a high-priority thread 2.
(priority-change) Thread 2 now lowering priority.
(priority-change) Thread 2 should have just lowered its priority.
(priority-change) Thread 2 exiting.
(priority-change) Thread 2 should have just exited.
(priority-change) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-change.ck | Perl | oos | 400 |
# -*- makefile -*-
# 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)
# 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
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): KERNELFLAGS += -mlfqs
$(MLFQS_OUTPUTS): TIMEOUT = 480
| 10cm | trunk/10cm/pintos/src/tests/threads/Make.tests | Makefile | oos | 2,339 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
use tests::threads::mlfqs;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
@output = get_core_output ("run", @output);
# Get actual values.
local ($_);
my (@actual);
foreach (@output) {
my ($t, $load_avg) = /After (\d+) seconds, load average=(\d+\.\d+)\./
or next;
$actual[$t] = $load_avg;
}
# Calculate expected values.
my ($load_avg) = 0;
my ($recent) = 0;
my (@expected);
for (my ($t) = 0; $t < 180; $t++) {
my ($ready) = $t < 60 ? $t : $t < 120 ? 120 - $t : 0;
$load_avg = (59/60) * $load_avg + (1/60) * $ready;
$expected[$t] = $load_avg;
}
mlfqs_compare ("time", "%.2f", \@actual, \@expected, 2.5, [2, 178, 2],
"Some load average values were missing or "
. "differed from those expected "
. "by more than 2.5.");
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-load-avg.ck | Perl | oos | 883 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(priority-donate-nest) begin
(priority-donate-nest) Low thread should have priority 32. Actual priority: 32.
(priority-donate-nest) Low thread should have priority 33. Actual priority: 33.
(priority-donate-nest) Medium thread should have priority 33. Actual priority: 33.
(priority-donate-nest) Medium thread got the lock.
(priority-donate-nest) High thread got the lock.
(priority-donate-nest) High thread finished.
(priority-donate-nest) High thread should have just finished.
(priority-donate-nest) Middle thread finished.
(priority-donate-nest) Medium thread should just have finished.
(priority-donate-nest) Low thread should have priority 31. Actual priority: 31.
(priority-donate-nest) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-donate-nest.ck | Perl | oos | 798 |
/* 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.");
}
| 10cm | trunk/10cm/pintos/src/tests/threads/priority-change.c | C | oos | 838 |
/* Verifies that a single busy thread raises the load average to
0.5 in 38 to 45 seconds. The expected time is 42 seconds, as
you can verify:
perl -e '$i++,$a=(59*$a+1)/60while$a<=.5;print "$i\n"'
Then, verifies that 10 seconds of inactivity drop the load
average back below 0.5 again. */
#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"
void
test_mlfqs_load_1 (void)
{
int64_t start_time;
int elapsed;
int load_avg;
ASSERT (thread_mlfqs);
msg ("spinning for up to 45 seconds, please wait...");
start_time = timer_ticks ();
for (;;)
{
load_avg = thread_get_load_avg ();
ASSERT (load_avg >= 0);
elapsed = timer_elapsed (start_time) / TIMER_FREQ;
if (load_avg > 100)
fail ("load average is %d.%02d "
"but should be between 0 and 1 (after %d seconds)",
load_avg / 100, load_avg % 100, elapsed);
else if (load_avg > 50)
break;
else if (elapsed > 45)
fail ("load average stayed below 0.5 for more than 45 seconds");
}
if (elapsed < 38)
fail ("load average took only %d seconds to rise above 0.5", elapsed);
msg ("load average rose to 0.5 after %d seconds", elapsed);
msg ("sleeping for another 10 seconds, please wait...");
timer_sleep (TIMER_FREQ * 10);
load_avg = thread_get_load_avg ();
if (load_avg < 0)
fail ("load average fell below 0");
if (load_avg > 50)
fail ("load average stayed above 0.5 for more than 10 seconds");
msg ("load average fell back below 0.5 (to %d.%02d)",
load_avg / 100, load_avg % 100);
pass ();
}
| 10cm | trunk/10cm/pintos/src/tests/threads/mlfqs-load-1.c | C | oos | 1,737 |
# -*- perl -*-
use tests::tests;
use tests::threads::alarm;
check_alarm (1);
| 10cm | trunk/10cm/pintos/src/tests/threads/alarm-single.ck | Perl | oos | 77 |
#include "tests/threads/tests.h"
#include <debug.h>
#include <string.h>
#include <stdio.h>
struct test
{
const char *name;
test_func *function;
};
static const struct test tests[] =
{
{"alarm-single", test_alarm_single},
{"alarm-multiple", test_alarm_multiple},
{"alarm-simultaneous", test_alarm_simultaneous},
{"alarm-priority", test_alarm_priority},
{"alarm-zero", test_alarm_zero},
{"alarm-negative", test_alarm_negative},
{"priority-change", test_priority_change},
{"priority-donate-one", test_priority_donate_one},
{"priority-donate-multiple", test_priority_donate_multiple},
{"priority-donate-multiple2", test_priority_donate_multiple2},
{"priority-donate-nest", test_priority_donate_nest},
{"priority-donate-sema", test_priority_donate_sema},
{"priority-donate-lower", test_priority_donate_lower},
{"priority-donate-chain", test_priority_donate_chain},
{"priority-fifo", test_priority_fifo},
{"priority-preempt", test_priority_preempt},
{"priority-sema", test_priority_sema},
{"priority-condvar", test_priority_condvar},
{"mlfqs-load-1", test_mlfqs_load_1},
{"mlfqs-load-60", test_mlfqs_load_60},
{"mlfqs-load-avg", test_mlfqs_load_avg},
{"mlfqs-recent-1", test_mlfqs_recent_1},
{"mlfqs-fair-2", test_mlfqs_fair_2},
{"mlfqs-fair-20", test_mlfqs_fair_20},
{"mlfqs-nice-2", test_mlfqs_nice_2},
{"mlfqs-nice-10", test_mlfqs_nice_10},
{"mlfqs-block", test_mlfqs_block},
};
static const char *test_name;
/* Runs the test named NAME. */
void
run_test (const char *name)
{
const struct test *t;
for (t = tests; t < tests + sizeof tests / sizeof *tests; t++)
if (!strcmp (name, t->name))
{
test_name = name;
msg ("begin");
t->function ();
msg ("end");
return;
}
PANIC ("no test named \"%s\"", name);
}
/* Prints FORMAT as if with printf(),
prefixing the output by the name of the test
and following it with a new-line character. */
void
msg (const char *format, ...)
{
va_list args;
printf ("(%s) ", test_name);
va_start (args, format);
vprintf (format, args);
va_end (args);
putchar ('\n');
}
/* Prints failure message FORMAT as if with printf(),
prefixing the output by the name of the test and FAIL:
and following it with a new-line character,
and then panics the kernel. */
void
fail (const char *format, ...)
{
va_list args;
printf ("(%s) FAIL: ", test_name);
va_start (args, format);
vprintf (format, args);
va_end (args);
putchar ('\n');
PANIC ("test failed");
}
/* Prints a message indicating the current test passed. */
void
pass (void)
{
printf ("(%s) PASS\n", test_name);
}
| 10cm | trunk/10cm/pintos/src/tests/threads/tests.c | C | oos | 2,735 |