Porting a bunch of tests over.

This commit is contained in:
Eric Holk 2011-08-12 18:34:19 -07:00
parent cc353aa17a
commit c3535f5842
8 changed files with 86 additions and 80 deletions

View File

@ -1,19 +1,20 @@
// xfail for now, due to some problem with polymorphic types.
// xfail-stage2
use std;
import std::task;
import std::task::task_id;
import std::comm;
import std::comm::chan_t;
import std::comm::_chan;
import std::comm::send;
fn main() { log "===== WITHOUT THREADS ====="; test00(); }
fn test00_start(ch: chan_t[int], message: int, count: int) {
fn test00_start(ch: _chan[int], message: int, count: int) {
log "Starting test00_start";
let i: int = 0;
while i < count {
log "Sending Message";
send(ch, message);
send(ch, message+0);
i = i + 1;
}
log "Ending test00_start";
@ -26,34 +27,34 @@ fn test00() {
log "Creating tasks";
let po = comm::mk_port();
let ch = po.mk_chan2();
let ch = po.mk_chan();
let i: int = 0;
// Create and spawn tasks...
let tasks: [task] = ~[];
let tasks = [];
while i < number_of_tasks {
tasks +=
[spawn test00_start(ch.unsafe_ptr(), i, number_of_messages)];
[task::_spawn(bind test00_start(ch, i, number_of_messages))];
i = i + 1;
}
// Read from spawned tasks...
let sum: int = 0;
for t: task in tasks {
let sum = 0;
for t: task_id in tasks {
i = 0;
while i < number_of_messages {
let value: int;
value = po.recv();
let value = po.recv();
sum += value;
i = i + 1;
}
}
// Join spawned tasks...
for t: task in tasks { task::join(t); }
for t: task_id in tasks { task::join_id(t); }
log "Completed: Final number is: ";
log_err sum;
// assert (sum == (((number_of_tasks * (number_of_tasks - 1)) / 2) *
// number_of_messages));
assert (sum == 480);

View File

@ -1,6 +1,11 @@
use std;
import std::task;
import std::task::task_id;
import std::comm;
import std::comm::_chan;
import std::comm::_port;
import std::comm::send;
fn main() {
test00();
@ -12,10 +17,10 @@ fn main() {
test06();
}
fn test00_start(ch: chan[int], message: int, count: int) {
fn test00_start(ch: _chan[int], message: int, count: int) {
log "Starting test00_start";
let i: int = 0;
while i < count { log "Sending Message"; ch <| message; i = i + 1; }
while i < count { log "Sending Message"; send(ch, message+0); i = i + 1; }
log "Ending test00_start";
}
@ -24,53 +29,48 @@ fn test00() {
let number_of_messages: int = 4;
log "Creating tasks";
let po: port[int] = port();
let ch: chan[int] = chan(po);
let po = comm::mk_port();
let ch = po.mk_chan();
let i: int = 0;
let tasks: [task] = ~[];
let tasks = [];
while i < number_of_tasks {
i = i + 1;
tasks += ~[spawn test00_start(ch, i, number_of_messages)];
tasks += [task::_spawn(bind test00_start(ch, i, number_of_messages))];
}
let sum: int = 0;
for t: task in tasks {
for t: task_id in tasks {
i = 0;
while i < number_of_messages {
let value: int;
po |> value;
sum += value;
sum += po.recv();
i = i + 1;
}
}
for t: task in tasks { task::join(t); }
for t: task_id in tasks { task::join_id(t); }
log "Completed: Final number is: ";
assert (sum ==
number_of_messages *
(number_of_tasks * number_of_tasks + number_of_tasks) /
2);
number_of_messages *
(number_of_tasks * number_of_tasks + number_of_tasks) / 2);
}
fn test01() {
let p: port[int] = port();
let p = comm::mk_port();
log "Reading from a port that is never written to.";
let value: int;
p |> value;
let value: int = p.recv();
log value;
}
fn test02() {
let p: port[int] = port();
let c: chan[int] = chan(p);
let p = comm::mk_port();
let c = p.mk_chan();
log "Writing to a local task channel.";
c <| 42;
send(c, 42);
log "Reading from a local task port.";
let value: int;
p |> value;
let value: int = p.recv();
log value;
}
@ -96,26 +96,26 @@ fn test04_start() {
fn test04() {
log "Spawning lots of tasks.";
let i: int = 4;
while i > 0 { i = i - 1; spawn test04_start(); }
while i > 0 { i = i - 1; task::_spawn(bind test04_start()); }
log "Finishing up.";
}
fn test05_start(ch: chan[int]) {
ch <| 10;
ch <| 20;
ch <| 30;
ch <| 30;
ch <| 30;
fn test05_start(ch: _chan[int]) {
send(ch, 10);
send(ch, 20);
send(ch, 30);
send(ch, 30);
send(ch, 30);
}
fn test05() {
let po: port[int] = port();
let ch: chan[int] = chan(po);
spawn test05_start(ch);
let po = comm::mk_port();
let ch = po.mk_chan();
task::_spawn(bind test05_start(ch));
let value: int;
po |> value;
po |> value;
po |> value;
value = po.recv();
value = po.recv();
value = po.recv();
log value;
}
@ -132,12 +132,12 @@ fn test06() {
let i: int = 0;
let tasks: [task] = ~[];
let tasks = [];
while i < number_of_tasks {
i = i + 1; tasks += ~[spawn test06_start(i)]; }
i = i + 1; tasks += [task::_spawn(bind test06_start(i))]; }
for t: task in tasks { task::join(t); }
for t: task_id in tasks { task::join_id(t); }
}

View File

@ -1,13 +1,11 @@
// xfail-stage1
// xfail-stage2
// xfail-stage3
/**
A test case for issue #577, which also exposes #588
*/
use std;
import std::task::join;
import std::task;
import std::task::join_id;
import std::comm;
fn child() { }
@ -16,8 +14,8 @@ fn main() {
let t1;
let t2;
t1 = spawn child();
t2 = spawn child();
t1 = task::_spawn(bind child());
t2 = task::_spawn(bind child());
assert (t1 == t1);
assert (t1 != t2);
@ -26,8 +24,8 @@ fn main() {
let p1;
let p2;
p1 = port[int]();
p2 = port[int]();
p1 = comm::mk_port[int]();
p2 = comm::mk_port[int]();
assert (p1 == p1);
assert (p1 != p2);
@ -36,12 +34,12 @@ fn main() {
let c1;
let c2;
c1 = chan(p1);
c2 = chan(p2);
c1 = p1.mk_chan();
c2 = p2.mk_chan();
assert (c1 == c1);
assert (c1 != c2);
join(t1);
join(t2);
join_id(t1);
join_id(t2);
}

View File

@ -20,13 +20,13 @@ fn supervisor() {
// Unsupervise this task so the process doesn't return a failure status as
// a result of the main task being killed.
task::unsupervise();
let t = spawn supervised();
task::join(t);
let t = task::_spawn(bind supervised());
task::join_id(t);
}
fn main() {
let dom2 = spawn supervisor();
task::join(dom2);
let dom2 = task::_spawn(bind supervisor());
task::join_id(dom2);
}
// Local Variables:

View File

@ -1,5 +1,7 @@
fn main() { spawn child("Hello"); }
use std;
import std::task;
fn main() { task::_spawn(bind child("Hello")); }
fn child(s: str) {
}
}

View File

@ -1,19 +1,18 @@
// xfail-stage1
// xfail-stage2
// xfail-stage3
// -*- rust -*-
use std;
import std::task;
fn main() {
let int i = 10;
let i = 10;
while (i > 0) {
spawn thread "child" child(i);
task::_spawn(bind child(i));
i = i - 1;
}
log "main thread exiting";
}
fn child(int x) {
fn child(x : int) {
log x;
}

View File

@ -1,15 +1,16 @@
// -*- rust -*-
use std;
import std::task;
import std::task::*;
fn main() {
let other = spawn child();
let other = task::_spawn(bind child());
log_err "1";
yield();
log_err "2";
yield();
log_err "3";
join(other);
join_id(other);
}
fn child() { log_err "4"; yield(); log_err "5"; yield(); log_err "6"; }

View File

@ -1,7 +1,12 @@
// -*- rust -*-
use std;
import std::task;
import std::task::*;
fn main() { let other = spawn child(); log_err "1"; yield(); join(other); }
fn main() {
let other = task::_spawn(bind child());
log_err "1"; yield();
join_id(other);
}
fn child() { log_err "2"; }
fn child() { log_err "2"; }