Skip to content

Commit eec181f

Browse files
committed
---
yaml --- r: 647 b: refs/heads/master c: a6aebda h: refs/heads/master i: 645: 8610f05 643: 7f574ec 639: d9e1cf5 v: v3
1 parent f38e9b2 commit eec181f

File tree

6 files changed

+187
-3
lines changed

6 files changed

+187
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5375b3916095970bc87675969b2fb00d9bebcfd8
2+
refs/heads/master: a6aebdaedd4abb95b040c9cd09cfdb6b9b940789

trunk/src/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ RUNTIME_CS := rt/sync/timer.cpp \
269269
rt/isaac/randport.cpp \
270270
rt/rust_srv.cpp \
271271
rt/rust_kernel.cpp \
272-
rt/memory_region.cpp
272+
rt/memory_region.cpp \
273+
rt/test/rust_test_harness.cpp \
274+
rt/test/rust_test_util.cpp
273275

274276
RUNTIME_HDR := rt/globals.h \
275277
rt/rust.h \
@@ -294,7 +296,9 @@ RUNTIME_HDR := rt/globals.h \
294296
rt/rust_srv.h \
295297
rt/rust_kernel.h \
296298
rt/memory_region.h \
297-
rt/memory.h
299+
rt/memory.h \
300+
rt/test/rust_test_harness.h \
301+
rt/test/rust_test_util.h
298302

299303
RUNTIME_INCS := -Irt/isaac -Irt/uthash
300304
RUNTIME_OBJS := $(RUNTIME_CS:.cpp=$(CFG_OBJ_SUFFIX))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "../rust_internal.h"
2+
3+
bool
4+
rust_test::run() {
5+
return false;
6+
}
7+
8+
const char *
9+
rust_test::name() {
10+
return "untitled";
11+
}
12+
13+
rust_test_suite::rust_test_suite() {
14+
tests.append(new rust_array_list_test());
15+
tests.append(new rust_synchronized_indexed_list_test());
16+
}
17+
18+
rust_test_suite::~rust_test_suite() {
19+
20+
}
21+
22+
bool
23+
rust_test_suite::run() {
24+
bool pass = true;
25+
for (size_t i = 0; i < tests.size(); i++) {
26+
rust_test *test = tests[i];
27+
printf("test: %s running ... \n", test->name());
28+
if (tests[i]->run() == false) {
29+
printf("test: %s FAILED\n", test->name());
30+
pass = false;
31+
} else {
32+
printf("test: %s PASSED\n", test->name());
33+
}
34+
}
35+
return pass;
36+
}
37+

trunk/src/rt/test/rust_test_harness.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef RUST_TEST_HARNESS_H
2+
#define RUST_TEST_HARNESS_H
3+
4+
#define CHECK(x) if ((x) == false) \
5+
{ printf("condition: %s failed at file: %s, line: %d\n", #x, \
6+
__FILE__, __LINE__ ); return false; }
7+
8+
class rust_test {
9+
public:
10+
virtual bool run();
11+
virtual const char *name();
12+
};
13+
14+
class rust_test_suite : public rust_test {
15+
public:
16+
array_list<rust_test*> tests;
17+
rust_test_suite();
18+
virtual ~rust_test_suite();
19+
bool run();
20+
};
21+
22+
#endif /* RUST_TEST_HARNESS_H */

trunk/src/rt/test/rust_test_util.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "../rust_internal.h"
2+
3+
#define COUNT 1000
4+
#define LARGE_COUNT 100000
5+
#define THREADS 10
6+
7+
bool
8+
rust_array_list_test::run() {
9+
array_list<int> list;
10+
11+
for (int i = 0; i < COUNT; i++) {
12+
list.append(i);
13+
}
14+
15+
for (int i = 0; i < COUNT; i++) {
16+
CHECK (list[i] == i);
17+
}
18+
19+
for (int i = 0; i < COUNT; i++) {
20+
CHECK (list.index_of(i) == i);
21+
}
22+
23+
for (int i = 0; i < COUNT; i++) {
24+
CHECK (list.replace(i, -i));
25+
CHECK (list.replace(-i, i));
26+
CHECK (list.index_of(i) == i);
27+
}
28+
29+
for (int i = COUNT - 1; i >= 0; i--) {
30+
CHECK (list.pop(NULL));
31+
}
32+
33+
return true;
34+
}
35+
36+
bool
37+
rust_synchronized_indexed_list_test::run() {
38+
array_list<worker*> workers;
39+
40+
for (int i = 0; i < THREADS; i++) {
41+
worker *worker =
42+
new rust_synchronized_indexed_list_test::worker(this);
43+
workers.append(worker);
44+
}
45+
46+
for (uint32_t i = 0; i < workers.size(); i++) {
47+
workers[i]->start();
48+
}
49+
50+
while(workers.is_empty() == false) {
51+
worker *worker;
52+
workers.pop(&worker);
53+
worker->join();
54+
delete worker;
55+
}
56+
57+
long long expected_items = LARGE_COUNT * THREADS;
58+
59+
CHECK(list.length() == expected_items);
60+
61+
long long sum = 0;
62+
for (size_t i = 0; i < list.length(); i++) {
63+
sum += list[i]->value;
64+
}
65+
66+
long long expected_sum = LARGE_COUNT;
67+
expected_sum = expected_sum * (expected_sum - 1) / 2 * THREADS;
68+
CHECK (sum == expected_sum);
69+
return true;
70+
}
71+
72+
void
73+
rust_synchronized_indexed_list_test::worker::run() {
74+
for (int i = 0; i < LARGE_COUNT; i++) {
75+
parent->list.append(new indexed_list_element<int>(i));
76+
}
77+
return;
78+
}

trunk/src/rt/test/rust_test_util.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef RUST_TEST_UTIL_H
2+
#define RUST_TEST_UTIL_H
3+
4+
class rust_test_util : public rust_test {
5+
public:
6+
7+
};
8+
9+
class rust_array_list_test : public rust_test {
10+
public:
11+
bool run();
12+
const char *name() {
13+
return "rust_array_list_test";
14+
}
15+
};
16+
17+
18+
class rust_synchronized_indexed_list_test : public rust_test {
19+
public:
20+
rust_srv srv;
21+
memory_region region;
22+
synchronized_indexed_list<indexed_list_element<int> > list;
23+
24+
rust_synchronized_indexed_list_test() :
25+
region(&srv, false), list(&region) {
26+
// Nop.
27+
}
28+
29+
class worker : public rust_thread {
30+
public:
31+
rust_synchronized_indexed_list_test *parent;
32+
worker(rust_synchronized_indexed_list_test *parent) : parent(parent) {
33+
// Nop.
34+
}
35+
void run();
36+
};
37+
bool run();
38+
const char *name() {
39+
return "rust_synchronized_indexed_list_test";
40+
}
41+
};
42+
43+
#endif /* RUST_TEST_UTIL_H */

0 commit comments

Comments
 (0)