Esempio n. 1
0
    def CompareFiles(self, context, result, input_dir, runDir):

        expected_directories = "expected"

        if self.compare_dir == "":
            compare_dir = os.path.join(self.GetDatabase().GetRoot(), expected_directories, IdToDir(self))
        else:
            compare_dir = os.path.join(self.GetDatabase().GetRoot(), expected_directories, self.compare_dir)

        #Does this change test database?
        self.compare_dir = compare_dir

        try:
            generateExpectedResults = qm.parse_boolean(context["IPv6Suite.build"])
        except:
            generateExpectedResults = 0

        if generateExpectedResults:
            print "Generating expected results for test " + self.GetId() + " into " + compare_dir

        if not generateExpectedResults and not os.path.exists(compare_dir):
            return result.SetOutcome(result.ERROR, " compare_dir "+ self.compare_dir + " does not exist")


        self.differences = ""
        def diffResults(unused ,path, names):
            for f in names:
                if os.path.isfile(os.path.join(path, f)):
                    if not os.path.isfile(os.path.join(runDir, f)):
                        return result.Fail("Result file " + f + " was not produced!")
                    if not filecmp.cmp(os.path.join(path, f), os.path.join(runDir, f)):
                        self.differences += f + " "
                    continue
                    if re.match(r'2\.3', sys.version):
                        result[f] = result.Quote(''.join(
                            difflib.unified_diff(open(os.path.join(path, f)).read(),
                                                 open(os.path.join(runDir, f)).read())))
                    else:
                        diff = ndiff(open(os.path.join(path, f)).read(),
                                     open(os.path.join(runDir, f)).read())
                        result[f] = result.Quote(''.join(diff))

        #Compare output to expected and preverified results
        if os.path.exists(compare_dir):
            os.path.walk(compare_dir, diffResults, None)
            if self.differences:
                result["different results"] = result.Quote(self.differences)
                result.Fail(" Resulting output files differ: " + self.differences)

        #Copy result files to output dir for later perusal
        output_dir = os.path.join(self.GetDatabase().GetRoot(), "test_output", IdToDir(self))
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        def copyOutputFiles(dest, path, names):
            for f in names:
                file = os.path.join(path, f)
                if os.path.isfile(file):
                    if re.search(r'\.vec$|\.sca', f):
                        print " moving " + f + " to " + dest
                        #os.rename(file, os.path.join(dest, f)) #Does not work as it uses link so needs same filesystem
                        shutil.copy2(file, dest)
                        os.remove(file)

        if not generateExpectedResults:
            os.path.walk(runDir, copyOutputFiles, output_dir)
        else:
            os.path.walk(runDir, copyOutputFiles, compare_dir)
Esempio n. 2
0
    def CompareFiles(self, context, result, input_dir, runDir):

        expected_directories = "expected"

        if self.compare_dir == "":
            compare_dir = os.path.join(self.GetDatabase().GetRoot(),
                                       expected_directories, IdToDir(self))
        else:
            compare_dir = os.path.join(self.GetDatabase().GetRoot(),
                                       expected_directories, self.compare_dir)

        #Does this change test database?
        self.compare_dir = compare_dir

        try:
            generateExpectedResults = qm.parse_boolean(
                context["IPv6Suite.build"])
        except:
            generateExpectedResults = 0

        if generateExpectedResults:
            print "Generating expected results for test " + self.GetId(
            ) + " into " + compare_dir

        if not generateExpectedResults and not os.path.exists(compare_dir):
            return result.SetOutcome(
                result.ERROR,
                " compare_dir " + self.compare_dir + " does not exist")

        self.differences = ""

        def diffResults(unused, path, names):
            for f in names:
                if os.path.isfile(os.path.join(path, f)):
                    if not os.path.isfile(os.path.join(runDir, f)):
                        return result.Fail("Result file " + f +
                                           " was not produced!")
                    if not filecmp.cmp(os.path.join(path, f),
                                       os.path.join(runDir, f)):
                        self.differences += f + " "
                    continue
                    if re.match(r'2\.3', sys.version):
                        result[f] = result.Quote(''.join(
                            difflib.unified_diff(
                                open(os.path.join(path, f)).read(),
                                open(os.path.join(runDir, f)).read())))
                    else:
                        diff = ndiff(
                            open(os.path.join(path, f)).read(),
                            open(os.path.join(runDir, f)).read())
                        result[f] = result.Quote(''.join(diff))

        #Compare output to expected and preverified results
        if os.path.exists(compare_dir):
            os.path.walk(compare_dir, diffResults, None)
            if self.differences:
                result["different results"] = result.Quote(self.differences)
                result.Fail(" Resulting output files differ: " +
                            self.differences)

        #Copy result files to output dir for later perusal
        output_dir = os.path.join(self.GetDatabase().GetRoot(), "test_output",
                                  IdToDir(self))
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        def copyOutputFiles(dest, path, names):
            for f in names:
                file = os.path.join(path, f)
                if os.path.isfile(file):
                    if re.search(r'\.vec$|\.sca', f):
                        print " moving " + f + " to " + dest
                        #os.rename(file, os.path.join(dest, f)) #Does not work as it uses link so needs same filesystem
                        shutil.copy2(file, dest)
                        os.remove(file)

        if not generateExpectedResults:
            os.path.walk(runDir, copyOutputFiles, output_dir)
        else:
            os.path.walk(runDir, copyOutputFiles, compare_dir)
Esempio n. 3
0
    def SetUp(self, context, result):
#        if not context.has_key("IPv6Suite.srcDir"):
            # By default we assume there is a compiler.
        srcDir = context["IPv6Suite.srcDir"]
        srcDir = os.path.expanduser(srcDir)
        context["IPv6Suite.srcDir"] = srcDir
        if not os.path.exists(srcDir):
            result.SetOutcome(result.ERROR,
                              "srcDir does not exist. Where will we get source"
                              "files from?")
            return


        buildDir = context["IPv6Suite.buildDir"]
        buildDir = os.path.abspath(buildDir)
        context["IPv6Suite.buildDir"] = buildDir

        buildDir = os.path.join(buildDir, IdToDir(self))

        self.wipe_build_dir = qm.parse_boolean(context["IPv6Suite.wipe_build_dir"])
        #Can't use bool since the boolean_value is a string of 'true|false' and since bool
        # thinks of any string as true except empty or none.
        #self.wipe_build_dir = bool(self.wipe_build_dir)

        #We want clean builds especially when previously failed ones may have broken generated code
        if self.wipe_build_dir and os.path.exists(buildDir):
            shutil.rmtree(buildDir)

        mkdirs(buildDir)

        if self.wipe_build_dir:
            print "Wiping all files"

        context["IPv6Suite.myBuildDir"] = buildDir
        self.myBuildDir = buildDir
        #srcdir/test is where we store the related input files like ini/xml etc.
        #Well database of qmtest would be where we store these input files but what structure underneath?

        make_executable = RedirectedExecutable()
        #We actually want a gui to relace this value if possible?
        cmake_defines = string.split(self.ipv6suite_build_options)
        cmake_options = "-DOPP_USE_TK:BOOL=OFF"
##        "-DLIBRARY_OUTPUT_PATH:PATH=lib -DEXECUTABLE_OUTPUT_PATH:PATH=exe"
        for o in cmake_defines:
            cmake_options = "-D"+o+":BOOL=ON"+ " " + cmake_options

        if not os.path.exists(os.path.join(buildDir, "CMakeCache.txt")):
            cmake_command = ["cmake"] + string.split(cmake_options) + [srcDir]
            #print cmake_command
            status = make_executable.Run(cmake_command, dir=buildDir)
            if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
                q_stdout = result.Quote(make_executable.stdout)
                q_stderr = result.Quote(make_executable.stderr)
                result.SetOutcome(result.ERROR,
                                  "Error in cmake Makefile generation",
                                  {"status": str(status),
                                   "stdout": q_stdout,
                                   "stderr": q_stderr,
                                   "command": " ".join(cmake_command),
                                   })
                return

        if os.environ.has_key("RPM_BUILD_NCPUS"):
            cpus = os.environ["RPM_BUILD_NCPUS"]
        else:
            cpus = "1"
        make_command =["make", "-j" + cpus] + string.split(self.make_options)
        status = make_executable.Run(make_command, dir=buildDir)
        if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
                q_stdout = result.Quote(make_executable.stdout)
                q_stderr = result.Quote(make_executable.stderr)
                result.SetOutcome(result.ERROR,
                                  "Error building IPv6Suite",
                                  {"status": str(status),
                                   "stdout": q_stdout,
                                   "stderr": q_stderr,
                                   "command": " ".join(make_command),
                                   })
                return
Esempio n. 4
0
    def SetUp(self, context, result):
        #        if not context.has_key("IPv6Suite.srcDir"):
        # By default we assume there is a compiler.
        srcDir = context["IPv6Suite.srcDir"]
        srcDir = os.path.expanduser(srcDir)
        context["IPv6Suite.srcDir"] = srcDir
        if not os.path.exists(srcDir):
            result.SetOutcome(
                result.ERROR, "srcDir does not exist. Where will we get source"
                "files from?")
            return

        buildDir = context["IPv6Suite.buildDir"]
        buildDir = os.path.abspath(buildDir)
        context["IPv6Suite.buildDir"] = buildDir

        buildDir = os.path.join(buildDir, IdToDir(self))

        self.wipe_build_dir = qm.parse_boolean(
            context["IPv6Suite.wipe_build_dir"])
        #Can't use bool since the boolean_value is a string of 'true|false' and since bool
        # thinks of any string as true except empty or none.
        #self.wipe_build_dir = bool(self.wipe_build_dir)

        #We want clean builds especially when previously failed ones may have broken generated code
        if self.wipe_build_dir and os.path.exists(buildDir):
            shutil.rmtree(buildDir)

        mkdirs(buildDir)

        if self.wipe_build_dir:
            print "Wiping all files"

        context["IPv6Suite.myBuildDir"] = buildDir
        self.myBuildDir = buildDir
        #srcdir/test is where we store the related input files like ini/xml etc.
        #Well database of qmtest would be where we store these input files but what structure underneath?

        make_executable = RedirectedExecutable()
        #We actually want a gui to relace this value if possible?
        cmake_defines = string.split(self.ipv6suite_build_options)
        cmake_options = "-DOPP_USE_TK:BOOL=OFF"
        ##        "-DLIBRARY_OUTPUT_PATH:PATH=lib -DEXECUTABLE_OUTPUT_PATH:PATH=exe"
        for o in cmake_defines:
            cmake_options = "-D" + o + ":BOOL=ON" + " " + cmake_options

        if not os.path.exists(os.path.join(buildDir, "CMakeCache.txt")):
            cmake_command = ["cmake"] + string.split(cmake_options) + [srcDir]
            #print cmake_command
            status = make_executable.Run(cmake_command, dir=buildDir)
            if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
                q_stdout = result.Quote(make_executable.stdout)
                q_stderr = result.Quote(make_executable.stderr)
                result.SetOutcome(
                    result.ERROR, "Error in cmake Makefile generation", {
                        "status": str(status),
                        "stdout": q_stdout,
                        "stderr": q_stderr,
                        "command": " ".join(cmake_command),
                    })
                return

        if os.environ.has_key("RPM_BUILD_NCPUS"):
            cpus = os.environ["RPM_BUILD_NCPUS"]
        else:
            cpus = "1"
        make_command = ["make", "-j" + cpus] + string.split(self.make_options)
        status = make_executable.Run(make_command, dir=buildDir)
        if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
            q_stdout = result.Quote(make_executable.stdout)
            q_stderr = result.Quote(make_executable.stderr)
            result.SetOutcome(
                result.ERROR, "Error building IPv6Suite", {
                    "status": str(status),
                    "stdout": q_stdout,
                    "stderr": q_stderr,
                    "command": " ".join(make_command),
                })
            return