aboutsummaryrefslogtreecommitdiff
path: root/tests/threads/accept
diff options
context:
space:
mode:
Diffstat (limited to 'tests/threads/accept')
-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
9 files changed, 98 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;
+}