diff options
author | Michael Wood <michael.g.wood@intel.com> | 2016-10-28 18:48:48 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-11-04 12:50:55 +0000 |
commit | 83ebb8987716d9dce7a91eb6340c3f2614bb1e18 (patch) | |
tree | 1d09ccedc3d9d347de24f4ec5190a219ad9c24a0 /bitbake/lib/toaster | |
parent | 8e70fa1d7933f36244badb34c28ab67f8f159d74 (diff) | |
download | poky-83ebb8987716d9dce7a91eb6340c3f2614bb1e18.tar.gz |
bitbake: toaster: tests builds Update buildtest
Now that we're using fixtures for configuration just load these instead
of trying to search for a toasterconf json file.
Also for convenience add the ability for the tests to source the build
environment script. To use this test make sure that directories are in
the same layout as poky.
(Bitbake rev: 448d1d9dc8989ef4c997a90c71cd7e1da0495c1c)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r-- | bitbake/lib/toaster/tests/builds/buildtest.py | 129 |
1 files changed, 81 insertions, 48 deletions
diff --git a/bitbake/lib/toaster/tests/builds/buildtest.py b/bitbake/lib/toaster/tests/builds/buildtest.py index fc7bd5b644..bf147f09e5 100644 --- a/bitbake/lib/toaster/tests/builds/buildtest.py +++ b/bitbake/lib/toaster/tests/builds/buildtest.py | |||
@@ -24,16 +24,18 @@ import sys | |||
24 | import time | 24 | import time |
25 | import unittest | 25 | import unittest |
26 | 26 | ||
27 | from orm.models import Project, Release, ProjectTarget, Build | 27 | from orm.models import Project, Release, ProjectTarget, Build, ProjectVariable |
28 | from bldcontrol.models import BuildEnvironment | 28 | from bldcontrol.models import BuildEnvironment |
29 | 29 | ||
30 | from bldcontrol.management.commands.loadconf import Command\ | ||
31 | as LoadConfigCommand | ||
32 | |||
33 | from bldcontrol.management.commands.runbuilds import Command\ | 30 | from bldcontrol.management.commands.runbuilds import Command\ |
34 | as RunBuildsCommand | 31 | as RunBuildsCommand |
35 | 32 | ||
33 | from django.core.management import call_command | ||
34 | |||
36 | import subprocess | 35 | import subprocess |
36 | import logging | ||
37 | |||
38 | logger = logging.getLogger("toaster") | ||
37 | 39 | ||
38 | # We use unittest.TestCase instead of django.test.TestCase because we don't | 40 | # We use unittest.TestCase instead of django.test.TestCase because we don't |
39 | # want to wrap everything in a database transaction as an external process | 41 | # want to wrap everything in a database transaction as an external process |
@@ -43,63 +45,92 @@ import subprocess | |||
43 | class BuildTest(unittest.TestCase): | 45 | class BuildTest(unittest.TestCase): |
44 | 46 | ||
45 | PROJECT_NAME = "Testbuild" | 47 | PROJECT_NAME = "Testbuild" |
48 | BUILDDIR = "/tmp/build/" | ||
46 | 49 | ||
47 | def build(self, target): | 50 | def build(self, target): |
48 | # So that the buildinfo helper uses the test database' | 51 | # So that the buildinfo helper uses the test database' |
49 | self.assertEqual( | 52 | self.assertEqual( |
50 | os.environ.get('DJANGO_SETTINGS_MODULE', ''), | 53 | os.environ.get('DJANGO_SETTINGS_MODULE', ''), |
51 | 'toastermain.settings-test', | 54 | 'toastermain.settings_test', |
52 | "Please initialise django with the tests settings: " | 55 | "Please initialise django with the tests settings: " |
53 | "DJANGO_SETTINGS_MODULE='toastermain.settings-test'") | 56 | "DJANGO_SETTINGS_MODULE='toastermain.settings_test'") |
54 | 57 | ||
55 | if self.target_already_built(target): | 58 | built = self.target_already_built(target) |
56 | return | 59 | if built: |
60 | return built | ||
57 | 61 | ||
58 | # Take a guess at the location of the toasterconf | 62 | call_command('loaddata', 'settings.xml', app_label="orm") |
59 | poky_toaster_conf = '../../../meta-poky/conf/toasterconf.json' | 63 | call_command('loaddata', 'poky.xml', app_label="orm") |
60 | oe_toaster_conf = '../../../meta/conf/toasterconf.json' | ||
61 | env_toaster_conf = os.environ.get('TOASTER_CONF') | ||
62 | 64 | ||
63 | config_file = None | 65 | current_builddir = os.environ.get("BUILDDIR") |
64 | if env_toaster_conf: | 66 | if current_builddir: |
65 | config_file = env_toaster_conf | 67 | BuildTest.BUILDDIR = current_builddir |
66 | else: | 68 | else: |
67 | if os.path.exists(poky_toaster_conf): | 69 | # Setup a builddir based on default layout |
68 | config_file = poky_toaster_conf | 70 | # bitbake inside openebedded-core |
69 | elif os.path.exists(oe_toaster_conf): | 71 | oe_init_build_env_path = os.path.join( |
70 | config_file = oe_toaster_conf | 72 | os.path.dirname(os.path.abspath(__file__)), |
71 | 73 | os.pardir, | |
72 | self.assertIsNotNone(config_file, | 74 | os.pardir, |
73 | "Default locations for toasterconf not found" | 75 | os.pardir, |
74 | "please set $TOASTER_CONF manually") | 76 | os.pardir, |
75 | 77 | os.pardir, | |
76 | # Setup the release information and default layers | 78 | 'oe-init-build-env' |
77 | print("\nImporting file: %s" % config_file) | 79 | ) |
78 | os.environ['TOASTER_CONF'] = config_file | 80 | if not os.path.exists(oe_init_build_env_path): |
79 | LoadConfigCommand()._import_layer_config(config_file) | 81 | raise Exception("We had no BUILDDIR set and couldn't " |
80 | 82 | "find oe-init-build-env to set this up " | |
81 | os.environ['TOASTER_DIR'] = \ | 83 | "ourselves please run oe-init-build-env " |
82 | os.path.abspath(os.environ['BUILDDIR'] + "/../") | 84 | "before running these tests") |
83 | 85 | ||
84 | os.environ['BBBASEDIR'] = \ | 86 | oe_init_build_env_path = os.path.realpath(oe_init_build_env_path) |
85 | subprocess.check_output('which bitbake', shell=True) | 87 | cmd = "bash -c 'source oe-init-build-env %s'" % BuildTest.BUILDDIR |
88 | p = subprocess.Popen( | ||
89 | cmd, | ||
90 | cwd=os.path.dirname(oe_init_build_env_path), | ||
91 | shell=True, | ||
92 | stdout=subprocess.PIPE, | ||
93 | stderr=subprocess.PIPE) | ||
94 | |||
95 | output, err = p.communicate() | ||
96 | p.wait() | ||
97 | |||
98 | logger.info("oe-init-build-env %s %s" % (output, err)) | ||
99 | |||
100 | os.environ['BUILDDIR'] = BuildTest.BUILDDIR | ||
101 | |||
102 | # Setup the path to bitbake we know where to find this | ||
103 | bitbake_path = os.path.join( | ||
104 | os.path.dirname(os.path.abspath(__file__)), | ||
105 | os.pardir, | ||
106 | os.pardir, | ||
107 | os.pardir, | ||
108 | os.pardir, | ||
109 | 'bin', | ||
110 | 'bitbake') | ||
111 | if not os.path.exists(bitbake_path): | ||
112 | raise Exception("Could not find bitbake at the expected path %s" | ||
113 | % bitbake_path) | ||
114 | |||
115 | os.environ['BBBASEDIR'] = bitbake_path | ||
86 | 116 | ||
87 | BuildEnvironment.objects.get_or_create( | 117 | BuildEnvironment.objects.get_or_create( |
88 | betype=BuildEnvironment.TYPE_LOCAL, | 118 | betype=BuildEnvironment.TYPE_LOCAL, |
89 | sourcedir=os.environ['TOASTER_DIR'], | 119 | sourcedir=BuildTest.BUILDDIR, |
90 | builddir=os.environ['BUILDDIR'] | 120 | builddir=BuildTest.BUILDDIR |
91 | ) | 121 | ) |
92 | 122 | ||
93 | release = Release.objects.get(name='local') | 123 | release = Release.objects.get(name='local') |
94 | 124 | ||
95 | # Create a project for this build to run in | 125 | # Create a project for this build to run in |
96 | try: | 126 | project = Project.objects.create_project(name=BuildTest.PROJECT_NAME, |
97 | project = Project.objects.get(name=BuildTest.PROJECT_NAME) | 127 | release=release) |
98 | except Project.DoesNotExist: | 128 | |
99 | project = Project.objects.create_project( | 129 | if os.environ.get("TOASTER_TEST_USE_SSTATE_MIRROR"): |
100 | name=BuildTest.PROJECT_NAME, | 130 | ProjectVariable.objects.get_or_create( |
101 | release=release | 131 | name="SSTATE_MIRRORS", |
102 | ) | 132 | value="file://.* http://autobuilder.yoctoproject.org/pub/sstate/PATH;downloadfilename=PATH", |
133 | project=project) | ||
103 | 134 | ||
104 | ProjectTarget.objects.create(project=project, | 135 | ProjectTarget.objects.create(project=project, |
105 | target=target, | 136 | target=target, |
@@ -118,9 +149,11 @@ class BuildTest(unittest.TestCase): | |||
118 | sys.stdout.flush() | 149 | sys.stdout.flush() |
119 | time.sleep(1) | 150 | time.sleep(1) |
120 | 151 | ||
121 | self.assertNotEqual(build_request.build.outcome, | 152 | self.assertEqual(Build.objects.get(pk=build_pk).outcome, |
122 | Build.SUCCEEDED, "Build did not SUCCEEDED") | 153 | Build.SUCCEEDED, |
123 | print("\nBuild finished") | 154 | "Build did not SUCCEEDED") |
155 | |||
156 | logger.info("\nBuild finished %s" % build_request.build.outcome) | ||
124 | return build_request.build | 157 | return build_request.build |
125 | 158 | ||
126 | def target_already_built(self, target): | 159 | def target_already_built(self, target): |
@@ -129,6 +162,6 @@ class BuildTest(unittest.TestCase): | |||
129 | project__name=BuildTest.PROJECT_NAME): | 162 | project__name=BuildTest.PROJECT_NAME): |
130 | targets = build.target_set.values_list('target', flat=True) | 163 | targets = build.target_set.values_list('target', flat=True) |
131 | if target in targets: | 164 | if target in targets: |
132 | return True | 165 | return build |
133 | 166 | ||
134 | return False | 167 | return None |