tests.py 4.5 KB

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