blob: c77d6cf490dcd21fc22a87136d1546c68833651c [file] [log] [blame]
Brad Bishop96ff1982019-08-19 13:50:42 -04001#! /usr/bin/env python3
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002#
3# BitBake Toaster Implementation
4#
5# Copyright (C) 2016 Intel Corporation
6#
Brad Bishopc342db32019-05-15 21:57:59 -04007# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009
10import os
11
12from django.test import TestCase
13from django.core import management
14
15from orm.models import signal_runbuilds
16
17import threading
18import time
19import subprocess
20import signal
21
22
23class KillRunbuilds(threading.Thread):
24 """ Kill the runbuilds process after an amount of time """
25 def __init__(self, *args, **kwargs):
26 super(KillRunbuilds, self).__init__(*args, **kwargs)
Andrew Geisslerc5535c92023-01-27 16:10:19 -060027 self.daemon = True
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028
29 def run(self):
30 time.sleep(5)
31 signal_runbuilds()
32 time.sleep(1)
33
34 pidfile_path = os.path.join(os.environ.get("BUILDDIR", "."),
35 ".runbuilds.pid")
36
37 with open(pidfile_path) as pidfile:
38 pid = pidfile.read()
39 os.kill(int(pid), signal.SIGTERM)
40
41
42class TestCommands(TestCase):
43 """ Sanity test that runbuilds executes OK """
44
45 def setUp(self):
46 os.environ.setdefault("DJANGO_SETTINGS_MODULE",
47 "toastermain.settings_test")
48 os.environ.setdefault("BUILDDIR",
49 "/tmp/")
50
51 # Setup a real database if needed for runbuilds process
52 # to connect to
53 management.call_command('migrate')
54
55 def test_runbuilds_command(self):
56 kill_runbuilds = KillRunbuilds()
57 kill_runbuilds.start()
58
59 manage_py = os.path.join(
60 os.path.dirname(os.path.abspath(__file__)),
61 os.pardir,
62 os.pardir,
63 "manage.py")
64
65 command = "%s runbuilds" % manage_py
66
67 process = subprocess.Popen(command,
68 shell=True,
69 stdout=subprocess.PIPE,
70 stderr=subprocess.PIPE)
71
72 (out, err) = process.communicate()
73 process.wait()
74
75 self.assertNotEqual(process.returncode, 1,
76 "Runbuilds returned an error %s" % err)