Example #1
0
def genInlineAssemblyParser(args=None, out=None):
    """generate inline assembly parser and scanner if corresponding grammer is new"""
    generatedParserDir = _inlineAssemblySrcDir + _inlineAssemblyPackageName.replace(".", "/") + "/"
    generatedFiles = [generatedParserDir + "Parser.java", generatedParserDir + "Scanner.java"]
    configFiles = [
        _inlineAssemblySrcDir + "InlineAssembly.atg",
        _inlineAssemblySrcDir + "Parser.frame",
        _inlineAssemblySrcDir + "Scanner.frame",
        _inlineAssemblySrcDir + "Copyright.frame",
    ]
    isAllGeneratedFilesExists = all([isfile(fileName) for fileName in generatedFiles])
    latestGeneratedFile = (
        sorted(generatedFiles, key=os.path.getmtime, reverse=True)[0] if isAllGeneratedFilesExists else ""
    )
    latestConfigFile = sorted(configFiles, key=os.path.getmtime, reverse=True)[0]
    # If any auto-generated file is missing or any config file is updated after last auto-generation then regenerate the files
    if not isAllGeneratedFilesExists or os.path.getmtime(latestConfigFile) >= os.path.getmtime(latestGeneratedFile):
        localCocoJarFile = _suite.dir + "/lib/Coco.jar"
        if not isfile(localCocoJarFile):
            jarFileUrls = ["https://lafo.ssw.uni-linz.ac.at/pub/sulong-deps/Coco.jar"]
            mx.download(localCocoJarFile, jarFileUrls)
        command = [
            mx.get_jdk(tag="jvmci").java,
            "-jar",
            localCocoJarFile,
            "-package",
            _inlineAssemblyPackageName,
            "-o",
            generatedParserDir,
            _inlineAssemblyGrammer,
        ]
        mx.run(command)
        # Files get generated in Windows file format. Convert them to avoid style check failure during regression testing
        dos2unix(generatedFiles)
Example #2
0
def _testJalangi(args, analysisHome, analysis, force=False, testsuites=[]):
    analysisOpt = [];
    if os.path.exists (join(analysisHome, "config")):
        config = open (join(analysisHome, "config"));
        for line in config:
            line = line.rstrip()
            f = line.split(" ")[0];
            if not os.path.exists (join(analysisHome, f)):
                if len(line.split(" ")) == 1:
                    print("analysis file "+f + " doesn't exist!")
                    continue;
                elif len(line.split(" ")) > 1:
                    url = line.split(" ")[-1]
                    mx.download(join(analysisHome, f), [url])
                    if not os.path.exists (join(analysisHome, f)):
                        print("analysis file "+f + " doesn't exist and cannot download it from "+url)
                        continue;
                    else:
                        print("downloaded analysis file "+f + " from "+url)
                else:
                    continue;
            analysisOpt += ["--analysis"];
            analysisOpt += [join(analysisHome, f)];
    else:
        for analysisJS in os.listdir(analysisHome):
            if analysisJS.endswith(".js"):
                analysisOpt += ["--analysis"];
                analysisOpt += [join(analysisHome, analysisJS)];
    if not analysisOpt:
        return;
    testdir = join(_suite.dir, 'src/ch.usi.inf.nodeprof.test/js')
    if not testsuites:
        testsuites = os.listdir(testdir)
    for testSuite in testsuites:
        testHome = join(testdir, testSuite);
        for testfile in os.listdir(testHome):
            if testfile.endswith('.js') and not(testfile.endswith('_jalangi_.js')):

                fn = join(analysisHome, testSuite+"."+testfile+".expected");
                expectExist = os.path.exists(fn);
                if not force and not expectExist:
                    continue;
                print('Testing ' + testfile + " in " + testSuite+" with analysis "+analysis)
                outFile = join(analysisHome,testSuite+"."+testfile+".output");
                runJalangi(args + analysisOpt+[join(testHome,testfile)], outFile=outFile, tracable=False);
                if not expectExist:
                    print("Ignored @"+analysis);
                    continue;
                with open(fn) as fexp:
                    with open(outFile) as foutput:
                        if(foutput.read() == fexp.read()):
                            print("Pass @"+analysis);
                        else:
                            print("Fail @"+analysis);
                            if not force:
                                sys.exit(1);
Example #3
0
def download_file(name, url, unpack_dir, is_compressed, sha1sum, suffix=''):
    if not is_compressed:
        filepath = unpack_dir + name + suffix
        if not os.path.exists(filepath) or mx.sha1OfFile(filepath) != sha1sum:
            mx.download(filepath, [url])
    else:
        zip_file_path = downloads_compressed_path + name + '.zip'
        if not os.path.exists(
                zip_file_path) or mx.sha1OfFile(zip_file_path) != sha1sum:
            mx.download(zip_file_path, [url])
        unpack_zip(name, unpack_dir, zip_file_path)
Example #4
0
def pullsuite(suiteDir, urls):
    name = os.path.basename(urls[0])
    localPath = join(suiteDir, name)
    mx.download(localPath, urls)
    return localPath
Example #5
0
def pullsuite(suiteDir, urls):
    name = os.path.basename(urls[0])
    localPath = join(suiteDir, name)
    mx.download(localPath, urls)
    return localPath
Example #6
0
def _testJalangi(args, analysisHome, analysis, force=False, testsuites=[]):
    analysisOpt = []
    if os.path.exists(join(analysisHome, "config")):
        config = open(join(analysisHome, "config"))
        for line in config:
            line = line.rstrip()
            words = line.split(" ")
            f = words[0]
            if not os.path.exists(join(analysisHome, f)):
                if len(line.split(" ")) == 1:
                    print("analysis file " + f + " doesn't exist!")
                    continue
                elif len(line.split(" ")) > 1:
                    url = line.split(" ")[-1]
                    mx.download(join(analysisHome, f), [url])
                    if not os.path.exists(join(analysisHome, f)):
                        print("analysis file " + f +
                              " doesn't exist and cannot download it from " +
                              url)
                        continue
                    else:
                        print("downloaded analysis file " + f + " from " + url)
                else:
                    continue

            mx.logv("analysis parameters from config: " + str(words[1:]))

            # read analysis parameters from config
            for w in words[1:]:
                # ignore download URLs
                if w.startswith('http'):
                    continue
                # detect --nodeprof.Foo=bar style parameters
                if w.startswith('--nodeprof'):
                    args += [w]
                # otherwise treat as analysis (jalangi.js) parameters
                else:
                    analysisOpt += [w]

            analysisOpt += ["--analysis"]
            analysisOpt += [join(analysisHome, f)]
    else:
        for analysisJS in os.listdir(analysisHome):
            if analysisJS.endswith(".js"):
                analysisOpt += ["--analysis"]
                analysisOpt += [join(analysisHome, analysisJS)]
    if not analysisOpt:
        return
    testdir = join(_suite.dir, 'src/ch.usi.inf.nodeprof.test/js')
    if not testsuites:
        testsuites = os.listdir(testdir)
    for testSuite in testsuites:
        testHome = join(testdir, testSuite)
        for testfile in os.listdir(testHome):
            if testfile.endswith('.js') and not (
                    testfile.endswith('_jalangi_.js')):

                fn = join(analysisHome,
                          testSuite + "." + testfile + ".expected")
                expectExist = os.path.exists(fn)
                if not force and not expectExist:
                    continue
                print('Testing ' + testfile + " in " + testSuite +
                      " with analysis " + analysis)
                outFile = join(analysisHome,
                               testSuite + "." + testfile + ".output")
                runJalangi(args + analysisOpt + [join(testHome, testfile)],
                           outFile=outFile,
                           tracable=False)
                if not expectExist:
                    print("Ignored @" + analysis)
                    continue
                with open(fn) as fexp:
                    with open(outFile) as foutput:
                        if (foutput.read() == fexp.read()):
                            print("Pass @" + analysis)
                        else:
                            print("Fail @" + analysis)
                            from subprocess import call
                            call(["diff", fn, outFile])
                            if not force:
                                sys.exit(1)
Example #7
0
 def downloadSource(self):
     download = join(self.npmDir, self.name + '.zip')
     mx.download(download, [self.url])
     with zipfile.ZipFile(download) as zf:
         zf.extractall(self.downloadRoot)