From f6f8a06d6bf010b8d30c23786976792cccfbd6de Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 28 Jun 2011 12:54:41 -0700 Subject: Resurrecting the runtime unit tests, and modifying them so they compile under the latest refactoring changes. --- src/rt/test/rust_test_util.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/rt/test/rust_test_util.cpp (limited to 'src/rt/test/rust_test_util.cpp') diff --git a/src/rt/test/rust_test_util.cpp b/src/rt/test/rust_test_util.cpp new file mode 100644 index 00000000000..2e9d764f69b --- /dev/null +++ b/src/rt/test/rust_test_util.cpp @@ -0,0 +1,78 @@ +#include "../rust_internal.h" + +#define COUNT 1000 +#define LARGE_COUNT 10000 +#define THREADS 10 + +bool +rust_array_list_test::run() { + array_list list; + + for (int i = 0; i < COUNT; i++) { + list.append(i); + } + + for (int i = 0; i < COUNT; i++) { + CHECK (list[i] == i); + } + + for (int i = 0; i < COUNT; i++) { + CHECK (list.index_of(i) == i); + } + + for (int i = 0; i < COUNT; i++) { + CHECK (list.replace(i, -i)); + CHECK (list.replace(-i, i)); + CHECK (list.index_of(i) == i); + } + + for (int i = COUNT - 1; i >= 0; i--) { + CHECK (list.pop(NULL)); + } + + return true; +} + +bool +rust_synchronized_indexed_list_test::run() { + array_list workers; + + for (int i = 0; i < THREADS; i++) { + worker *worker = + new rust_synchronized_indexed_list_test::worker(this); + workers.append(worker); + } + + for (uint32_t i = 0; i < workers.size(); i++) { + workers[i]->start(); + } + + while(workers.is_empty() == false) { + worker *worker; + workers.pop(&worker); + worker->join(); + delete worker; + } + + long long expected_items = LARGE_COUNT * THREADS; + + CHECK(list.length() == expected_items); + + long long sum = 0; + for (size_t i = 0; i < list.length(); i++) { + sum += list[i]->value; + } + + long long expected_sum = LARGE_COUNT; + expected_sum = expected_sum * (expected_sum - 1) / 2 * THREADS; + CHECK (sum == expected_sum); + return true; +} + +void +rust_synchronized_indexed_list_test::worker::run() { + for (int i = 0; i < LARGE_COUNT; i++) { + parent->list.append(new indexed_list_element(i)); + } + return; +} -- cgit 1.4.1-3-g733a5