blob: 6b6781d8609046246728e0f3a0c3e15777993731 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Copyright (C) 2013 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5
6# testimage.bbclass enables testing of qemu images using python unittests.
7# Most of the tests are commands run on target image over ssh.
8# To use it add testimage to global inherit and call your target image with -c testimage
9# You can try it out like this:
10# - first build a qemu core-image-sato
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011# - add IMAGE_CLASSES += "testimage" in local.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012# - then bitbake core-image-sato -c testimage. That will run a standard suite of tests.
13
14# You can set (or append to) TEST_SUITES in local.conf to select the tests
15# which you want to run for your target.
16# The test names are the module names in meta/lib/oeqa/runtime.
17# Each name in TEST_SUITES represents a required test for the image. (no skipping allowed)
18# Appending "auto" means that it will try to run all tests that are suitable for the image (each test decides that on it's own).
19# Note that order in TEST_SUITES is relevant: tests are run in an order such that
20# tests mentioned in @skipUnlessPassed run before the tests that depend on them,
21# but without such dependencies, tests run in the order in which they are listed
22# in TEST_SUITES.
23#
24# A layer can add its own tests in lib/oeqa/runtime, provided it extends BBPATH as normal in its layer.conf.
25
26# TEST_LOG_DIR contains a command ssh log and may contain infromation about what command is running, output and return codes and for qemu a boot log till login.
27# Booting is handled by this class, and it's not a test in itself.
28# TEST_QEMUBOOT_TIMEOUT can be used to set the maximum time in seconds the launch code will wait for the login prompt.
29
30TEST_LOG_DIR ?= "${WORKDIR}/testimage"
31
32TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033TEST_INSTALL_TMP_DIR ?= "${WORKDIR}/testimage/install_tmp"
34TEST_NEEDED_PACKAGES_DIR ?= "${WORKDIR}/testimage/packages"
35TEST_EXTRACTED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/extracted"
36TEST_PACKAGED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/packaged"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38RPMTESTSUITE = "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'smart rpm', '', d)}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039MINTESTSUITE = "ping"
40NETTESTSUITE = "${MINTESTSUITE} ssh df date scp syslog"
41DEVTESTSUITE = "gcc kernelmodule ldd"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043DEFAULT_TEST_SUITES = "${MINTESTSUITE} auto"
44DEFAULT_TEST_SUITES_pn-core-image-minimal = "${MINTESTSUITE}"
45DEFAULT_TEST_SUITES_pn-core-image-minimal-dev = "${MINTESTSUITE}"
46DEFAULT_TEST_SUITES_pn-core-image-full-cmdline = "${NETTESTSUITE} perl python logrotate"
47DEFAULT_TEST_SUITES_pn-core-image-x11 = "${MINTESTSUITE}"
48DEFAULT_TEST_SUITES_pn-core-image-lsb = "${NETTESTSUITE} pam parselogs ${RPMTESTSUITE}"
49DEFAULT_TEST_SUITES_pn-core-image-sato = "${NETTESTSUITE} connman xorg parselogs ${RPMTESTSUITE} \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050 ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python', '', d)}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050051DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "${NETTESTSUITE} connman xorg perl python \
52 ${DEVTESTSUITE} parselogs ${RPMTESTSUITE}"
53DEFAULT_TEST_SUITES_pn-core-image-lsb-dev = "${NETTESTSUITE} pam perl python parselogs ${RPMTESTSUITE}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054DEFAULT_TEST_SUITES_pn-core-image-lsb-sdk = "${NETTESTSUITE} buildcvs buildiptables buildgalculator \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055 connman ${DEVTESTSUITE} pam perl python parselogs ${RPMTESTSUITE}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056DEFAULT_TEST_SUITES_pn-meta-toolchain = "auto"
57
58# aarch64 has no graphics
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050059DEFAULT_TEST_SUITES_remove_aarch64 = "xorg"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
Patrick Williamsc0f7c042017-02-23 20:41:17 -060061# qemumips is quite slow and has reached the timeout limit several times on the YP build cluster,
62# mitigate this by removing build tests for qemumips machines.
63MIPSREMOVE ??= "buildcvs buildiptables buildgalculator"
64DEFAULT_TEST_SUITES_remove_qemumips = "${MIPSREMOVE}"
65DEFAULT_TEST_SUITES_remove_qemumips64 = "${MIPSREMOVE}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
67TEST_SUITES ?= "${DEFAULT_TEST_SUITES}"
68
69TEST_QEMUBOOT_TIMEOUT ?= "1000"
70TEST_TARGET ?= "qemu"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071
72TESTIMAGEDEPENDS = ""
73TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
75TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
76TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'createrepo-native:do_populate_sysroot', '', d)}"
77TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python-smartpm-native:do_populate_sysroot', '', d)}"
78TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg-utils-native:do_populate_sysroot', '', d)}"
79TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'deb', 'apt-native:do_populate_sysroot', '', d)}"
80
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081
82TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
83TESTIMAGELOCK_qemuall = ""
84
85TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
86
87testimage_dump_target () {
88 top -bn1
89 ps
90 free
91 df
92 # The next command will export the default gateway IP
93 export DEFAULT_GATEWAY=$(ip route | awk '/default/ { print $3}')
94 ping -c3 $DEFAULT_GATEWAY
95 dmesg
96 netstat -an
97 ip address
98 # Next command will dump logs from /var/log/
99 find /var/log/ -type f 2>/dev/null -exec echo "====================" \; -exec echo {} \; -exec echo "====================" \; -exec cat {} \; -exec echo "" \;
100}
101
102testimage_dump_host () {
103 top -bn1
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500104 iostat -x -z -N -d -p ALL 20 2
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 ps -ef
106 free
107 df
108 memstat
109 dmesg
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500110 ip -s link
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111 netstat -an
112}
113
114python do_testimage() {
115 testimage_main(d)
116}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600117
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500118addtask testimage
119do_testimage[nostamp] = "1"
120do_testimage[depends] += "${TESTIMAGEDEPENDS}"
121do_testimage[lockfiles] += "${TESTIMAGELOCK}"
122
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123def testimage_main(d):
124 import unittest
125 import os
126 import oeqa.runtime
127 import time
128 import signal
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500129 from oeqa.oetest import ImageTestContext
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 from oeqa.targetcontrol import get_target_controller
131 from oeqa.utils.dump import get_host_dumper
132
133 pn = d.getVar("PN", True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600135 test_create_extract_dirs(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 # we need the host dumper in test context
138 host_dumper = get_host_dumper(d)
139
140 # the robot dance
141 target = get_target_controller(d)
142
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143 # test context
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500144 tc = ImageTestContext(d, target, host_dumper)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145
146 # this is a dummy load of tests
147 # we are doing that to find compile errors in the tests themselves
148 # before booting the image
149 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500150 tc.loadTests()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 except Exception as e:
152 import traceback
153 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
154
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155 tc.extract_packages()
156 target.deploy()
157 try:
158 bootparams = None
159 if d.getVar('VIRTUAL-RUNTIME_init_manager', '') == 'systemd':
160 bootparams = 'systemd.log_level=debug systemd.log_target=console'
161 target.start(extra_bootparams=bootparams)
162 starttime = time.time()
163 result = tc.runTests()
164 stoptime = time.time()
165 if result.wasSuccessful():
166 bb.plain("%s - Ran %d test%s in %.3fs" % (pn, result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime))
167 msg = "%s - OK - All required tests passed" % pn
168 skipped = len(result.skipped)
169 if skipped:
170 msg += " (skipped=%d)" % skipped
171 bb.plain(msg)
172 else:
173 bb.fatal("%s - FAILED - check the task log and the ssh log" % pn)
174 finally:
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500175 signal.signal(signal.SIGTERM, tc.origsigtermhandler)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176 target.stop()
177
178def test_create_extract_dirs(d):
179 install_path = d.getVar("TEST_INSTALL_TMP_DIR", True)
180 package_path = d.getVar("TEST_PACKAGED_DIR", True)
181 extracted_path = d.getVar("TEST_EXTRACTED_DIR", True)
182 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
183 bb.utils.remove(package_path, recurse=True)
184 bb.utils.mkdirhier(install_path)
185 bb.utils.mkdirhier(package_path)
186 bb.utils.mkdirhier(extracted_path)
187
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500188
189testimage_main[vardepsexclude] =+ "BB_ORIGENV"
190
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500191inherit testsdk