about summary refs log tree commit diff
path: root/src/rt/test
diff options
context:
space:
mode:
authorMichael Bebenita <mbebenita@mozilla.com>2010-09-10 01:21:29 -0700
committerMichael Bebenita <mbebenita@mozilla.com>2010-09-10 14:38:31 -0700
commita493350eb5ab38ba8a6563f3eb4a090d257b0d3a (patch)
treedc984eaa28a55de9f05db0b961a0e67f80ca35ef /src/rt/test
parentf985fded3ede8a7677ca6c9c77817d27bc9ae492 (diff)
downloadrust-a493350eb5ab38ba8a6563f3eb4a090d257b0d3a.tar.gz
rust-a493350eb5ab38ba8a6563f3eb4a090d257b0d3a.zip
Cleanup, refactoring, and some runtime tests.
Diffstat (limited to 'src/rt/test')
-rw-r--r--src/rt/test/rust_test_harness.cpp13
-rw-r--r--src/rt/test/rust_test_harness.h3
-rw-r--r--src/rt/test/rust_test_runtime.cpp77
-rw-r--r--src/rt/test/rust_test_runtime.h51
-rw-r--r--src/rt/test/rust_test_util.cpp2
-rw-r--r--src/rt/test/rust_test_util.h4
6 files changed, 140 insertions, 10 deletions
diff --git a/src/rt/test/rust_test_harness.cpp b/src/rt/test/rust_test_harness.cpp
index c33e170ebe3..41000a6dbc6 100644
--- a/src/rt/test/rust_test_harness.cpp
+++ b/src/rt/test/rust_test_harness.cpp
@@ -10,7 +10,9 @@ rust_test::name() {
     return "untitled";
 }
 
-rust_test_suite::rust_test_suite() {
+rust_test_suite::rust_test_suite(rust_crate *crate) : crate(crate) {
+    tests.append(new rust_domain_test());
+    tests.append(new rust_task_test(this));
     tests.append(new rust_array_list_test());
     tests.append(new rust_synchronized_indexed_list_test());
 }
@@ -25,11 +27,12 @@ rust_test_suite::run() {
     for (size_t i = 0; i < tests.size(); i++) {
         rust_test *test = tests[i];
         printf("test: %s running ... \n", test->name());
-        if (tests[i]->run() == false) {
-            printf("test: %s FAILED\n", test->name());
+        timer timer;
+        bool result = tests[i]->run();
+        printf("test: %s %s %.2f ms\n", test->name(),
+               result ? "PASSED" : "FAILE", timer.get_elapsed_time_in_ms());
+        if (result == false) {
             pass = false;
-        } else {
-            printf("test: %s PASSED\n", test->name());
         }
     }
     return pass;
diff --git a/src/rt/test/rust_test_harness.h b/src/rt/test/rust_test_harness.h
index 401015e4508..8dd8baaadc2 100644
--- a/src/rt/test/rust_test_harness.h
+++ b/src/rt/test/rust_test_harness.h
@@ -13,8 +13,9 @@ public:
 
 class rust_test_suite : public rust_test {
 public:
+    rust_crate *crate;
     array_list<rust_test*> tests;
-    rust_test_suite();
+    rust_test_suite(rust_crate *crate);
     virtual ~rust_test_suite();
     bool run();
 };
diff --git a/src/rt/test/rust_test_runtime.cpp b/src/rt/test/rust_test_runtime.cpp
new file mode 100644
index 00000000000..b10be5edf40
--- /dev/null
+++ b/src/rt/test/rust_test_runtime.cpp
@@ -0,0 +1,77 @@
+#include "rust_test_runtime.h"
+
+rust_test_runtime::rust_test_runtime() {
+    // TODO Auto-generated constructor stub
+}
+
+rust_test_runtime::~rust_test_runtime() {
+    // TODO Auto-generated destructor stub
+}
+
+#define DOMAINS 32
+#define TASKS 32
+
+void
+rust_domain_test::worker::run() {
+    rust_handle<rust_dom> *handle = kernel->create_domain(NULL, "test");
+    for (int i = 0; i < TASKS; i++) {
+        handle->referent()->create_task(NULL, "child");
+    }
+    sync::random_sleep(1000);
+    kernel->destroy_domain(handle->_referent);
+}
+
+bool
+rust_domain_test::run() {
+    rust_srv srv;
+    rust_kernel kernel(&srv);
+
+    array_list<worker *> workers;
+    for (int i = 0; i < DOMAINS; i++) {
+        worker *worker = new rust_domain_test::worker (&kernel);
+        workers.append(worker);
+        worker->start();
+    }
+
+    // We don't join the worker threads here in order to simulate ad-hoc
+    // termination of domains. If we join_all_domains before all domains
+    // are actually spawned, this could crash, thus the reason for the
+    // sleep below.
+
+    sync::sleep(100);
+    kernel.join_all_domains();
+    return true;
+}
+
+void task_entry() {
+    printf("task entry\n");
+}
+
+void
+rust_task_test::worker::run() {
+    rust_crate *crate = parent->suite->crate;
+    rust_handle<rust_dom> *handle =
+        kernel->create_domain(crate, "test");
+    rust_dom *domain = handle->referent();
+    domain->root_task->start(crate->get_exit_task_glue(),
+                             (uintptr_t)&task_entry, NULL, 0);
+    domain->start_main_loop();
+    kernel->destroy_domain(domain);
+}
+
+bool
+rust_task_test::run() {
+    rust_srv srv;
+    rust_kernel kernel(&srv);
+
+    array_list<worker *> workers;
+    for (int i = 0; i < DOMAINS; i++) {
+        worker *worker = new rust_task_test::worker (&kernel, this);
+        workers.append(worker);
+        worker->start();
+    }
+
+    sync::random_sleep(1000);
+    kernel.join_all_domains();
+    return true;
+}
diff --git a/src/rt/test/rust_test_runtime.h b/src/rt/test/rust_test_runtime.h
new file mode 100644
index 00000000000..8d4f38ecb79
--- /dev/null
+++ b/src/rt/test/rust_test_runtime.h
@@ -0,0 +1,51 @@
+#include "../rust_internal.h"
+
+#ifndef RUST_TEST_RUNTIME_H
+#define RUST_TEST_RUNTIME_H
+
+class rust_test_runtime {
+public:
+    rust_test_runtime();
+    virtual ~rust_test_runtime();
+};
+
+
+class rust_domain_test : public rust_test {
+public:
+    class worker : public rust_thread {
+        public:
+        rust_kernel *kernel;
+        worker(rust_kernel *kernel) : kernel(kernel) {
+            // Nop.
+        }
+        void run();
+    };
+    bool run();
+    const char *name() {
+        return "rust_domain_test";
+    }
+};
+
+class rust_task_test : public rust_test {
+public:
+    rust_test_suite *suite;
+    rust_task_test(rust_test_suite *suite) : suite(suite) {
+        // Nop.
+    }
+    class worker : public rust_thread {
+        public:
+        rust_kernel *kernel;
+        rust_task_test *parent;
+        worker(rust_kernel *kernel, rust_task_test *parent) :
+            kernel(kernel), parent(parent) {
+            // Nop.
+        }
+        void run();
+    };
+    bool run();
+    const char *name() {
+        return "rust_task_test";
+    }
+};
+
+#endif /* RUST_TEST_RUNTIME_H */
diff --git a/src/rt/test/rust_test_util.cpp b/src/rt/test/rust_test_util.cpp
index 76bd7990600..2e9d764f69b 100644
--- a/src/rt/test/rust_test_util.cpp
+++ b/src/rt/test/rust_test_util.cpp
@@ -1,7 +1,7 @@
 #include "../rust_internal.h"
 
 #define COUNT 1000
-#define LARGE_COUNT 100000
+#define LARGE_COUNT 10000
 #define THREADS 10
 
 bool
diff --git a/src/rt/test/rust_test_util.h b/src/rt/test/rust_test_util.h
index fb8490cb074..41c3579043a 100644
--- a/src/rt/test/rust_test_util.h
+++ b/src/rt/test/rust_test_util.h
@@ -18,11 +18,9 @@ public:
 class rust_synchronized_indexed_list_test : public rust_test {
 public:
     rust_srv srv;
-    memory_region region;
     synchronized_indexed_list<indexed_list_element<int> > list;
 
-    rust_synchronized_indexed_list_test() :
-        region(&srv, false), list(&region) {
+    rust_synchronized_indexed_list_test() {
         // Nop.
     }