From 6c6c9acd96e567d46331a2491a90831c0510d72d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 7 Jan 2011 23:14:16 -0500 Subject: Rename test to reflect that the circular_buffer runtime class is what's being tested --- src/test/run-pass/chan-poweroftwo.rs | 104 -------------------------------- src/test/run-pass/rt-circular-buffer.rs | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 104 deletions(-) delete mode 100644 src/test/run-pass/chan-poweroftwo.rs create mode 100644 src/test/run-pass/rt-circular-buffer.rs (limited to 'src') diff --git a/src/test/run-pass/chan-poweroftwo.rs b/src/test/run-pass/chan-poweroftwo.rs deleted file mode 100644 index 044d8238..00000000 --- a/src/test/run-pass/chan-poweroftwo.rs +++ /dev/null @@ -1,104 +0,0 @@ -// -*- rust -*- - -// Regression tests for circular_buffer when using a unit -// that has a size that is not a power of two - -use std; - -import std.option; -import std._uint; -import std._vec; - -// A 12-byte unit to send over the channel -type record = rec(u32 val1, u32 val2, u32 val3); - -// Assuming that the default buffer size needs to hold 8 units, -// then the minimum buffer size needs to be 96. That's not a -// power of two so needs to be rounded up. Don't trigger any -// assertions. -impure fn test_init() { - let port[record] myport = port(); - auto mychan = chan(myport); - - let record val = rec(val1=0u32, val2=0u32, val3=0u32); - - mychan <| val; -} - -// Dump lots of items into the channel so it has to grow. -// Don't trigger any assertions. -impure fn test_grow() { - let port[record] myport = port(); - auto mychan = chan(myport); - - let record val = rec(val1=0u32, val2=0u32, val3=0u32); - - for each (uint i in _uint.range(0u, 100u)) { - mychan <| val; - } -} - -// Don't allow the buffer to shrink below it's original size -impure fn test_shrink1() { - let port[i8] myport = port(); - auto mychan = chan(myport); - - mychan <| 0i8; - auto x <- myport; -} - -impure fn test_shrink2() { - let port[record] myport = port(); - auto mychan = chan(myport); - - let record val = rec(val1=0u32, val2=0u32, val3=0u32); - - for each (uint i in _uint.range(0u, 100u)) { - mychan <| val; - } - - for each (uint i in _uint.range(0u, 100u)) { - auto x <- myport; - } -} - -// Test rotating the buffer when the unit size is not a power of two -impure fn test_rotate() { - let port[record] myport = port(); - auto mychan = chan(myport); - - let record val = rec(val1=0u32, val2=0u32, val3=0u32); - - for each (uint j in _uint.range(0u, 10u)) { - for each (uint i in _uint.range(0u, 10u)) { - let record val = rec(val1=i as u32, - val2=i as u32, - val3=i as u32); - mychan <| val; - } - - for each (uint i in _uint.range(0u, 10u)) { - auto x <- myport; - check (x.val1 == i as u32); - check (x.val2 == i as u32); - check (x.val3 == i as u32); - } - } -} - -impure fn main() { - test_init(); - test_grow(); - test_shrink1(); - test_shrink2(); - test_rotate(); -} - -// Local Variables: -// mode: rust; -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; -// End: diff --git a/src/test/run-pass/rt-circular-buffer.rs b/src/test/run-pass/rt-circular-buffer.rs new file mode 100644 index 00000000..044d8238 --- /dev/null +++ b/src/test/run-pass/rt-circular-buffer.rs @@ -0,0 +1,104 @@ +// -*- rust -*- + +// Regression tests for circular_buffer when using a unit +// that has a size that is not a power of two + +use std; + +import std.option; +import std._uint; +import std._vec; + +// A 12-byte unit to send over the channel +type record = rec(u32 val1, u32 val2, u32 val3); + +// Assuming that the default buffer size needs to hold 8 units, +// then the minimum buffer size needs to be 96. That's not a +// power of two so needs to be rounded up. Don't trigger any +// assertions. +impure fn test_init() { + let port[record] myport = port(); + auto mychan = chan(myport); + + let record val = rec(val1=0u32, val2=0u32, val3=0u32); + + mychan <| val; +} + +// Dump lots of items into the channel so it has to grow. +// Don't trigger any assertions. +impure fn test_grow() { + let port[record] myport = port(); + auto mychan = chan(myport); + + let record val = rec(val1=0u32, val2=0u32, val3=0u32); + + for each (uint i in _uint.range(0u, 100u)) { + mychan <| val; + } +} + +// Don't allow the buffer to shrink below it's original size +impure fn test_shrink1() { + let port[i8] myport = port(); + auto mychan = chan(myport); + + mychan <| 0i8; + auto x <- myport; +} + +impure fn test_shrink2() { + let port[record] myport = port(); + auto mychan = chan(myport); + + let record val = rec(val1=0u32, val2=0u32, val3=0u32); + + for each (uint i in _uint.range(0u, 100u)) { + mychan <| val; + } + + for each (uint i in _uint.range(0u, 100u)) { + auto x <- myport; + } +} + +// Test rotating the buffer when the unit size is not a power of two +impure fn test_rotate() { + let port[record] myport = port(); + auto mychan = chan(myport); + + let record val = rec(val1=0u32, val2=0u32, val3=0u32); + + for each (uint j in _uint.range(0u, 10u)) { + for each (uint i in _uint.range(0u, 10u)) { + let record val = rec(val1=i as u32, + val2=i as u32, + val3=i as u32); + mychan <| val; + } + + for each (uint i in _uint.range(0u, 10u)) { + auto x <- myport; + check (x.val1 == i as u32); + check (x.val2 == i as u32); + check (x.val3 == i as u32); + } + } +} + +impure fn main() { + test_init(); + test_grow(); + test_shrink1(); + test_shrink2(); + test_rotate(); +} + +// Local Variables: +// mode: rust; +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: -- cgit v1.2.3