admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 3 | Created on 20-Dec-2012 |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | Copyright 2012 Open Networking Foundation |
Jon Hall | 5f15fef | 2015-07-17 14:22:14 -0700 | [diff] [blame] | 5 | |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 9 | |
| 10 | TestON is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 13 | ( at your option ) any later version. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 14 | |
| 15 | TestON is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 21 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 22 | |
| 23 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 24 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 25 | """ |
| 26 | cli will provide the CLI shell for teston framework. |
| 27 | |
| 28 | A simple command-line interface for TestON. |
| 29 | |
| 30 | The TestON CLI provides a simple console which |
| 31 | makes it easy to launch the test. For example, the command run will execute the test. |
| 32 | |
| 33 | teston> run test DpctlTest |
| 34 | Several useful commands are provided. |
| 35 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 36 | from subprocess import call |
| 37 | from cmd import Cmd |
| 38 | from os import isatty |
| 39 | import sys |
| 40 | import re |
| 41 | import os |
| 42 | import time |
| 43 | import threading |
| 44 | import __builtin__ |
| 45 | import pprint |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 46 | dump = pprint.PrettyPrinter( indent=4 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 47 | __builtin__.testthread = False |
| 48 | introduction = "TestON is the testing framework \nDeveloped by Paxterra Solutions (www.paxterrasolutions.com)" |
Jon Hall | 0bde9ba | 2015-03-19 11:32:57 -0700 | [diff] [blame] | 49 | __builtin__.COLORS = False |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 50 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 51 | path = re.sub( "/bin$", "", sys.path[ 0 ] ) |
Jon Hall | 1dd5a0a | 2015-07-08 10:49:26 -0700 | [diff] [blame] | 52 | sys.path.insert( 1, path ) |
Jon Hall | 0bde9ba | 2015-03-19 11:32:57 -0700 | [diff] [blame] | 53 | from core.teston import * |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 54 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 55 | |
| 56 | class CLI( threading.Thread, Cmd, object ): |
| 57 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 58 | "command-line interface to execute the test." |
| 59 | |
| 60 | prompt = 'teston> ' |
| 61 | |
| 62 | def __init__( self, teston, stdin=sys.stdin ): |
| 63 | self.teston = teston |
Jon Hall | 0bde9ba | 2015-03-19 11:32:57 -0700 | [diff] [blame] | 64 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 65 | self._mainevent = threading.Event() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 66 | threading.Thread.__init__( self ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 67 | self.main_stop = False |
| 68 | self.locals = { 'test': teston } |
| 69 | self.stdin = stdin |
| 70 | Cmd.__init__( self ) |
| 71 | self.pause = False |
| 72 | self.stop = False |
| 73 | __builtin__.cli = self |
| 74 | |
| 75 | def emptyline( self ): |
| 76 | "Don't repeat last command when you hit return." |
| 77 | pass |
| 78 | |
| 79 | helpStr = ( |
| 80 | " teston help" |
| 81 | ) |
| 82 | |
| 83 | def do_help( self, line ): |
| 84 | "Describe available CLI commands." |
| 85 | Cmd.do_help( self, line ) |
| 86 | if line is '': |
| 87 | output( self.helpStr ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 88 | |
| 89 | def do_run( self, args ): |
| 90 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 91 | run command will execute the test with following optional command line arguments |
| 92 | logdir <directory to store logs in> |
| 93 | testcases <list of testcases separated by comma or range of testcases separated by hypen> |
| 94 | mail <mail-id or list of mail-ids seperated by comma> |
| 95 | example 1, to execute the examples specified in the ~/examples diretory. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 96 | """ |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 97 | try: |
| 98 | args = args.split() |
| 99 | options = {} |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 100 | options = self.parseArgs( args, options ) |
| 101 | options = dictToObj( options ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 102 | if not testthread: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 103 | test = TestThread( options ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 104 | test.start() |
| 105 | while test.isAlive(): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 106 | test.join( 1 ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 107 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 108 | print main.TEST + " test execution paused, please resume that before executing to another test" |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 109 | except KeyboardInterrupt, SystemExit: |
| 110 | print "Interrupt called, Exiting." |
| 111 | test._Thread__stop() |
| 112 | main.cleanup() |
| 113 | main.exit() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 114 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 115 | def do_resume( self, line ): |
| 116 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 117 | resume command will continue the execution of paused test. |
| 118 | teston>resume |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 119 | [ 2013-01-07 23:03:44.640723 ] [ PoxTest ] [ STEP ] 1.1: Checking the host reachability using pingHost |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 120 | 2013-01-07 23:03:44,858 - PoxTest - INFO - Expected Prompt Found |
| 121 | .... |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 122 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 123 | if testthread: |
| 124 | testthread.play() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 125 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 126 | print "There is no test to resume" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 127 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 128 | def do_nextstep( self, line ): |
| 129 | """ |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 130 | nextstep will execute the next-step of the paused test and |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 131 | it will pause the test after finishing of step. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 132 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 133 | teston> nextstep |
| 134 | Will pause the test's execution, after completion of this step..... |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 135 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 136 | teston> [ 2013-01-07 21:24:26.286601 ] [ PoxTest ] [ STEP ] 1.8: Checking the host reachability using pingHost |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 137 | 2013-01-07 21:24:26,455 - PoxTest - INFO - Expected Prompt Found |
| 138 | ..... |
| 139 | teston> |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 140 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 141 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 142 | if testthread: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 143 | main.log.info( "Executing the nextstep, Will pause test execution, after completion of the step" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 144 | testthread.play() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 145 | time.sleep( .1 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 146 | testthread.pause() |
| 147 | else: |
| 148 | print "There is no paused test " |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 149 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 150 | def do_dumpvar( self, line ): |
| 151 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 152 | dumpvar will print all the test data in raw format. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 153 | usgae : |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 154 | teston>dumpvar main |
| 155 | Here 'main' will be the test object. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 156 | |
| 157 | teston>dumpvar params |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 158 | here 'params' will be the parameters specified in the params file. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 159 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 160 | teston>dumpvar topology |
| 161 | here 'topology' will be topology specification of the test specified in topo file. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 162 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 163 | if testthread: |
| 164 | if line == "main": |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 165 | dump.pprint( vars( main ) ) |
| 166 | else: |
| 167 | try: |
| 168 | dump.pprint( vars( main )[ line ] ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 169 | except KeyError as e: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 170 | print e |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 171 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 172 | print "There is no paused test " |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 173 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 174 | def do_currentcase( self, line ): |
| 175 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 176 | currentcase will return the current case in the test execution. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 177 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 178 | teston>currentcase |
| 179 | Currently executing test case is: 2 |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 180 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 181 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 182 | if testthread: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 183 | print "Currently executing test case is: " + str( main.CurrentTestCaseNumber ) |
| 184 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 185 | print "There is no paused test " |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 186 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 187 | def do_currentstep( self, line ): |
| 188 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 189 | currentstep will return the current step in the test execution. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 190 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 191 | teston>currentstep |
| 192 | Currently executing test step is: 2.3 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 193 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 194 | if testthread: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 195 | print "Currently executing test step is: " + str( main.CurrentTestCaseNumber ) + '.' + str( main.stepCount ) |
| 196 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 197 | print "There is no paused test " |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 198 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 199 | def do_stop( self, line ): |
| 200 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 201 | Will stop the paused test, if any ! |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 202 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 203 | if testthread: |
| 204 | testthread.stop() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 205 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 206 | return 'exited by user command' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 207 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 208 | def do_gettest( self, line ): |
| 209 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 210 | gettest will return the test name which is under execution or recently executed. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 211 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 212 | Test under execution: |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 213 | teston>gettest |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 214 | Currently executing Test is: PoxTest |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 215 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 216 | Test recently executed: |
| 217 | Recently executed test is: MininetTest |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 218 | """ |
| 219 | try: |
| 220 | if testthread: |
| 221 | print "Currently executing Test is: " + main.TEST |
| 222 | else: |
| 223 | print "Recently executed test is: " + main.TEST |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 224 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 225 | except NameError: |
| 226 | print "There is no previously executed Test" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 227 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 228 | def do_showlog( self, line ): |
| 229 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 230 | showlog will show the test's Log |
| 231 | teston>showlog |
| 232 | Last executed test's log is : //home/openflow/TestON/logs/PoxTest_07_Jan_2013_21_42_11/PoxTest_07_Jan_2013_21_42_11.log |
| 233 | ..... |
| 234 | teston>showlog |
| 235 | Currently executing Test's log is: /home/openflow/TestON/logs/PoxTest_07_Jan_2013_21_46_58/PoxTest_07_Jan_2013_21_46_58.log |
| 236 | ..... |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 237 | """ |
| 238 | try: |
| 239 | if testthread: |
| 240 | print "Currently executing Test's log is: " + main.LogFileName |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 241 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 242 | else: |
| 243 | print "Last executed test's log is : " + main.LogFileName |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 244 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 245 | logFile = main.LogFileName |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 246 | logFileHandler = open( logFile, 'r' ) |
| 247 | for msg in logFileHandler.readlines(): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 248 | print msg, |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 249 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 250 | logFileHandler.close() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 251 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 252 | except NameError: |
| 253 | print "There is no previously executed Test" |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 254 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 255 | def parseArgs( self, args, options ): |
| 256 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 257 | This will parse the command line arguments. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 258 | """ |
| 259 | options = self.initOptions( options ) |
| 260 | try: |
YPZhang | 16f6e56 | 2016-07-12 15:50:31 -0700 | [diff] [blame] | 261 | index = 0 |
| 262 | while index < len( args ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 263 | option = args[ index ] |
| 264 | if index > 0: |
| 265 | if re.match( "--params", option, flags=0 ): |
YPZhang | 1c89e76 | 2016-06-29 10:43:58 -0700 | [diff] [blame] | 266 | # check if there is a params |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 267 | options[ 'params' ].append( args[ index + 1 ] ) |
| 268 | elif re.match( "logdir|mail|example|testdir|testcases|onoscell", option, flags=0 ): |
| 269 | options[ option ] = args[ index + 1 ] |
| 270 | options = self.testcasesInRange( index + 1, option, args, options ) |
YPZhang | 16f6e56 | 2016-07-12 15:50:31 -0700 | [diff] [blame] | 271 | index += 2 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 272 | else: |
| 273 | options[ 'testname' ] = option |
YPZhang | 16f6e56 | 2016-07-12 15:50:31 -0700 | [diff] [blame] | 274 | index += 1 |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 275 | except IndexError as e: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 276 | print ( e ) |
YPZhang | 16f6e56 | 2016-07-12 15:50:31 -0700 | [diff] [blame] | 277 | main.cleanup() |
| 278 | main.exit() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 279 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 280 | return options |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 281 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 282 | def initOptions( self, options ): |
| 283 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 284 | This will initialize the commandline options. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 285 | """ |
| 286 | options[ 'logdir' ] = None |
| 287 | options[ 'mail' ] = None |
| 288 | options[ 'example' ] = None |
| 289 | options[ 'testdir' ] = None |
| 290 | options[ 'testcases' ] = None |
| 291 | options[ 'onoscell' ] = None |
YPZhang | 1c89e76 | 2016-06-29 10:43:58 -0700 | [diff] [blame] | 292 | # init params as a empty list |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 293 | options[ 'params' ] = [] |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 294 | return options |
| 295 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 296 | def testcasesInRange( self, index, option, args, options ): |
| 297 | """ |
| 298 | This method will handle testcases list,specified in range [ 1-10 ]. |
| 299 | """ |
| 300 | if re.match( "testcases", option, 1 ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 301 | testcases = [] |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 302 | args[ index ] = re.sub( "\[|\]", "", args[ index ], 0 ) |
| 303 | m = re.match( "(\d+)\-(\d+)", args[ index ], flags=0 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 304 | if m: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 305 | start_case = eval( m.group( 1 ) ) |
| 306 | end_case = eval( m.group( 2 ) ) |
| 307 | if ( start_case <= end_case ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 308 | i = start_case |
| 309 | while i <= end_case: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 310 | testcases.append( i ) |
| 311 | i = i + 1 |
| 312 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 313 | print "Please specify testcases properly like 1-5" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 314 | else: |
| 315 | options[ option ] = args[ index ] |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 316 | return options |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 317 | options[ option ] = str( testcases ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 318 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 319 | return options |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 320 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 321 | def cmdloop( self, intro=introduction ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 322 | print introduction |
| 323 | while True: |
| 324 | try: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 325 | super( CLI, self ).cmdloop( intro="" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 326 | self.postloop() |
| 327 | except KeyboardInterrupt: |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 328 | if testthread: |
| 329 | testthread.pause() |
| 330 | else: |
| 331 | print "KeyboardInterrupt, Exiting." |
| 332 | sys.exit() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 333 | |
| 334 | def do_echo( self, line ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 335 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 336 | Echoing of given input. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 337 | """ |
| 338 | output( line ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 339 | |
| 340 | def do_sh( self, line ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 341 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 342 | Run an external shell command |
| 343 | sh pwd |
| 344 | sh ifconfig etc. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 345 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 346 | call( line, shell=True ) |
| 347 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 348 | def do_py( self, line ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 349 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 350 | Evaluate a Python expression. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 351 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 352 | py main.log.info( "Sample Log Information" ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 353 | 2013-01-07 12:07:26,804 - PoxTest - INFO - Sample Log Information |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 354 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 355 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 356 | try: |
| 357 | exec( line ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 358 | except Exception as e: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 359 | output( str( e ) + '\n' ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 360 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 361 | def do_interpret( self, line ): |
| 362 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 363 | interpret will translate the single line openspeak statement to equivalent python script. |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 364 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 365 | teston> interpret ASSERT result EQUALS main.TRUE ONPASS "Ping executed successfully" ONFAIL "Ping failed" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 366 | utilities.assert_equals( expect=main.TRUE,actual=result,onpass="Ping executed successfully",onfail="Ping failed" ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 367 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 368 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 369 | from core import openspeak |
| 370 | ospk = openspeak.OpenSpeak() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 371 | try: |
| 372 | translated_code = ospk.interpret( text=line ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 373 | print translated_code |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 374 | except AttributeError as e: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 375 | print 'Dynamic params are not allowed in single statement translations' |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 376 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 377 | def do_do( self, line ): |
| 378 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 379 | Do will translate and execute the openspeak statement for the paused test. |
| 380 | do <OpenSpeak statement> |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 381 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 382 | if testthread: |
| 383 | from core import openspeak |
| 384 | ospk = openspeak.OpenSpeak() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 385 | try: |
| 386 | translated_code = ospk.interpret( text=line ) |
| 387 | eval( translated_code ) |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 388 | except ( AttributeError, SyntaxError ) as e: |
| 389 | print 'Dynamic params are not allowed in single statement translations:' |
| 390 | print e |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 391 | else: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 392 | print "Do will translate and execute the openspeak statement for the paused test.\nPlease use interpret to translate the OpenSpeak statement." |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 393 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 394 | def do_compile( self, line ): |
| 395 | """ |
| 396 | compile will translate the openspeak ( .ospk ) file into TestON test script ( python ). |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 397 | It will receive the openspeak file path as input and will generate |
| 398 | equivalent test-script file in the same directory. |
| 399 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 400 | usage: |
| 401 | ----- |
| 402 | teston>compile /home/openflow/TestON/PoxTest.ospk |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 403 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 404 | Auto-generated test-script file is /home/openflow/TestON/PoxTest.py |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 405 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 406 | from core import openspeak |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 407 | openspeak = openspeak.OpenSpeak() |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 408 | openspeakfile = line |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 409 | if os.path.exists( openspeakfile ): |
| 410 | openspeak.compiler( openspeakfile=openspeakfile, writetofile=1 ) |
| 411 | print "Auto-generated test-script file is " + re.sub( "ospk", "py", openspeakfile, 0 ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 412 | else: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 413 | print 'There is no such file : ' + line |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 414 | |
| 415 | def do_exit( self, _line ): |
| 416 | "Exit" |
| 417 | if testthread: |
| 418 | testthread.stop() |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 419 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 420 | sys.exit() |
| 421 | |
| 422 | return 'exited by user command' |
| 423 | |
| 424 | def do_quit( self, line ): |
| 425 | "Exit" |
| 426 | return self.do_exit( line ) |
| 427 | |
| 428 | def do_EOF( self, line ): |
| 429 | "Exit" |
| 430 | output( '\n' ) |
| 431 | return self.do_exit( line ) |
| 432 | |
| 433 | def isatty( self ): |
| 434 | "Is our standard input a tty?" |
| 435 | return isatty( self.stdin.fileno() ) |
| 436 | |
| 437 | def do_source( self, line ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 438 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 439 | Read shell commands from an input file and execute them sequentially. |
| 440 | cmdsource.txt : |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 441 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 442 | "pwd |
| 443 | ls " |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 444 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 445 | teston>source /home/openflow/cmdsource.txt |
| 446 | /home/openflow/TestON/bin/ |
| 447 | cli.py __init__.py |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 448 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 449 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 450 | args = line.split() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 451 | if len( args ) != 1: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 452 | error( 'usage: source <file>\n' ) |
| 453 | return |
| 454 | try: |
| 455 | self.inputFile = open( args[ 0 ] ) |
| 456 | while True: |
| 457 | line = self.inputFile.readline() |
| 458 | if len( line ) > 0: |
| 459 | call( line, shell=True ) |
| 460 | else: |
| 461 | break |
| 462 | except IOError: |
| 463 | error( 'error reading file %s\n' % args[ 0 ] ) |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 464 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 465 | def do_time( self, line ): |
| 466 | "Measure time taken for any command in TestON." |
| 467 | start = time.time() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 468 | self.onecmd( line ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 469 | elapsed = time.time() - start |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 470 | self.stdout.write( "*** Elapsed time: %0.6f secs\n" % elapsed ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 471 | |
| 472 | def default( self, line ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 473 | "Called on an input line when the command prefix is not recognized." |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 474 | first, args, line = self.parseline( line ) |
| 475 | if not args: |
| 476 | return |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 477 | if args and len( args ) > 0 and args[ -1 ] == '\n': |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 478 | args = args[ :-1 ] |
| 479 | rest = args.split( ' ' ) |
| 480 | |
| 481 | error( '*** Unknown command: %s\n' % first ) |
| 482 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 483 | |
| 484 | class TestThread( threading.Thread ): |
| 485 | |
| 486 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 487 | TestThread class will handle the test execution and will communicate with the thread in the do_run. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 488 | """ |
| 489 | def __init__( self, options ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 490 | self._stopevent = threading.Event() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 491 | threading.Thread.__init__( self ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 492 | self.is_stop = False |
| 493 | self.options = options |
| 494 | __builtin__.testthread = self |
| 495 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 496 | def run( self ): |
| 497 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 498 | Will execute the test. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 499 | """ |
| 500 | while not self.is_stop: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 501 | if not self._stopevent.isSet(): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 502 | self.test_on = TestON( self.options ) |
| 503 | try: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 504 | if self.test_on.init_result: |
| 505 | result = self.test_on.run() |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 506 | if not self.is_stop: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 507 | result = self.test_on.cleanup() |
| 508 | self.is_stop = True |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 509 | except KeyboardInterrupt: |
| 510 | print "Recevied Interrupt, cleaning-up the logs and drivers before exiting" |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 511 | result = self.test_on.cleanup() |
| 512 | self.is_stop = True |
| 513 | |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 514 | __builtin__.testthread = False |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 515 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 516 | def pause( self ): |
| 517 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 518 | Will pause the test. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 519 | """ |
Jon Hall | 1306a56 | 2015-09-04 11:21:24 -0700 | [diff] [blame] | 520 | if not cli.pause: |
| 521 | print "Will pause the test's execution, after completion of this step.....\n\n\n\n" |
| 522 | cli.pause = True |
| 523 | self._stopevent.set() |
| 524 | elif cli.pause and self.is_stop: |
| 525 | print "KeyboardInterrupt, Exiting." |
| 526 | self.test_on.exit() |
| 527 | else: |
| 528 | print "Recevied Interrupt, cleaning-up the logs and drivers before exiting" |
| 529 | result = self.test_on.cleanup() |
| 530 | self.is_stop = True |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 531 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 532 | def play( self ): |
| 533 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 534 | Will resume the paused test. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 535 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 536 | self._stopevent.clear() |
| 537 | cli.pause = False |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 538 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 539 | def stop( self ): |
| 540 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 541 | Will stop the test execution. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 542 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 543 | print "Stopping the test" |
| 544 | self.is_stop = True |
| 545 | cli.stop = True |
| 546 | __builtin__.testthread = False |
Jon Hall | 4ba53f0 | 2015-07-29 13:07:41 -0700 | [diff] [blame] | 547 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 548 | |
| 549 | def output( msg ): |
| 550 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 551 | Simply, print the message in console |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 552 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 553 | print msg |
| 554 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 555 | |
| 556 | def error( msg ): |
| 557 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 558 | print the error message. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 559 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 560 | print msg |
| 561 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 562 | |
| 563 | def dictToObj( dictionary ): |
| 564 | """ |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 565 | This will facilitates the converting of the dictionary to the object. |
| 566 | This method will help to send options as object format to the test. |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 567 | """ |
| 568 | if isinstance( dictionary, list ): |
| 569 | dictionary = [ dictToObj( x ) for x in dictionary ] |
| 570 | if not isinstance( dictionary, dict ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 571 | return dictionary |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 572 | |
| 573 | class Convert( object ): |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 574 | pass |
| 575 | obj = Convert() |
| 576 | for k in dictionary: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 577 | obj.__dict__[ k ] = dictToObj( dictionary[ k ] ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 578 | return obj |
| 579 | |
| 580 | |
| 581 | if __name__ == '__main__': |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 582 | if len( sys.argv ) > 1: |
Jon Hall | 0bde9ba | 2015-03-19 11:32:57 -0700 | [diff] [blame] | 583 | __builtin__.COLORS = True |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 584 | CLI( "test" ).onecmd( ' '.join( sys.argv[ 1: ] ) ) |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 585 | else: |
Jon Hall | 0bde9ba | 2015-03-19 11:32:57 -0700 | [diff] [blame] | 586 | __builtin__.COLORS = False |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 587 | CLI( "test" ).cmdloop() |