Preface

This book is organised as three sub-books; getting started, writing tests and reference.

Why Megatest?

The Megatest project was started for two reasons, the first was an immediate and pressing need for a generalized tool to manage a suite of regression tests and the second was the fact that the author had written or maintained several such tools at different companies over the years and it seemed a good thing to have a single open source tool, flexible enough to meet the needs of any team doing continuous integrating and or running a complex suite of tests for release qualification.

Megatest Design Philosophy

Megatest is intended to provide the minimum needed resources to make writing a suite of tests and tasks for implementing continuous build for software, design engineering or process control (via owlfs for example) without being specialized for any specific problem space. Megatest in of itself does not know what constitutes a PASS or FAIL of a test or task. In most cases megatest is best used in conjunction with logpro or a similar tool to parse, analyze and decide on the test outcome.

  • Self-checking -Repeatable strive for directed or self-checking test as opposed to delta based tests

  • Traceable - environment variables, host OS and other possibly influential variables are captured and kept recorded.

  • Immutable - once this test is run it cannot be easily overwritten or accidentally modified.

  • Repeatable - this test result can be recreated in the future

  • Relocatable - the testsuite or automation area can be checked out and the tests run anywhere

  • Encapsulated - the tests run in self-contained directories and all inputs and outputs to the process can be found in the run areas.

  • Deployable - anyone on the team, at any site, at any time can run the flow

Megatest Architecture

All data to specify the tests and configure the system is stored in plain text files. All system state is stored in an sqlite3 database. Tests are launched using the launching system available for the distributed compute platform in use. A template script is provided which can launch jobs on local and remote Linux hosts. Currently megatest uses the network filesystem to call home to your master sqlite3 database.

Road Map

Note 1: This road-map is still evolving and subject to change without notice.

Architecture Refactor

Goals

  1. Reduce load on the file system. Sqlite3 files on network filesystem can be a burden.

  2. Reduce number of servers and frequency of start/stop. This is mostly an issue of clutter but also a reduction in "moving parts".

  3. Coalesce activities to a single home host where possible. Give the user feedback that they have started the dashboard on a host other than the home host.

  4. Reduce number of processes involved in managing running tests.

Changes Needed

  1. ACID compliant db will be on /tmp and synced to megatest.db with a five second max delay.

  2. Read/writes to db for processes on homehost will go direct to /tmp megatest.db file.

  3. Read/wites fron non-homehost processes will go through one server. Bulk reads (e.g. for dashboard or list-runs) will be cached on the current host in /tmp and synced from the home megatest.db in the testsuite area.

  4. Db syncs rely on the target db file timestame minus some margin.

  5. Since bulk reads do not use the server we can switch to simple RPC for the network transport.

  6. Test running manager process extended to manage multiple running tests.

Current Items

ww05 - migrate to inmem-db

  1. Switch to inmem db with fast sync to on disk db’s [DONE]

  2. Server polls tasks table for next action

    1. Task table used for tracking runner process [DONE]

    2. Task table used for jobs to run

    3. Task table used for queueing runner actions (remove runs, cleanRunExecute, etc)

shifting, note that the preceding blank line is needed.

Installation

Dependencies

Chicken scheme and a number of "eggs" are required for building Megatest. See the script installall.sh in the utils directory of the source distribution for an automated way to install everything needed for building Megatest on Linux.

Getting Started

Getting started with Megatest

Creating a testsuite or flow and your first test or task.

After installing Megatest you can create a flow or testsuite and add some tests using the helpers. Here is a quickstart sequence to get you up and running your first automated testsuite.

Creating a Megatest Area

Choose Target Keys

First choose your "target" keys. These are used to organise your runs in a way that is meaningful to your project. If you are unsure about what to use for keys just use a single generic key such as "RUNTYPE". These keys will be used to hand values to your tests via environment variables so ensure they are unique. Prefixing them with something such as PROJKEYS_ is a good strategy.

Examples of keys:

Table 1. Example keys
Option Description

RELEASE/ITERATION

This example is used by Megatest for its internal QA.

ARCH/OS/RELEASE

For a software project targeting multiple platforms

UCTRLR/NODETYPE

Microcontroller project with different controllers running same software

Create Area Config Files

You will need to choose locations for your runs (the data generated every time you run the testsuite) and link tree. For getting started answer the prompts with "runs" and "links". We use the Unix editor "vi" in the examples below but you can use any plain text editor.

Using the helper to create a Megatest area
megatest -create-megatest-area

# optional: verify that the settings are ok
vi megatest.config
vi runconfigs.config

Creating a Test

Choose the test name for your first test and run the helper. You can edit the files after the initial creation. You will need to enter names and scripts for the steps to be run and then edit the tests/<testname>/testconfig file and modify the logpro rules to properly process the log output from your steps. For your first test just hit enter for the "waiton", "priority" and iteration variable prompts.

Hint: for geting started make your logpro rules very liberal. expect:error patterns should match nothing and comment out expect:required rules.

Using the helper to create a Megatest test
megatest -create-test myfirsttest

# then edit the generated config
vi tests/myfirsttest/testconfig

Running your test

First choose a target and runname. If you have a two-place target such as RELEASE/ITERATION a target would look like v1.0/aff3 where v1.0 is the RELEASE and aff3 is the ITERATION. For a run name just use something like run1.

Running all tests (testpatt of "%" matches all tests)
megatest -run -target v1.0/aff3 -runname run1 -testpatt % -log run1.log

Viewing the results

Start the dashboard and browse your run in the "Runs" tab.

Starting dashboard
dashboard -rows 24

Writing Tests

Creating a new Test

The following steps will add a test "yourtestname" to your testsuite. This assumes starting from a directory where you already have a megatest.config and runconfigs.config.

  1. Create a directory tests/yourtestname

  2. Create a file tests/yourtestname/testconfig

Contents of minimal testconfig
[ezsteps]
stepname1 stepname.sh

# test_meta is a section for storing additional data on your test
[test_meta]
author myname
owner  myname
description An example test
reviewed never

This test runs a single step called "stepname1" which runs a script "stepname.sh". Note that although it is common to put the actions needed for a test step into a script it is not necessary.

How To Do Things

Process Runs

Remove Runs

From the dashboard click on the button (PASS/FAIL…) for one of the tests. From the test control panel that comes up push the clean test button. The command field will be prefilled with a template command for removing that test. You can edit the command, for example change the argument to -testpatt to "%" to remove all tests.

Remove the test diskperf and all it’s items
megatest -remove-runs -target ubuntu/nfs/none -runname ww28.1a -testpatt diskperf/% -v
Remove all tests for all runs and all targets
megatest -remove-runs -target %/%/% -runname % -testpatt % -v

Archive Runs

Megatest supports using the bup backup tool (https://bup.github.io/) to archive your tests for efficient storage and retrieval. Archived data can be rapidly retrieved if needed. The metadata for the run (PASS/FAIL status, run durations, time stamps etc.) are all preserved in the megatest database.

For setup information see the Archiving topic in the reference section of this manual.

To Archive

Hint: use the test control panel to create a template command by pushing the "Archive Tests" button.

Archive a full run
megatest -target ubuntu/nfs/none -runname ww28.1a -archive save-remove -testpatt %
To Restore
Retrieve a single test
megatest -target ubuntu/nfs/none -runname ww28.1a -archive restore -testpatt diskperf/%

Hint: You can browse the archive using bup commands directly.

bup -d /path/to/bup/archive ftp

Submit jobs to Host Types based on Test Name

In megatest.config
[host-types]
general ssh #{getbgesthost general}
nbgeneral nbjob run JOBCOMMAND -log $MT_LINKTREE/$MT_TARGET/$MT_RUNNAME.$MT_TESTNAME-$MT_ITEM_PATH.lgo

[hosts]
general cubian xena

[launchers]
envsetup general
xor/%/n 4C16G
% nbgeneral

[jobtools]
launcher bsub
# if defined and not "no" flexi-launcher will bypass launcher unless there is no
# match.
flexi-launcher yes

Tricks

This section is a compendium of a various useful tricks for debugging, configuring and generally getting the most out of Megatest.

Limiting your running jobs

The following example will limit a test in the jobgroup "group1" to no more than 10 tests simultaneously.

In your testconfig:

[test_meta]
jobgroup group1

In your megatest.config:

[jobgroups]
group1 10
custdes 4

Debugging Tricks

Examining The Environment

Test Control Panel - xterm

From the dashboard click on a test PASS/FAIL button. This brings up a test control panel. Aproximately near the center left of the window there is a button "Start Xterm". Push this to get an xterm with the full context and environment loaded for that test. You can run scripts or ezsteps by copying from the testconfig (hint, load up the testconfig in a separate gvim or emacs window). This is the easiest way to debug your tests.

During Config File Processing

It is often helpful to know the content of variables in various contexts as Megatest does the actions needed to run your tests. A handy technique is to force the startup of an xterm in the context being examined.

For example, if an item list is not being generated as expected you can inject the startup of an xterm as if it were an item:

Original items table
[items]
CELLNAME [system getcellname.sh]
Items table modified for debug
[items]
DEBUG [system xterm]
CELLNAME [system getcellnames.sh]

When this test is run an xterm will pop up. In that xterm the environment is exactly that in which the script "getcellnames.sh" would run. You can now debug the script to find out why it isn’t working as expected.

Organising Your Tests and Tasks

The default location "tests" for storing tests can be extended by adding to your tests-paths section.

[misc]
parent #{shell dirname $(readlink -f .)}

[tests-paths]
1 #{get misc parent}/simplerun/tests

The above example shows how you can use addition sections in your config file to do complex processing. By putting results of relatively slow operations into variables the processing of your configs can be kept fast.

Alternative Method for Running your Job Script

Directly running job in testconfig
[setup]
runscript main.csh

The runscript method is essentially a brute force way to run scripts where the user is responsible for setting STATE and STATUS and managing the details of running a test.

Debugging Server Problems

Some handy Unix commands to track down issues with servers not communicating with your test manager processes. Please put in tickets at https://www.kiatoa.com/fossils/megatest if you have problems with servers getting stuck.

sudo lsof -i
sudo netstat -lptu
sudo netstat -tulpn

Reference

Config File Helpers

Various helpers for more advanced config files.

Table 2. Helpers
Helper Purpose Valid values Comments

#{scheme (scheme code…)}

Execute arbitrary scheme code

Any valid scheme

Value returned from the call is converted to a string and processed as part of the config file

#{system command}

Execute program, inserts exit code

Any valid Unix command

Discards the output from the program

#{shell command} or #{sh …}

Execute program, inserts result from stdout

Any valid Unix command

Value returned from the call is converted to a string and processed as part of the config file

#{realpath path} or #{rp …}

Replace with normalized path

Must be a valid path

#{getenv VAR} or #{gv VAR}

Replace with content of env variable

Must be a valid var

#{get s v} or #{g s v}

Replace with variable v from section s

Variable must be defined before use

#{rget v}

Replace with variable v from target or default of runconfigs file

Replace with the path to the megatest testsuite area

Config File Settings

Settings in megatest.config

Config File Additional Features

Including output from a script as if it was inline to the config file:

[scriptinc myscript.sh]

If the script outputs:

[items]
A a b c
B d e f

Then the config file would effectively appear to contain an items section exactly like the output from the script. This is extremely useful when dynamically creating items, itemstables and other config structures. You can see the expansion of the call by looking in the cached files (look in your linktree for megatest.config and runconfigs.config cache files and in your test run areas for the expanded and cached testconfig).

Disk Space Checks

Some parameters you can put in the [setup] section of megatest.config:

# minimum space required in a run disk
minspace 10000000

# minimum space required in dbdir:
dbdir-space-required 100000

# script that takes path as parameter and returns number of bytes available:
free-space-script check-space.sh

Trim trailing spaces

[configf:settings trim-trailing-spaces yes]

Job Submission Control

Submit jobs to Host Types based on Test Name
In megatest.config
[host-types]
general   nbfake
remote    bsub

[launchers]
runfirst/sum% remote
% general

[jobtools]
launcher bsub
# if defined and not "no" flexi-launcher will bypass launcher unless
# there is no host-type match.
flexi-launcher yes
host-types

List of host types and the commandline to run a job on that host type.

host-type ⇒ launch command
general nbfake
launchers
test/itempath ⇒ host-type
runfirst/sum% remote
Miscellaneous Setup Items

Attempt to rerun tests in "STUCK/DEAD", "n/a", "ZERO_ITEMS" states.

In megatest.config
[setup]
reruns 5
Run time limit
[setup]
# this will automatically kill the test if it runs for more than 1h 2m and 3s
runtimelim 1h 2m 3s

Tests browser view

The tests browser (see the Run Control tab on the dashboard) has two views for displaying the tests.

  1. Dot (graphviz) based tree

  2. No dot, plain listing

The default is the graphviz based tree but if your tests don’t view well in that mode then use "nodot" to turn it off.

[setup]
nodot

Dashboard settings

Runs tab buttons, font and size
[dashboard]
btn-height x14
btn-fontsz 10
cell-width 60

Database settings

Table 3. Database config settings in [setup] section of megatest.config
Var Purpose Valid values Comments

delay-on-busy

Prevent concurrent access issues

yes|no or not defined

Default=no, may help on some network file systems, may slow things down also.

daemonize

Daemonize the server on start

yes|no or not defined

Default=no

faststart

All direct file access to sqlite db files

yes|no or not defined

Default=yes, suggest no for central automated systems and yes for interactive use

homehost

Start servers on this host

<hostname>

Defaults to local host

hostname

Hostname to bind to

<hostname>|-

On multi-homed hosts allows binding to specific hostname

lowport

Start searching for a port at this portnum

32768

required

Server required

yes|no or not defined

Default=no, force start of server always

server-query-threshold

Start server when queries take longer than this

number in milliseconds

Default=300

timeout

http api timeout

number in hours

Default is 1 minute, do not change

The testconfig File

Setup section

Header

[setup]

The runscript method is a brute force way to run scripts where the user is responsible for setting STATE and STATUS

runscript main.csh

Requirements section

Header
[requirements]

Wait on Other Tests

# A normal waiton waits for the prior tests to be COMPLETED
# and PASS, CHECK or WAIVED
waiton test1 test2

Mode

The default (i.e. if mode is not specified) is normal. All pre-dependent tests must be COMPLETED and PASS, CHECK or WAIVED before the test will start

[requirements]
mode   normal

The toplevel mode requires only that the prior tests are COMPLETED.

[requirements]
mode toplevel

A item based waiton will start items in a test when the same-named item is COMPLETED and PASS, CHECK or WAIVED in the prior test. This was historically called "itemwait" mode. The terms "itemwait" and "itemmatch" are synonyms.

[requirements]
mode itemmatch

Overriding Enviroment Variables

Override variables before starting the test. Can include files (perhaps generated by megatest -envdelta or similar).

[pre-launch-env-vars]
VAR1 value1

# Get some generated settings
[include ../generated-vars.config]

# Use this trick to unset variables
#{scheme (unsetenv "FOOBAR")}

Itemmap Handling

For cases were the dependent test has a similar but not identical itempath to the downstream test an itemmap can allow for itemmatch mode

[requirements]
mode itemmatch
itemmap .*x/ y/

# ## pattern replacement notes
#
# ## Example
# ## Remove everything up to the last /
itemmap .*/
#
# ## Example
# ## Replace foo/ with bar/
itemmap foo/ bar/

# multi-line; matches are applied in the listed order
# The following would map:
#   a123b321 to b321fooa123 then to 321fooa123p
#
itemmap (a\d+)(b\d+) \2foo\1
  b(.*) \1p

Complex mappings

Complex mappings can be handled with the [itemmap] section

complex-itemmap.png

Example:

  1. Request to run D/1/res

  2. Megatest uses rule "(\d+)/res" → "\1/aa" to create item C/1/aa from D/1/res

  3. Full list to be run is now: D/1/res, C/1/aa

  4. Megatest uses rule "(\d+)/aa" → "aa/\1" to create item A/aa/1

  5. Full list to be run is now: D/1/res, C/1/aa, A/aa/1

Testconfig for Test C
[requirements]
waiton A B

[itemmap]
A (\d+)/aa aa/\1
B (\d+)/bb
Testconfig for Test D
[requirements]
waiton C
itemmap (\d+)/res \1/aa
Testconfig for Test E
[requirements]
waiton C
itemmap (\d+)/res \1/bb

Dynamic Flow Dependency Tree

Autogeneration waiton list for dynamic flow dependency trees
[requirements]
# With a toplevel test you may wish to generate your list
# of tests to run dynamically
#
waiton #{shell get-valid-tests-to-run.sh}

Run time limit

[requirements]
runtimelim 1h 2m 3s  # this will automatically kill the test if it runs for more than 1h 2m and 3s

Skip

A test with a skip section will conditional skip running.

Skip section example
[skip]
prevrunning x
# rundelay 30m 15s

Skip on Still-running Tests

# NB// If the prevrunning line exists with *any* value the test will
# automatically SKIP if the same-named test is currently RUNNING. The
# "x" can be any string. Comment out the prevrunning line to turn off
# skip.

[skip]
prevrunning x

Skip if a File Exists

[skip]
fileexists /path/to/a/file # skip if /path/to/a/file exists

Skip if test ran more recently than specified time

Skip if this test has been run in the past fifteen minutes and 15 seconds.
[skip]
rundelay 15m 15s

Disks

A disks section in testconfig will override the disks section in megatest.config. This can be used to allocate disks on a per-test or per item basis.

Controlled waiver propagation

If test is FAIL and previous test in run with same MT_TARGET is WAIVED then apply the following rules from the testconfig: If a waiver check is specified in the testconfig apply the check and if it passes then set this FAIL to WAIVED

Waiver check has two parts, 1) a list of waiver, rulename, filepatterns and 2) the rulename script spec (note that "diff" and "logpro" are predefined)

###### EXAMPLE FROM testconfig #########
# matching file(s) will be diff'd with previous run and logpro applied
# if PASS or WARN result from logpro then WAIVER state is set
#
[waivers]
# logpro_file    rulename      input_glob
waiver_1         logpro        lookittmp.log

[waiver_rules]

# This builtin rule is the default if there is no <waivername>.logpro file
# diff   diff %file1% %file2%

# This builtin rule is applied if a <waivername>.logpro file exists
# logpro diff %file1% %file2% | logpro %waivername%.logpro %waivername%.html

Ezsteps

Example ezsteps with logpro rules
[ezsteps]
lookittmp   ls /tmp

[logpro]
lookittmp ;; Note: config file format supports multi-line entries where leading whitespace is removed from each line
  ;;     a blank line indicates the end of the block of text
  (expect:required in "LogFileBody" > 0 "A file name that should never exist!" #/This is a awfully stupid file name that should never be found in the temp dir/)

To transfer the environment to the next step you can do the following:

$MT_MEGATEST -env2file .ezsteps/${stepname}

Triggers

In your testconfig triggers can be specified

[triggers]

# Call script running.sh when test goes to state=RUNNING, status=PASS
RUNNING/PASS running.sh

# Call script running.sh any time state goes to RUNNING
RUNNING/ running.sh

# Call script onpass.sh any time status goes to PASS
PASS/ onpass.sh

Scripts called will have; test-id test-rundir trigger, added to the commandline.

HINT

To start an xterm (useful for debugging), use a command line like the following:

[triggers]
COMPLETED/ xterm -e bash -s --
Note There is a trailing space after the --

Override the Toplevel HTML File

Megatest generates a simple html file summary for top level tests of iterated tests. The generation can be overridden. NOTE: the output of the script is captured from stdout to create the html.

For test "runfirst" override the toplevel generation with a script "mysummary.sh"
# Override the rollup for specific tests
[testrollup]
runfirst mysummary.sh

Archiving Setup

In megatest.config add the following sections:

megatest.config
[archive]
# where to get bup executable
# bup /path/to/bup

[archive-disks]

# Archives will be organised under these paths like this:
#  <testsuite>/<creationdate>
# Within the archive the data is structured like this:
#  <target>/<runname>/<test>/
archive0 /mfs/myarchive-data/adisk1

Handling Environment Variables

It is often necessary to capture and or manipulate environment variables. Megatest has some facilities built in to help.

Capture variables

Commands
# capture the current enviroment into a db called envdat.db under
# the context "before"
megatest -envcap before

# capture the current environment into a db called startup.db with
# context "after"
megatest -envcap after startup.db

# write the diff from before to after
megatest -envdelta before-after -dumpmode bash

Dump modes include bash, csh and config. You can include config data into megatest.config or runconfigs.config.

Example of generating and using config data
megatest -envcap original
# do some stuff here
megatest -envcap munged
megatest -envdelta original-munged -dumpmode ini -o modified.config

Then in runconfigs.config

Example of using modified.config in a testconfig
cat testconfig

[pre-launch-env-vars]
[include modified.config]

Programming API

These routines can be called from the megatest repl.

Table 4. API Keys Related Calls
API Call Purpose comments Returns Comments

(rmt:get-key-val-pairs run-id)

#t=success/#f=fail

Works only if the server is still reachable

(rmt:get-keys run-id)

( key1 key2 … )

Megatest Internals

server.png

Example Index