import sys import os import subprocess test_array = dict([ ('core' , 'top' ) ]) test_keys = test_array.keys() def param_help(): print ''' +-------------------------------------------------------------+ | Script: test.py | | | | Description: This top level python script | | spawns a number of test scripts according to | | the following command line switches: | | | | -help : Shows this message | | | | -list : displays the block names | | | | -block= : Specifies which IP block requires testing, | | "all" tests all available blocks | | | | -name= : Specifies which test requires running, | | "all" runs all the available tests | | | | -batch : Runs the selected tests | | in batch rather than interactive mode | | | | -qsys : Generates source code from Qsys project | | | | -jenkins : run in Jenkins mode | | | +-------------------------------------------------------------+ ''' def test_list(): print 'The list of available block names is as follows:' for i in test_keys: print i def arg_check(): myArgs = sys.argv myArgs.pop(0) doHelp = 0 doList = 0 doTest = 0 batchMode = 0 buildQsys = 0 testBlock = '' testName = 'all' badParam = 0 isJenkins = False if len(myArgs)==0: doHelp = 1 for i in myArgs: myList = i.split('=') opcode = myList[0] opcode = opcode[1:] print opcode if opcode=='help': doHelp = 1 elif opcode=='list': doList = 1 elif opcode=='batch': batchMode = 1 elif opcode=='qsys': buildQsys = 1 elif ((opcode=='block') and (len(myList)==2)): doTest = 1 testBlock = myList[1] elif ((opcode=='name') and len(myList)==2): testName = myList[1] print 'Found specific test '+myList[1] elif opcode == 'jenkins' : isJenkins = True else: badParam = 1 print 'Parameter not recognised...' if ((doHelp==1) or (badParam==1)): param_help() print doTest elif doList==1: test_list() elif doTest==1: setup_test(testBlock, testName, batchMode, buildQsys, isJenkins) def setup_test(testBlock, testName, batchMode, buildQsys, isJenkins): if (testBlock=='all'): for i in test_keys: print 'Doing test: ' + i do_test(i, testName, batchMode, buildQsys, isJenkins) elif (testBlock in test_keys): print 'Doing test: ' + testBlock do_test(testBlock, testName, batchMode, buildQsys, isJenkins) else: print 'Test not recognised...' test_list() def do_test(testBlock, testName, batchMode, buildQsys, isJenkins): if isJenkins : os.chdir(os.path.join(os.getcwd(), 'firmware', 'FujiDigimax', 'HMB-FD-GMA', 'firmware', test_array[testBlock], 'sim')) else : os.chdir(os.path.join(os.path.dirname(os.path.dirname(os.getcwd())),test_array[testBlock],'sim')) j = [testBlock, ".py"] k = "".join(j) l = "noBatch" m = "noQsys" n = testName if batchMode==1: l = "yesBatch" if buildQsys==1: m = "yesQsys" print "currently in directory: {}".format(os.getcwd()) print "test.py: do_test:: about to call with {},{},{},{}".format(k,l,m,n) try : subprocess.check_call(["python", k, l, m, n]) except : print '***ERROR:' + k + ' returned with non-zero status' exit(1) arg_check()