Skip to content

Commit

Permalink
test: fix the bitfield-offset fix
Browse files Browse the repository at this point in the history
Many systems on which CTF is too old for tst.bitfield-offset.d to pass will
also be too old for objdump --ctf=.ctf to work: in that case, we have no way
to tell how new the CTF is (and thus whether this bug is expected to be
fixed), so we have to skip it.

Even figuring out if this is the case is hard.  We don't want to try to
objdump the entire kernel CTFA again in case it works (it's huge and takes
ages to dump: we're not exiting early on a version check here, after all).
But objdump returns with an exitcode of 1 both if an unrecognized option is
found *and* if the target contains no CTF at all -- so we must literally
grep for 'Unrecognized option' (under LANG=C) to be sure of spotting an
instance we must skip.  (We also check for a zero exit code, because if our
random test executable *does* contain CTF and dumping it works there's no
need to grep the stderr for anything at all.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock authored and kvanhees committed Mar 6, 2024
1 parent feb883f commit f7f7b65
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/unittest/bitfields/tst.bitfield-offset.x
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@
# objdump, because the CTF version number differs.
#
# Alas objdump cannot read vmlinux.ctfa of this vintage on its
# own: we must embed it into an ELF file ourselves.
# own: we must embed it into an ELF file ourselves. Worse yet,
# objdump might be too old to read CTF at all: in this case, just
# skip the test, since we can't possibly tell what it was
# generated by.

if ! objdump --ctf=.ctf --ctf-parent=shared_ctf /bin/true > /dev/null 2>&1 && \
LANG=C objdump --ctf=.ctf --ctf-parent=shared_ctf /bin/true 2>&1 | \
grep 'unrecognized option' > /dev/null 2>&1; then
exit 2
fi

ctfa=$tmpdir/vmlinux.ctfa
trap "rm -f $ctfa" EXIT ERR

objcopy --add-section=.ctf=/lib/modules/$(uname -r)/kernel/vmlinux.ctfa /bin/true $ctfa

objdump --ctf=.ctf --ctf-parent=shared_ctf $ctfa |\
awk '/Version: 3/ { exit 1; } /Version: / { exit 0; }'

0 comments on commit f7f7b65

Please sign in to comment.