. "$BST_LIB" require kmod kmod/present # kmod is a multi-call binary that dispatches on basename(argv[0]); "kmod # " is not a thing (help/list/static-nodes are the only real # subcommands). The applets are reached by symlink NAME, and busybox provides # the same names, so the bare modinfo/lsmod/depmod belong to whichever # implementation won update-alternatives -- kmod registers at priority 70. # # Do NOT drive the .kmod links instead: they are the alternatives TARGETS, and # invoking /sbin/modinfo.kmod directly makes basename(argv[0]) "modinfo.kmod", # which matches no command, so kmod exits 254 having printed nothing. That is # upstream behaviour and reproduces identically on a native x86_64 build; it is # not a platform fault, and a suite driving those paths measures nothing. # # Each applet is therefore identified before it is trusted: kmod answers # --version with "kmod version 31", busybox's applets do not. check_out kmod/version "kmod version 31" kmod --version check_out kmod/modinfo-is-kmod "kmod version 31" modinfo --version check_out kmod/depmod-is-kmod "kmod version 31" depmod --version check_out kmod/insmod-is-kmod "kmod version 31" insmod --version check_out kmod/modprobe-is-kmod "kmod version 31" modprobe --version # The PACKAGECONFIG this port ships with, asserted rather than assumed: the # compressed-module cases below only mean something if the feature is compiled # in, and kmod prints its feature set beside its version. check_out kmod/features-xz "+XZ" kmod --version check_out kmod/features-zlib "+ZLIB" kmod --version # The fixtures are upstream's own testsuite modules, shipped xz-compressed -- # they are x86_64 ELF, and brintos-selftests is an allarch recipe whose # sysroot_strip has no llvm-strip to hand an ELF file to. That kmod parses # foreign-architecture modules is the supported case, not a stretch: it is why # upstream ships i386/x86_64/sparc64 fixtures in one tree. SIMPLE_XZ="$BST_DATA/kmod-mod-simple-x86_64.ko.xz" FOO_XZ="$BST_DATA/kmod-mod-foo.ko.xz" # --- the xz path: libkmod decompressing a module in-process --- check_out kmod/modinfo-xz-license "LGPL" modinfo "$SIMPLE_XZ" check_eq kmod/modinfo-xz-depends "mod-foo-c,mod-foo-b,mod-foo-a" \ "$(modinfo -F depends "$FOO_XZ" 2>/dev/null)" # --- the plain-ELF path, isolated from decompression, so a red on one of the # two says which half it belongs to --- tmpd=${TMPDIR:-/tmp}/bst-kmod.$$ mkdir -p "$tmpd" xz -dc "$SIMPLE_XZ" > "$tmpd/mod-simple.ko" 2>/dev/null xz -dc "$FOO_XZ" > "$tmpd/mod-foo.ko" 2>/dev/null if [ -s "$tmpd/mod-simple.ko" ]; then check_out kmod/modinfo-license "LGPL" modinfo "$tmpd/mod-simple.ko" check_out kmod/modinfo-author "Lucas De Marchi" modinfo "$tmpd/mod-simple.ko" check_out kmod/modinfo-vermagic "3.19.0" modinfo "$tmpd/mod-simple.ko" check_out kmod/modinfo-filename "mod-simple" modinfo "$tmpd/mod-simple.ko" # -F extracts one field; the value must come back bare, not as a # "field: value" line, which is what separates a working parser from an echo. check_eq kmod/modinfo-field-license "LGPL" \ "$(modinfo -F license "$tmpd/mod-simple.ko" 2>/dev/null)" else bst_notok kmod/modinfo-license "xz -dc produced no output for $SIMPLE_XZ" fi if [ -s "$tmpd/mod-foo.ko" ]; then # Dependency parsing: mod-foo declares three, in this order. This is the # field depmod's whole dependency graph is derived from. check_eq kmod/modinfo-field-depends "mod-foo-c,mod-foo-b,mod-foo-a" \ "$(modinfo -F depends "$tmpd/mod-foo.ko" 2>/dev/null)" else bst_notok kmod/modinfo-field-depends "xz -dc produced no output for $FOO_XZ" fi # Error path: a missing file must be reported, not silently accepted -- an # always-zero modinfo would pass every assertion above that only greps output. check_rc kmod/modinfo-missing 1 modinfo /nonexistent-module.ko rm -rf "$tmpd" # lsmod reads /proc/modules, which this kernel does not create: it is built # without loadable-module support, so there is no module list to report. The # CORRECT behaviour is to say so and exit non-zero, and that is what is asserted # here -- an lsmod that printed an empty list and exited 0 would be the bug. lsmod_out=$(lsmod 2>&1); lsmod_rc=$? if [ "$lsmod_rc" -ne 0 ] && [ ! -e /proc/modules ] && \ { printf '%s\n' "$lsmod_out" | grep -q "could not get list of modules"; }; then bst_ok kmod/lsmod-reports-no-module-support else bst_notok kmod/lsmod-reports-no-module-support \ "rc=$lsmod_rc procmodules=$([ -e /proc/modules ] && echo yes || echo no) $(_bst_1line "$lsmod_out")" fi # The applets that need a live module loader cannot be exercised at all here, # and that is the kernel's shape rather than a defect in the port: no # CONFIG_MODULES means no /proc/modules, no /lib/modules and no init_module(2). bst_skip kmod/module-load-unload \ "kernel has no loadable-module support (/proc/modules and /lib/modules absent); insmod/rmmod/modprobe have nothing to act on" # --- the upstream ptest suite, which ptest-runner owns --- # Recorded here as a RED because the suite is BLOCKED, not legitimately absent: # it is installed, it runs, and it is this ticket's acceptance gate. Downgrading # it to a skip would make the run green about the one thing it is meant to prove. # # BRINTOS-WORKAROUND: brintos/linux#53 remove — kmod's harness collects each # forked child's stdout/stderr through an epoll set, and epoll_create1() returns # ENOSYS on this arch (compiled in, but no epoll entry in the wasm32 syscall # table). The test bodies themselves pass -- the children exit 0 -- so this case # turns green with no kmod change once #53 lands. bst_notok kmod/ptest-suite \ "harness needs epoll: epoll_create1() ENOSYS (brintos/linux#53), so every case reports 'exit ok but outputs do not match' though the forked children exit 0" # BRINTOS-WORKAROUND: hwjs-cc#10 revisit — kmod fakes the filesystem, uname(2), # init_module(2) and delete_module(2) with four LD_PRELOADed -shared libraries, # and no DSO can be linked on this whole-program-bitcode arm, so the 11 test # programs whose cases set a .config vector cannot be built at all. Revisit when # shared objects exist here; there is nothing to fix in kmod. bst_skip kmod/ptest-preload-cases \ "62 of upstream's 88 cases need LD_PRELOAD override DSOs; no shared library can be linked on this arm"