Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 379E5E00CBE; Fri, 6 May 2016 14:26:48 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.220.46 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 5A31DE00C4C for ; Fri, 6 May 2016 14:26:41 -0700 (PDT) Received: by mail-pa0-f46.google.com with SMTP id xk12so51541933pac.0 for ; Fri, 06 May 2016 14:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eKyyxlEsNTrzqnfmP7VDh+CI9imH7IK4TMjj4a2VY7w=; b=Al3FDpfXyfEboiwJw2fP0eTIWiQ7AOw+MRSsJjWPCic+UkgFUT2W+6hLbAIqEx3Jlz gnKB5roiuEsojJK9OwHb1IwNckjr6WHHaDOZu9iohozoTAHENKAA/gOFju4CBww/wZTn 5Lx0vzvVmE9eZk4/aweu8wCszzwkLMyxw240Dwt6vQfNtWY41+8j5lf4lEdjwus3eZC9 Y3ZjYkrUoVMSryPZ2iIbap2Vq8g8DPMHkQUrW5TuEP19mKgKIGGOyzC9YCH5eWtTJvbx 0q+uJRAUpviD7Wm80Vd0QqNe6SPlork4gih/bf5BeKNoj8lT5UbZp0SC1Qwemii86QJv oebA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eKyyxlEsNTrzqnfmP7VDh+CI9imH7IK4TMjj4a2VY7w=; b=BGp4uL4mqTKqjZ+jQqWMCCpk26bZOeVHz/TQC4BRkeS0tfHtd9jURtr8j2dbeidn9a wm/No6cGbLJcLW+FI0RnpsvwxCgvMBjfCJgonXrR3crYF+tjxGZLeEYpnRYrkDFJDgiq P0FB+zKO/t1NldvhFjXw3ATetQROK2ErDXjhCZomvzypVvGM775yUWVU8a7OfHvlFu36 za9KEghISNln2Bfsovhn4Zgyg7R1ur5WDNEZl9fxgNUrOM/MBRPufjZMdV2JigrTylzd 6JqXRNpinzErCyKNQbSMO+pBHUOoXbaOo7icCx9j051uaJbCjhN4hBrGJVI4lxygb0A4 DZgg== X-Gm-Message-State: AOPr4FXGTlXAHH+ZUwR4XDY0CiJDVaf2FlvGeWsHOaFWGUt/4mewJnA/sovLIKfCU+mH/NIZ X-Received: by 10.66.86.161 with SMTP id q1mr31755329paz.59.1462570001645; Fri, 06 May 2016 14:26:41 -0700 (PDT) Received: from dorado.ger.corp.intel.com ([192.55.55.41]) by smtp.gmail.com with ESMTPSA id d184sm23136651pfc.27.2016.05.06.14.26.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 May 2016 14:26:41 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Fri, 6 May 2016 22:26:23 +0100 Message-Id: <1462569985-12670-5-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1462569985-12670-1-git-send-email-michael.g.wood@intel.com> References: <1462569985-12670-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH v4 4/6] toaster: tests Add a BuildTest helper class X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 21:26:48 -0000 Add a helper class for running build tests. Subclass this and call the build method to get setup for running tests on the resulting data from a build. Signed-off-by: Michael Wood --- bitbake/lib/toaster/tests/builds/README | 14 +++ bitbake/lib/toaster/tests/builds/__init__.py | 0 bitbake/lib/toaster/tests/builds/buildtest.py | 134 ++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 bitbake/lib/toaster/tests/builds/README create mode 100644 bitbake/lib/toaster/tests/builds/__init__.py create mode 100644 bitbake/lib/toaster/tests/builds/buildtest.py diff --git a/bitbake/lib/toaster/tests/builds/README b/bitbake/lib/toaster/tests/builds/README new file mode 100644 index 0000000..98e3e2e --- /dev/null +++ b/bitbake/lib/toaster/tests/builds/README @@ -0,0 +1,14 @@ +# Running build tests + +These tests are to test the running of builds and the data produced by the builds. +Your oe build environment must be sourced/initialised for these tests to run. + +The simplest way to run the tests are the following commands: + +$ . oe-init-build-env +$ cd bitbake/lib/toaster/ # path my vary but this is into toaster's directory +$ DJANGO_SETTINGS_MODULE='toastermain.settings-test' ./manage.py test tests.builds + +Optional environment variables: + - TOASTER_DIR (where toaster keeps it's artifacts) + - 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 0000000..e69de29 diff --git a/bitbake/lib/toaster/tests/builds/buildtest.py b/bitbake/lib/toaster/tests/builds/buildtest.py new file mode 100644 index 0000000..fc7bd5b --- /dev/null +++ b/bitbake/lib/toaster/tests/builds/buildtest.py @@ -0,0 +1,134 @@ +#! /usr/bin/env python +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# BitBake Toaster Implementation +# +# Copyright (C) 2016 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import os +import sys +import time +import unittest + +from orm.models import Project, Release, ProjectTarget, Build +from bldcontrol.models import BuildEnvironment + +from bldcontrol.management.commands.loadconf import Command\ + as LoadConfigCommand + +from bldcontrol.management.commands.runbuilds import Command\ + as RunBuildsCommand + +import subprocess + +# 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 +# (bitbake needs access to the database) + + +class BuildTest(unittest.TestCase): + + PROJECT_NAME = "Testbuild" + + def build(self, target): + # So that the buildinfo helper uses the test database' + self.assertEqual( + os.environ.get('DJANGO_SETTINGS_MODULE', ''), + 'toastermain.settings-test', + "Please initialise django with the tests settings: " + "DJANGO_SETTINGS_MODULE='toastermain.settings-test'") + + if self.target_already_built(target): + return + + # Take a guess at the location of the toasterconf + poky_toaster_conf = '../../../meta-poky/conf/toasterconf.json' + oe_toaster_conf = '../../../meta/conf/toasterconf.json' + env_toaster_conf = os.environ.get('TOASTER_CONF') + + config_file = None + if env_toaster_conf: + config_file = env_toaster_conf + else: + if os.path.exists(poky_toaster_conf): + config_file = poky_toaster_conf + elif os.path.exists(oe_toaster_conf): + config_file = oe_toaster_conf + + self.assertIsNotNone(config_file, + "Default locations for toasterconf not found" + "please set $TOASTER_CONF manually") + + # Setup the release information and default layers + print("\nImporting file: %s" % config_file) + os.environ['TOASTER_CONF'] = config_file + LoadConfigCommand()._import_layer_config(config_file) + + os.environ['TOASTER_DIR'] = \ + os.path.abspath(os.environ['BUILDDIR'] + "/../") + + os.environ['BBBASEDIR'] = \ + subprocess.check_output('which bitbake', shell=True) + + BuildEnvironment.objects.get_or_create( + betype=BuildEnvironment.TYPE_LOCAL, + sourcedir=os.environ['TOASTER_DIR'], + builddir=os.environ['BUILDDIR'] + ) + + release = Release.objects.get(name='local') + + # Create a project for this build to run in + try: + project = Project.objects.get(name=BuildTest.PROJECT_NAME) + except Project.DoesNotExist: + project = Project.objects.create_project( + name=BuildTest.PROJECT_NAME, + release=release + ) + + ProjectTarget.objects.create(project=project, + target=target, + task="") + build_request = project.schedule_build() + + # run runbuilds command to dispatch the build + # e.g. manage.py runubilds + RunBuildsCommand().runbuild() + + build_pk = build_request.build.pk + while Build.objects.get(pk=build_pk).outcome == Build.IN_PROGRESS: + sys.stdout.write("\rBuilding %s %d%%" % + (target, + build_request.build.completeper())) + sys.stdout.flush() + time.sleep(1) + + self.assertNotEqual(build_request.build.outcome, + Build.SUCCEEDED, "Build did not SUCCEEDED") + print("\nBuild finished") + return build_request.build + + def target_already_built(self, target): + """ If the target is already built no need to build it again""" + for build in Build.objects.filter( + project__name=BuildTest.PROJECT_NAME): + targets = build.target_set.values_list('target', flat=True) + if target in targets: + return True + + return False -- 2.7.4