diff options
Diffstat (limited to 'meta/lib/oeqa/selftest')
-rw-r--r-- | meta/lib/oeqa/selftest/__init__.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/base.py | 98 |
2 files changed, 100 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/__init__.py b/meta/lib/oeqa/selftest/__init__.py new file mode 100644 index 0000000000..3ad9513f40 --- /dev/null +++ b/meta/lib/oeqa/selftest/__init__.py | |||
@@ -0,0 +1,2 @@ | |||
1 | from pkgutil import extend_path | ||
2 | __path__ = extend_path(__path__, __name__) | ||
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 | |||
9 | import unittest | ||
10 | import os | ||
11 | import sys | ||
12 | import logging | ||
13 | import errno | ||
14 | |||
15 | import oeqa.utils.ftools as ftools | ||
16 | |||
17 | |||
18 | class 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 | ||