Add a bunch of comm tests.

This commit is contained in:
Michael Bebenita 2010-07-28 16:58:17 -07:00 committed by Graydon Hoare
parent fa70212c86
commit 74a79fff3a
6 changed files with 167 additions and 6 deletions

View File

@ -374,6 +374,7 @@ TEST_XFAILS_X86 := test/run-pass/bind-obj-ctor.rs \
test/run-pass/task-comm-2.rs \
test/run-pass/task-comm-3.rs \
test/run-pass/task-comm-5.rs \
test/run-pass/task-comm-6.rs \
test/compile-fail/bad-recv.rs \
test/compile-fail/bad-send.rs \
test/compile-fail/infinite-tag-type-recursion.rs \
@ -479,6 +480,10 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
task-comm-3.rs \
task-comm-4.rs \
task-comm-5.rs \
task-comm-6.rs \
task-comm-7.rs \
task-comm-8.rs \
task-comm-9.rs \
threads.rs \
type-sizes.rs \
u8-incr.rs \

View File

@ -1,8 +1,8 @@
fn main() -> () {
log "===== THREADS =====";
test00(true);
log "====== TASKS ======";
test00(false);
fn main() -> () {
log "===== THREADS =====";
test00(true);
log "====== TASKS ======";
// test00(false);
}
fn start(int task_number) {
@ -15,7 +15,7 @@ fn start(int task_number) {
}
fn test00(bool create_threads) {
let int number_of_tasks = 32;
let int number_of_tasks = 0;
let int i = 0;
let vec[task] tasks = vec();
@ -31,4 +31,6 @@ fn test00(bool create_threads) {
for (task t in tasks) {
join t;
}
log "Joined all task.";
}

View File

@ -0,0 +1,36 @@
io fn main() -> () {
test00();
}
io fn test00() {
let int r = 0;
let int sum = 0;
let port[int] p = port();
let chan[int] c0 = chan(p);
let chan[int] c1 = chan(p);
let chan[int] c2 = chan(p);
let chan[int] c3 = chan(p);
let int number_of_messages = 1000;
let int i = 0;
while (i < number_of_messages) {
c0 <| i;
c1 <| i;
c2 <| i;
c3 <| i;
i += 1;
}
i = 0;
while (i < number_of_messages) {
r <- p; sum += r;
r <- p; sum += r;
r <- p; sum += r;
r <- p; sum += r;
i += 1;
}
check (sum == 4 * ((number_of_messages * (number_of_messages - 1)) / 2));
}

View File

@ -0,0 +1,44 @@
io fn main() -> () {
test00();
}
io fn test00_start(chan[int] c, int start, int number_of_messages) {
let int i = 0;
while (i < number_of_messages) {
c <| start + i;
i += 1;
}
}
io fn test00() {
let int r = 0;
let int sum = 0;
let port[int] p = port();
let int number_of_messages = 10;
let task t0 = spawn test00_start(chan(p),
number_of_messages * 0, number_of_messages);
let task t1 = spawn test00_start(chan(p),
number_of_messages * 1, number_of_messages);
let task t2 = spawn test00_start(chan(p),
number_of_messages * 2, number_of_messages);
let task t3 = spawn test00_start(chan(p),
number_of_messages * 3, number_of_messages);
let int i = 0;
while (i < number_of_messages) {
r <- p; sum += r;
r <- p; sum += r;
r <- p; sum += r;
r <- p; sum += r;
i += 1;
}
join t0;
join t1;
join t2;
join t3;
check (sum == (((number_of_messages * 4) *
((number_of_messages * 4) - 1)) / 2));
}

View File

@ -0,0 +1,44 @@
io fn main() -> () {
test00();
}
io fn test00_start(chan[int] c, int start, int number_of_messages) {
let int i = 0;
while (i < number_of_messages) {
c <| start + i;
i += 1;
}
}
io fn test00() {
let int r = 0;
let int sum = 0;
let port[int] p = port();
let int number_of_messages = 10;
let task t0 = spawn thread test00_start(chan(p),
number_of_messages * 0, number_of_messages);
let task t1 = spawn thread test00_start(chan(p),
number_of_messages * 1, number_of_messages);
let task t2 = spawn thread test00_start(chan(p),
number_of_messages * 2, number_of_messages);
let task t3 = spawn thread test00_start(chan(p),
number_of_messages * 3, number_of_messages);
let int i = 0;
while (i < number_of_messages) {
r <- p; sum += r;
r <- p; sum += r;
r <- p; sum += r;
r <- p; sum += r;
i += 1;
}
join t0;
join t1;
join t2;
join t3;
check (sum == (((number_of_messages * 4) *
((number_of_messages * 4) - 1)) / 2));
}

View File

@ -0,0 +1,30 @@
io fn main() -> () {
test00();
}
io fn test00_start(chan[int] c, int number_of_messages) {
let int i = 0;
while (i < number_of_messages) {
c <| i;
i += 1;
}
}
io fn test00() {
let int r = 0;
let int sum = 0;
let port[int] p = port();
let int number_of_messages = 10;
let task t0 = spawn thread test00_start(chan(p), number_of_messages);
let int i = 0;
while (i < number_of_messages) {
r <- p; sum += r; log (r);
i += 1;
}
join t0;
check (sum == (number_of_messages * (number_of_messages - 1)) / 2);
}