aboutsummaryrefslogtreecommitdiff
path: root/tests/programs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/programs')
-rw-r--r--tests/programs/gc.zc2
-rw-r--r--tests/programs/trace.expected9
-rw-r--r--tests/programs/trace.zc36
-rw-r--r--tests/programs/trace_jit.expected6
-rw-r--r--tests/programs/trace_jit.zc24
-rw-r--r--tests/programs/trace_more.expected38
-rw-r--r--tests/programs/trace_more.zc40
-rw-r--r--tests/programs/trace_run.zc36
8 files changed, 190 insertions, 1 deletions
diff --git a/tests/programs/gc.zc b/tests/programs/gc.zc
index 7d2441b..44fde5d 100644
--- a/tests/programs/gc.zc
+++ b/tests/programs/gc.zc
@@ -12,7 +12,7 @@ fn main() {
churn(1000);
rt.put_n(rt.live_objects() - base); rt.put_c(' ');
f = rt.gc();
- rt.put_n(f >= 990); rt.put_c(' '); // conservative: a stale word or two may keep one alive
+ rt.put_n(f >= 950); rt.put_c(' '); // conservative: stale words, and genome code words that happen to look like heap addresses, keep a few alive
rt.put_n(keep[0]); rt.put_c(' '); // the one a global still points at survives
churn(200000); // 3.2m words through a 393k word heap: needs the automatic collector
rt.put_n(rt.gc_runs > 1); rt.put_c(' ');
diff --git a/tests/programs/trace.expected b/tests/programs/trace.expected
new file mode 100644
index 0000000..2c7dce3
--- /dev/null
+++ b/tests/programs/trace.expected
@@ -0,0 +1,9 @@
+ at <stdin>:18 in where
+ at <stdin>:23 in outer
+ at <stdin>:30 in main
+1
+10
+zy: index 4 out of range (length 4)
+ at <stdin>:5 in get
+ at <stdin>:11 in sum
+ at <stdin>:34 in main
diff --git a/tests/programs/trace.zc b/tests/programs/trace.zc
new file mode 100644
index 0000000..c283f75
--- /dev/null
+++ b/tests/programs/trace.zc
@@ -0,0 +1,36 @@
+namespace;
+include rt;
+
+int get(int[?] t, int i) {
+ return t[i];
+}
+
+int sum(int[?] t, int n) {
+ int s = 0, i = 0;
+ while (i < n) {
+ s = s + get(t, i);
+ i++;
+ }
+ return s;
+}
+
+int where() {
+ rt.trace();
+ return 1;
+}
+
+int outer() {
+ int r = where();
+ return r;
+}
+
+int main() {
+ int[?] t = rt.new(int[?]);
+ t.push(1); t.push(2); t.push(3); t.push(4);
+ rt.put_n(outer());
+ rt.put_c(10);
+ rt.put_n(sum(t, 4));
+ rt.put_c(10);
+ rt.put_n(sum(t, 5));
+ return 0;
+}
diff --git a/tests/programs/trace_jit.expected b/tests/programs/trace_jit.expected
new file mode 100644
index 0000000..68e2eb4
--- /dev/null
+++ b/tests/programs/trace_jit.expected
@@ -0,0 +1,6 @@
+ at <stdin>:9 in down
+ at <stdin>:12 in down
+ at <stdin>:12 in down
+ at <stdin>:12 in down
+ at <stdin>:18 in main
+20000
diff --git a/tests/programs/trace_jit.zc b/tests/programs/trace_jit.zc
new file mode 100644
index 0000000..e864c50
--- /dev/null
+++ b/tests/programs/trace_jit.zc
@@ -0,0 +1,24 @@
+namespace;
+include rt;
+
+// a hot path: the jits have translated down() and the loop in main long before
+// the last call, so the return stack pointer comes from translated code (op 56
+// reads it at the gate store, cb_r on both jits)
+int down(int n, int last) {
+ if (n == 0) {
+ if (last) rt.trace();
+ return 1;
+ }
+ return down(n - 1, last) + 1;
+}
+
+int main() {
+ int i = 0, s = 0;
+ while (i < 5000) {
+ s = s + down(3, i == 4999);
+ i++;
+ }
+ rt.put_n(s);
+ rt.put_c(10);
+ return 0;
+}
diff --git a/tests/programs/trace_more.expected b/tests/programs/trace_more.expected
new file mode 100644
index 0000000..b35d42d
--- /dev/null
+++ b/tests/programs/trace_more.expected
@@ -0,0 +1,38 @@
+ at <stdin>:6 in pt.get
+ at <stdin>:31 in main
+3
+ at <stdin>:34 in <closure>
+ at <stdin>:11 in apply
+ at <stdin>:32 in main
+9
+ at <stdin>:14 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ ... 35 more frames
+ at <stdin>:15 in rec
+ at <stdin>:15 in rec
+ at <stdin>:37 in main
+ at ADDR in quiet
+ at <stdin>:24 in loud
+ at <stdin>:38 in main
diff --git a/tests/programs/trace_more.zc b/tests/programs/trace_more.zc
new file mode 100644
index 0000000..512f93f
--- /dev/null
+++ b/tests/programs/trace_more.zc
@@ -0,0 +1,40 @@
+namespace;
+include rt;
+struct pt {
+ int x;
+ int get() {
+ rt.trace();
+ return this.x;
+ }
+};
+int apply(fn(int) f, int v) {
+ return f(v);
+}
+int rec(int n) {
+ if (n == 0) { rt.trace(); return 0; }
+ return rec(n - 1) + 1;
+}
+lines off;
+int quiet(int n) {
+ rt.trace();
+ return n;
+}
+lines on;
+int loud(int n) {
+ return quiet(n) +
+ 1;
+}
+int main() {
+ pt* p = rt.new(pt);
+ p.x = 3;
+ int k = 5;
+ rt.put_n(p.get()); rt.put_c(10);
+ rt.put_n(apply(fn(int a) {
+ int b = a + k;
+ rt.trace();
+ return b;
+ }, 4)); rt.put_c(10);
+ rec(60);
+ loud(2);
+ return 0;
+}
diff --git a/tests/programs/trace_run.zc b/tests/programs/trace_run.zc
new file mode 100644
index 0000000..1d42e26
--- /dev/null
+++ b/tests/programs/trace_run.zc
@@ -0,0 +1,36 @@
+namespace;
+include rt;
+
+int get(word t, int i) {
+ if (i >= 4) rt.oob(i, 4); return t[i];
+}
+
+int sum(word t, int n) {
+ int s = 0, i = 0;
+ while (i < n) {
+ s = s + get(t, i);
+ i++;
+ }
+ return s;
+}
+
+int where() {
+ rt.trace();
+ return 1;
+}
+
+int outer() {
+ int r = where();
+ return r;
+}
+
+int main() {
+ word t = rt.new(4);
+ t[0] = 1; t[1] = 2; t[2] = 3; t[3] = 4;
+ rt.put_n(outer());
+ rt.put_c(10);
+ rt.put_n(sum(t, 4));
+ rt.put_c(10);
+ rt.put_n(sum(t, 5));
+ return 0;
+}