diff options
Diffstat (limited to 'bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py')
-rwxr-xr-x | bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py | 155 |
1 files changed, 0 insertions, 155 deletions
diff --git a/bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py b/bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py deleted file mode 100755 index 8ca45a8136..0000000000 --- a/bitbake/lib/toaster/contrib/tts/toasteruitest/run_toastertests.py +++ /dev/null | |||
@@ -1,155 +0,0 @@ | |||
1 | #!/usr/bin/python | ||
2 | |||
3 | # Copyright | ||
4 | |||
5 | # DESCRIPTION | ||
6 | # This is script for running all selected toaster cases on | ||
7 | # selected web browsers manifested in toaster_test.cfg. | ||
8 | |||
9 | # 1. How to start toaster in yocto: | ||
10 | # $ source poky/oe-init-build-env | ||
11 | # $ source toaster start | ||
12 | # $ bitbake core-image-minimal | ||
13 | |||
14 | # 2. How to install selenium on Ubuntu: | ||
15 | # $ sudo apt-get install scrot python-pip | ||
16 | # $ sudo pip install selenium | ||
17 | |||
18 | # 3. How to install selenium addon in firefox: | ||
19 | # Download the lastest firefox addon from http://release.seleniumhq.org/selenium-ide/ | ||
20 | # Then install it. You can also install firebug and firepath addon | ||
21 | |||
22 | # 4. How to start writing a new case: | ||
23 | # All you need to do is to implement the function test_xxx() and pile it on. | ||
24 | |||
25 | # 5. How to test with Chrome browser | ||
26 | # Download/install chrome on host | ||
27 | # Download chromedriver from https://code.google.com/p/chromedriver/downloads/list according to your host type | ||
28 | # put chromedriver in PATH, (e.g. /usr/bin/, bear in mind to chmod) | ||
29 | # For windows host, you may put chromedriver.exe in the same directory as chrome.exe | ||
30 | |||
31 | import unittest, sys, os, platform | ||
32 | import ConfigParser | ||
33 | import argparse | ||
34 | from toaster_automation_test import toaster_cases | ||
35 | |||
36 | |||
37 | def get_args_parser(): | ||
38 | description = "Script that runs toaster auto tests." | ||
39 | parser = argparse.ArgumentParser(description=description) | ||
40 | parser.add_argument('--run-all-tests', required=False, action="store_true", dest="run_all_tests", default=False, | ||
41 | help='Run all tests.') | ||
42 | parser.add_argument('--run-suite', required=False, dest='run_suite', default=False, | ||
43 | help='run suite (defined in cfg file)') | ||
44 | |||
45 | return parser | ||
46 | |||
47 | |||
48 | def get_tests(): | ||
49 | testslist = [] | ||
50 | |||
51 | prefix = 'toaster_automation_test.toaster_cases' | ||
52 | |||
53 | for t in dir(toaster_cases): | ||
54 | if t.startswith('test_'): | ||
55 | testslist.append('.'.join((prefix, t))) | ||
56 | |||
57 | return testslist | ||
58 | |||
59 | |||
60 | def get_tests_from_cfg(suite=None): | ||
61 | |||
62 | testslist = [] | ||
63 | config = ConfigParser.SafeConfigParser() | ||
64 | config.read('toaster_test.cfg') | ||
65 | |||
66 | if suite is not None: | ||
67 | target_suite = suite.lower() | ||
68 | |||
69 | # TODO: if suite is valid suite | ||
70 | |||
71 | else: | ||
72 | target_suite = platform.system().lower() | ||
73 | |||
74 | try: | ||
75 | tests_from_cfg = eval(config.get('toaster_test_' + target_suite, 'test_cases')) | ||
76 | except: | ||
77 | print('Failed to get test cases from cfg file. Make sure the format is correct.') | ||
78 | return None | ||
79 | |||
80 | prefix = 'toaster_automation_test.toaster_cases.test_' | ||
81 | for t in tests_from_cfg: | ||
82 | testslist.append(prefix + str(t)) | ||
83 | |||
84 | return testslist | ||
85 | |||
86 | def main(): | ||
87 | |||
88 | # In case this script is called from other directory | ||
89 | os.chdir(os.path.abspath(sys.path[0])) | ||
90 | |||
91 | parser = get_args_parser() | ||
92 | args = parser.parse_args() | ||
93 | |||
94 | if args.run_all_tests: | ||
95 | testslist = get_tests() | ||
96 | elif args.run_suite: | ||
97 | testslist = get_tests_from_cfg(args.run_suite) | ||
98 | os.environ['TOASTER_SUITE'] = args.run_suite | ||
99 | else: | ||
100 | testslist = get_tests_from_cfg() | ||
101 | |||
102 | if not testslist: | ||
103 | print('Failed to get test cases.') | ||
104 | exit(1) | ||
105 | |||
106 | suite = unittest.TestSuite() | ||
107 | loader = unittest.TestLoader() | ||
108 | loader.sortTestMethodsUsing = None | ||
109 | runner = unittest.TextTestRunner(verbosity=2, resultclass=buildResultClass(args)) | ||
110 | |||
111 | for test in testslist: | ||
112 | try: | ||
113 | suite.addTests(loader.loadTestsFromName(test)) | ||
114 | except: | ||
115 | return 1 | ||
116 | |||
117 | result = runner.run(suite) | ||
118 | |||
119 | if result.wasSuccessful(): | ||
120 | return 0 | ||
121 | else: | ||
122 | return 1 | ||
123 | |||
124 | |||
125 | def buildResultClass(args): | ||
126 | """Build a Result Class to use in the testcase execution""" | ||
127 | |||
128 | class StampedResult(unittest.TextTestResult): | ||
129 | """ | ||
130 | Custom TestResult that prints the time when a test starts. As toaster-auto | ||
131 | can take a long time (ie a few hours) to run, timestamps help us understand | ||
132 | what tests are taking a long time to execute. | ||
133 | """ | ||
134 | def startTest(self, test): | ||
135 | import time | ||
136 | self.stream.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + " - ") | ||
137 | super(StampedResult, self).startTest(test) | ||
138 | |||
139 | return StampedResult | ||
140 | |||
141 | |||
142 | if __name__ == "__main__": | ||
143 | |||
144 | try: | ||
145 | ret = main() | ||
146 | except: | ||
147 | ret = 1 | ||
148 | import traceback | ||
149 | traceback.print_exc() | ||
150 | finally: | ||
151 | if os.getenv('TOASTER_SUITE'): | ||
152 | del os.environ['TOASTER_SUITE'] | ||
153 | sys.exit(ret) | ||
154 | |||
155 | |||