示例#1
0
 def doCopy(self,**copyinfo):
     '''
     @param copyinfo:{'VI':(),
                      'VD':(),
                      'FD':(),
                      'FB':(),
                      'OD':'out file dir',
                      'OF':'out filename without extension(.c)', # suffix number in the case of multiple outfile
                     }
     '''
     self._copydir=''
     funcbodys=copyinfo.get('FB',())
     if self._funcname and self._funcname not in funcbodys:
         funcbodys=tuple(list(funcbodys)+[self._funcname,])
     if len(funcbodys)<1:
         return False
     outdir=copyinfo.get('OD','')
     outfile=copyinfo.get('OF','')
     if not outdir:
         return False
     funcfiles=self.filterFiles(self.findFunc())
     if not funcfiles:
         return False
     self._copydir=outdir
     if not os.path.exists(outdir) or not os.path.isdir(outdir):
         os.makedirs(outdir)
     fileset=set()
     for finfo in funcfiles:
         fileset.add(finfo['tokfile'])
     cinfo={'FB':funcbodys,
            'DMY':(),
            'VI':copyinfo.get('VI',()),
            'VD':copyinfo.get('VD',()),
            }
     if len(fileset)>1:
         for i,tokfile in enumerate(list(fileset)):
             cinfo['OF']=os.path.join(outdir,outfile+str(i+1)+'.c')
             cparser.copyFile(tokfile,cinfo)
     else:
         cinfo['OF']=os.path.join(outdir,outfile+'.c')
         cparser.copyFile(fileset.pop(),cinfo)
示例#2
0
    def generateProj(self, info):
        """
        @param info:{'driverfile':"xxx",
                     'srcpath':"xxx",
                     'tokpath':"xxx",
                     'autovc':True/False,
                     'vcproj':"xxx",
                     'mcdc':True/False,
                     'tplpath':"xxx", # folder for template files
                     'vcpath':"xxx",
                     'testrtpath':"xxx', # used when mcdc==True
                    }
        """
        if self._checkParam(info):
            self._dp.parse(info["driverfile"])
            # only one source file contains target_func?
            fdict = cparser.getFuncInfo(info["srcpath"], info["tokpath"], self._dp.target_func)
            fileset = set()
            for finfo in fdict[self._dp.target_func]:
                fileset.add(finfo["srcfile"])
            if len(fileset) > 1:
                self._log.error("Found function[%s] in multiple files:%s" % (self._dp.target_func, str(fileset)))
                return False
            tokfile = fdict[self._dp.target_func][0]["tokfile"]
            cinfo = {"FB": (self._dp.target_func,), "DMY": []}

            # copy driver file
            copieddir = normpath(info["driverfile"][0 : info["driverfile"].rfind(".")])
            if not exists(copieddir) or not isdir(copieddir):
                makedirs(copieddir)
            driverfile = split(info["driverfile"])[1]
            copyfile(info["driverfile"], join(copieddir, driverfile))

            # new source filename for the test
            copiedfile = join(copieddir, self._dp.target_func + ".c")
            cinfo["OF"] = copiedfile

            # function rename ?
            dmyinfo = {}
            dmyptn = re.compile(r"^dummy(?P<index>\d*)_(?P<name>.+)")
            for dfunc in self._dp.dummy_func:
                rret = dmyptn.search(dfunc)
                if rret:
                    fname = rret.group("name")
                    fidx = rret.group("index")
                    if fidx:
                        cnt = int(fidx)
                    else:
                        cnt = -1
                    if fname not in dmyinfo:
                        dmyinfo[fname] = []
                    dmyinfo[fname].append(cnt)
            for dfunc, cnts in dmyinfo.items():
                tmplist = [dfunc]
                for cnt in sorted(cnts):
                    if cnt >= 0:
                        tmplist.append("dummy%d_%s" % (cnt, dfunc))
                if -1 in cnts:
                    tmplist.append("dummy_%s" % (dfunc,))
                cinfo["DMY"].append(tuple(tmplist))

            # copy source file
            cparser.copyFile(tokfile, cinfo)

            # copy other template files
            tplfile = "common_func_c"
            outfile = "common_func.c"
            copyfile(join(info["tplpath"], tplfile), join(copieddir, outfile))

            # generate files based on template
            tplfile = "test_main_c"
            outfile = "test_main.c"
            self._genMain(self._dp.driver_func, join(info["tplpath"], tplfile), join(copieddir, outfile))
            incstr = "".join(cparser.copyFile(tokfile, {}))
            tplfile = "drvinputfileread_h"
            outfile = "drvinputfileread.h"
            self._genHeader(incstr, join(info["tplpath"], tplfile), join(copieddir, outfile))

            # set files to be linked
            filelist = [
                ".\\common_func.c",
                ".\\test_main.c",
                ".\\%s.c" % (self._dp.target_func,),
                ".\\%s" % (driverfile,),
            ]

            flag_mcdc = info.get("mcdc", False)
            if flag_mcdc and "testrtpath" not in info:
                flag_mcdc = False
            if flag_mcdc:
                outfile = "TP.obj"
                copyfile(join(info["tplpath"], outfile), join(copieddir, outfile))
                filelist.append(".\\TP.obj")

            # generate *.vcproj
            tplfile = "xxx_vcproj"
            outfile = "xxx.vcproj"
            if info.get("autovc", False):
                searchpath = split(fileset.pop())[0]
                self._vc.autoVcproj(searchpath, join(info["tplpath"], tplfile), join(copieddir, outfile), filelist)
            else:
                self._vc.generateVcproj(
                    info["vcproj"], join(info["tplpath"], tplfile), join(copieddir, outfile), filelist
                )

            if flag_mcdc:
                tplfile = "xxx_rsp"
                outfile = "xxx.rsp"
                self._genRsp(
                    self._vc._incpath,
                    self._vc._compileoption,
                    self._dp.target_func,
                    join(info["tplpath"], tplfile),
                    join(copieddir, outfile),
                )
                self._switchTestRT(True, info["tplpath"], info["vcpath"], info["testrtpath"])
                self._compileTestRT(copieddir, info["vcpath"])
                self._switchTestRT(False, info["tplpath"], info["vcpath"], info["testrtpath"])

            self._buildProj(copieddir, info["vcpath"])
            self._runProj(copieddir)
            return True
        else:
            return False