Skip to content

Commit 7c25744

Browse files
committed
tests/functional: Add tests for flamegraph profiler
The tests are mostly based on existing `function-trace.sh` with some tests for corner cases.
1 parent 141fc9f commit 7c25744

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
3+
source common.sh
4+
5+
set +x
6+
7+
expect_trace() {
8+
expr="$1"
9+
expect="$2"
10+
actual=$(
11+
nix-instantiate \
12+
--eval-profiler flamegraph \
13+
--eval-profiler-sample-period 0 \
14+
--eval-profile-file /dev/stdout \
15+
--expr "$expr" |
16+
grep "«string»" || true
17+
)
18+
19+
echo -n "Tracing expression '$expr'"
20+
msg=$(
21+
diff -swB \
22+
<(echo "$expect") \
23+
<(echo "$actual")
24+
) && result=0 || result=$?
25+
if [ "$result" -eq 0 ]; then
26+
echo " ok."
27+
else
28+
echo " failed. difference:"
29+
echo "$msg"
30+
return "$result"
31+
fi
32+
}
33+
34+
# lambda
35+
expect_trace 'let f = arg: arg; in f 1' "
36+
«string»:1:22:f 1
37+
"
38+
39+
# unnamed lambda
40+
expect_trace '(arg: arg) 1' "
41+
«string»:1:1 1
42+
"
43+
44+
# primop
45+
expect_trace 'builtins.head [0 1]' "
46+
«string»:1:1:primop head 1
47+
"
48+
49+
# primop application
50+
expect_trace 'let a = builtins.all (let f = x: x; in f); in a [1]' "
51+
«string»:1:9:primop all 1
52+
«string»:1:47:primop all 1
53+
«string»:1:47:primop all;«string»:1:31:f 1
54+
"
55+
56+
# functor
57+
expect_trace '{__functor = x: arg: arg;} 1' "
58+
«string»:1:1:functor 1
59+
«string»:1:1:functor;«string»:1:2 1
60+
"
61+
62+
# failure inside a tryEval
63+
expect_trace 'builtins.tryEval (throw "example")' "
64+
«string»:1:1:primop tryEval 1
65+
«string»:1:1:primop tryEval;«string»:1:19:primop throw 1
66+
"
67+
68+
# Missing argument to a formal function
69+
expect_trace 'let f = ({ x }: x); in f { }' "
70+
«string»:1:24:f 1
71+
"
72+
73+
# Too many arguments to a formal function
74+
expect_trace 'let f = ({ x }: x); in f { x = "x"; y = "y"; }' "
75+
«string»:1:24:f 1
76+
"
77+
78+
# Not enough arguments to a lambda
79+
expect_trace 'let f = (x: y: x + y); in f 1' "
80+
«string»:1:27:f 1
81+
"
82+
83+
# Too many arguments to a lambda
84+
expect_trace 'let f2 = (x: x); in f2 1 2' "
85+
«string»:1:21:f2 1
86+
"
87+
88+
# Not a function
89+
expect_trace '1 2' "
90+
«string»:1:1 1
91+
"

tests/functional/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ suites = [
133133
'post-hook.sh',
134134
'function-trace.sh',
135135
'formatter.sh',
136+
'flamegraph-profiler.sh',
136137
'eval-store.sh',
137138
'why-depends.sh',
138139
'derivation-json.sh',

0 commit comments

Comments
 (0)