WrapProcess.rst 1.8 KB
Newer Older
1 2
Wrap executables run by tests
=============================
3

4
Avocado allows the instrumentation of executables being run by a test
5 6
in a transparent way. The user specifies a script ("the wrapper") to be
used to run the actual program called by the test.
7

8 9 10
If the instrumentation script is implemented correctly, it should not
interfere with the test behavior. That is, the wrapper should avoid
changing the return status, standard output and standard error messages
11
of the original executable.
12

13 14 15
The user can be specific about which program to wrap (with a shell-like glob),
or if that is omitted, a global wrapper that will apply to all
programs called by the test.
16 17 18 19 20

Usage
-----

This feature is implemented as a plugin, that adds the `--wrapper` option
21
to the Avocado `run` command.  For a detailed explanation, please consult the
22
Avocado man page.
23 24 25 26 27 28

Example of a transparent way of running strace as a wrapper::

    #!/bin/sh
    exec strace -ff -o $AVOCADO_TEST_LOGDIR/strace.log -- $@

29
To have all programs started by ``test.py`` wrapped with ``~/bin/my-wrapper.sh``::
30 31 32

    $ scripts/avocado run --wrapper ~/bin/my-wrapper.sh tests/test.py

33
To have only ``my-binary`` wrapped with ``~/bin/my-wrapper.sh``::
34

35
    $ scripts/avocado run --wrapper ~/bin/my-wrapper.sh:*my-binary tests/test.py
36 37 38 39 40

Caveats
-------

* It is not possible to debug with GDB (`--gdb-run-bin`) and use
41 42
  wrappers (`--wrapper`) at the same time. These two options are
  mutually exclusive.
43

44 45 46
* You can only set one (global) wrapper. If you need functionality
  present in two wrappers, you have to combine those into a single
  wrapper script.
47

48
* Only executables that are run with the :mod:`avocado.utils.process` APIs
49 50
  (and other API modules that make use of it, like mod:`avocado.utils.build`)
  are affected by this feature.