Avocado Workshop

Get Started. It's Free
or sign up with your email address
Rocket clouds
Avocado Workshop by Mind Map: Avocado Workshop

1. Topics

1.1. Basic usage

1.1.1. Execute binary

1.1.1.1. ./scripts/avocado run /bin/true

1.1.1.1.1. when installed use only "avocado run /bin/true"

1.1.1.2. ./scripts/avocado run /bin/true /bin/false

1.1.1.3. ./scripts/avocado run passtest failtest warntest skiptest errortest sleeptest

1.1.2. Help and docs

1.1.2.1. ./scripts/avocado -h

1.1.2.2. ./scripts/avocado run -h

1.1.2.3. ...

1.1.2.4. cd docs && make html

1.1.3. Execute binary and compare outputs

1.1.3.1. Used for tests which should generate the same stdout/stderr

1.1.3.2. Possibility to combine with other plugins (run inside GDB,...)

1.1.3.3. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh

1.1.3.4. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh --output-check-record all

1.1.3.5. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh

1.1.3.6. # modify the file

1.1.3.7. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh

1.1.3.8. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh --disable-output-check

1.1.3.9. # exit -1

1.1.3.10. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh

1.1.3.11. ./scripts/avocado run ./DEVCONF/Basic_usage/output_compare.sh --disable-output-check

1.1.4. Execute binary and parse results using wrapper

1.1.4.1. Used to run the same steps with various wrappers

1.1.4.2. For example run complex testsuite with perf/strace/... (viz. Wrapper section)

1.1.4.3. Alternatively use it to "translate" existing binaries to Avocado (here)

1.1.4.4. DEVCONF/Basic_usage/testsuite.sh

1.1.4.4.1. nasty testsuite which doesn't return exit_code

1.1.4.5. ./scripts/avocado run DEVCONF/Basic_usage/testsuite.sh

1.1.4.6. ./scripts/avocado run DEVCONF/Basic_usage/testsuite.sh --wrapper DEVCONF/Basic_usage/testsuite-wrapper.sh:*testsuite.sh

1.1.4.7. # remove FAIL test

1.1.4.8. ./scripts/avocado run DEVCONF/Basic_usage/testsuite.sh --wrapper DEVCONF/Basic_usage/testsuite-wrapper.sh:*testsuite.sh

1.1.4.9. # remove WARN test

1.1.4.10. ./scripts/avocado run DEVCONF/Basic_usage/testsuite.sh --wrapper DEVCONF/Basic_usage/testsuite-wrapper.sh:*testsuite.sh

1.1.4.11. More details in Wrapper section

1.1.5. Multiplex using ENV

1.1.5.1. ./scripts/avocado run examples/tests/env_variables.sh

1.1.5.2. ./scripts/avocado run examples/tests/env_variables.sh -m examples/tests/env_variables.sh.data/env_variables.yaml

1.1.5.3. ./scripts/avocado multiplex

1.1.5.3.1. -c

1.1.5.3.2. -d

1.1.5.3.3. -t

1.1.5.3.4. -h ;-)

1.1.5.4. This is pretty close to QA, right?

1.1.5.5. More details in Multiplex section

1.1.6. Grab sysinfo

1.1.6.1. ./scripts/avocado run passtest --open-browser

1.2. Jenkins/CI

1.2.1. Jenkins?

1.2.1.1. Jenkins

1.2.2. Quick&dirty setup

1.2.3. avocado simple

1.2.4. avocado parametrized

1.2.5. avocado lots of tests

1.2.6. avocado multi

1.2.6.1. multi scenarios

1.2.6.2. multi archs

1.2.6.3. multi workers (OSs)

1.2.7. avocado git poll

1.3. Writing tests in Python

1.3.1. Can be executed as

1.3.1.1. Inside Avocado

1.3.1.1.1. ./scripts/avocado run examples/tests/passtest.py

1.3.1.2. As python scripts

1.3.1.2.1. examples/tests/passtest.py

1.3.2. Logging

1.3.2.1. Possibility to set test as WARN

1.3.2.1.1. self.log.warn("In the state of Denmark there was an odor of decay")

1.3.2.1.2. See warntest test

1.3.2.2. Log more important steps

1.3.2.2.1. self.log.info("I successfully executed this important step with %s args" % args)

1.3.2.2.2. self.log.debug("Executing iteration %s" % iteration)

1.3.2.2.3. self.log.warn("You already know me")

1.3.2.2.4. self.log.error("Everyone should check these messages on failure")

1.3.2.2.5. stdout

1.3.2.2.6. stderr

1.3.3. Whiteboard

1.3.3.1. ./scripts/avocado run examples/tests/whiteboard.py

1.3.3.2. cat ~/avocado/job-results/latest/test-results/examples/tests/whiteboard.py/whiteboard

1.3.4. Advanced usage of params

1.3.4.1. See Multiplexer section

1.3.5. Advanced GDB

1.3.5.1. See GDB section

1.3.6. Avocado-virt

1.3.6.1. See Avocado-virt section

1.4. Test on remote machine

1.4.1. remote

1.4.1.1. ./scripts/avocado run passtest --remote-hostname 192.168.122.235 --remote-username root --remote-password 123456

1.4.1.1.1. Connects

1.4.1.1.2. Copies tests directories

1.4.1.1.3. Runs avocado inside machine with --json --archive

1.4.1.1.4. Grab and store results

1.4.1.1.5. Report results localy

1.4.1.2. --remote-no-copy

1.4.2. vm

1.4.2.1. run in libvirt machine

1.4.2.2. ./scripts/avocado run examples/tests/passtest.py importerror.py corrupted.py pass.py passtest --vm-domain vm1 --vm-hostname 192.168.122.235 --vm-username root --vm-password 123456 --vm-cleanup

1.4.2.2.1. Checks if domain exists

1.4.2.2.2. Start it if not already started

1.4.2.2.3. (--vm-clenaup) Creates snapshot

1.4.2.2.4. call remote test

1.4.2.2.5. (--vm-cleanup) Restore snapshot

1.4.2.3. --vm-cleanup

1.4.2.4. --vm-no-copy

1.4.3. docker plugin

1.4.3.1. first think what we require

1.4.3.1.1. docker run -v $LOCAL_PATH:$CONT_PATH $IMAGE avocado run $tests

1.4.3.1.2. grab the results

1.4.3.1.3. we don't require any remote interaction, only simple execution

1.4.3.2. plugin initialization

1.4.3.2.1. 1) name, status

1.4.3.2.2. 2) configuration hook

1.4.3.2.3. 3) activation hook

1.4.3.2.4. class RunDocker

1.4.3.3. Prerequisites

1.4.3.3.1. prepare docker cmd

1.4.3.3.2. copy tests to shared location

1.4.3.3.3. class DockerTestResult

1.4.3.4. Actual execution

1.4.3.4.1. 1) Execute the tests

1.4.3.4.2. 2) Grab the results

1.4.3.4.3. class DockerTestRunner

1.5. GDB

1.5.1. ./scripts/avocado run DEVCONF/GDB/doublefree*.py

1.5.2. ./scripts/avocado run --gdb-run-bin=doublefree: DEVCONF/GDB/doublefree.py

1.5.2.1. backtrace

1.5.2.2. ...

1.5.3. ./scripts/avocado run --gdb-run-bin=doublefree DEVCONF/GDB/doublefree2.py

1.5.3.1. without ':' it stops at the beginning

1.5.3.2. we can use `ddd` or other GDB compatible programs

1.5.3.3. don't forget to resume the test (FIFO)

1.5.4. ./scripts/avocado run --gdb-run-bin=doublefree: DEVCONF/GDB/doublefree3.py --gdb-prerun-commands DEVCONF/GDB/doublefree3.py.data/gdb_pre --multiplex DEVCONF/GDB/doublefree3.py.data/iterations.yaml

1.5.4.1. OK, we reached the "handle_exception" function we want to investigate

1.5.4.2. n

1.5.4.3. n

1.5.4.4. jump +1

1.5.4.5. Works fine, hurray

1.6. Advanced GDB

1.6.1. vim DEVCONF/Advanced_GDB/modify_variable.py.data/doublefree.c

1.6.2. ./scripts/avocado run DEVCONF/Advanced_GDB/modify_variable.py --show-job-log

1.7. Wrappers

1.7.1. Valgrind

1.7.1.1. ./scripts/avocado run DEVCONF/Wrappers/doublefree.py --wrapper examples/wrappers/valgrind.sh:*doublefree --open-browser

1.7.1.2. cat /home/medic/avocado/job-results/latest/test-results/doublefree.py/valgrind.log.*

1.7.2. Strace

1.7.2.1. The same way as valgrind

1.7.2.2. Imagine for example crashing qemu machine running windows under very complex workload defined in test

1.7.3. Other

1.7.3.1. ltrace

1.7.3.2. perf

1.7.3.3. strace

1.7.3.4. time

1.7.3.5. valgrind

1.7.4. Custom wrappers

1.7.4.1. qemu on PPC

1.7.4.2. wrap executed programs

1.7.4.3. grab results

1.8. Multiplexer

1.8.1. Motivation

1.8.1.1. QA Engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 999999999 beers. Orders a lizard. Orders -1 beers. Orders a sfdeljknesv

1.8.1.1.1. by_order:     a_beer:         msg: a beer     0_beers:         msg: 0 beers     999999999:         msg: 999999999 beers     lizard:         msg: lizard     negative:         msg: -1 beers     noise:         msg: sfdeljknesv

1.8.2. How would you solve our problem?

1.8.2.1. !multiplex vs. !join

1.8.2.1.1. virt: hw: cpu: intel: amd: arm: fmt: !join qcow: qcow2: qcow2v3: raw: os: !join linux: !join Fedora: 19: Gentoo: windows: 3.11:

1.8.2.2. map tests to test->files

1.8.3. Usage

1.8.3.1. ./scripts/avocado multiplex -h

1.8.3.2. ./scripts/avocado multiplex -t

1.8.3.2.1. ./scripts/avocado multiplex -t DEVCONF/Multiplexer/nomux.yaml

1.8.3.2.2. ./scripts/avocado multiplex -t DEVCONF/Multiplexer/simple.yaml

1.8.3.2.3. ./scripts/avocado multiplex -t DEVCONF/Multiplexer/advanced.yaml

1.8.3.3. ./scripts/avocado multiplex -c

1.8.3.3.1. ./scripts/avocado multiplex -c DEVCONF/Multiplexer/simple.yaml

1.8.3.3.2. ./scripts/avocado multiplex -c DEVCONF/Multiplexer/advanced.yaml

1.8.3.4. ./scripts/avocado multiplex -cd examples/mux-selftest-advanced.yaml

1.8.3.4.1. eg. variant: 21

1.8.3.5. ./scripts/avocado run examples/tests/sleeptenmin.py -m DEVCONF/Multiplexer/simple.yaml

1.8.3.6. ./scripts/avocado run examples/tests/sleeptenmin.py -m DEVCONF/Multiplexer/advanced.yaml

1.8.3.7. ./scripts/avocado multiplex --filter-only/filter-out

1.8.3.7.1. ./scripts/avocado multiplex -c DEVCONF/Multiplexer/advanced.yaml --filter-only /by_method/shell

1.8.3.7.2. 2nd level filters

1.8.3.8. Additional tags

1.8.3.8.1. !using

1.8.3.8.2. !include

1.8.3.8.3. !remove_node

1.8.3.8.4. !remove_value

1.8.3.8.5. !join

1.8.4. Let's go crazy

1.8.4.1. ./scripts/avocado multiplex DEVCONF/Multiplexer/crazy.yaml

1.8.5. Future

1.8.5.1. Currently we update environment from used leaves

1.8.5.1.1. by_something:     first:         foo: bar by_whatever:     something:         foo: baz

1.8.5.2. Soon we want provide the whole layout

1.8.5.2.1. by_something:     first:         hello: world         foo: bar by_whatever:     something:         foo: baz

1.8.5.3. Automatic multiplexation

1.8.5.3.1. 1) without multiplexation

1.8.5.3.2. 2) test's file multiplexation

1.8.5.3.3. 3) global file multiplexation

1.9. Eclipse

1.9.1. Debugging

1.9.2. Remote debugging

1.9.2.1. download pydev

1.9.2.2. copy it to $PYTHONPATH

1.9.2.2.1. or add path in code:     import sys     sys.path.append('$PATH_TO_YOUR_PYDEV')

1.9.2.3. import pydevd pydevd.settrace("$ECLIPSE_IP_ADDR", True, True)

1.9.2.3.1. 1. True = forward stdout (optional)

1.9.2.3.2. 2. True = forward stderr (optional)

1.10. Install Avocado

1.10.1. Using from sources

1.10.1.1. # Uninstall previously installed versions

1.10.1.2. git clone https://github.com/avocado-framework/avocado.git

1.10.1.3. cd avocado

1.10.1.4. ./scripts/avocado ...

1.10.2. git

1.10.2.1. git clone https://github.com/avocado-framework/avocado.git

1.10.2.2. # pip install -r requirements.txt

1.10.2.3. python setup.py install

1.10.2.4. avocado ...

1.10.3. rpm

1.10.3.1. sudo curl http://copr.fedoraproject.org/coprs/lmr/Autotest/repo/fedora-20/lmr-Autotest-fedora-20.repo -o /etc/yum.repos.d/autotest.repo

1.10.3.2. sudo yum update

1.10.3.3. sudo yum install avocado

1.10.3.4. avocado ...

1.10.4. deb

1.10.4.1. echo "deb http://ppa.launchpad.net/lmr/avocado/ubuntu trusty main" >> /etc/apt/sources.list

1.10.4.2. sudo apt-get update

1.10.4.3. sudo apt-get install avocado

1.10.4.4. avocado ...

1.11. avocado-virt

1.11.1. Currently only demonstration of the Avocado flexibility

1.11.2. using git version

1.11.2.1. 1) git clone $avocado

1.11.2.2. 2) git clone $avocado-virt

1.11.2.3. 3) git clone $avocado-virt-tests

1.11.2.4. cd avocado/avocado ln -s ../../avocado-virt/avocado/virt virt cd -

1.11.2.5. cd avocado/avocado/plugins ln -s ../../avocado-virt/avocado/plugins/virt.py virt.py ln -s ../../avocado-virt/avocado/plugins/virt_bootstrap.py cd -

1.11.3. using installed version

1.11.3.1. python setup.py install

1.11.3.2. yum install avocado-virt

1.11.4. ./scripts/avocado virt-bootstrap

1.11.4.1. Downloads JeOS

1.11.4.2. Check permissions

1.11.5. ./scripts/avocado run ../avocado-virt-tests/qemu/boot.py

1.11.6. ./scripts/avocado run ../avocado-virt-tests/qemu/migration/migration.py

1.11.7. ./scripts/avocado run ../avocado-virt-tests/qemu/usb_boot.py

1.11.8. Qemu templates

1.11.8.1. ./scripts/avocado run DEVCONF/avocado-virt/boot_lspci.py --show-job-log

1.11.8.2. ./scripts/avocado run DEVCONF/avocado-virt/boot_lspci.py --show-job-log --qemu-template DEVCONF/avocado-virt/basic.tpl

2. About me

2.1. Lukáš Doktor

2.2. Happy Software Engineer at Red Hat

2.2.1. RHTS (bash)

2.2.2. Autotest/virt-test (python, virtualization)

2.2.3. Avocado (~3 months)

2.3. _

3. Introduction

3.1. Avocado is a next generation testing framework inspired by Autotest and modern development tools such as git. Whether you want to automate the test plan made by your development team, do continuous integration, or develop quick tests for the feature you're working on, avocado delivers the tools to help you out.

3.2. What is Avocado for me

3.2.1. .

3.2.2. Program which stores results of anything I want

3.2.3. Binary which provides means to help me execute anything using various environments

3.2.4. Set of python* libraries to simplify writing tests

3.2.5. Something easily integrateable with Jenkins (or othe CI)

3.2.6. Tool which allows me to share the results

3.2.7. Most importantly tool which allows me to do all the above in all possible variants

3.2.8. .

3.3. Avocado structure

4. Links:

4.1. Avocado homepage: http://avocado-framework.github.io/

4.2. Data for this presentation: https://www.dropbox.com/sh/1ucmenbf76vnmn5/AAB4pn157uOOn916JDg2yYzKa?dl=0

4.3. Recording: https://www.youtube.com/watch?feature=player_detailpage&v=rj3XMTS-fwE