def testToXml(self):
     dom = minidom.parseString(self.cd.toxml())
     self.assertEquals(dom.documentElement.tagName,'compile')
     self.assertEquals(int(getfield(dom,'time')),1124659109)
     self.assertEquals(getfield(dom,'timestr'),'Sun Aug 21 17:18:29 2005')
     self.assertEquals(getfield(dom,'subject'),'fifi')
     self.assertEquals(getfield(dom,'command'),'gcc')
     self.assertEquals(int(getfield(dom,'time_interval')),8)
    def testRecordingPath(self):
        xml =  '\n'.join(["<log>,",
                          self.cd.toxml(),
                          "</log>"])
	dom = minidom.parseString(xml)
	sfnode = dom.getElementsByTagName('sourcefile')[0]
	self.assertEquals(getfield(sfnode,'path'),'/foo/bar/baz')
    def testScript(self):
	scr = """#!/usr/bin/bash
# This is an example of a test script
lamboot $PBS_NODEFILE

mpirun C myprog

lamhalt
"""
	self.assertEquals(base64.decodestring(getfield(self.job,'script')),scr)
    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 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 testCommand(self):
	self.assertEquals(getfield(self.job,'command'),"pat_hwpc -f -o test/testsource/perflog aprun -n4 ./cg 1000 1000")
    def testTimestr(self):
	self.assertEquals(getfield(self.job,'timestr'),
			  'Sun Aug 21 17:18:29 2005')
    def testTime(self):
	self.assertEquals(int(getfield(self.job,'time')),1124659109)
    def testSubject(self):
	self.assertEquals(getfield(self.job,'subject'),'foobar')
 def testContents(self):
     self.assertEquals(getfield(self.repnode,'contents'),"This <is> the report")
 def testProfileData(self):
     self.assertEquals(getfield(self.job,'profiledata'),open('test/testsource/perflog.hwpc').read())
 def testSubject(self):
     self.assertEquals(getfield(self.repnode,'subject'),'lorin')
    def testPath(self):
	self.assertEquals(getfield(self.job,'path'),'/tmp')
    def testCommand(self):
	self.assertEquals(getfield(self.job,'command'),"qsub -lnodes=2 test/testsource/run.sh")
 def testProfileData(self):
     self.assertEquals(getfield(self.job, "profiledata"), open(self.outfile).read())
 def testPath(self):
     self.assertEquals(getfield(self.job,'path'),'/home/resh/lorin/src')
 def testTimeInterval(self):
     self.assertEquals(float(getfield(self.job,'time_interval')),.15)
 def testCommand(self):
     self.assertEquals(getfield(self.repnode,'command'),'gprof ./loop')
    def testToXml(self):
        xml =  '\n'.join(["<log>,",
                          self.cd.toxml(),
                          "</log>"])
        dom = minidom.parseString(xml)
        self.assertEquals(dom.documentElement.tagName,'log')
        sfnodes = dom.getElementsByTagName('sourcefile')
        self.assertEquals(getfield(sfnodes[0],'name'),
                          'test/testsource/syntax_error.c')
        self.assertEquals(getfield(sfnodes[1],'name'),
                          'test/testsource/outerr.c')
        self.assertEquals(base64.decodestring(getfield(sfnodes[0],'source')),
                          open('test/testsource/syntax_error.c').read())
        self.assertEquals(base64.decodestring(getfield(sfnodes[1],'source')),
                          open('test/testsource/outerr.c').read())

        for sfnode in sfnodes:
            self.assertEquals(int(getfield(sfnode,'time')),
                              1124659109)
            self.assertEquals(getfield(sfnode,'timestr'),
                              'Sun Aug 21 17:18:29 2005')
            self.assertEquals(getfield(sfnode,'subject'),
                              'foobar'),
            self.assertEquals(getfield(sfnode,'command'),
                              'mpicc -o foobar test/testsource/syntax_error.c test/testsource/outerr.c')

        
        hfnodes = dom.getElementsByTagName('headerfile')
        self.assertEquals(getfield(hfnodes[0],'name'),
                          'test/testsource/outerr.h')
        self.assertEquals(getfield(hfnodes[1],'name'),
                          'test/testsource/syntax_error.h')
        self.assertEquals(base64.decodestring(getfield(hfnodes[0],'source')),
                          open('test/testsource/outerr.h').read())
        self.assertEquals(base64.decodestring(getfield(hfnodes[1],'source')),
                          open('test/testsource/syntax_error.h').read())

        for hfnode in hfnodes:
            self.assertEquals(int(getfield(hfnode,'time')),
                              1124659109)
            self.assertEquals(getfield(hfnode,'timestr'),
                              'Sun Aug 21 17:18:29 2005')
            self.assertEquals(getfield(hfnode,'subject'),
                              'foobar'),
            self.assertEquals(getfield(hfnode,'command'),
                              'mpicc -o foobar test/testsource/syntax_error.c test/testsource/outerr.c')
 def testPath(self):
     self.assertEquals(getfield(self.repnode,'path'),'/foo/bar/baz')