#!/usr/bin/expect # selftest_nmon.exp -- the curses half of 85-nmon.test. # # Everything in the .test file's batch section runs with cursed=0, so none of it # exercises initscr(), terminfo lookup, or the key dispatcher. This drives the # interactive editor over a real pty for exactly those, and prints one # "N- OK" line per verdict plus a final ALL-NMON-OK, which the .test greps. # # The needles are each a SINGLE CONTIGUOUS ncurses write and were measured # against a native build of this same 16m source; anything that ncurses splits # with a cursor-motion escape (the boxed field values, the per-CPU bars) is not # used. nmon repaints the whole screen every refresh, so a needle that is late is # still a needle -- the timeouts below are generous rather than tight because a # /proc reader on this arm may block where the control did not. set timeout 60 set failed 0 proc want {tag pat} { global failed expect { -re $pat { puts "\nN-$tag OK" } timeout { puts "\nN-$tag FAILED (timeout)"; set failed 1 } eof { puts "\nN-$tag FAILED (eof)"; set failed 1 } } } spawn -noecho nmon # The welcome screen is painted by initscr()+refresh() before any key is read, # so it is the single strongest statement that the curses layer came up: TERM # resolved out of /etc/terminfo, a WINDOW was allocated and it reached the pty. want N1welcome {Use these keys to toggle statistics on/off} # The key legend is a separate contiguous write further down the same pane. want N2keybar {t = Top-processes} want N3quithint {To stop nmon type q to Quit} # smacs -- the alternate character set nmon draws its box frame with. This is the # one needle here that tests the TERMINFO DATABASE rather than the library: a # build that found no acsc would still paint text, just without a frame. # # BOTH SPELLINGS ARE ACCEPTED BECAUSE smacs IS TERMINFO DATA, NOT A CONSTANT, and # this image and a modern desktop disagree about it for the same TERM. Measured: # Ubuntu's xterm entry gives smacs=\E(0 / rmacs=\E(B (the SCS G0 designation), # while THIS image's xterm entry gives smacs=^N / rmacs=^O (SO/SI shift-out), # with an identical acsc string in both. Pinning either spelling alone asserts # which terminfo entry got installed rather than whether ncurses found one, which # is not what this case is for -- so match the shift-out form or the designation # form and let the entry be the entry. want N4acsbox "\x0e|\x1b\\(0" # 'c' switches to the CPU panel, which is the first thing driven by a KEYSTROKE # rather than by the initial paint -- so it covers the input half (cbreak() and # the getch() dispatcher) and a second reader writing to a live screen. send "c" want N5cpuview {CPU Utilisation} # 'q' is the documented quit. nmon must leave curses cleanly (endwin) and exit, # which is what makes it safe to run from the selftest runner's own tty at all. send "q" expect { eof { puts "\nN-N6quit OK" } timeout { puts "\nN-N6quit FAILED (nmon did not exit on q)"; set failed 1 } } catch wait result set code [lindex $result 3] if {$code != 0} { puts "\nN-exit FAILED (nmon exit status $code)" set failed 1 } if {$failed == 0} { puts "\nALL-NMON-OK" } exit $failed