summaryrefslogtreecommitdiffstats
path: root/scripts/oe-selftest
diff options
context:
space:
mode:
authorAdrian Dudau <adrian.dudau@enea.com>2014-06-26 14:36:22 +0200
committerAdrian Dudau <adrian.dudau@enea.com>2014-06-26 15:32:53 +0200
commitf4cf9fe05bb3f32fabea4e54dd92d368967a80da (patch)
tree487180fa9866985ea7b28e625651765d86f515c3 /scripts/oe-selftest
downloadpoky-f4cf9fe05bb3f32fabea4e54dd92d368967a80da.tar.gz
initial commit for Enea Linux 4.0
Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'scripts/oe-selftest')
-rwxr-xr-xscripts/oe-selftest162
1 files changed, 162 insertions, 0 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest
new file mode 100755
index 0000000000..8c4ea92610
--- /dev/null
+++ b/scripts/oe-selftest
@@ -0,0 +1,162 @@
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
100
101def remove_inc_files():
102 try:
103 os.remove(os.path.join(os.environ.get("BUILDDIR"), "conf/selftest.inc"))
104 for root, _, files in os.walk(get_test_layer()):
105 for f in files:
106 if f == 'test_recipe.inc':
107 os.remove(os.path.join(root, f))
108 except OSError as e:
109 pass
110
111def get_tests():
112 testslist = []
113 for x in sys.argv[1:]:
114 testslist.append('oeqa.selftest.' + x)
115 if not testslist:
116 testpath = os.path.abspath(os.path.dirname(oeqa.selftest.__file__))
117 files = sorted([f for f in os.listdir(testpath) if f.endswith('.py') and not f.startswith('_') and f != 'base.py'])
118 for f in files:
119 module = 'oeqa.selftest.' + f[:-3]
120 testslist.append(module)
121
122 return testslist
123
124def main():
125 if not preflight_check():
126 return 1
127
128 testslist = get_tests()
129 suite = unittest.TestSuite()
130 loader = unittest.TestLoader()
131 loader.sortTestMethodsUsing = None
132 runner = unittest.TextTestRunner(verbosity=2)
133 # we need to do this here, otherwise just loading the tests
134 # will take 2 minutes (bitbake -e calls)
135 oeSelfTest.testlayer_path = get_test_layer()
136 for test in testslist:
137 log.info("Loading tests from: %s" % test)
138 try:
139 suite.addTests(loader.loadTestsFromName(test))
140 except AttributeError as e:
141 log.error("Failed to import %s" % test)
142 log.error(e)
143 return 1
144 add_include()
145 result = runner.run(suite)
146 log.info("Finished")
147 if result.wasSuccessful():
148 return 0
149 else:
150 return 1
151
152if __name__ == "__main__":
153 try:
154 ret = main()
155 except Exception:
156 ret = 1
157 import traceback
158 traceback.print_exc(5)
159 finally:
160 remove_include()
161 remove_inc_files()
162 sys.exit(ret)