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>
This commit is contained in:
Michael Wood 2016-10-28 18:48:48 +03:00 committed by Richard Purdie
parent 8e70fa1d79
commit 83ebb89877
1 changed files with 77 additions and 44 deletions

View File

@ -24,16 +24,18 @@ import sys
import time import time
import unittest import unittest
from orm.models import Project, Release, ProjectTarget, Build from orm.models import Project, Release, ProjectTarget, Build, ProjectVariable
from bldcontrol.models import BuildEnvironment from bldcontrol.models import BuildEnvironment
from bldcontrol.management.commands.loadconf import Command\
as LoadConfigCommand
from bldcontrol.management.commands.runbuilds import Command\ from bldcontrol.management.commands.runbuilds import Command\
as RunBuildsCommand as RunBuildsCommand
from django.core.management import call_command
import subprocess import subprocess
import logging
logger = logging.getLogger("toaster")
# We use unittest.TestCase instead of django.test.TestCase because we don't # We use unittest.TestCase instead of django.test.TestCase because we don't
# want to wrap everything in a database transaction as an external process # want to wrap everything in a database transaction as an external process
@ -43,63 +45,92 @@ import subprocess
class BuildTest(unittest.TestCase): class BuildTest(unittest.TestCase):
PROJECT_NAME = "Testbuild" PROJECT_NAME = "Testbuild"
BUILDDIR = "/tmp/build/"
def build(self, target): def build(self, target):
# So that the buildinfo helper uses the test database' # So that the buildinfo helper uses the test database'
self.assertEqual( self.assertEqual(
os.environ.get('DJANGO_SETTINGS_MODULE', ''), os.environ.get('DJANGO_SETTINGS_MODULE', ''),
'toastermain.settings-test', 'toastermain.settings_test',
"Please initialise django with the tests settings: " "Please initialise django with the tests settings: "
"DJANGO_SETTINGS_MODULE='toastermain.settings-test'") "DJANGO_SETTINGS_MODULE='toastermain.settings_test'")
if self.target_already_built(target): built = self.target_already_built(target)
return if built:
return built
# Take a guess at the location of the toasterconf call_command('loaddata', 'settings.xml', app_label="orm")
poky_toaster_conf = '../../../meta-poky/conf/toasterconf.json' call_command('loaddata', 'poky.xml', app_label="orm")
oe_toaster_conf = '../../../meta/conf/toasterconf.json'
env_toaster_conf = os.environ.get('TOASTER_CONF')
config_file = None current_builddir = os.environ.get("BUILDDIR")
if env_toaster_conf: if current_builddir:
config_file = env_toaster_conf BuildTest.BUILDDIR = current_builddir
else: else:
if os.path.exists(poky_toaster_conf): # Setup a builddir based on default layout
config_file = poky_toaster_conf # bitbake inside openebedded-core
elif os.path.exists(oe_toaster_conf): oe_init_build_env_path = os.path.join(
config_file = oe_toaster_conf os.path.dirname(os.path.abspath(__file__)),
os.pardir,
os.pardir,
os.pardir,
os.pardir,
os.pardir,
'oe-init-build-env'
)
if not os.path.exists(oe_init_build_env_path):
raise Exception("We had no BUILDDIR set and couldn't "
"find oe-init-build-env to set this up "
"ourselves please run oe-init-build-env "
"before running these tests")
self.assertIsNotNone(config_file, oe_init_build_env_path = os.path.realpath(oe_init_build_env_path)
"Default locations for toasterconf not found" cmd = "bash -c 'source oe-init-build-env %s'" % BuildTest.BUILDDIR
"please set $TOASTER_CONF manually") p = subprocess.Popen(
cmd,
cwd=os.path.dirname(oe_init_build_env_path),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Setup the release information and default layers output, err = p.communicate()
print("\nImporting file: %s" % config_file) p.wait()
os.environ['TOASTER_CONF'] = config_file
LoadConfigCommand()._import_layer_config(config_file)
os.environ['TOASTER_DIR'] = \ logger.info("oe-init-build-env %s %s" % (output, err))
os.path.abspath(os.environ['BUILDDIR'] + "/../")
os.environ['BBBASEDIR'] = \ os.environ['BUILDDIR'] = BuildTest.BUILDDIR
subprocess.check_output('which bitbake', shell=True)
# Setup the path to bitbake we know where to find this
bitbake_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
os.pardir,
os.pardir,
os.pardir,
os.pardir,
'bin',
'bitbake')
if not os.path.exists(bitbake_path):
raise Exception("Could not find bitbake at the expected path %s"
% bitbake_path)
os.environ['BBBASEDIR'] = bitbake_path
BuildEnvironment.objects.get_or_create( BuildEnvironment.objects.get_or_create(
betype=BuildEnvironment.TYPE_LOCAL, betype=BuildEnvironment.TYPE_LOCAL,
sourcedir=os.environ['TOASTER_DIR'], sourcedir=BuildTest.BUILDDIR,
builddir=os.environ['BUILDDIR'] builddir=BuildTest.BUILDDIR
) )
release = Release.objects.get(name='local') release = Release.objects.get(name='local')
# Create a project for this build to run in # Create a project for this build to run in
try: project = Project.objects.create_project(name=BuildTest.PROJECT_NAME,
project = Project.objects.get(name=BuildTest.PROJECT_NAME) release=release)
except Project.DoesNotExist:
project = Project.objects.create_project( if os.environ.get("TOASTER_TEST_USE_SSTATE_MIRROR"):
name=BuildTest.PROJECT_NAME, ProjectVariable.objects.get_or_create(
release=release name="SSTATE_MIRRORS",
) value="file://.* http://autobuilder.yoctoproject.org/pub/sstate/PATH;downloadfilename=PATH",
project=project)
ProjectTarget.objects.create(project=project, ProjectTarget.objects.create(project=project,
target=target, target=target,
@ -118,9 +149,11 @@ class BuildTest(unittest.TestCase):
sys.stdout.flush() sys.stdout.flush()
time.sleep(1) time.sleep(1)
self.assertNotEqual(build_request.build.outcome, self.assertEqual(Build.objects.get(pk=build_pk).outcome,
Build.SUCCEEDED, "Build did not SUCCEEDED") Build.SUCCEEDED,
print("\nBuild finished") "Build did not SUCCEEDED")
logger.info("\nBuild finished %s" % build_request.build.outcome)
return build_request.build return build_request.build
def target_already_built(self, target): def target_already_built(self, target):
@ -129,6 +162,6 @@ class BuildTest(unittest.TestCase):
project__name=BuildTest.PROJECT_NAME): project__name=BuildTest.PROJECT_NAME):
targets = build.target_set.values_list('target', flat=True) targets = build.target_set.values_list('target', flat=True)
if target in targets: if target in targets:
return True return build
return False return None