Skip to content

Commit c699fd1

Browse files
art049claude
andcommitted
feat(tracegrind): add regression tests and CI integration
Add vg_regtest-based regression tests covering basic tracing, markers, instrumentation toggle, toggle collect, call chains, inlining behavior, and schema validation. Extend CI matrix to run tracegrind tests alongside callgrind on both Ubuntu 22.04 and 24.04. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ea18a5b commit c699fd1

33 files changed

Lines changed: 447 additions & 9 deletions

.github/workflows/ci.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11-
test-callgrind:
11+
test:
1212
strategy:
1313
matrix:
1414
runner:
1515
- platform: ubuntu-22.04
1616
ubuntu-version: 22.04
1717
- platform: ubuntu-24.04
1818
ubuntu-version: 24.04
19+
tool:
20+
- callgrind
21+
- tracegrind
1922

2023
runs-on: ${{ matrix.runner.platform }}
2124

@@ -32,7 +35,7 @@ jobs:
3235
path-exclude /usr/share/man/*
3336
path-exclude /usr/share/info/*
3437
EOF
35-
38+
3639
- name: Update apt-get cache
3740
run: sudo apt-get update
3841

@@ -51,6 +54,10 @@ jobs:
5154
docbook-xml \
5255
xsltproc
5356
57+
- name: Install uv
58+
if: matrix.tool == 'tracegrind'
59+
uses: astral-sh/setup-uv@v7
60+
5461
- name: Run autogen
5562
run: ./autogen.sh
5663

@@ -63,17 +70,17 @@ jobs:
6370
- name: Build test dependencies
6471
run: |
6572
make -C tests arch_test os_test true
66-
make -C callgrind/tests check
73+
make -C ${{ matrix.tool }}/tests check
6774
68-
- name: Run Callgrind tests
75+
- name: Run tests
6976
run: |
70-
cd callgrind/tests
77+
cd ${{ matrix.tool }}/tests
7178
TESTS=$(ls *.vgtest | grep -v bug497723.vgtest)
7279
perl ../../tests/vg_regtest --valgrind=../../vg-in-place $TESTS
7380
7481
- name: Upload test logs
7582
if: failure()
7683
uses: actions/upload-artifact@v4
7784
with:
78-
name: callgrind-test-logs-${{ matrix.runner.ubuntu-version }}
79-
path: callgrind/tests/*.log
85+
name: ${{ matrix.tool }}-test-logs-${{ matrix.runner.ubuntu-version }}
86+
path: ${{ matrix.tool }}/tests/*.log

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
/tracegrind/tests/Makefile.in
188188
/tracegrind/tests/tracegrind.out.*
189189
/tracegrind/tests/fibo
190+
/tracegrind/tests/*.bin
190191

191192
# /coregrind/
192193
/coregrind/*.a

tracegrind/tests/Makefile.am

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1-
dist_noinst_SCRIPTS =
21

3-
EXTRA_DIST =
2+
include $(top_srcdir)/Makefile.tool-tests.am
3+
4+
SUBDIRS = .
5+
DIST_SUBDIRS = .
6+
7+
dist_noinst_SCRIPTS = filter_stderr filter_trace
8+
9+
check_PROGRAMS = \
10+
test_basic.bin \
11+
test_marker.bin \
12+
test_instr_toggle.bin \
13+
test_toggle_collect.bin \
14+
test_foo_bar_baz.bin \
15+
test_inline.bin
16+
17+
AM_CFLAGS += $(AM_FLAG_M3264_PRI)
18+
AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
19+
20+
test_basic_bin_SOURCES = test_basic.c
21+
test_marker_bin_SOURCES = test_marker.c
22+
test_instr_toggle_bin_SOURCES = test_instr_toggle.c
23+
test_toggle_collect_bin_SOURCES = test_toggle_collect.c
24+
test_foo_bar_baz_bin_SOURCES = test_foo_bar_baz.c
25+
test_inline_bin_SOURCES = test_inline.c
26+
test_inline_bin_CFLAGS = $(AM_CFLAGS) -O2 -g
27+
28+
EXTRA_DIST = \
29+
test_basic.vgtest test_basic.stderr.exp test_basic.post.exp \
30+
test_marker.vgtest test_marker.stderr.exp test_marker.post.exp \
31+
test_instr_toggle.vgtest test_instr_toggle.stderr.exp test_instr_toggle.post.exp \
32+
test_toggle_collect.vgtest test_toggle_collect.stderr.exp test_toggle_collect.post.exp \
33+
test_foo_bar_baz.vgtest test_foo_bar_baz.stderr.exp test_foo_bar_baz.post.exp \
34+
test_inline.vgtest test_inline.stderr.exp test_inline.post.exp \
35+
test_schema.vgtest test_schema.stderr.exp test_schema.post.exp

tracegrind/tests/filter_stderr

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! /bin/sh
2+
3+
dir=`dirname $0`
4+
5+
$dir/../../tests/filter_stderr_basic |
6+
7+
# Remove "Tracegrind, ..." line and the following copyright line.
8+
sed "/^Tracegrind, a call-graph generating cache profiler/ , /./ d" |
9+
10+
# Remove pointer to tracegrind_control
11+
sed "/^For interactive control,.*$/d" |
12+
13+
# Remove numbers from "Collected" line
14+
sed "s/^\(Collected *:\)[ 0-9]*$/\1/" |
15+
16+
# Remove numbers from I/D/LL "refs:" lines
17+
perl -p -e 's/((I|D|LL) *refs:)[ 0-9,()+rdw]*$/\1/' |
18+
19+
# Remove numbers from I1/D1/LL/LLi/LLd "misses:" and "miss rates:" lines
20+
perl -p -e 's/((I1|D1|LL|LLi|LLd) *(misses|miss rate):)[ 0-9,()+rdw%\.]*$/\1/' |
21+
22+
# Remove numbers from "Branches:", "Mispredicts:, and "Mispred rate:" lines
23+
perl -p -e 's/((Branches|Mispredicts|Mispred rate):)[ 0-9,()+condi%\.]*$/\1/' |
24+
25+
# Remove CPUID warnings lines for P4s and other machines
26+
sed "/warning: Pentium 4 with 12 KB micro-op instruction trace cache/d" |
27+
sed "/Simulating a 16 KB I-cache with 32 B lines/d" |
28+
sed "/warning: L3 cache found, using its data for the LL simulation./d" |
29+
sed "/warning: L4 cache found, using its data for the LL simulation./d" |
30+
sed "/Warning: Cannot auto-detect cache config, using defaults./d" |
31+
sed "/Run with -v to see./d" |
32+
sed "/warning: specified LL cache: line_size .*$/d" |
33+
sed "/warning: simulated LL cache: line_size .*$/d" |
34+
35+
# Remove trace output file path messages
36+
sed "/^Trace output to /d"

tracegrind/tests/filter_trace

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
#
3+
# Filter tracegrind trace output (from tracegrind-analyzer)
4+
# to normalize machine-dependent values for regression testing.
5+
#
6+
7+
# Normalize format/schema version numbers
8+
sed 's/^Format Version: [0-9]\+$/Format Version: N/' |
9+
sed 's/^Schema Version: [0-9]\+$/Schema Version: N/' |
10+
11+
# Normalize object paths: replace full path to test binary with just the basename
12+
# e.g. obj=/home/user/valgrind/tracegrind/tests/test_marker -> obj=test_marker
13+
sed 's|obj=[^ |]*[/]||g' |
14+
15+
# Normalize file paths: replace full source paths with just the basename
16+
# e.g. file=/home/user/.../test_marker.c -> file=test_marker.c
17+
sed 's|file=[^ |]*[/]||g' |
18+
19+
# Normalize function address/stats that vary: Ir counts
20+
# Replace Ir=<number> with Ir=N
21+
sed 's|Ir=[0-9]\+|Ir=N|g' |
22+
23+
# Remove the separator line
24+
sed '/^-\{10,\}$/d' |
25+
26+
# Normalize "Total rows:" count
27+
sed 's/^Total rows: [0-9,]\+$/Total rows: N/' |
28+
29+
# Normalize "Showing X of Y rows"
30+
sed 's/^Showing [0-9,]\+ of [0-9,]\+ rows$/Showing N of N rows/' |
31+
32+
# Normalize "Sequence range:" numbers
33+
sed 's/^Sequence range: [0-9,]\+ - [0-9,]\+$/Sequence range: N - N/' |
34+
35+
# Normalize event count percentages in stats
36+
sed 's/\([0-9,]\+\) ([0-9.]\+%)/N (P%)/g' |
37+
38+
# Normalize "Threads: N ([...])"
39+
sed 's/^Threads: \([0-9]\+\) (\[.*\])/Threads: \1/' |
40+
41+
# Remove "Top 10 functions" section (platform-dependent)
42+
sed '/^Top 10 functions/,/^$/d' |
43+
44+
# Remove "Fork events" section (platform-dependent)
45+
sed '/^Fork events/,/^$/d' |
46+
47+
# Normalize seq numbers in raw arrays: [1234, ...] -> [N, ...]
48+
sed 's/^\[\([0-9]\+\),/[N,/g' |
49+
50+
# Normalize seq=<number> in formatted output
51+
sed 's/seq=[0-9]\+/seq=N/g' |
52+
53+
# Strip GCC optimization suffixes from function names (e.g. .constprop.0, .isra.0, .part.0)
54+
sed 's/\.\(constprop\|isra\|part\|cold\|lto_priv\)\.[0-9]*//g'

tracegrind/tests/test_basic.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "tracegrind.h"
2+
3+
static int factorial(int n) {
4+
if (n <= 1) return 1;
5+
return n * factorial(n - 1);
6+
}
7+
8+
int main(void) {
9+
int result = factorial(5);
10+
return result != 120;
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Format Version: N
2+
Format Name: tracegrind-msgpack
3+
Schema Version: N
4+
5+
Event Schemas (discriminated union):
6+
0 (MARKER): ['seq', 'tid', 'event', 'marker']
7+
1 (ENTER): ['seq', 'tid', 'event', 'fn', 'obj', 'file', 'line', 'Ir']
8+
2 (EXIT): ['seq', 'tid', 'event', 'fn', 'obj', 'file', 'line', 'Ir']
9+
3 (FORK): ['seq', 'tid', 'event', 'child_pid']
10+
11+
Total rows: N
12+
13+
Events by type:
14+
ENTER: N (P%)
15+
EXIT: N (P%)
16+
17+
Threads: 1
18+
Sequence range: N - N
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
Events : Ir
4+
Collected :
5+
6+
I refs:

tracegrind/tests/test_basic.vgtest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
prereq: ../../tracegrind/scripts/tracegrind-analyzer --help 2>/dev/null
2+
prog: test_basic.bin
3+
vgopts: --tracegrind-out-file=tracegrind.out.test_basic
4+
post: ../../tracegrind/scripts/tracegrind-analyzer tracegrind.out.test_basic.msgpack.lz4 --stats | ./filter_trace
5+
cleanup: rm -f tracegrind.out.test_basic.msgpack.lz4

0 commit comments

Comments
 (0)