xref: /linux/tools/objtool/tests/generic/test-checksum-debug.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# "klp checksum --debug-checksum" prints a per-instruction checksum stream,
5# and klp-build -f (--show-first-changed) parses it to report where a function
6# first differs between the original and patched builds.
7#
8# It is a debugging aid, so nothing fails when it breaks: klp-build greps the
9# stream, and an unmatched grep just yields no output, which reads as "no
10# instruction changed".  That is exactly how the format drifted out from under
11# it once already.  Pin the shape klp-build depends on:
12#
13#   DEBUG: <object>: checksum: <func>(): <sym>+0x<offset> <16 hex digits>
14#
15# and that --dry-run leaves the object alone, since klp-build runs this against
16# objects it is going to checksum again for real.
17
18. "$(dirname "$0")/../lib.sh"
19
20setup
21build_pair basic.c
22
23before="$(md5sum < "$workdir/orig.o")"
24
25"$OBJTOOL" klp checksum --dry-run --debug-checksum=changed \
26	"$workdir/orig.o" > "$workdir/debug.log" 2>&1 ||
27	fail "klp checksum --debug-checksum failed"
28
29# --dry-run has to mean it: klp-build checksums these objects again afterwards,
30# and "already has .discard.sym_checksum, skipping" would lose the real run.
31[ "$(md5sum < "$workdir/orig.o")" = "$before" ] ||
32	fail "--dry-run modified the object"
33has_input_section orig.o .discard.sym_checksum &&
34	fail "--dry-run created .discard.sym_checksum"
35
36grep -qE '^DEBUG: .*: checksum: changed\(\): [^ ]+\+0x[0-9a-f]+ [0-9a-f]{16}$' \
37	"$workdir/debug.log" ||
38	fail "unexpected --debug-checksum format: $(head -1 "$workdir/debug.log")"
39
40# This is the pattern klp-build greps with.  Keep it working verbatim.
41grep -qE "^DEBUG: .*checksum: changed\(\): " "$workdir/debug.log" ||
42	fail "klp-build's --show-first-changed pattern no longer matches"
43
44# Only the requested function, or klp-build attributes instructions to the
45# wrong one.
46grep -qE 'checksum: untouched\(\)' "$workdir/debug.log" &&
47	fail "--debug-checksum=changed also dumped untouched()"
48
49pass "--debug-checksum format is the one klp-build -f parses"
50