. "$BST_LIB" # cmatrix 2.0 (meta-oe recipes-extended) -- the terminal "Matrix" screen effect: # a single binary, /usr/bin/cmatrix, that fills the screen with falling glyphs # until a key is pressed. It is on this image as a compact exerciser of the # ncurses already here, which is what shapes the split below. # # THE FILE IS IN TWO HALVES, AND THEY CLAIM DIFFERENT THINGS. # # The first half runs without a terminal. Every case in it is decided inside the # getopt loop, which runs to completion before initscr() is ever called (source # order: the switch ends at cmatrix.c:376, initscr() is at :379). So it exercises # the argument parser and the process's exit protocol and NOTHING about curses -- # a cmatrix that could not open a terminal at all would pass all of it. It is # still worth having, because it is the half that survives on an image where # expect is absent, and because two of its verdicts are about exit status rather # than output. # # The second half is the port. It hands cmatrix a real pty via expect and reads # what the animation actually puts on it -- see data/selftest_cmatrix.exp, whose # header states what each verdict claims and why that assertion was the one # chosen. 45-expect.test is what says whether the pty machinery works at all, so # a failure there is not attributed here. # # WHAT NEITHER HALF CLAIMS: whether the rain looks right. Column advance, trail # fade, glyph shape and the bold arms are a rendering judgement, and no scrape # through a pty can make it -- BRINTOS-339 ran headless, so no human watched this # port. BRINTOS-420 carries that pass. # # EXIT STATUS IS 0 ON EVERY PATH, INCLUDING THE ERRORS. cmatrix routes its # failure exits through c_die(), which ends in exit(0) (cmatrix.c:126) -- so # `cmatrix -C nosuchcolor` reports the error and still succeeds. That is # upstream's behaviour, not a port defect, and the cases below assert the # behaviour rather than the exit code it "should" have had; check_out, which # requires rc 0 AND the message, happens to be exactly right for it. require cmatrix cmatrix/present # --- the surface that needs no terminal --------------------------------------- # The version string carries the recipe's SRCREV indirectly: 2.0 is what # CMakeLists.txt sets, so a mismatch here means the image took some other cmatrix. check_out cmatrix/version "CMatrix version 2.0" cmatrix -V check_out cmatrix/usage "Usage: cmatrix" cmatrix -h # An unrecognised option is not an error path in this program: getopt's '?' falls # through to the same case as -h (cmatrix.c:350), so the usage text is the whole # response. Asserting that explicitly keeps a future "improved" error path from # passing silently. check_out cmatrix/unknown-opt "Usage: cmatrix" cmatrix -Z # The colour table is parsed by name, and the rejection message names the eight # it accepts. This is the one diagnostic cmatrix emits on stderr. check_out cmatrix/bad-color "Invalid color selection" cmatrix -C chartreuse check_out cmatrix/bad-color-lists-valid "green, red, blue" cmatrix -C chartreuse # ...and a valid colour must NOT take that path. Without this, the case above # would pass just as well against a build that rejected every colour. if cmatrix -C green -V 2>&1 | grep -q "Invalid color"; then bst_notok cmatrix/good-color "cmatrix -C green was rejected by the colour parser" else bst_ok cmatrix/good-color fi # --- the port: a curses animation on a real pty -------------------------------- require expect cmatrix/expect-present out=$(expect "$BST_DATA/selftest_cmatrix.exp" 2>&1); rc=$? case "$out" in *ALL-CMATRIX-OK*) all=1 ;; *) all=0 ;; esac if [ "$rc" -eq 0 ] && [ "$all" -eq 1 ]; then bst_ok cmatrix/all-ok else bst_notok cmatrix/all-ok "rc=$rc $(_bst_1line "$out")"; fi # Each verdict is reported on its own so a single red names the capability that # broke rather than just "the pty leg failed". The payload's header says what # each one claims. for tag in M1start M2cursoff M3paint M7green M4quit M5saver M6red; do case "$out" in *"M-$tag OK"*) bst_ok "cmatrix/$tag" ;; *"M-$tag FAIL"*) bst_notok "cmatrix/$tag" "payload reported FAIL (rc=$rc)" ;; *) bst_notok "cmatrix/$tag" "payload emitted no verdict for $tag (rc=$rc) $(_bst_1line "$out")" ;; esac done # The glyph census is reported whatever the verdict, so a build that paints a # little but not enough is distinguishable from one that paints nothing. The # threshold lives in the payload (>= 20 of the 91 characters in 33..123); this # only surfaces the number that was measured. g=$(printf '%s\n' "$out" | awk '/^M-glyphs/{print $2}') b=$(printf '%s\n' "$out" | awk '/^M-bytes/{print $2}') if [ -n "$g" ]; then bst_ok "cmatrix/measured-glyphs-$g-bytes-${b:-0}" else bst_notok cmatrix/measured "the payload reported no glyph census at all" fi