tapper-autoreport
is a "bash include file" you can add ("source") at
the end of your own bash script.
It then magically turns your bash script into an "Tapper test suite".
It also allows your bash script to be executed locally via the prove
command, a standard tool to run test scripts that produce TAP output
("Test Anything Protocol") -- without requiring an actual Tapper
framework.
Due to that and no other external dependecies it's a good starting point to write actual *function tests that are reusable.
It collects meta information from system, reports test results and can upload logs and other files over network to a Tapper server.
Run the scripts locally in a subdir where the tapper-autoreport
script is located.
- script:
#! /bin/bash
# your own stuff here ...
. /tapper-autoreport
Explanation:
- First it imports utility functions to be used by your script.
- Then you write your test.
- Then calls the actual reporting of test results, with all the Tapper details, like:
- TAP
- filename gets name
- run itself is already a success
- meta information
- report grouping heuristics
- self-report to Tapper
- upload files
- print out Tapper report URL
The tool prove
is a standard tool available in every Linux
distribution. Use it this way:
$ prove ./trivial-example-1.sh
./trivial-example-1.sh .. ok
All tests successful.
Files=1, Tests=5, 20 wallclock secs
Result: PASS
Explanation:
- "prove" is an existing standard tool
- it prints success statistics
- no report sending happens
- is meant for manual developing/testing
Cmd line and output:
$ ./trivial-example-1.sh
# http://tapper/tapper/reports/id/129218
# - upload ./trivial-example-1.sh ...
# - upload /boot/config-2.6.32-22-generic ...
# - upload /proc/cpuinfo ...
# - upload /proc/devices ...
# - upload /proc/version ...
Explanation:
- execute script
- report output to Tapper server
- upload files
- prints out Tapper report URL
- is meant for final reporting
You can influence the meta information when the automagic and defaults don't work perfectly:
#! /bin/bash
. ./tapper-autoreport nok /tmp/results.log $?
ok 0 "affe loewe tiger"
ok 0 "some other description"
ok 0 "yet another test description"
append_tapdata "timecpb: 12.345"
append_tapdata "timenocpb: 23.456"
SUITENAME="CPUID-ON"
SUITEVERSION="2.007"
OSNAME="Gentoo 10.1"
CHANGESET="98765"
HOSTNAME="J-F-Sebastian"
TICKETURL='https://mybugtracker/bugs/show_bug.cgi?id=901'
WIKIURL=https://mywiki/wiki/SomeTopic
PLANNINGID=foocompany.coolproduct.qa.coolfeature.test
TAPPER_REPORT_SERVER="tapper-devel"
NOSEND=1
uname -a | grep -q Linux # example for exit code
. ./tapper-autoreport nok /tmp/my-results.txt $?
Explanation:
- define additional test results, using fix success status of 0 (0 is TRUE in shell)
- define additional YAML data lines
- overwrite suite name
- overwrite suite version
- overwrite OS name
- overwrite changeset, usually kernel
- overwrite hostname
- specify relevant URL in used ticket system (like Bugzilla, RT, ...)
- specify relevant URL in used wiki
- specify relevant task planning id (like MS Project, TaskJuggler, ...)
- use different report server (e.g. "tapper-devel" for experiments)
- set NOSEND=1 to suppress sending to reports server completely
- param "nok" say "something was not ok"
- param of filename /tmp/my-results.txt means upload the file
- param of integer ($? is last exit code, 0 means ok, else not ok)
Import utility functions at the beginning of the script via
. ./tapper-autoreport --import-utils
Then you have several functions available.
Evaluates the first argument with Shell boolean semantics (0 is true) and appends a corresponding TAP line.
See also "require_ok" below.
Evaluates the first argument with Shell inverse boolean semantics (0 is false) and appends a corresponding TAP line.
Tests if ARG1 and ARG2 are equal and appends a corresponding TAP line.
Tests if ARG1 and ARG2 are not equal and appends a corresponding TAP line.
Appends a complete TAP line where you have taken care for the "ok"/"not ok" at the beginning.
Appends a complete comment line starting with "#". It appears directly after the last added TAP line so it can be used for diagnostics.
Appends a key:value line at the final tapdata YAML block. The key must start with letter and consist of only alphanum an underscore.
Appends a diagnostic comment that starts with "#".
All require_*
functions check for something and gracefully exit
the script if the requirement is not fulfilled. Use this to
allow the script to run everywhere without polluting results with
false negatives.
Evaluates the first argument with Shell boolean semantics (0 is true) and appends a corresponding TAP line.
If it reports "not ok" the script gracefully exits.
Ensures vendor is AMD and cpu family from /proc/cpuinfo
is in a
minimum/maximum range. If you don't specify MIN it defaults to 0. If
you don't specify MAX it defaults to MIN.
Verifies that the string "foo" occurs in /proc/cpuinfo
flags section.
Verify that regex "^CONFIG_FOO=." occurs in /proc/config.gz or /boot/config/$(uname -r).
Verify that the Linux kernel sources are installed under the /lib/modules directory.
Verify that the file "foo" exists.
Verify that the program "foo" is available.
Use it to declare external programs you call, like "awk", "bc", "perl", etc.
Verify that L3 cache is available (checked in /sys/devices/system/cpu/cpu0/cache/index3).
Verify that a variant of netcat
(netcat, nc) is available.
Verify that the user executing the script is root (UID 0).
Verify that the criticality level N of the script is allowed to be run, which is controlled by environment variable CRITICALITY. See "has_crit_level" for meaning of criticality levels.
Enables cpufreq and disables boosting. In case of errors the calling test is skipped.
Enables cpufreq and also core boosting. In case of errors the calling test is skipped.
Verify that the current LK release is less than version number.
Verify that the current LK release is less than required 1st level version number.
Verify that the current LK release is less than required 2nd level version number.
Verify that the current LK release is less than required 3rd level version number.
Verify if we are in a Xen guest.
Verify if we are in a KVM guest.
Verify if we are in a virtualized guest (Xen or KVM).
Verify if we are in a Tapper automation guest environment.
Verify that the CPU vendor is AMD.
Verify that the CPU vendor is Intel.
Verify that the CPU architecture is x86_64.
Verify that Linux kernel module MODULE_FOO is loaded.
All request_*
functions try to enable something and if that fails
mark it as #TODO but continue the test. It's kind of an "uncritical
require_*".
Enables cpufreq and disables boosting. The result will be reported and returned. Errors are marked as TODO.
Enables cpufreq and also core boosting. The result will be reported and returned. Errors are marked as TODO.
These are really just utilities to help you but they don't influence the behaviour like the require_* functions do.
Returns 0 (shell TRUE) if L3 cache is available (checked in /sys/devices/system/cpu/cpu0/cache/index3).
Returns 0 (shell TRUE) if Linux kernel module MODULE_FOO is loaded.
Returns 0 (shell TRUE) if string "foo" occurs in /proc/cpuinfo
flags
section.
Returns 0 (shell TRUE) if regex "^CONFIG_FOO=." occurs in /proc/config.gz or /boot/config/$(uname -r).
Returns 0 (shell TRUE) if the Linux kernel sources are installed under the /lib/modules directory.
Return 0 (shell TRUE) if the file "foo" exists.
Return 0 (shell TRUE) if the program "foo" is available.
Checks whether the criticality level N of the script is allowed to be run, which is controlled by environment variable CRITICALITY.
The criticality levels are defined as this:
- 0: not critical
- 1: read sysfs/debugfs/proc files
- 2: read HW (MSRs/Northbridge)
- 3: write sysfs/debugfs/proc files
- 4: write HW (MSRs/Northbridge) or potentially crash the machine
Prints vendor "AMD" or "Intel" from /proc/cpuinfo
.
Returns 0 (shell TRUE) if vendor is Intel.
Returns 0 (shell TRUE) if vendor is AMD.
Returns 0 (shell TRUE) if processor type is ARM.
Prints a random integer between 0 and MAX (default 32768).
Print cpu family from /proc/cpuinfo
.
Print cpu family from /proc/cpuinfo in hex syntax (0x...).
Print cpu stepping from /proc/cpuinfo
Print cpu model from /proc/cpuinfo in decimal.
Print cpu model from /proc/cpuinfo in hex.
Print number of cpus.
Returns 0 (shell TRUE) if cpu family from /proc/cpuinfo is greater or equal to MINFAMILY. Defaults to 0.
Returns 0 (shell TRUE) if cpu family from /proc/cpuinfo is less or equal to MAXFAMILY. Defaults to 999.
Returns 0 (shell TRUE) if cpu model from /proc/cpuinfo is greater or equal to MINMODEL. Defaults to 0.
Returns 0 (shell TRUE) if cpu model from /proc/cpuinfo is less or equal to MAXMODEL. Defaults to 2,457.
Goes through all specified filenames and prints the first one that exists and is readable.
Returns 0 (shell TRUE) if WORD appears in "SPACE SEPARATED LIST OF WORDS". Remember the usual shell quoting rules.
Prints the entire kernel verion from uname -r.
Prints the 1st part of the kernel version number from uname -r.
Prints the 2nd part of the kernel version number from uname -r.
Prints the 3rd part of the kernel version number from uname -r.
Check if we are in a Xen guest.
Check if we are in a KVM guest.
Check if we are in a virtualized guest (Xen or KVM).
Check if we are in a Tapper automation guest environment.
Check if we are running on an x86_64 machine. Returns 0 (shell TRUE) if CPU architecture is x86_64.
Prepares the Linux kernel sources under the /usr/src/linux directory using the make command.
You can
- use environment variables to provide more content
- provide commandline params that "Do What I Mean"
- define hooks (functions and files) to be called
These variables are expected to be set inside the script to declare meta information or influence behaviour:
TAP[*]
- Array of TAP linesTAPDATA[*]
- Array of YAML lines that contain data in TAPHEADERS[*]
- Array of Tapper headersOUTPUT[*]
- Array of additional output linesSUITENAME
- alternative suite name instead of $0SUITEVERSION
- alternative suite versionKEYWORDS
- space separated keywords to influence suite nameOSNAME
- alternative OS descriptionCHANGESET
- alternative changesetHOSTNAME
- alternative hostnameTICKETURL
- relevant URL in used ticket system (Bugzilla)WIKIURL
- relevant URL in used wikiPLANNINGID
- relevant task planning id (MS Project, TaskJuggler)NOSEND
- if "1" no sending to Tapper happensNOUPLOAD
- if "1" no uploading of default files happensREQUIRES_GENERATE_TAP
- if "1" then require_* functions generate additional "ok" line on success
These variables are expected to be set from outside of the script to influence behaviour:
EXIT_ON_SKIPALL
- if "1" then on skip_all we immediately exit with 254 and do not send a reportCRITICALITY
- Sets the allowed maximal criticality level. Scripts with higher level do skip_allTAPPER_REPORT_SERVER
- alternative report server
--version
- print version number and exitnok
- declare something was not ok- [integer] - exit code of a program, 0 == ok, else not (Hint: use '$?' to refer to last program)
- [filename] - upload the file
These are optional shell functions that you can define in your test script and that will be called in certain places.
- executed at the end of autoreport's main()
- all stdout will be part of the report
They look like this: http://tapper/tapper/reports/id/129218
- report group
- testrun
- suite name
- suite version
- machine name
- reporter name (owner)
- uname
- OS name
- kernel version
- changeset
- kernel flags
- cpuinfo
- ram
- execution time
- bogomips
- itself
- /proc/cpuinfo
- /proc/devices
- /proc/version
- other files you give as params