diff options
| -rw-r--r-- | bitbake/lib/toaster/tests/builds/README | 14 | ||||
| -rw-r--r-- | bitbake/lib/toaster/tests/builds/__init__.py | 0 | ||||
| -rw-r--r-- | bitbake/lib/toaster/tests/builds/buildtest.py | 134 |
3 files changed, 148 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/tests/builds/README b/bitbake/lib/toaster/tests/builds/README new file mode 100644 index 0000000000..a32721eb5d --- /dev/null +++ b/bitbake/lib/toaster/tests/builds/README | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | # Running build tests | ||
| 2 | |||
| 3 | These tests are to test the running of builds and the data produced by the builds. | ||
| 4 | Your oe build environment must be sourced/initialised for these tests to run. | ||
| 5 | |||
| 6 | The simplest way to run the tests are the following commands: | ||
| 7 | |||
| 8 | $ . oe-init-build-env | ||
| 9 | $ cd lib/toaster/ # path my vary but this is into toaster's directory | ||
| 10 | $ DJANGO_SETTINGS_MODULE='toastermain.settings-test' ./manage.py test tests.builds | ||
| 11 | |||
| 12 | Optional environment variables: | ||
| 13 | - TOASTER_DIR (where toaster keeps it's artifacts) | ||
| 14 | - TOASTER_CONF a path to the toasterconf.json file. This will need to be set if you don't execute the tests from toaster's own directory. | ||
diff --git a/bitbake/lib/toaster/tests/builds/__init__.py b/bitbake/lib/toaster/tests/builds/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bitbake/lib/toaster/tests/builds/__init__.py | |||
diff --git a/bitbake/lib/toaster/tests/builds/buildtest.py b/bitbake/lib/toaster/tests/builds/buildtest.py new file mode 100644 index 0000000000..fc7bd5b644 --- /dev/null +++ b/bitbake/lib/toaster/tests/builds/buildtest.py | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | #! /usr/bin/env python | ||
| 2 | # ex:ts=4:sw=4:sts=4:et | ||
| 3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 4 | # | ||
| 5 | # BitBake Toaster Implementation | ||
| 6 | # | ||
| 7 | # Copyright (C) 2016 Intel Corporation | ||
| 8 | # | ||
| 9 | # This program is free software; you can redistribute it and/or modify | ||
| 10 | # it under the terms of the GNU General Public License version 2 as | ||
| 11 | # published by the Free Software Foundation. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License along | ||
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 21 | |||
| 22 | import os | ||
| 23 | import sys | ||
| 24 | import time | ||
| 25 | import unittest | ||
| 26 | |||
| 27 | from orm.models import Project, Release, ProjectTarget, Build | ||
| 28 | from bldcontrol.models import BuildEnvironment | ||
| 29 | |||
| 30 | from bldcontrol.management.commands.loadconf import Command\ | ||
| 31 | as LoadConfigCommand | ||
| 32 | |||
| 33 | from bldcontrol.management.commands.runbuilds import Command\ | ||
| 34 | as RunBuildsCommand | ||
| 35 | |||
| 36 | import subprocess | ||
| 37 | |||
| 38 | # 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 | ||
| 40 | # (bitbake needs access to the database) | ||
| 41 | |||
| 42 | |||
| 43 | class BuildTest(unittest.TestCase): | ||
| 44 | |||
| 45 | PROJECT_NAME = "Testbuild" | ||
| 46 | |||
| 47 | def build(self, target): | ||
| 48 | # So that the buildinfo helper uses the test database' | ||
| 49 | self.assertEqual( | ||
| 50 | os.environ.get('DJANGO_SETTINGS_MODULE', ''), | ||
| 51 | 'toastermain.settings-test', | ||
| 52 | "Please initialise django with the tests settings: " | ||
| 53 | "DJANGO_SETTINGS_MODULE='toastermain.settings-test'") | ||
| 54 | |||
| 55 | if self.target_already_built(target): | ||
| 56 | return | ||
| 57 | |||
| 58 | # Take a guess at the location of the toasterconf | ||
| 59 | poky_toaster_conf = '../../../meta-poky/conf/toasterconf.json' | ||
| 60 | oe_toaster_conf = '../../../meta/conf/toasterconf.json' | ||
| 61 | env_toaster_conf = os.environ.get('TOASTER_CONF') | ||
| 62 | |||
| 63 | config_file = None | ||
| 64 | if env_toaster_conf: | ||
| 65 | config_file = env_toaster_conf | ||
| 66 | else: | ||
| 67 | if os.path.exists(poky_toaster_conf): | ||
| 68 | config_file = poky_toaster_conf | ||
| 69 | elif os.path.exists(oe_toaster_conf): | ||
| 70 | config_file = oe_toaster_conf | ||
| 71 | |||
| 72 | self.assertIsNotNone(config_file, | ||
| 73 | "Default locations for toasterconf not found" | ||
| 74 | "please set $TOASTER_CONF manually") | ||
| 75 | |||
| 76 | # Setup the release information and default layers | ||
| 77 | print("\nImporting file: %s" % config_file) | ||
| 78 | os.environ['TOASTER_CONF'] = config_file | ||
| 79 | LoadConfigCommand()._import_layer_config(config_file) | ||
| 80 | |||
| 81 | os.environ['TOASTER_DIR'] = \ | ||
| 82 | os.path.abspath(os.environ['BUILDDIR'] + "/../") | ||
| 83 | |||
| 84 | os.environ['BBBASEDIR'] = \ | ||
| 85 | subprocess.check_output('which bitbake', shell=True) | ||
| 86 | |||
| 87 | BuildEnvironment.objects.get_or_create( | ||
| 88 | betype=BuildEnvironment.TYPE_LOCAL, | ||
| 89 | sourcedir=os.environ['TOASTER_DIR'], | ||
| 90 | builddir=os.environ['BUILDDIR'] | ||
| 91 | ) | ||
| 92 | |||
| 93 | release = Release.objects.get(name='local') | ||
| 94 | |||
| 95 | # Create a project for this build to run in | ||
| 96 | try: | ||
| 97 | project = Project.objects.get(name=BuildTest.PROJECT_NAME) | ||
| 98 | except Project.DoesNotExist: | ||
| 99 | project = Project.objects.create_project( | ||
| 100 | name=BuildTest.PROJECT_NAME, | ||
| 101 | release=release | ||
| 102 | ) | ||
| 103 | |||
| 104 | ProjectTarget.objects.create(project=project, | ||
| 105 | target=target, | ||
| 106 | task="") | ||
| 107 | build_request = project.schedule_build() | ||
| 108 | |||
| 109 | # run runbuilds command to dispatch the build | ||
| 110 | # e.g. manage.py runubilds | ||
| 111 | RunBuildsCommand().runbuild() | ||
| 112 | |||
| 113 | build_pk = build_request.build.pk | ||
| 114 | while Build.objects.get(pk=build_pk).outcome == Build.IN_PROGRESS: | ||
| 115 | sys.stdout.write("\rBuilding %s %d%%" % | ||
| 116 | (target, | ||
| 117 | build_request.build.completeper())) | ||
| 118 | sys.stdout.flush() | ||
| 119 | time.sleep(1) | ||
| 120 | |||
| 121 | self.assertNotEqual(build_request.build.outcome, | ||
| 122 | Build.SUCCEEDED, "Build did not SUCCEEDED") | ||
| 123 | print("\nBuild finished") | ||
| 124 | return build_request.build | ||
| 125 | |||
| 126 | def target_already_built(self, target): | ||
| 127 | """ If the target is already built no need to build it again""" | ||
| 128 | for build in Build.objects.filter( | ||
| 129 | project__name=BuildTest.PROJECT_NAME): | ||
| 130 | targets = build.target_set.values_list('target', flat=True) | ||
| 131 | if target in targets: | ||
| 132 | return True | ||
| 133 | |||
| 134 | return False | ||
