Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 1400BE00AB0; Mon, 7 Nov 2016 07:48:00 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -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 * -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no * trust * [74.125.82.47 listed in list.dnswl.org] Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 774B6E009DA for ; Mon, 7 Nov 2016 07:47:57 -0800 (PST) Received: by mail-wm0-f47.google.com with SMTP id a197so190673999wmd.0 for ; Mon, 07 Nov 2016 07:47:57 -0800 (PST) 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=WzUClMYJfJ1+ZzOqzXaPQ8FY+TQ6OIk7UgWLD79CkXw=; b=gxMZRAGdD5groR5HMTropBhMNJ/iW6GiGwR2tuyTJe+T2CBEBBT03Y1UKFMXQMvHPi 0c/jn8fZtbLzZYjy5SoYvIUuom15IHF/OeARn7dngMPSYImdylg7IxIUWJvpqi+4yoe9 zfEBG2ckaUpSUO0EB8ifUCQkuEGC4YQt/m27r8ARZWe60/WrN/I1v8qtpEGInPNIUpm/ 0Y+k9N7+nrJKDm5mBXqAOKD6h5+xr/icO9kZvYgwHhNC5mV4I7vM0syR1qwd4QzmxOoB 2k8MA0s5obunYFJEkIN3HyLRs0uIfCdK8WmQAFou2El8O6wPVqNjaIQpYnob3qySFVKi Fdzw== 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=WzUClMYJfJ1+ZzOqzXaPQ8FY+TQ6OIk7UgWLD79CkXw=; b=bvA5HMp6aiDoyzmbk6nJ+U5FkiFvzY1QR88eeTPSQC6z+Nrkg9p2yedgW3WIQboI0C ZLAPWEd/ij+SZf+Okn7Elf8f5SG+H2BPZC9E2wmNCySHTkR3mpe6EILfR/Kf1+/PQfQW rGrHyu7c9UTeoOXyfmzci/zkIBFlH1mxsyPSo6HN13zSKLFncDAYcJh75Qz7TODlWMnH 9I6AWcEtTYO1CY8eVwaCMEMgwgADudRBcB8TGmALNxWTS/3gMqVnYKRHQ1ZpaolIMJPl b0G1a6cCbwKQLprpFkuwv9qJMfwIFsJx/qq1zgmhZI3Ajofaezl3y9jXXZPzKCgw+GUH h5Eg== X-Gm-Message-State: ABUngvfaTwUifqbB1sW8QVxZFvpm30RPHQ/I0EtcImhFgDr4tRcCEcVCH3HMLvFbxcxiIRY0 X-Received: by 10.194.189.198 with SMTP id gk6mr5972816wjc.167.1478533676054; Mon, 07 Nov 2016 07:47:56 -0800 (PST) Received: from orion.home (host31-48-249-102.range31-48.btcentralplus.com. [31.48.249.102]) by smtp.gmail.com with ESMTPSA id v2sm31719971wja.41.2016.11.07.07.47.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Nov 2016 07:47:55 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 7 Nov 2016 15:47:52 +0000 Message-Id: <1478533672-19640-2-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478533672-19640-1-git-send-email-michael.g.wood@intel.com> References: <1478533672-19640-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 2/2] toaster: tests Add management command tests 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: Mon, 07 Nov 2016 15:48:00 -0000 Add some simple sanity tests for the management commands that we use for Toaster. Can be executed with ./manage.py test tests.commands For faster execution use the test settings and keepdb flag: DJANGO_SETTINGS_MODULE=toastermain.settings_test ./manage.py test tests.commands --keepdb Signed-off-by: Michael Wood --- bitbake/lib/toaster/tests/commands/__init__.py | 0 .../lib/toaster/tests/commands/test_loaddata.py | 61 +++++++++++++++ .../lib/toaster/tests/commands/test_lsupdates.py | 45 +++++++++++ .../lib/toaster/tests/commands/test_runbuilds.py | 88 ++++++++++++++++++++++ 4 files changed, 194 insertions(+) create mode 100644 bitbake/lib/toaster/tests/commands/__init__.py create mode 100644 bitbake/lib/toaster/tests/commands/test_loaddata.py create mode 100644 bitbake/lib/toaster/tests/commands/test_lsupdates.py create mode 100644 bitbake/lib/toaster/tests/commands/test_runbuilds.py diff --git a/bitbake/lib/toaster/tests/commands/__init__.py b/bitbake/lib/toaster/tests/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bitbake/lib/toaster/tests/commands/test_loaddata.py b/bitbake/lib/toaster/tests/commands/test_loaddata.py new file mode 100644 index 0000000..951f6ff --- /dev/null +++ b/bitbake/lib/toaster/tests/commands/test_loaddata.py @@ -0,0 +1,61 @@ +#! /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. + +from django.test import TestCase +from django.core import management + +from orm.models import Layer_Version, Layer, Release, ToasterSetting + + +class TestLoadDataFixtures(TestCase): + """ Test loading our 3 provided fixtures """ + def test_run_loaddata_poky_command(self): + management.call_command('loaddata', 'poky') + + num_releases = Release.objects.count() + + self.assertTrue( + Layer_Version.objects.filter( + layer__name="meta-poky").count() == num_releases, + "Loaded poky fixture but don't have a meta-poky for all releases" + " defined") + + def test_run_loaddata_oecore_command(self): + management.call_command('loaddata', 'oe-core') + + # We only have the one layer for oe-core setup + self.assertTrue( + Layer.objects.filter(name="openembedded-core").count() > 0, + "Loaded oe-core fixture but still have no openemebedded-core" + " layer") + + def test_run_loaddata_settings_command(self): + management.call_command('loaddata', 'settings') + + self.assertTrue( + ToasterSetting.objects.filter(name="DEFAULT_RELEASE").count() > 0, + "Loaded settings but have no DEFAULT_RELEASE") + + self.assertTrue( + ToasterSetting.objects.filter( + name__startswith="DEFCONF").count() > 0, + "Loaded settings but have no DEFCONF (default project " + "configuration values)") diff --git a/bitbake/lib/toaster/tests/commands/test_lsupdates.py b/bitbake/lib/toaster/tests/commands/test_lsupdates.py new file mode 100644 index 0000000..49897a4 --- /dev/null +++ b/bitbake/lib/toaster/tests/commands/test_lsupdates.py @@ -0,0 +1,45 @@ +#! /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. + +from django.test import TestCase +from django.core import management + +from orm.models import Layer_Version, Machine, Recipe + + +class TestLayerIndexUpdater(TestCase): + def test_run_lsupdates_command(self): + # Load some release information for us to fetch from the layer index + management.call_command('loaddata', 'poky') + + old_layers_count = Layer_Version.objects.count() + old_recipes_count = Recipe.objects.count() + old_machines_count = Machine.objects.count() + + # Now fetch the metadata from the layer index + management.call_command('lsupdates') + + self.assertTrue(Layer_Version.objects.count() > old_layers_count, + "lsupdates ran but we still have no more layers!") + self.assertTrue(Recipe.objects.count() > old_recipes_count, + "lsupdates ran but we still have no more Recipes!") + self.assertTrue(Machine.objects.count() > old_machines_count, + "lsupdates ran but we still have no more Machines!") diff --git a/bitbake/lib/toaster/tests/commands/test_runbuilds.py b/bitbake/lib/toaster/tests/commands/test_runbuilds.py new file mode 100644 index 0000000..3e63483 --- /dev/null +++ b/bitbake/lib/toaster/tests/commands/test_runbuilds.py @@ -0,0 +1,88 @@ +#! /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 + +from django.test import TestCase +from django.core import management + +from orm.models import signal_runbuilds + +import threading +import time +import subprocess +import signal + + +class KillRunbuilds(threading.Thread): + """ Kill the runbuilds process after an amount of time """ + def __init__(self, *args, **kwargs): + super(KillRunbuilds, self).__init__(*args, **kwargs) + self.setDaemon(True) + + def run(self): + time.sleep(5) + signal_runbuilds() + time.sleep(1) + + pidfile_path = os.path.join(os.environ.get("BUILDDIR", "."), + ".runbuilds.pid") + + with open(pidfile_path) as pidfile: + pid = pidfile.read() + os.kill(int(pid), signal.SIGTERM) + + +class TestCommands(TestCase): + """ Sanity test that runbuilds executes OK """ + + def setUp(self): + os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "toastermain.settings_test") + os.environ.setdefault("BUILDDIR", + "/tmp/") + + # Setup a real database if needed for runbuilds process + # to connect to + management.call_command('migrate') + + def test_runbuilds_command(self): + kill_runbuilds = KillRunbuilds() + kill_runbuilds.start() + + manage_py = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + os.pardir, + os.pardir, + "manage.py") + + command = "%s runbuilds" % manage_py + + process = subprocess.Popen(command, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + (out, err) = process.communicate() + process.wait() + + self.assertNotEqual(process.returncode, 1, + "Runbuilds returned an error %s" % err) -- 2.7.4