aboutsummaryrefslogtreecommitdiff
path: root/tests/threads
diff options
context:
space:
mode:
Diffstat (limited to 'tests/threads')
-rw-r--r--tests/threads/accept/actor_identity.zc10
-rw-r--r--tests/threads/accept/cancel.zc8
-rw-r--r--tests/threads/accept/cancel_o3.zc9
-rw-r--r--tests/threads/accept/channels.zc9
-rw-r--r--tests/threads/accept/close_order.zc10
-rw-r--r--tests/threads/accept/failed_worker.zc9
-rw-r--r--tests/threads/accept/isolation.zc17
-rw-r--r--tests/threads/accept/nested.zc15
-rw-r--r--tests/threads/accept/parallel.zc11
-rw-r--r--tests/threads/regression/ffi_o3.zc16
-rw-r--r--tests/threads/regression/recycle.zc11
-rw-r--r--tests/threads/regression/resources.zc15
-rw-r--r--tests/threads/regression/resources_counts.zc13
-rw-r--r--tests/threads/reject/invalid.zc3
14 files changed, 156 insertions, 0 deletions
diff --git a/tests/threads/accept/actor_identity.zc b/tests/threads/accept/actor_identity.zc
new file mode 100644
index 0000000..cf2d4bf
--- /dev/null
+++ b/tests/threads/accept/actor_identity.zc
@@ -0,0 +1,10 @@
+namespace;
+include rt, actor;
+typecheck on;
+fn main() {
+ let process = rt.syscall(53, 0, 0, 0), thread = rt.syscall(54, 0, 0, 0), result = 0;
+ actor.Actor<int,int>* a = rt.new(actor.Actor<int,int>);
+ a.spawn(fn(int n) { return rt.syscall(53, 0, 0, 0) == process && rt.syscall(54, 0, 0, 0) != thread; });
+ a.recv(fn(int n) { result = n; return 0; }); a.send(1); a.await();
+ rt.put_n(result); rt.put_c(10); a.close(); return 0;
+}
diff --git a/tests/threads/accept/cancel.zc b/tests/threads/accept/cancel.zc
new file mode 100644
index 0000000..db4f7c7
--- /dev/null
+++ b/tests/threads/accept/cancel.zc
@@ -0,0 +1,8 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int fd = 0;
+ let context = rt.syscall(51, fn() { while (1) {} return 0; } as word, &fd, 0);
+ rt.syscall(48, 20, 0, 0); let started = rt.syscall(50, 0, 0, 0);
+ rt.put_n(rt.syscall(52, context, 1, 0)); rt.put_c(10); rt.put_n(rt.syscall(50, 0, 0, 0) - started); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/cancel_o3.zc b/tests/threads/accept/cancel_o3.zc
new file mode 100644
index 0000000..e196a13
--- /dev/null
+++ b/tests/threads/accept/cancel_o3.zc
@@ -0,0 +1,9 @@
+namespace;
+include rt;
+o3 int spin() { int n = 0; while (1) n++; return n; }
+unchecked fn main() {
+ int fd = 0;
+ let context = rt.syscall(51, fn() { return spin(); } as word, &fd, 0);
+ rt.syscall(48, 20, 0, 0); let started = rt.syscall(50, 0, 0, 0);
+ rt.put_n(rt.syscall(52, context, 1, 0)); rt.put_c(10); rt.put_n(rt.syscall(50, 0, 0, 0) - started); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/channels.zc b/tests/threads/accept/channels.zc
new file mode 100644
index 0000000..e1e966f
--- /dev/null
+++ b/tests/threads/accept/channels.zc
@@ -0,0 +1,9 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int first_fd = 0, second_fd = 0;
+ let first = rt.syscall(51, fn() { int value; rt.syscall(45, first_fd, &value, 1); return 0; } as word, &first_fd, 0);
+ let second = rt.syscall(51, fn() { int value = 9; int result = rt.syscall(44, first_fd, &value, 1); rt.syscall(44, second_fd, &result, 1); return 0; } as word, &second_fd, 0);
+ int result; rt.syscall(45, second_fd, &result, 1); rt.syscall(52, second, 0, 0);
+ rt.put_n(result); rt.put_c(' '); rt.put_n(rt.syscall(52, first, 1, 0)); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/close_order.zc b/tests/threads/accept/close_order.zc
new file mode 100644
index 0000000..5c0949f
--- /dev/null
+++ b/tests/threads/accept/close_order.zc
@@ -0,0 +1,10 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int fd = 0;
+ let first = rt.syscall(51, fn() { rt.syscall(2, fd, 0, 0); return 0; } as word, &fd, 0);
+ rt.put_n(rt.syscall(52, first, 0, 0)); rt.put_c(' ');
+ let second = rt.syscall(51, fn() { int value; rt.syscall(45, fd, &value, 1); return 0; } as word, &fd, 0);
+ rt.syscall(2, fd, 0, 0); rt.put_n(rt.syscall(52, second, 1, 0)); rt.put_c(' ');
+ rt.put_n(rt.syscall(52, second, 1, 0)); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/failed_worker.zc b/tests/threads/accept/failed_worker.zc
new file mode 100644
index 0000000..b214cac
--- /dev/null
+++ b/tests/threads/accept/failed_worker.zc
@@ -0,0 +1,9 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int fd = 0;
+ let first = rt.syscall(51, fn() { rt.syscall(7, 5, 0, 0); return 0; } as word, &fd, 0);
+ rt.put_n(rt.syscall(52, first, 0, 0)); rt.put_c(' ');
+ let second = rt.syscall(51, fn() { int value = 7; rt.syscall(44, fd, &value, 1); return 0; } as word, &fd, 0);
+ int result; rt.syscall(45, fd, &result, 1); rt.syscall(52, second, 0, 0); rt.put_n(result); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/isolation.zc b/tests/threads/accept/isolation.zc
new file mode 100644
index 0000000..cb1a5e7
--- /dev/null
+++ b/tests/threads/accept/isolation.zc
@@ -0,0 +1,17 @@
+namespace;
+include rt;
+int global_state = 16;
+unchecked fn main() {
+ int fd = 0, state = 7; word heap = rt.new(1); heap[0] = 4;
+ let parent_process = rt.syscall(53, 0, 0, 0), parent_thread = rt.syscall(54, 0, 0, 0);
+ let callback = fn() {
+ global_state += 5; state += 9; heap[0] += 3;
+ int reply[5]; reply[0] = global_state; reply[1] = state; reply[2] = heap[0]; reply[3] = rt.syscall(53, 0, 0, 0); reply[4] = rt.syscall(54, 0, 0, 0);
+ rt.syscall(44, fd, reply, 5); return 0;
+ };
+ let context = rt.syscall(51, callback as word, &fd, 0);
+ int result[5]; rt.syscall(45, fd, result, 5); rt.syscall(52, context, 0, 0);
+ rt.put_n(result[0]); rt.put_c(' '); rt.put_n(result[1]); rt.put_c(' '); rt.put_n(result[2]); rt.put_c(' ');
+ rt.put_n(global_state); rt.put_c(' '); rt.put_n(state); rt.put_c(' '); rt.put_n(heap[0]); rt.put_c(' ');
+ rt.put_n(result[3] == parent_process); rt.put_c(' '); rt.put_n(result[4] != parent_thread); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/nested.zc b/tests/threads/accept/nested.zc
new file mode 100644
index 0000000..e231aad
--- /dev/null
+++ b/tests/threads/accept/nested.zc
@@ -0,0 +1,15 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int fd = 0;
+ let worker = rt.syscall(51, fn() {
+ int child_fd = 0;
+ let run_child = fn() { while (1) {} return 0; };
+ let child = rt.syscall(51, run_child as word, &child_fd, 0);
+ int reply = child > 0; rt.syscall(44, fd, &reply, 1);
+ while (1) {} return 0;
+ } as word, &fd, 0);
+ int result; rt.syscall(45, fd, &result, 1); rt.syscall(52, worker, 1, 0);
+ rt.put_n(result); rt.put_c(' '); rt.put_n(rt.syscall(55, 0, 0, 0)); rt.put_c(' ');
+ rt.put_n(rt.syscall(55, 1, 0, 0)); rt.put_c(' '); rt.put_n(rt.syscall(55, 2, 0, 0)); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/accept/parallel.zc b/tests/threads/accept/parallel.zc
new file mode 100644
index 0000000..567f829
--- /dev/null
+++ b/tests/threads/accept/parallel.zc
@@ -0,0 +1,11 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int left_fd = 0, right_fd = 0;
+ let started = rt.syscall(50, 0, 0, 0);
+ let left = rt.syscall(51, fn() { int value = 11; rt.syscall(48, 300, 0, 0); rt.syscall(44, left_fd, &value, 1); return 0; } as word, &left_fd, 0);
+ let right = rt.syscall(51, fn() { int value = 21; rt.syscall(48, 300, 0, 0); rt.syscall(44, right_fd, &value, 1); return 0; } as word, &right_fd, 0);
+ int a, b; rt.syscall(45, left_fd, &a, 1); rt.syscall(45, right_fd, &b, 1);
+ rt.put_n(a); rt.put_c(' '); rt.put_n(b); rt.put_c(10); rt.put_n(rt.syscall(50, 0, 0, 0) - started); rt.put_c(10);
+ rt.syscall(52, left, 0, 0); rt.syscall(52, right, 0, 0); return 0;
+}
diff --git a/tests/threads/regression/ffi_o3.zc b/tests/threads/regression/ffi_o3.zc
new file mode 100644
index 0000000..ecf8c0c
--- /dev/null
+++ b/tests/threads/regression/ffi_o3.zc
@@ -0,0 +1,16 @@
+namespace;
+include rt;
+extern void qsort(word* base, long length, long size, void* compare);
+int calls;
+int compare(int* a, int* b) { calls++; return *a - *b; }
+o3 int sum(int n) { int total = 0; for (int i = 0; i <= n; i++) total += i; return total; }
+unchecked fn main() {
+ word comparator = cfunc(compare); int fd = 0;
+ let context = rt.syscall(51, fn() {
+ int values[3]; values[0] = 3; values[1] = 1; values[2] = 2; qsort(values, 3, 8, comparator);
+ int result[3]; result[0] = values[0] == 1 && values[2] == 3 && calls > 0; result[1] = sum(100); result[2] = calls;
+ rt.syscall(44, fd, result, 3); return 0;
+ } as word, &fd, 0);
+ int result[3]; rt.syscall(45, fd, result, 3); rt.syscall(52, context, 0, 0);
+ rt.put_n(result[0]); rt.put_c(' '); rt.put_n(result[1]); rt.put_c(' '); rt.put_n(calls); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/regression/recycle.zc b/tests/threads/regression/recycle.zc
new file mode 100644
index 0000000..4f0454a
--- /dev/null
+++ b/tests/threads/regression/recycle.zc
@@ -0,0 +1,11 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int i = 0, total = 0;
+ while (i < 12) {
+ int fd = 0;
+ let context = rt.syscall(51, fn() { int value = i; rt.syscall(44, fd, &value, 1); return 0; } as word, &fd, 0);
+ int result = 0; rt.syscall(45, fd, &result, 1); total += result; rt.syscall(52, context, 0, 0); i++;
+ }
+ rt.put_n(total); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/regression/resources.zc b/tests/threads/regression/resources.zc
new file mode 100644
index 0000000..abc0229
--- /dev/null
+++ b/tests/threads/regression/resources.zc
@@ -0,0 +1,15 @@
+namespace;
+include rt;
+extern int fcntl(int fd, int command);
+int descriptors() { int count = 0; for (int fd = 0; fd < 256; fd++) if (fcntl(fd, 1) >= 0) count++; return count; }
+unchecked fn main() {
+ int before = descriptors(), i = 0, closed = 0;
+ while (i < 24) {
+ int fd = 0;
+ let context = rt.syscall(51, fn() { int value = 1; rt.syscall(44, fd, &value, 1); return 0; } as word, &fd, 0);
+ int result; rt.syscall(45, fd, &result, 1); rt.syscall(52, context, 0, 0);
+ closed += rt.syscall(44, fd, &result, 1) == -1; i++;
+ }
+ rt.put_n(descriptors() == before); rt.put_c(' '); rt.put_n(closed); rt.put_c(' ');
+ rt.put_n(rt.syscall(55, 0, 0, 0)); rt.put_c(' '); rt.put_n(rt.syscall(55, 1, 0, 0)); rt.put_c(' '); rt.put_n(rt.syscall(55, 2, 0, 0)); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/regression/resources_counts.zc b/tests/threads/regression/resources_counts.zc
new file mode 100644
index 0000000..66cfc91
--- /dev/null
+++ b/tests/threads/regression/resources_counts.zc
@@ -0,0 +1,13 @@
+namespace;
+include rt;
+unchecked fn main() {
+ int closed = 0;
+ for (int i = 0; i < 24; i++) {
+ int fd = 0;
+ let context = rt.syscall(51, fn() { int value = 1; rt.syscall(44, fd, &value, 1); return 0; } as word, &fd, 0);
+ int result; rt.syscall(45, fd, &result, 1); rt.syscall(52, context, 0, 0);
+ closed += rt.syscall(44, fd, &result, 1) == -1;
+ }
+ rt.put_n(closed); rt.put_c(' '); rt.put_n(rt.syscall(55, 0, 0, 0)); rt.put_c(' ');
+ rt.put_n(rt.syscall(55, 1, 0, 0)); rt.put_c(' '); rt.put_n(rt.syscall(55, 2, 0, 0)); rt.put_c(10); return 0;
+}
diff --git a/tests/threads/reject/invalid.zc b/tests/threads/reject/invalid.zc
new file mode 100644
index 0000000..e5d98aa
--- /dev/null
+++ b/tests/threads/reject/invalid.zc
@@ -0,0 +1,3 @@
+namespace;
+include rt;
+unchecked fn main() { int fd = 0; rt.put_n(rt.syscall(51, -1, &fd, 0)); rt.put_c(' '); rt.put_n(rt.syscall(52, 123456, 0, 0)); rt.put_c(10); return 0; }