mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Add a bunch of comm tests.
This commit is contained in:
parent
fa70212c86
commit
74a79fff3a
@ -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 \
|
||||
|
@ -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.";
|
||||
}
|
36
src/test/run-pass/task-comm-6.rs
Normal file
36
src/test/run-pass/task-comm-6.rs
Normal 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));
|
||||
}
|
44
src/test/run-pass/task-comm-7.rs
Normal file
44
src/test/run-pass/task-comm-7.rs
Normal 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));
|
||||
}
|
44
src/test/run-pass/task-comm-8.rs
Normal file
44
src/test/run-pass/task-comm-8.rs
Normal 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));
|
||||
}
|
30
src/test/run-pass/task-comm-9.rs
Normal file
30
src/test/run-pass/task-comm-9.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user