From d647c163fd936c853d76f59ab2c656d554068ab3 Mon Sep 17 00:00:00 2001 From: Michael Bebenita Date: Mon, 9 Aug 2010 06:53:37 -0700 Subject: [PATCH] Updated/added test cases. --- src/test/run-pass/arith-0.rs | 5 +++++ src/test/run-pass/arith-1.rs | 22 ++++++++++++++++++++++ src/test/run-pass/arith-2.rs | 5 +++++ src/test/run-pass/basic-1.rs | 25 +++++++++++++++++++++++++ src/test/run-pass/basic-2.rs | 26 ++++++++++++++++++++++++++ src/test/run-pass/task-comm-0.rs | 2 +- src/test/run-pass/task-comm-2.rs | 8 ++++---- src/test/run-pass/task-comm-3.rs | 19 +++++++++++-------- src/test/run-pass/task-comm-6.rs | 6 ++++-- src/test/run-pass/task-comm.rs | 18 +++++++++--------- 10 files changed, 112 insertions(+), 24 deletions(-) create mode 100644 src/test/run-pass/arith-0.rs create mode 100644 src/test/run-pass/arith-1.rs create mode 100644 src/test/run-pass/arith-2.rs create mode 100644 src/test/run-pass/basic-1.rs create mode 100644 src/test/run-pass/basic-2.rs diff --git a/src/test/run-pass/arith-0.rs b/src/test/run-pass/arith-0.rs new file mode 100644 index 00000000000..7587b0050ad --- /dev/null +++ b/src/test/run-pass/arith-0.rs @@ -0,0 +1,5 @@ +fn main() -> () { + let int a = 10; + log a; + check (a * (a - 1) == 90); +} \ No newline at end of file diff --git a/src/test/run-pass/arith-1.rs b/src/test/run-pass/arith-1.rs new file mode 100644 index 00000000000..bac6a055e80 --- /dev/null +++ b/src/test/run-pass/arith-1.rs @@ -0,0 +1,22 @@ +fn main() -> () { + let int i32_a = 10; + check(i32_a == 10); + check(i32_a - 10 == 0); + check(i32_a / 10 == 1); + check(i32_a - 20 == -10); + check(i32_a << 10 == 10240); + check(i32_a << 16 == 655360); + check(i32_a * 16 == 160); + check(i32_a * i32_a * i32_a == 1000); + check(i32_a * i32_a * i32_a * i32_a == 10000); + check(((i32_a * i32_a) / i32_a) * i32_a == 100); + check(i32_a * (i32_a - 1) << 2 + i32_a == 368640); + + let int i32_b = 0x10101010; + check(i32_b + 1 - 1 == i32_b); + check(i32_b << 1 == i32_b << 1); + check(i32_b >> 1 == i32_b >> 1); + check((i32_b & (i32_b << 1)) == 0); + log ((i32_b | (i32_b << 1))); + check((i32_b | (i32_b << 1)) == 0x30303030); +} \ No newline at end of file diff --git a/src/test/run-pass/arith-2.rs b/src/test/run-pass/arith-2.rs new file mode 100644 index 00000000000..33a740c84fc --- /dev/null +++ b/src/test/run-pass/arith-2.rs @@ -0,0 +1,5 @@ +fn main() -> () { + let int i32_c = 0x10101010; + check (i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3) == + i32_c + (((i32_c * 2) / 3) * 2) + (i32_c - (7 % 3))); +} \ No newline at end of file diff --git a/src/test/run-pass/basic-1.rs b/src/test/run-pass/basic-1.rs new file mode 100644 index 00000000000..bdd7ee25641 --- /dev/null +++ b/src/test/run-pass/basic-1.rs @@ -0,0 +1,25 @@ +// -*- rust -*- + +io fn a(chan[int] c) { + c <| 10; +} + +io fn main() { + let port[int] p = port(); + spawn a(chan(p)); + spawn b(chan(p)); + let int n = 0; + n <- p; + n <- p; +// log "Finished."; +} + +io fn b(chan[int] c) { +// log "task b0"; +// log "task b1"; +// log "task b2"; +// log "task b3"; +// log "task b4"; +// log "task b5"; + c <| 10; +} \ No newline at end of file diff --git a/src/test/run-pass/basic-2.rs b/src/test/run-pass/basic-2.rs new file mode 100644 index 00000000000..975a0d4b896 --- /dev/null +++ b/src/test/run-pass/basic-2.rs @@ -0,0 +1,26 @@ +// -*- rust -*- + +io fn a(chan[int] c) { + log "task a0"; + log "task a1"; + c <| 10; +} + +io fn main() { + let port[int] p = port(); + spawn a(chan(p)); + spawn b(chan(p)); + let int n = 0; + n <- p; + n <- p; + log "Finished."; +} + +io fn b(chan[int] c) { + log "task b0"; + log "task b1"; + log "task b2"; + log "task b2"; + log "task b3"; + c <| 10; +} diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index 5992ba5cf6f..28294422b5c 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -15,5 +15,5 @@ io fn test05() { let int value <- po; value <- po; value <- po; - log value; + check(value == 30); } diff --git a/src/test/run-pass/task-comm-2.rs b/src/test/run-pass/task-comm-2.rs index 9c85da34cc2..864d49de1e0 100644 --- a/src/test/run-pass/task-comm-2.rs +++ b/src/test/run-pass/task-comm-2.rs @@ -1,8 +1,8 @@ fn main() -> () { - log "===== THREADS ====="; + log "===== SPAWNING and JOINING TASKS ====="; + test00(false); + log "===== SPAWNING and JOINING THREAD TASKS ====="; 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 = 0; + let int number_of_tasks = 8; let int i = 0; let vec[task] tasks = vec(); diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index 6dd620cc762..9a3f9e16919 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -1,6 +1,8 @@ io fn main() -> () { - log "===== THREADS ====="; + log "===== WITHOUT THREADS ====="; test00(false); + log "====== WITH THREADS ======"; + test00(true); } io fn test00_start(chan[int] ch, int message, int count) { @@ -15,8 +17,9 @@ io fn test00_start(chan[int] ch, int message, int count) { } io fn test00(bool is_multithreaded) { - let int number_of_tasks = 1; - let int number_of_messages = 0; + let int number_of_tasks = 16; + let int number_of_messages = 4; + log "Creating tasks"; let port[int] po = port(); @@ -27,13 +30,13 @@ io fn test00(bool is_multithreaded) { // Create and spawn tasks... let vec[task] tasks = vec(); while (i < number_of_tasks) { - i = i + 1; if (is_multithreaded) { tasks += vec( spawn thread test00_start(ch, i, number_of_messages)); } else { tasks += vec(spawn test00_start(ch, i, number_of_messages)); } + i = i + 1; } // Read from spawned tasks... @@ -53,7 +56,7 @@ io fn test00(bool is_multithreaded) { } log "Completed: Final number is: "; - check (sum + 1 == number_of_messages * - (number_of_tasks * number_of_tasks + number_of_tasks) / 2); - log sum; -} \ No newline at end of file + // check (sum == (((number_of_tasks * (number_of_tasks - 1)) / 2) * + // number_of_messages)); + check (sum == 480); +} diff --git a/src/test/run-pass/task-comm-6.rs b/src/test/run-pass/task-comm-6.rs index c579a98ca0a..2774c0ba545 100644 --- a/src/test/run-pass/task-comm-6.rs +++ b/src/test/run-pass/task-comm-6.rs @@ -31,6 +31,8 @@ io fn test00() { r <- p; sum += r; i += 1; } - - check (sum == 4 * ((number_of_messages * (number_of_messages - 1)) / 2)); + + check (sum == 1998000); + // check (sum == 4 * ((number_of_messages * + // (number_of_messages - 1)) / 2)); } \ No newline at end of file diff --git a/src/test/run-pass/task-comm.rs b/src/test/run-pass/task-comm.rs index ef71c6e1bcf..3c5d321689f 100644 --- a/src/test/run-pass/task-comm.rs +++ b/src/test/run-pass/task-comm.rs @@ -1,11 +1,11 @@ -fn main() -> () { - // test00(true); +io fn main() -> () { + test00(true); // test01(); - // test02(); - // test03(); - // test04(); - // test05(); + test02(); + test03(); + test04(); + test05(); test06(); } @@ -22,7 +22,7 @@ io fn test00_start(chan[int] ch, int message, int count) { io fn test00(bool is_multithreaded) { let int number_of_tasks = 1; - let int number_of_messages = 64; + let int number_of_messages = 4; log "Creating tasks"; let port[int] po = port(); @@ -103,7 +103,7 @@ fn test04_start() { fn test04() { log "Spawning lots of tasks."; - let int i = 64; + let int i = 4; while (i > 0) { i = i - 1; spawn thread test04_start(); @@ -139,7 +139,7 @@ fn test06_start(int task_number) { } fn test06() { - let int number_of_tasks = 32; + let int number_of_tasks = 4; log "Creating tasks"; let int i = 0;