summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/contrib
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-05-18 14:04:53 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-29 11:59:46 +0100
commit225daf45a46aca31dfd21897ee302b32f671cd4b (patch)
tree76ab4e06c3239b7e04b332eaaed5da62fce5edc8 /bitbake/lib/toaster/contrib
parent29143915ae543f3cd389a7b1e32967ab42730e45 (diff)
downloadpoky-225daf45a46aca31dfd21897ee302b32f671cd4b.tar.gz
bitbake: toaster tests: enable url check test
Integrate the HTML5 validation as a test instead of calling a separate script. This enables us to get the HTML5 validation report as part of patch-level testing. gitignore the cache directory created by the http client (Bitbake rev: 931caab56301876cb8632b289835c2545a096ef6) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/contrib')
-rw-r--r--bitbake/lib/toaster/contrib/tts/config.py21
-rwxr-xr-xbitbake/lib/toaster/contrib/tts/runner.py2
-rw-r--r--bitbake/lib/toaster/contrib/tts/tests.py55
-rw-r--r--bitbake/lib/toaster/contrib/tts/urlcheck.py41
4 files changed, 94 insertions, 25 deletions
diff --git a/bitbake/lib/toaster/contrib/tts/config.py b/bitbake/lib/toaster/contrib/tts/config.py
index a4ea8cf5fa..c0e05369e6 100644
--- a/bitbake/lib/toaster/contrib/tts/config.py
+++ b/bitbake/lib/toaster/contrib/tts/config.py
@@ -22,6 +22,7 @@
22# everything that would be a global variable goes here 22# everything that would be a global variable goes here
23 23
24import os, sys, logging 24import os, sys, logging
25import socket
25 26
26LOGDIR = "log" 27LOGDIR = "log"
27SETTINGS_FILE = os.path.join(os.path.dirname(__file__), "settings.json") 28SETTINGS_FILE = os.path.join(os.path.dirname(__file__), "settings.json")
@@ -29,6 +30,26 @@ TEST_DIR_NAME = "tts_testdir"
29 30
30OWN_PID = os.getpid() 31OWN_PID = os.getpid()
31 32
33W3C_VALIDATOR = "http://icarus.local/w3c-validator/check?doctype=HTML5&uri="
34
35#TODO assign port dynamically
36TOASTER_PORT=56789
37
38#we parse the w3c URL to know where to connect
39
40import urlparse
41
42def get_public_ip():
43 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
44 p = urlparse.urlparse("http://icarus.local/w3c-validator/check?doctype=HTML5&uri=")
45 s.connect(( p.netloc, 80 if p.port is None else p.port))
46 hn = s.getsockname()[0]
47 s.close()
48 return hn
49
50TOASTER_BASEURL="http://%s:%d/" % (get_public_ip(), TOASTER_PORT)
51
52
32OWN_EMAIL_ADDRESS = "Toaster Testing Framework <alexandru.damian@intel.com>" 53OWN_EMAIL_ADDRESS = "Toaster Testing Framework <alexandru.damian@intel.com>"
33REPORT_EMAIL_ADDRESS = "alexandru.damian@intel.com" 54REPORT_EMAIL_ADDRESS = "alexandru.damian@intel.com"
34 55
diff --git a/bitbake/lib/toaster/contrib/tts/runner.py b/bitbake/lib/toaster/contrib/tts/runner.py
index f55c4934cc..e7e4dd2d2e 100755
--- a/bitbake/lib/toaster/contrib/tts/runner.py
+++ b/bitbake/lib/toaster/contrib/tts/runner.py
@@ -181,7 +181,7 @@ if __name__ == "__main__":
181 no_failures = 1 181 no_failures = 1
182 try: 182 try:
183 if options.testdir is not None and os.path.exists(options.testdir): 183 if options.testdir is not None and os.path.exists(options.testdir):
184 testdir = options.testdir 184 testdir = os.path.abspath(options.testdir)
185 config.logger.info("No checkout, using %s" % testdir) 185 config.logger.info("No checkout, using %s" % testdir)
186 else: 186 else:
187 need_cleanup = True 187 need_cleanup = True
diff --git a/bitbake/lib/toaster/contrib/tts/tests.py b/bitbake/lib/toaster/contrib/tts/tests.py
index 2e630db575..15a9a874ff 100644
--- a/bitbake/lib/toaster/contrib/tts/tests.py
+++ b/bitbake/lib/toaster/contrib/tts/tests.py
@@ -26,6 +26,9 @@
26import unittest 26import unittest
27from shellutils import * 27from shellutils import *
28 28
29import pexpect
30import sys, os, signal, time
31
29class TestPyCompilable(unittest.TestCase): 32class TestPyCompilable(unittest.TestCase):
30 ''' Verifies that all Python files are syntactically correct ''' 33 ''' Verifies that all Python files are syntactically correct '''
31 def test_compile_file(self): 34 def test_compile_file(self):
@@ -44,14 +47,62 @@ class TestPySystemStart(unittest.TestCase):
44 47
45 def test_start_interactive_mode(self): 48 def test_start_interactive_mode(self):
46 try: 49 try:
47 run_shell_cmd("bash -c 'source %s/oe-init-build-env && source toaster start webport=56789 && source toaster stop'" % config.testdir, config.testdir) 50 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)
48 except ShellCmdException as e: 51 except ShellCmdException as e:
49 self.fail("Failed starting interactive mode: %s" % (e)) 52 self.fail("Failed starting interactive mode: %s" % (e))
50 53
51 def test_start_managed_mode(self): 54 def test_start_managed_mode(self):
52 try: 55 try:
53 run_shell_cmd("./poky/bitbake/bin/toaster webport=56789 & sleep 10 && curl http://localhost:56789/ && kill -2 %1") 56 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)
54 pass 57 pass
55 except ShellCmdException as e: 58 except ShellCmdException as e:
56 self.fail("Failed starting managed mode: %s" % (e)) 59 self.fail("Failed starting managed mode: %s" % (e))
57 60
61class TestHTML5Compliance(unittest.TestCase):
62 def setUp(self):
63 self.origdir = os.getcwd()
64 self.crtdir = os.path.dirname(config.testdir)
65 os.chdir(self.crtdir)
66 if not os.path.exists(os.path.join(self.crtdir, "toaster.sqlite")):
67 run_shell_cmd("%s/bitbake/lib/toaster/manage.py syncdb --noinput" % config.testdir)
68 run_shell_cmd("%s/bitbake/lib/toaster/manage.py migrate orm" % config.testdir)
69 run_shell_cmd("%s/bitbake/lib/toaster/manage.py migrate bldcontrol" % config.testdir)
70 run_shell_cmd("%s/bitbake/lib/toaster/manage.py loadconf %s/meta-yocto/conf/toasterconf.json" % (config.testdir, config.testdir))
71
72 setup = pexpect.spawn("%s/bitbake/lib/toaster/manage.py checksettings" % config.testdir)
73 setup.logfile = sys.stdout
74 setup.expect(r".*or type the full path to a different directory: ")
75 setup.sendline('')
76 setup.sendline('')
77 setup.expect(r".*or type the full path to a different directory: ")
78 setup.sendline('')
79 setup.expect(r"Enter your option: ")
80 setup.sendline('0')
81
82 self.child = pexpect.spawn("%s/bitbake/bin/toaster webport=%d nobrowser" % (config.testdir, config.TOASTER_PORT))
83 self.child.logfile=sys.stdout
84 self.child.expect("Toaster is now running. You can stop it with Ctrl-C")
85
86 def test_html5_compliance(self):
87 import urllist, urlcheck
88 results = {}
89 for url in urllist.URLS:
90 results[url] = urlcheck.validate_html5(config.TOASTER_BASEURL + url)
91
92 failed = []
93 for url in results:
94 if results[url][1] != 0:
95 failed.append((url, results[url]))
96
97
98 self.assertTrue(len(failed)== 0, "Not all URLs validate: \n%s " % "\n".join(map(lambda x: "".join(str(x)),failed)))
99
100 #(config.TOASTER_BASEURL + url, status, errors, warnings))
101
102 def tearDown(self):
103 while self.child.isalive():
104 self.child.kill(signal.SIGINT)
105 time.sleep(1)
106 os.chdir(self.origdir)
107# if os.path.exists(os.path.join(self.crtdir, "toaster.sqlite")):
108# os.remove(os.path.join(self.crtdir, "toaster.sqlite"))
diff --git a/bitbake/lib/toaster/contrib/tts/urlcheck.py b/bitbake/lib/toaster/contrib/tts/urlcheck.py
index a94af5000b..86d7caac2a 100644
--- a/bitbake/lib/toaster/contrib/tts/urlcheck.py
+++ b/bitbake/lib/toaster/contrib/tts/urlcheck.py
@@ -7,38 +7,35 @@ import time
7import config 7import config
8import urllist 8import urllist
9 9
10# TODO: spawn server here
11BASEURL="http://localhost:8000/"
12
13#def print_browserlog(url):
14# driver = webdriver.Firefox()
15# driver.get(url)
16# body = driver.find_element_by_tag_name("body")
17# body.send_keys(Keys.CONTROL + 't')
18# for i in driver.get_log('browser'):
19# print(i)
20# driver.close()
21
22 10
23# TODO: turn to a test 11# TODO: turn to a test
24def validate_html(url): 12def validate_html5(url):
25 h = httplib2.Http(".cache") 13 h = httplib2.Http(".cache")
14 status = "Failed"
15 errors = -1
16 warnings = -1
17
26 # TODO: the w3c-validator must be a configurable setting 18 # TODO: the w3c-validator must be a configurable setting
27 urlrequest = "http://icarus.local/w3c-validator/check?doctype=HTML5&uri="+url 19 urlrequest = config.W3C_VALIDATOR+url
28 try: 20 try:
29 resp, content = h.request(urlrequest, "HEAD") 21 resp, content = h.request(urlrequest, "HEAD")
30 if resp['x-w3c-validator-status'] == "Abort": 22 if resp['x-w3c-validator-status'] != "Abort":
31 config.logger.error("FAILed call %s" % url) 23 status = resp['x-w3c-validator-status']
32 else: 24 errors = int(resp['x-w3c-validator-errors'])
33 config.logger.error("url %s is %s\terrors %s warnings %s (check at %s)" % (url, resp['x-w3c-validator-status'], resp['x-w3c-validator-errors'], resp['x-w3c-validator-warnings'], urlrequest)) 25 warnings = int(resp['x-w3c-validator-warnings'])
34 except Exception as e: 26 except Exception as e:
35 config.logger.warn("Failed validation call: %s" % e.__str__()) 27 config.logger.warn("Failed validation call: %s" % e.__str__())
36 28 return (status, errors, warnings)
37 print("done %s" % url)
38 29
39if __name__ == "__main__": 30if __name__ == "__main__":
31 print("Testing %s with %s" % (config.TOASTER_BASEURL, config.W3C_VALIDATOR))
32
33 def print_validation(url):
34 status, errors, warnings = validate_html5(url)
35 config.logger.error("url %s is %s\terrors %s warnings %s (check at %s)" % (url, status, errors, warnings, config.W3C_VALIDATOR+url))
36
40 if len(sys.argv) > 1: 37 if len(sys.argv) > 1:
41 validate_html(sys.argv[1]) 38 print_validation(sys.argv[1])
42 else: 39 else:
43 for url in urllist.URLS: 40 for url in urllist.URLS:
44 validate_html(BASEURL+url) 41 print_validation(config.TOASTER_BASEURL+url)