summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/base.py
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 /meta/lib/oeqa/selftest/base.py
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 'meta/lib/oeqa/selftest/base.py')
-rw-r--r--meta/lib/oeqa/selftest/base.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/base.py b/meta/lib/oeqa/selftest/base.py
new file mode 100644
index 0000000000..30a71e886f
--- /dev/null
+++ b/meta/lib/oeqa/selftest/base.py
@@ -0,0 +1,98 @@
1# Copyright (c) 2013 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5
6# DESCRIPTION
7# Base class inherited by test classes in meta/lib/selftest
8
9import unittest
10import os
11import sys
12import logging
13import errno
14
15import oeqa.utils.ftools as ftools
16
17
18class oeSelfTest(unittest.TestCase):
19
20 log = logging.getLogger("selftest.base")
21 longMessage = True
22
23 def __init__(self, methodName="runTest"):
24 self.builddir = os.environ.get("BUILDDIR")
25 self.localconf_path = os.path.join(self.builddir, "conf/local.conf")
26 self.testinc_path = os.path.join(self.builddir, "conf/selftest.inc")
27 self.testlayer_path = oeSelfTest.testlayer_path
28 super(oeSelfTest, self).__init__(methodName)
29
30 def setUp(self):
31 os.chdir(self.builddir)
32 # we don't know what the previous test left around in config or inc files
33 # if it failed so we need a fresh start
34 try:
35 os.remove(self.testinc_path)
36 except OSError as e:
37 if e.errno != errno.ENOENT:
38 raise
39 for root, _, files in os.walk(self.testlayer_path):
40 for f in files:
41 if f == 'test_recipe.inc':
42 os.remove(os.path.join(root, f))
43 # tests might need their own setup
44 # but if they overwrite this one they have to call
45 # super each time, so let's give them an alternative
46 self.setUpLocal()
47
48 def setUpLocal(self):
49 pass
50
51 def tearDown(self):
52 self.tearDownLocal()
53
54 def tearDownLocal(self):
55 pass
56
57 # write to <builddir>/conf/selftest.inc
58 def write_config(self, data):
59 self.log.debug("Writing to: %s\n%s\n" % (self.testinc_path, data))
60 ftools.write_file(self.testinc_path, data)
61
62 # append to <builddir>/conf/selftest.inc
63 def append_config(self, data):
64 self.log.debug("Appending to: %s\n%s\n" % (self.testinc_path, data))
65 ftools.append_file(self.testinc_path, data)
66
67 # remove data from <builddir>/conf/selftest.inc
68 def remove_config(self, data):
69 self.log.debug("Removing from: %s\n\%s\n" % (self.testinc_path, data))
70 ftools.remove_from_file(self.testinc_path, data)
71
72 # write to meta-sefltest/recipes-test/<recipe>/test_recipe.inc
73 def write_recipeinc(self, recipe, data):
74 inc_file = os.path.join(self.testlayer_path, 'recipes-test', recipe, 'test_recipe.inc')
75 self.log.debug("Writing to: %s\n%s\n" % (inc_file, data))
76 ftools.write_file(inc_file, data)
77
78 # append data to meta-sefltest/recipes-test/<recipe>/test_recipe.inc
79 def append_recipeinc(self, recipe, data):
80 inc_file = os.path.join(self.testlayer_path, 'recipes-test', recipe, 'test_recipe.inc')
81 self.log.debug("Appending to: %s\n%s\n" % (inc_file, data))
82 ftools.append_file(inc_file, data)
83
84 # remove data from meta-sefltest/recipes-test/<recipe>/test_recipe.inc
85 def remove_recipeinc(self, recipe, data):
86 inc_file = os.path.join(self.testlayer_path, 'recipes-test', recipe, 'test_recipe.inc')
87 self.log.debug("Removing from: %s\n%s\n" % (inc_file, data))
88 ftools.remove_from_file(inc_file, data)
89
90 # delete meta-sefltest/recipes-test/<recipe>/test_recipe.inc file
91 def delete_recipeinc(self, recipe):
92 inc_file = os.path.join(self.testlayer_path, 'recipes-test', recipe, 'test_recipe.inc')
93 self.log.debug("Deleting file: %s" % inc_file)
94 try:
95 os.remove(self.testinc_path)
96 except OSError as e:
97 if e.errno != errno.ENOENT:
98 raise