Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # ex:ts=4:sw=4:sts=4:et |
| 4 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 5 | # |
| 6 | # Copyright (C) 2015 Alexandru Damian for Intel Corp. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License version 2 as |
| 10 | # published by the Free Software Foundation. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License along |
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | |
| 21 | |
| 22 | # Test definitions. The runner will look for and auto-discover the tests |
| 23 | # no matter what they file are they in, as long as they are in the same directory |
| 24 | # as this file. |
| 25 | |
| 26 | import unittest |
| 27 | from shellutils import run_shell_cmd, ShellCmdException |
| 28 | import config |
| 29 | |
| 30 | import pexpect |
| 31 | import sys, os, signal, time |
| 32 | |
| 33 | class Test00PyCompilable(unittest.TestCase): |
| 34 | ''' Verifies that all Python files are syntactically correct ''' |
| 35 | def test_compile_file(self): |
| 36 | try: |
| 37 | run_shell_cmd("find . -name *py -type f -print0 | xargs -0 -n1 -P20 python -m py_compile", config.TESTDIR) |
| 38 | except ShellCmdException as exc: |
| 39 | self.fail("Error compiling python files: %s" % (exc)) |
| 40 | |
| 41 | def test_pylint_file(self): |
| 42 | try: |
| 43 | run_shell_cmd(r"find . -iname \"*\.py\" -type f -print0 | PYTHONPATH=${PYTHONPATH}:. xargs -r -0 -n1 pylint --load-plugins pylint_django -E --reports=n 2>&1", cwd=config.TESTDIR + "/bitbake/lib/toaster") |
| 44 | except ShellCmdException as exc: |
| 45 | self.fail("Pylint fails: %s\n" % exc) |
| 46 | |
| 47 | class Test01PySystemStart(unittest.TestCase): |
| 48 | ''' Attempts to start Toaster, verify that it is succesfull, and stop it ''' |
| 49 | def setUp(self): |
| 50 | run_shell_cmd("bash -c 'rm -f build/*log'") |
| 51 | |
| 52 | def test_start_interactive_mode(self): |
| 53 | try: |
| 54 | run_shell_cmd("bash -c 'source %s/oe-init-build-env && source toaster start webport=%d && source toaster stop'" % (config.TESTDIR, config.TOASTER_PORT), config.TESTDIR) |
| 55 | except ShellCmdException as exc: |
| 56 | self.fail("Failed starting interactive mode: %s" % (exc)) |
| 57 | |
| 58 | def test_start_managed_mode(self): |
| 59 | try: |
| 60 | run_shell_cmd("%s/bitbake/bin/toaster webport=%d nobrowser & sleep 10 && curl http://localhost:%d/ && kill -2 %%1" % (config.TESTDIR, config.TOASTER_PORT, config.TOASTER_PORT), config.TESTDIR) |
| 61 | except ShellCmdException as exc: |
| 62 | self.fail("Failed starting managed mode: %s" % (exc)) |
| 63 | |
| 64 | class Test02HTML5Compliance(unittest.TestCase): |
| 65 | def setUp(self): |
| 66 | self.origdir = os.getcwd() |
| 67 | self.crtdir = os.path.dirname(config.TESTDIR) |
| 68 | self.cleanup_database = False |
| 69 | os.chdir(self.crtdir) |
| 70 | if not os.path.exists(os.path.join(self.crtdir, "toaster.sqlite")): |
| 71 | self.cleanup_database = True |
| 72 | run_shell_cmd("%s/bitbake/lib/toaster/manage.py syncdb --noinput" % config.TESTDIR) |
| 73 | run_shell_cmd("%s/bitbake/lib/toaster/manage.py migrate orm" % config.TESTDIR) |
| 74 | run_shell_cmd("%s/bitbake/lib/toaster/manage.py migrate bldcontrol" % config.TESTDIR) |
| 75 | run_shell_cmd("%s/bitbake/lib/toaster/manage.py loadconf %s/meta-yocto/conf/toasterconf.json" % (config.TESTDIR, config.TESTDIR)) |
| 76 | run_shell_cmd("%s/bitbake/lib/toaster/manage.py lsupdates" % config.TESTDIR) |
| 77 | |
| 78 | setup = pexpect.spawn("%s/bitbake/lib/toaster/manage.py checksettings" % config.TESTDIR) |
| 79 | setup.logfile = sys.stdout |
| 80 | setup.expect(r".*or type the full path to a different directory: ") |
| 81 | setup.sendline('') |
| 82 | setup.sendline('') |
| 83 | setup.expect(r".*or type the full path to a different directory: ") |
| 84 | setup.sendline('') |
| 85 | setup.expect(r"Enter your option: ") |
| 86 | setup.sendline('0') |
| 87 | |
| 88 | self.child = pexpect.spawn("bash", ["%s/bitbake/bin/toaster" % config.TESTDIR, "webport=%d" % config.TOASTER_PORT, "nobrowser"], cwd=self.crtdir) |
| 89 | self.child.logfile = sys.stdout |
| 90 | self.child.expect("Toaster is now running. You can stop it with Ctrl-C") |
| 91 | |
| 92 | def test_html5_compliance(self): |
| 93 | import urllist, urlcheck |
| 94 | results = {} |
| 95 | for url in urllist.URLS: |
| 96 | results[url] = urlcheck.validate_html5(config.TOASTER_BASEURL + url) |
| 97 | |
| 98 | failed = [] |
| 99 | for url in results: |
| 100 | if results[url][1] != 0: |
| 101 | failed.append((url, results[url])) |
| 102 | |
| 103 | |
| 104 | self.assertTrue(len(failed) == 0, "Not all URLs validate: \n%s " % "\n".join(["".join(str(x)) for x in failed])) |
| 105 | |
| 106 | #(config.TOASTER_BASEURL + url, status, errors, warnings)) |
| 107 | |
| 108 | def tearDown(self): |
| 109 | while self.child.isalive(): |
| 110 | self.child.kill(signal.SIGINT) |
| 111 | time.sleep(1) |
| 112 | os.chdir(self.origdir) |
| 113 | toaster_sqlite_path = os.path.join(self.crtdir, "toaster.sqlite") |
| 114 | if self.cleanup_database and os.path.exists(toaster_sqlite_path): |
| 115 | os.remove(toaster_sqlite_path) |