def testCapture(self): logfile = wrap.getlogfilepath(self.logfiledir) wrap.capture_profiled_run(runprog=self.runprog, outfile=self.outfile, argv=self.args, logex=logfile) dom = minidom.parse(wrap.getlogfilepath(self.logfiledir)) self.job = dom.getElementsByTagName('job')[0] # Profile data should be just a space self.assertEquals(getfield(self.job,'profiledata'),' ')
def tearDown(self): # Remove the subject logfile, if it exists try: os.unlink(wrap.getlogfilepath(self.logfiledir)) except OSError, e: if e.errno!=errno.ENOENT: raise e
def testCapture(self): # gprof will output a lot to standard out, which we will redirect # to /dev/null stdout = sys.stdout try: sys.stdout.flush() sys.stdout = open("/dev/null", "w") logfile = wrap.getlogfilepath(self.logfiledir) wrap.capture_profile_report(self.runprog, argv=self.args, logex=logfile) finally: sys.stdout = stdout logfile = wrap.getlogfilepath(self.logfiledir) dom = minidom.parseString(wrap.printable(open(logfile).read())) report = dom.getElementsByTagName("profile_report")[0] # Contents should be the same as contents of running gprof gprof_output = commands.getoutput("gprof ./loop") self.assertEquals(getfield(report, "contents"), wrap.printable(gprof_output))
def testCapture(self): command = 'gcc -c test/testsource/outerr.c' args = command.split() logfile = wrap.getlogfilepath(self.logfiledir) wrap.capture_compile(self.compiler,args,logex=logfile) xml = xmlifyfile(logfile) dom = minidom.parseString(xml) # Just check if it stored the fields self.assertEquals(dom.documentElement.tagName,'log') self.assertEquals(len(dom.getElementsByTagName('sourcefile')),1) self.assertEquals(len(dom.getElementsByTagName('headerfile')),1)
def setUp(self): # Build the "loop.c" program os.system("gcc -g -o loop test/testsource/loop.c") # Create a subdirectory to hold the log file dirname = "testcaptureprofiledrun" self.logfiledir = os.path.abspath(os.path.join(".", dirname)) try: os.mkdir(self.logfiledir) except OSError: pass # The profiler used depends on the OS # Linux: valgirnd # OS X: shark osname = commands.getoutput("uname") if osname == "Linux": # Generates a file called cachegrind.out self.runprog = "test/testsource/valgrind.py" os.chmod(self.runprog, 0755) self.args = "valgrind --tool=cachegrind ./loop".split() self.outfile = "cachegrind.out" elif osname == "Darwin": # Delete all files that start with session_ for fname in os.listdir("."): if fname.startswith("session_"): os.unlink(fname) self.runprog = "test/testsource/shark.py" self.args = "shark -G -i ./loop".split() self.outfile = "session_001-report.txt" programcheck(self.runprog) logfile = wrap.getlogfilepath(self.logfiledir) wrap.capture_profiled_run(runprog=self.runprog, outfile=self.outfile, argv=self.args, logex=logfile) dom = minidom.parse(wrap.getlogfilepath(self.logfiledir)) self.job = dom.getElementsByTagName("job")[0]
def testCapture(self): logfile = wrap.getlogfilepath(self.logfiledir) wrap.capture_batch_run(self.runprog,logex=logfile) dom = minidom.parse(logfile) self.assertEquals(dom.documentElement.tagName,'job')
def testLogfileName(self): """Test the function that determines the logfile path""" logfiledir = '/foo/bar/baz' self.assertEquals(wrap.getlogfilepath(logfiledir), '/foo/bar/baz/' + wrap.getlogin() + '.log')