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