about summary refs log tree commit diff
path: root/src/rt/test/rust_test_runtime.cpp
blob: cf82818c4ff0a9741db0b9f88b034093214cdbb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "rust_test_runtime.h"

rust_test_runtime::rust_test_runtime() {
}

rust_test_runtime::~rust_test_runtime() {
}

#define DOMAINS 32
#define TASKS 32

void
rust_domain_test::worker::run() {
    rust_handle<rust_dom> *handle = kernel->create_domain("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_handle<rust_dom> *handle =
        kernel->create_domain("test");
    rust_dom *domain = handle->referent();
    domain->root_task->start((uintptr_t)&task_entry, (uintptr_t)NULL);
    domain->start_main_loop(0);
    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;
}