Classes | |
class | IPv6SuiteInit |
class | IPv6SuiteTest |
Functions | |
def | mkdirs |
def | IdToDir |
def | CleanUp |
def | Run |
def | findFile |
def | copyInputFiles |
os.path.walk(os.path.join(buildDir, "exe"), findFile, self.scenario) | |
def | fixPaths |
def | CompareFiles |
# self.RunProgram("./" + os.path.basename(self.scenario), args, context, result) self.RunProgram('/tmp/IPv6Suite/build-init/ipv6suite/testnew/MIPv6Network', ['/tmp/IPv6Suite/build-init/ipv6suite/testnew/MIPv6Network', '-r1'], context, result) # self.RunProgram("/bin/echo", ["/bin/echo", "hello ", " world"], context, result) | |
def | RunProgram |
Copied from ExecTestBase.RunProgram and modified so that stdout/stderr is always displayed. | |
Variables | |
scenario | |
compare_dir | |
compare_dir | |
differences |
def ipv6suite_test::mkdirs | ( | newdir, | ||
mode = 0775 | ||||
) |
More use than the usual os.makedirs as it allows a directory to exist without giving error so I don't have to test if it exists etc.
00046 : 00047 """ More use than the usual os.makedirs as it allows a directory to exist without giving error so I don't have to test if it exists etc. 00048 """ 00049 try: os.makedirs(newdir, mode) 00050 except OSError, err: 00051 if err.errno != errno.EEXIST or not os.path.isdir(newdir): 00052 raise 00053 def IdToDir(self):
def ipv6suite_test::IdToDir | ( | self | ) |
As QMTest default XML database only accepts filenames with one . it is better to create the hierarchical directories without the '.' in the dir name if the test/resource is in a subdirectory. self is either a descendent of Test or Resource.
00054 : 00055 """ As QMTest default XML database only accepts filenames with one . it is better to create the hierarchical directories without the '.' in the dir name if the test/resource is in a subdirectory. self is either a descendent of Test or Resource. 00056 """ 00057 00058 return re.sub(r'\.', "/", self.GetId()) 00059 ########################################################################
def ipv6suite_test::CleanUp | ( | self, | ||
result | ||||
) |
def ipv6suite_test::findFile | ( | absfile, | ||
path, | ||||
names | ||||
) |
def ipv6suite_test::copyInputFiles | ( | unused, | ||
path, | ||||
names | ||||
) |
os.path.walk(os.path.join(buildDir, "exe"), findFile, self.scenario)
00361 : 00362 for f in names: 00363 if not os.path.isfile(os.path.join(path, f)): 00364 del names[names.index(f)] #prevent *.vec files from been copied too as compare_dir is subdir 00365 #Need to reiterate again as deletion causes the iterator to point to one past the next one so we miss a file :( 00366 #If there was more than one subdir then above loop would fail since the iterator problem would miss a directory and we'd end up in a subdir again. Need to read up further. For now assume only a subdir 00367 for f in names: 00368 if os.path.isfile(os.path.join(path, f)): 00369 shutil.copy2(os.path.join(path, f), runDir) 00370 00371 os.path.walk(input_dir, copyInputFiles, "")
def ipv6suite_test::fixPaths | ( | unused, | ||
path, | ||||
names | ||||
) |
def ipv6suite_test::CompareFiles | ( | self, | ||
context, | ||||
result, | ||||
input_dir, | ||||
runDir | ||||
) |
# self.RunProgram("./" + os.path.basename(self.scenario), args, context, result) self.RunProgram('/tmp/IPv6Suite/build-init/ipv6suite/testnew/MIPv6Network', ['/tmp/IPv6Suite/build-init/ipv6suite/testnew/MIPv6Network', '-r1'], context, result) # self.RunProgram("/bin/echo", ["/bin/echo", "hello ", " world"], context, result)
00411 : 00412 00413 expected_directories = "expected" 00414 00415 if self.compare_dir == "": 00416 compare_dir = os.path.join(self.GetDatabase().GetRoot(), expected_directories, IdToDir(self)) 00417 else: 00418 compare_dir = os.path.join(self.GetDatabase().GetRoot(), expected_directories, self.compare_dir) 00419 00420 #Does this change test database? 00421 self.compare_dir = compare_dir 00422 00423 try: 00424 generateExpectedResults = qm.parse_boolean(context["IPv6Suite.build"]) 00425 except: 00426 generateExpectedResults = 0 00427 00428 if generateExpectedResults: 00429 print "Generating expected results for test " + self.GetId() + " into " + compare_dir 00430 00431 if not generateExpectedResults and not os.path.exists(compare_dir): 00432 return result.SetOutcome(result.ERROR, " compare_dir "+ self.compare_dir + " does not exist") 00433 00434 00435 self.differences = "" 00436 def diffResults(unused ,path, names): 00437 for f in names: 00438 if os.path.isfile(os.path.join(path, f)): 00439 if not os.path.isfile(os.path.join(runDir, f)): 00440 return result.Fail("Result file " + f + " was not produced!") 00441 if not filecmp.cmp(os.path.join(path, f), os.path.join(runDir, f)): 00442 self.differences += f + " " 00443 continue 00444 if re.match(r'2\.3', sys.version): 00445 result[f] = result.Quote(''.join( 00446 difflib.unified_diff(open(os.path.join(path, f)).read(), 00447 open(os.path.join(runDir, f)).read()))) 00448 else: 00449 diff = ndiff(open(os.path.join(path, f)).read(), 00450 open(os.path.join(runDir, f)).read()) 00451 result[f] = result.Quote(''.join(diff)) 00452 00453 #Compare output to expected and preverified results 00454 if os.path.exists(compare_dir): 00455 os.path.walk(compare_dir, diffResults, None) 00456 if self.differences: 00457 result["different results"] = result.Quote(self.differences) 00458 result.Fail(" Resulting output files differ: " + self.differences) 00459 00460 #Copy result files to output dir for later perusal 00461 output_dir = os.path.join(self.GetDatabase().GetRoot(), "test_output", IdToDir(self)) 00462 if not os.path.exists(output_dir): 00463 os.makedirs(output_dir) 00464 00465 def copyOutputFiles(dest, path, names): 00466 for f in names: 00467 file = os.path.join(path, f) 00468 if os.path.isfile(file): 00469 if re.search(r'\.vec$|\.sca', f): 00470 print " moving " + f + " to " + dest 00471 #os.rename(file, os.path.join(dest, f)) #Does not work as it uses link so needs same filesystem 00472 shutil.copy2(file, dest) 00473 os.remove(file) 00474 00475 if not generateExpectedResults: 00476 os.path.walk(runDir, copyOutputFiles, output_dir) 00477 else: 00478 os.path.walk(runDir, copyOutputFiles, compare_dir) 00479 00480 00481 ## Copied from ExecTestBase.RunProgram and modified so that stdout/stderr is always displayed
def ipv6suite_test::RunProgram | ( | self, | ||
program, | ||||
arguments, | ||||
context, | ||||
result | ||||
) |
Copied from ExecTestBase.RunProgram and modified so that stdout/stderr is always displayed.
Run the 'program'. 'program' -- The path to the program to run. 'arguments' -- A list of the arguments to the program. This list must contain a first argument corresponding to 'argv[0]'. 'context' -- A 'Context' giving run-time parameters to the test. 'result' -- A 'Result' object. The outcome will be 'Result.PASS' when this method is called. The 'result' may be modified by this method to indicate outcomes other than 'Result.PASS' or to add annotations.
00483 : 00484 """Run the 'program'. 00485 00486 'program' -- The path to the program to run. 00487 00488 'arguments' -- A list of the arguments to the program. This 00489 list must contain a first argument corresponding to 'argv[0]'. 00490 00491 'context' -- A 'Context' giving run-time parameters to the 00492 test. 00493 00494 'result' -- A 'Result' object. The outcome will be 00495 'Result.PASS' when this method is called. The 'result' may be 00496 modified by this method to indicate outcomes other than 00497 'Result.PASS' or to add annotations.""" 00498 00499 # Construct the environment. 00500 environment = self.MakeEnvironment(context) 00501 # Create the executable. 00502 if self.timeout >= 0: 00503 timeout = self.timeout 00504 else: 00505 # If no timeout was specified, we sill run this process in a 00506 # separate process group and kill the entire process group 00507 # when the child is done executing. That means that 00508 # orphaned child processes created by the test will be 00509 # cleaned up. 00510 timeout = -2 00511 e = qm.executable.Filter(self.stdin, timeout) 00512 # Run it. 00513 # print arguments 00514 # print " path "+ program 00515 exit_status = e.Run(arguments, environment, path = program) 00516 00517 # Get the output generated by the program regardless of how program finished 00518 stdout = e.stdout 00519 stderr = e.stderr 00520 # Record the results. 00521 00522 #Stdout is too big we need to just discard it I guess or save it as stdout.out in output 00523 result["ExecTest.stdout"] = result.Quote(stdout) 00524 result["ExecTest.stderr"] = result.Quote(stderr) 00525 00526 if not re.search(r'End run of OMNeT',e.stdout) and not re.search(r'Calling finish', e.stdout): 00527 return result.Fail("Simulation did not end properly") 00528 00529 # If the process terminated normally, check the outputs. 00530 if sys.platform == "win32" or os.WIFEXITED(exit_status): 00531 # There are no causes of failure yet. 00532 causes = [] 00533 # The target program terminated normally. Extract the 00534 # exit code, if this test checks it. 00535 if self.exit_code is None: 00536 exit_code = None 00537 elif sys.platform == "win32": 00538 exit_code = exit_status 00539 else: 00540 exit_code = os.WEXITSTATUS(exit_status) 00541 ## result["ExecTest.exit_code"] = str(exit_code)