]> git.lizzy.rs Git - rust.git/blob - src/rt/test/rust_test_runtime.cpp
7bfa06fdc99477c79e6473fac1c96ada45a740f9
[rust.git] / src / rt / test / rust_test_runtime.cpp
1 #include "rust_test_runtime.h"
2
3 rust_test_runtime::rust_test_runtime() {
4 }
5
6 rust_test_runtime::~rust_test_runtime() {
7 }
8
9 #define DOMAINS 32
10 #define TASKS 32
11
12 void
13 rust_domain_test::worker::run() {
14     for (int i = 0; i < TASKS; i++) {
15         kernel->create_task(NULL, "child");
16     }
17     //sync::sleep(rand(&handle->rctx) % 1000);
18 }
19
20 bool
21 rust_domain_test::run() {
22     rust_env env;
23     rust_srv srv(&env);
24     rust_kernel kernel(&srv, 1);
25
26     array_list<worker *> workers;
27     for (int i = 0; i < DOMAINS; i++) {
28         worker *worker = new rust_domain_test::worker (&kernel);
29         workers.append(worker);
30         worker->start();
31     }
32
33     // We don't join the worker threads here in order to simulate ad-hoc
34     // termination of domains. If we join_all_domains before all domains
35     // are actually spawned, this could crash, thus the reason for the
36     // sleep below.
37
38     sync::sleep(100);
39     return true;
40 }
41
42 void task_entry(void *, rust_boxed_closure *, void *) {
43     printf("task entry\n");
44 }
45
46 void
47 rust_task_test::worker::run() {
48     rust_task_id root_id = kernel->create_task(NULL, "main");
49     rust_task *root_task = kernel->get_task_by_id(root_id);
50     root_task->start(&task_entry, NULL, NULL);
51     root_task->sched->start_main_loop();
52 }
53
54 bool
55 rust_task_test::run() {
56     rust_env env;
57     rust_srv srv(&env);
58     rust_kernel kernel(&srv, 1);
59
60     array_list<worker *> workers;
61     for (int i = 0; i < DOMAINS; i++) {
62         worker *worker = new rust_task_test::worker (&kernel, this);
63         workers.append(worker);
64         worker->start();
65     }
66
67     //sync::sleep(rand(&kernel.sched->rctx) % 1000);
68     return true;
69 }