1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

tests/functional: Add tests for flamegraph profiler

The tests are mostly based on existing `function-trace.sh`
with some tests for corner cases.
This commit is contained in:
Sergei Zimmerman 2025-05-18 22:52:48 +00:00
parent 5e74c0e4d6
commit 33141cd133
No known key found for this signature in database
GPG key ID: A9B0B557CA632325
2 changed files with 92 additions and 0 deletions

View file

@ -0,0 +1,91 @@
#!/usr/bin/env bash
source common.sh
set +x
expect_trace() {
expr="$1"
expect="$2"
actual=$(
nix-instantiate \
--eval-profiler flamegraph \
--eval-profiler-frequency 0 \
--eval-profile-file /dev/stdout \
--expr "$expr" |
grep "«string»" || true
)
echo -n "Tracing expression '$expr'"
msg=$(
diff -swB \
<(echo "$expect") \
<(echo "$actual")
) && result=0 || result=$?
if [ "$result" -eq 0 ]; then
echo " ok."
else
echo " failed. difference:"
echo "$msg"
return "$result"
fi
}
# lambda
expect_trace 'let f = arg: arg; in f 1' "
«string»:1:22:f 1
"
# unnamed lambda
expect_trace '(arg: arg) 1' "
«string»:1:1 1
"
# primop
expect_trace 'builtins.head [0 1]' "
«string»:1:1:primop head 1
"
# primop application
expect_trace 'let a = builtins.all (let f = x: x; in f); in a [1]' "
«string»:1:9:primop all 1
«string»:1:47:primop all 1
«string»:1:47:primop all;«string»:1:31:f 1
"
# functor
expect_trace '{__functor = x: arg: arg;} 1' "
«string»:1:1:functor 1
«string»:1:1:functor;«string»:1:2 1
"
# failure inside a tryEval
expect_trace 'builtins.tryEval (throw "example")' "
«string»:1:1:primop tryEval 1
«string»:1:1:primop tryEval;«string»:1:19:primop throw 1
"
# Missing argument to a formal function
expect_trace 'let f = ({ x }: x); in f { }' "
«string»:1:24:f 1
"
# Too many arguments to a formal function
expect_trace 'let f = ({ x }: x); in f { x = "x"; y = "y"; }' "
«string»:1:24:f 1
"
# Not enough arguments to a lambda
expect_trace 'let f = (x: y: x + y); in f 1' "
«string»:1:27:f 1
"
# Too many arguments to a lambda
expect_trace 'let f2 = (x: x); in f2 1 2' "
«string»:1:21:f2 1
"
# Not a function
expect_trace '1 2' "
«string»:1:1 1
"

View file

@ -133,6 +133,7 @@ suites = [
'post-hook.sh',
'function-trace.sh',
'formatter.sh',
'flamegraph-profiler.sh',
'eval-store.sh',
'why-depends.sh',
'derivation-json.sh',