diff options
Diffstat (limited to 'bitbake/lib/toaster/bldcontrol/tests.py')
| -rw-r--r-- | bitbake/lib/toaster/bldcontrol/tests.py | 73 |
1 files changed, 69 insertions, 4 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/tests.py b/bitbake/lib/toaster/bldcontrol/tests.py index 501deb776c..ebe477d8a8 100644 --- a/bitbake/lib/toaster/bldcontrol/tests.py +++ b/bitbake/lib/toaster/bldcontrol/tests.py | |||
| @@ -7,10 +7,75 @@ Replace this with more appropriate tests for your application. | |||
| 7 | 7 | ||
| 8 | from django.test import TestCase | 8 | from django.test import TestCase |
| 9 | 9 | ||
| 10 | from bldcontrol.bbcontroller import LocalhostBEController, BitbakeController | ||
| 11 | from bldcontrol.models import BuildEnvironment, BuildRequest | ||
| 12 | from bldcontrol.management.commands.runbuilds import Command | ||
| 10 | 13 | ||
| 11 | class SimpleTest(TestCase): | 14 | import socket |
| 12 | def test_basic_addition(self): | 15 | import subprocess |
| 16 | |||
| 17 | class LocalhostBEControllerTests(TestCase): | ||
| 18 | def test_StartAndStopServer(self): | ||
| 19 | obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL) | ||
| 20 | lbc = LocalhostBEController(obe) | ||
| 21 | |||
| 22 | # test start server and stop | ||
| 23 | self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Port already occupied") | ||
| 24 | lbc.startBBServer() | ||
| 25 | self.assertFalse(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Server not answering") | ||
| 26 | |||
| 27 | lbc.stopBBServer() | ||
| 28 | self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Server not stopped") | ||
| 29 | |||
| 30 | # clean up | ||
| 31 | import subprocess | ||
| 32 | out, err = subprocess.Popen("netstat -tapn 2>/dev/null | grep 8200 | awk '{print $7}' | sort -fu | cut -d \"/\" -f 1 | grep -v -- - | tee /dev/fd/2 | xargs -r kill", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() | ||
| 33 | |||
| 34 | self.assertTrue(err == '', "bitbake server pid %s not stopped" % err) | ||
| 35 | |||
| 36 | obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL) | ||
| 37 | lbc = LocalhostBEController(obe) | ||
| 38 | |||
| 39 | bbc = lbc.getBBController() | ||
| 40 | self.assertTrue(isinstance(bbc, BitbakeController)) | ||
| 41 | # test set variable | ||
| 42 | try: | ||
| 43 | bbc.setVariable | ||
| 44 | except Exception as e : | ||
| 45 | self.fail("setVariable raised %s", e) | ||
| 46 | |||
| 47 | lbc.stopBBServer() | ||
| 48 | out, err = subprocess.Popen("netstat -tapn 2>/dev/null | grep 8200 | awk '{print $7}' | sort -fu | cut -d \"/\" -f 1 | grep -v -- - | tee /dev/fd/2 | xargs -r kill", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() | ||
| 49 | self.assertTrue(err == '', "bitbake server pid %s not stopped" % err) | ||
| 50 | |||
| 51 | |||
| 52 | class RunBuildsCommandTests(TestCase): | ||
| 53 | def test_bec_select(self): | ||
| 13 | """ | 54 | """ |
| 14 | Tests that 1 + 1 always equals 2. | 55 | Tests that we can find and lock a build environment |
| 15 | """ | 56 | """ |
| 16 | self.assertEqual(1 + 1, 2) | 57 | |
| 58 | obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL) | ||
| 59 | command = Command() | ||
| 60 | bec = command._selectBuildEnvironment() | ||
| 61 | |||
| 62 | # make sure we select the object we've just built | ||
| 63 | self.assertTrue(bec.be.id == obe.id, "Environment is not properly selected") | ||
| 64 | # we have a locked environment | ||
| 65 | self.assertTrue(bec.be.lock == BuildEnvironment.LOCK_LOCK, "Environment is not locked") | ||
| 66 | # no more selections possible here | ||
| 67 | self.assertRaises(IndexError, command._selectBuildEnvironment) | ||
| 68 | |||
| 69 | def test_br_select(self): | ||
| 70 | from orm.models import Project | ||
| 71 | p, created = Project.objects.get_or_create(pk=1) | ||
| 72 | obr = BuildRequest.objects.create(state = BuildRequest.REQ_QUEUED, project = p) | ||
| 73 | command = Command() | ||
| 74 | br = command._selectBuildRequest() | ||
| 75 | |||
| 76 | # make sure we select the object we've just built | ||
| 77 | self.assertTrue(obr.id == br.id, "Request is not properly selected") | ||
| 78 | # we have a locked environment | ||
| 79 | self.assertTrue(br.state == BuildRequest.REQ_INPROGRESS, "Request is not updated") | ||
| 80 | # no more selections possible here | ||
| 81 | self.assertRaises(IndexError, command._selectBuildRequest) | ||
