summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2013-11-27 19:08:50 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-12-03 17:45:50 +0000
commit645dd61cd21b2b1c9d9c927447c68841685a1adf (patch)
tree9dd603414037879c7092a24e959fd8171f619720 /scripts
parent1fa51bf949cf6e789b942c1b4c0321fd68a39b10 (diff)
downloadpoky-645dd61cd21b2b1c9d9c927447c68841685a1adf.tar.gz
scripts/oe-selftest: script to run builds as unittest against bitbake or various scripts
The purpose of oe-selftest is to run unittest modules added from meta/lib/oeqa/selftest, which are tests against bitbake tools. Right now the script it's useful for simple tests like: - "bitbake --someoption, change some metadata, bitbake X, check something" type scenarios (PR service, error output, etc) - or "bitbake-layers <...>" type scripts and yocto-bsp tools. This commit also adds some helper modules that the tests will use and a base class. Also, most of the tests will have a dependency on a meta-selftest layer which contains specially modified recipes/bbappends/include files for the purpose of the tests. The tests themselves will usually write to ".inc" files from the layer or in conf/selftest.inc (which is added as an include in local.conf at the start and removed at the end) It's a simple matter or sourcing the enviroment, adding the meta-selftest layer to bblayers.conf and running: oe-selftest to get some results. It would finish faster if at least a core-image-minimal was built before. [ YOCTO #4740 ] (From OE-Core rev: 41a4f8fb005328d3a631a9036ceb6dcf75754410) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/oe-selftest148
1 files changed, 148 insertions, 0 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest
new file mode 100755
index 0000000000..db42e73470
--- /dev/null
+++ b/scripts/oe-selftest
@@ -0,0 +1,148 @@
1#!/usr/bin/env python
2
3# Copyright (c) 2013 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18# DESCRIPTION
19# This script runs tests defined in meta/lib/selftest/
20# It's purpose is to automate the testing of different bitbake tools.
21# To use it you just need to source your build environment setup script and
22# add the meta-selftest layer to your BBLAYERS.
23# Call the script as: "oe-selftest" to run all the tests in in meta/lib/selftest/
24# Call the script as: "oe-selftest <module>.<Class>.<method>" to run just a single test
25# E.g: "oe-selftest bboutput.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/selftest/bboutput.py
26
27
28import os
29import sys
30import unittest
31import logging
32
33sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'meta/lib')))
34
35import oeqa.selftest
36import oeqa.utils.ftools as ftools
37from oeqa.utils.commands import runCmd, get_bb_var, get_test_layer
38from oeqa.selftest.base import oeSelfTest
39
40def logger_create():
41 log = logging.getLogger("selftest")
42 log.setLevel(logging.DEBUG)
43
44 fh = logging.FileHandler(filename='oe-selftest.log', mode='w')
45 fh.setLevel(logging.DEBUG)
46
47 ch = logging.StreamHandler(sys.stdout)
48 ch.setLevel(logging.INFO)
49
50 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
51 fh.setFormatter(formatter)
52 ch.setFormatter(formatter)
53
54 log.addHandler(fh)
55 log.addHandler(ch)
56
57 return log
58
59log = logger_create()
60
61def preflight_check():
62
63 log.info("Checking that everything is in order before running the tests")
64
65 if not os.environ.get("BUILDDIR"):
66 log.error("BUILDDIR isn't set. Did you forget to source your build environment setup script?")
67 return False
68
69 builddir = os.environ.get("BUILDDIR")
70 if os.getcwd() != builddir:
71 log.info("Changing cwd to %s" % builddir)
72 os.chdir(builddir)
73
74 if not "meta-selftest" in get_bb_var("BBLAYERS"):
75 log.error("You don't seem to have the meta-selftest layer in BBLAYERS")
76 return False
77
78 log.info("Running bitbake -p")
79 runCmd("bitbake -p")
80
81 return True
82
83def add_include():
84 builddir = os.environ.get("BUILDDIR")
85 if "#include added by oe-selftest.py" \
86 not in ftools.read_file(os.path.join(builddir, "conf/local.conf")):
87 log.info("Adding: \"include selftest.inc\" in local.conf")
88 ftools.append_file(os.path.join(builddir, "conf/local.conf"), \
89 "\n#include added by oe-selftest.py\ninclude selftest.inc")
90
91
92def remove_include():
93 builddir = os.environ.get("BUILDDIR")
94 if "#include added by oe-selftest.py" \
95 in ftools.read_file(os.path.join(builddir, "conf/local.conf")):
96 log.info("Removing the include from local.conf")
97 ftools.remove_from_file(os.path.join(builddir, "conf/local.conf"), \
98 "#include added by oe-selftest.py\ninclude selftest.inc")
99
100def get_tests():
101 testslist = []
102 for x in sys.argv[1:]:
103 testslist.append('oeqa.selftest.' + x)
104 if not testslist:
105 testpath = os.path.abspath(os.path.dirname(oeqa.selftest.__file__))
106 files = sorted([f for f in os.listdir(testpath) if f.endswith('.py') and not f.startswith('_') and f != 'base.py'])
107 for f in files:
108 module = 'oeqa.selftest.' + f[:-3]
109 testslist.append(module)
110
111 return testslist
112
113def main():
114 if not preflight_check():
115 return 1
116
117 testslist = get_tests()
118 suite = unittest.TestSuite()
119 loader = unittest.TestLoader()
120 loader.sortTestMethodsUsing = None
121 runner = unittest.TextTestRunner(verbosity=2)
122 # we need to do this here, otherwise just loading the tests
123 # will take 2 minutes (bitbake -e calls)
124 oeSelfTest.testlayer_path = get_test_layer()
125 for test in testslist:
126 log.info("Loading tests from: %s" % test)
127 try:
128 suite.addTests(loader.loadTestsFromName(test))
129 except AttributeError as e:
130 log.error("Failed to import %s" % test)
131 log.error(e)
132 return 1
133 add_include()
134 result = runner.run(suite)
135 log.info("Finished")
136
137 return 0
138
139if __name__ == "__main__":
140 try:
141 ret = main()
142 except Exception:
143 ret = 1
144 import traceback
145 traceback.print_exc(5)
146 finally:
147 remove_include()
148 sys.exit(ret)