示例#1
0
 def RunTestWithStar(self, commandline):
     #print 'os.environ is 1:\n'
     #print os.environ
     result = ''
     commandline = commandline.lstrip() #remove left space
     if(commandline.find('*') == -1 or self.mvn == 1):
         res = ''
         returncode,res = command.DoCmd(commandline,'')
         result = result + res
     else:
         testlist = glob(os.getcwd() + '/' + commandline)
         for test in testlist:
             command.DoCmd(test,'')
     return result
示例#2
0
    def RunSingleTest(self, unittestcommand):
        result = ""
        os.chdir(self.BasePath)

        if(self.onecommand == 1):
            returncode,res = command.DoCmd(self.unittestcommands,'')
            return res
        commandlines=unittestcommand.split(";");
        for line in commandlines:
            if(line.lstrip().startswith('cd ') == True):   # hard code here, to to modify
                newline = line.replace('cd', '').strip()
                if (newline.lstrip()[0] == '/'):
                    pwd = newline
                else:
                    pwd = os.getcwd() + '/' + newline # MUST using string adding here, instead of os.path.join()
                os.chdir(pwd) 
            elif(line.lstrip().startswith('export ') == True):   # hard code here, to to modify
                line = line.replace('export', '').strip()  #strip() in python remove NOT ONLY spce but also whitespace characters as well(eg. tabs and newlines)
                lines = line.split('=')
                if(len(lines) == 2):
                    key = lines[0]
                    value = lines[1]
                    os.environ[key] = value  # set linux environment value, DO NOT use os.putenv(), because putenv() does not change of.envrion directly.
            else:
                result = result + self.RunTestWithStar(line)
        return result
示例#3
0
 def output_log(self):
     log_dir = ''
     for root, dirs, files in os.walk(self.BasePath, None, False):
         for filename in files:
             if filename == log:
                 log_dir = os.path.abspath(os.path.join(root, filename))
     if '' != log_dir:
         command.DoCmd("cat " + log_dir, '')
     else:
         print "xml log does not exists"
示例#4
0
 def ToHtdocsForMvn(self):
     source = os.path.join(self.makefilepath, "target/site")
     if os.path.exists(source):
         now = datetime.datetime.now().strftime("%m-%d-%Y-%X")
         directory = '/tmp/' + now
         copy = "cp -r " + source + " " + directory
         command.DoCmd(copy, '')
         self.ToHtdocs(directory)
         self.DisplayURL(now)
     else:
         print "Couldn't generate coverage info"
示例#5
0
 def PackagesWithVersion(self,package,version,cmp):
     yumlist_cmd = "yum list " +package + " | grep "+package
     code,outputs = command.DoCmd(yumlist_cmd,'')
     if code == 0:
         results = outputs.split("\n")[:-1]
         for result in results:
             exist_version = result.split()[1]
             if self.StrCmp(exist_version.strip(),version.strip(),cmp):
                 package = package.strip() +"-"+exist_version.strip()
                 return package
     return package
示例#6
0
 def ToHtdocsForShell(self):
     if shellcov == "":
         print "the codecoverage does not exist"
         return
     now = datetime.datetime.now().strftime("%m-%d-%Y-%X")
     directory = "/tmp/" + now
     copy = "cp -r " + shellcov + " " + directory
     command.DoCmd(copy, '')
     self.ToHtdocs(directory)
     self.DisplayURL(now)
     if os.path.exists(shellcov + "/index.html"):
         self.output_lineinfo(shellcov + "/index.html")
示例#7
0
    def OutputHtmlDataForScons(self):
        self.Debug('Start to capture coverage data by lcov.....')
        if self.ignoreDirs != []:
            self.RemoveIgnoreDirs()

        lcov_cmd = self.Lcov + " -c -d ./build/ -b . -o " + " app.info"
        command.DoCmd1(lcov_cmd)

        self.lcov_info = os.path.abspath("app.info")

        import replacedir
        replacedir.visit_dir(self.BasePath)
        replacedir.deal_file("app.info")
        if os.path.exists("tmp.info"):
            subprocess.call("mv tmp.info app.info", shell=True)
        print 'replace dir processing end'

        os.system("find -name \"*.gcno\" |xargs rm -rf")
        os.system("find -name \"*.gcda\" |xargs rm -rf")
        #Get Current time and store html output to the directory named with current time
        self.Debug(
            'Store html output to the directory named with current time')
        now = datetime.datetime.now().strftime("%m-%d-%Y-%X")
        directory = '/tmp/' + now
        info_path = os.path.join(self.makefilepath, "app.info")
        genhtml_cmd = self.Genhtml + ' ' + info_path + ' -o ' + directory
        cp_info = "cp -r " + info_path + " " + directory
        command.WriteFile('genhtml_cmd is:\t' + genhtml_cmd)
        command.DoCmd(genhtml_cmd, '')
        command.DoCmd(cp_info, '')
        print "\nInfomations for code coverage in the: " + directory + "\n"

        self.OutPutLineInfoForGcov(self.LogFile)
        self.OutPutBranchInfoForGcov(self.LogFile)

        self.ToHtdocs(directory)
        self.DisplayURL(now)
示例#8
0
    def ToHtdocsForPython(self):
        cov_dir = ''
        for root, dirs, files in os.walk(self.BasePath, None, False):
            for directory in dirs:
                if directory == "htmlcov":
                    cov_dir = os.path.abspath(os.path.join(root, directory))

        if cov_dir != '':
            now = datetime.datetime.now().strftime("%m-%d-%Y-%X")
            directory = '/tmp/' + now
            copy = "cp -r " + cov_dir + " " + directory
            command.DoCmd(copy, '')
            self.ToHtdocs(directory)
            self.DisplayURL(now)
            #self.output_lineinfo()
            self.output_lineinfo(cov_dir + "/index.html")
        else:
            print "Couldn't generate coverage info"
示例#9
0
 def ToHtdocs(self, fromdir):
     self.Debug('copy html informations To htdocs/')
     if self.HTDOCS == 1:
         to=self.Htdocs
         self.ValidateExist(fromdir)
         cmd='cp -r '+fromdir+' '+to
         command.DoCmd(cmd,'')
     if self.IP != "" and self.ServerAccount !="" and self.ServerPwd != "" and self.ServerHtdocs != "":
         import pexpect
         to = self.ServerAccount+"@"+self.IP+":"+self.ServerHtdocs
         scp_cmd = "scp -r " + fromdir + " "+to
         try:
             send = pexpect.spawn(scp_cmd)
             fout = file(self.LogFile,'a')
             send.logfile = fout
             index = send.expect(['yes/no','(p|P)(a|A)(s|S)(s|S)(w|W)(o|O)(r|R)(d|D)',pexpect.EOF,pexpect.TIMEOUT])
             if index == 0:
                 send.sendline('yes')
                 pwd = send.expect(['(p|P)(a|A)(s|S)(s|S)(w|W)(o|O)(r|R)(d|D)',pexpect.EOF,pexpect.TIMEOUT])
                 if pwd == 0:
                     send.sendline(self.ServerPwd)
                 else:
                     print 'scp failed'
                     send.close(force=True)
             elif index == 1:
                 send.sendline(self.ServerPwd)
             else:
                 print "Can't connect to "+self.IP
                 send.close(force =True)
             send.expect(pexpect.EOF)
             fout.close()
             send.interact() 
         except:
             print "some unkown error"
             send.close(force=True)
     shutil.rmtree(fromdir)
示例#10
0
            return
        try:
            os.makedirs(reports_dir)
        except Exception, e:
            print "We meet an exception when creating surefire_reports directory"
            print e
            return

        #copy images and css to reports_dir
        images_dir = os.path.join(reports_dir, "images")
        css_dir = os.path.join(reports_dir, "css")
        if not os.path.exists(images_dir) or not os.path.exists(css_dir):
            images, css = self.find_images_css()
            if images != '':
                cp_images = "cp -r " + images + " " + images_dir
                command.DoCmd(cp_images, '')
            if css != '':
                cp_css = "cp -r " + css + " " + css_dir
                command.DoCmd(cp_css, '')

        for root, dirs, files in os.walk(self.makefilepath):
            for file_name in files:
                if file_name == "surefire-report.html" and root != self.makefilepath and not root.startswith(
                        reports_dir):
                    sub_dirs = root.replace(self.makefilepath,
                                            '').replace("/target/site",
                                                        '').split("/")
                    for sub_dir in sub_dirs:
                        if sub_dir == '':
                            sub_dirs.remove(sub_dir)
                    sub_dirs.append("surefire-report.html")
示例#11
0
    def OutputHtmlData(self):
        self.Debug('Start to capture coverage data by lcov.....')
        if self.ignoreDirs != []:
            self.RemoveIgnoreDirs()
        i = 0
        for root, dirs, files in os.walk(self.makefilepath, False):
            for dirname in dirs:
                dirname = os.path.join(root, dirname)
                command.WriteFile("lcovpath: " + dirname)
                if os.path.isdir(dirname) and self.HasGcda(dirname) == True:
                    os.chdir(dirname)
                    outputpath = os.path.join(self.makefilepath,
                                              str(i) + ".info")
                    lcov_cmd = self.Lcov + " -c -d . -b . -o " + outputpath + " >> " + self.LogFile
                    i = i + 1
                    command.DoCmd1(lcov_cmd)
        dirlist = os.listdir(self.makefilepath)
        hasgcda = False
        for myfile in dirlist:
            if os.path.isfile(os.path.join(
                    self.makefilepath, myfile)) and myfile.endswith(".gcda"):
                hasgcda = True
                break
        if hasgcda:
            os.chdir(self.makefilepath)
            outputpath = os.path.join(self.makefilepath, str(i) + ".info")
            lcov_cmd = self.Lcov + " -c -d . -b . -o " + outputpath + ">>" + self.LogFile
            command.DoCmd1(lcov_cmd)

        infolist = os.listdir(self.makefilepath)
        lcov = self.Lcov

        for myfile in infolist:
            if myfile.endswith(".info"):
                if dealinfo.check_file(os.path.join(self.makefilepath,
                                                    myfile)):
                    lcov = lcov + " -a " + myfile

        os.chdir(self.makefilepath)
        if (self.extract == 1):
            lcov = lcov + " -o app1.info"
            command.DoCmd(lcov, '')

            lcov = self.Lcov + " -e app1.info *" + self.makefilepath + "* -o app.info"
            command.DoCmd(lcov, '')
        else:
            lcov = lcov + " -o app.info"
            command.DoCmd(lcov, '')

        replacedir.visit_dir(self.BasePath)
        replacedir.deal_file("app.info")
        if os.path.exists("tmp.info"):
            subprocess.call("mv tmp.info app.info", shell=True)
        print 'replace dir processing end'

        self.lcov_info = os.path.abspath("app.info")

        if (self.keep == 1):
            dealinfo.modify_info("app.info", self.BasePath)

        os.system("find -name \"*.gcno\" |xargs rm -rf")
        os.system("find -name \"*.gcda\" |xargs rm -rf")
        #Get Current time and store html output to the directory named with current time
        self.Debug(
            'Store html output to the directory named with current time')
        now = datetime.datetime.now().strftime("%m-%d-%Y-%X")
        directory = '/tmp/' + now
        info_path = os.path.join(self.makefilepath, "app.info")
        genhtml_cmd = self.Genhtml + ' ' + info_path + ' -o ' + directory
        cp_info = "cp -r " + info_path + " " + directory
        command.WriteFile('genhtml_cmd is:\t' + genhtml_cmd)
        command.DoCmd(genhtml_cmd, '')
        command.DoCmd(cp_info, '')
        print "\nInfomations for code coverage in the: " + directory + "\n"

        self.OutPutLineInfoForGcov(self.LogFile)
        self.OutPutBranchInfoForGcov(self.LogFile)

        self.ToHtdocs(directory)
        self.DisplayURL(now)