コード例 #1
0
    def runTest(self):

        # Parse the test spec
        self.__parse_test_spec()

        # Run the test cases
        for testCase in self.__testCases:

            expectedOutput = "expected_" + testCase["test-case"] + "_output.txt"
            actualOutput = "actual_" + testCase["test-case"] + "_output.txt"

            # Convert '/' to '\' on Windows systems
            if platform.system() == 'Windows':
                cmd = testCase["cmd"].replace('/', '\\')
            else:
                cmd = testCase["cmd"]

            # Execute the command
            proc = subprocess.Popen(cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
                                    cwd=self.__dirTest)
            output = proc.communicate()[0]
            result = proc.wait()

            # Replace '\' so directory path output is consistent across platforms
            output = output.replace('\\', '/')

            fh = open(os.path.join(self.__dirTest, actualOutput), "wb")
            try:
                print >> fh, "result = %d" % (result)
                print >> fh, output
            except:
                fh.close()
                raise
            fh.close()

            # Always include the tool output in the diff
            diffFileSet = [(os.path.join(self.__dirTest, actualOutput),
                            os.path.join(self.__dirTest, expectedOutput))]

            for diffDict in testCase["diff"]:
                actualFile = os.path.join(self.__dirTest, diffDict["actual"])
                expectedFile = os.path.join(self.__dirTest,
                                            diffDict["expected"])
                diffFileSet.append((actualFile, expectedFile))

            for (actual, expected) in diffFileSet:
                result = ActualDiffers(actual, expected,
                                       self.__bUpdateExpected)
                if result:
                    self.fail(result)
コード例 #2
0
    def runTest(self):

        # Parse the HSL files
        parser = LoadTestHSLParser(self.__dirTest)

        # Dump actions, types, and errors to actual file
        actual = os.path.join(self.__dirTest, "actual.txt")
        fh = open(actual, "w")
        try:
            DumpHSLParser(fh, parser)
        except:
            fh.close()
            raise
        fh.close()

        # Compare actual with expected
        expected = os.path.join(self.__dirTest, "expected.txt")
        result = ActualDiffers(actual, expected, self.__bUpdateExpected)
        if result:
            self.fail(result)
コード例 #3
0
ファイル: runtests.py プロジェクト: vkanupuru/rdkb-Utopia
    def runTest(self):

        # Actual and expected file locations
        actualDir = os.path.join(
            self.__testDir,
            os.path.join("actual",
                         os.path.split(self.__buildDir)[1]))
        expectedDir = os.path.join(self.__testDir, "expected")
        actual = os.path.join(actualDir, self.__test + ".txt")

        expectedSuffix = ""

        if self.__platformExpected:
            if platform.system() == 'Windows':
                expectedSuffix = "-Windows"

        expected = os.path.join(expectedDir,
                                self.__test + expectedSuffix + ".txt")

        # Generate the command line arguments for the unittest harness binary.
        cmdLineArgs = "\"" + self.__methodName + "\" \"" + self.__httpHost + "\""

        if self.__networkObjectID is not None:
            cmdLineArgs = cmdLineArgs + " -o" + self.__networkObjectID

        if self.__httpUsername is not None:
            cmdLineArgs = cmdLineArgs + " -u" + self.__httpUsername

        if self.__httpPassword is not None:
            cmdLineArgs = cmdLineArgs + " -p" + self.__httpPassword

        if self.__httpTimeout is not None:
            cmdLineArgs = cmdLineArgs + " -t" + self.__httpTimeout

        # Write logging output to <Testname>.log
        cmdLineArgs = cmdLineArgs + " -l\"" + os.path.join(
            actualDir, self.__test + ".log\"")

        if self.__hnapInputFile is not None:
            cmdLineArgs = cmdLineArgs + " " + self.__hnapInputFile

        # Write the actual file
        if not os.path.isdir(actualDir):
            os.makedirs(actualDir)
        if os.path.isfile(actual):
            os.remove(actual)
        fhActual = open(actual, "wb")

        try:
            server = None

            # Parse the host and port from the http host URL
            url = urlparse(self.__httpHost)
            host = url.netloc
            port = url.port
            if port is None:
                if url.scheme == "https":
                    port = 443
                else:
                    port = 80
            else:
                # Must remove the port from the host
                host = re.search('(?P<host>.+?):\d', host).group("host")

            if host:
                server = UnittestServer(self.__testDir,
                                        host=host,
                                        port=port,
                                        fhLogFile=fhActual)

                # Use serve_forever so we can easily shutdown the server in the event of some exception trying to run the client code.
                serverThread = threading.Thread(target=server.serve_forever)
                serverThread.start()

            try:

                if platform.system() == 'Windows':
                    env = {
                        'SystemRoot': os.environ['SystemRoot']
                    }  # SystemRoot is required for SxS c runtime
                elif platform.system() == 'Darwin':
                    env = {
                        'DYLD_LIBRARY_PATH':
                        self.__buildDir,
                        'DYLD_INSERT_LIBRARIES':
                        os.path.join(self.__buildDir,
                                     'malloc_interposer.dylib')
                    }
                else:
                    env = {
                        'LD_LIBRARY_PATH':
                        self.__buildDir,
                        'LD_PRELOAD':
                        os.path.join(self.__buildDir, "malloc_interposer.so")
                    }

                # Run the test
                unittestProcess = subprocess.Popen(
                    os.path.join(self.__buildDir, self.__target) + " " +
                    cmdLineArgs,
                    shell=True,
                    env=env,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT)
                output = unittestProcess.communicate()[0]
                result = unittestProcess.wait()
                if result != 0:
                    self.fail(output)
                fhActual.write("\n******* Client Result ******\n")
                fhActual.write(output)

            finally:
                if server is not None:
                    # Wait until the server thread exits.
                    server.shutdown()
                    serverThread.join()

        finally:
            fhActual.close()

        fnDiffIgnore = []

        # Compare actual and expected files
        actualResult = ActualDiffers(
            actual,
            expected,
            self.__bUpdateExpected,
            bIgnoreMallocStats=not self.__bCheckMallocStats,
            fnDiffIgnore=fnDiffIgnore)
        if actualResult:
            self.fail(actualResult)
コード例 #4
0
ファイル: runtests.py プロジェクト: vkanupuru/rdkb-Utopia
    def runTest(self):

        # Parse the test case
        self.__parse_test_case()

        # Run the test cases
        for testCase in self.__testCases:

            # Set up the file paths
            fileRequest = os.path.join(self.__dirTest, testCase["request"])
            fileActualResponse = os.path.join(self.__dirActual,
                                              testCase["response"])
            fileExpectedResponse = os.path.join(self.__dirExpected,
                                                testCase["response"])
            fileStartState = os.path.join(self.__dirTest,
                                          testCase["start-state"])
            fileActualEndState = os.path.join(self.__dirActual,
                                              testCase["end-state"])
            fileExpectedEndState = os.path.join(self.__dirExpected,
                                                testCase["end-state"])

            # Set up the command args
            args = [
                os.path.abspath(self.__testProgram),
                os.path.abspath(self.__serverModule),
                testCase["method"].upper(), testCase["path"]
            ]
            if testCase["method"].lower() == "post":
                if not os.path.exists(fileRequest):
                    self.fail("Request file %s does not exist" % (fileRequest))
                args.append(os.path.abspath(fileRequest))
            else:
                args.append("-")
            args.extend([
                os.path.abspath(fileStartState),
                os.path.abspath(fileActualEndState)
            ])
            cmd = " ".join(args)

            # Ensure the actual directory exists
            if not os.path.isdir(self.__dirActual):
                os.makedirs(self.__dirActual)

            # Execute request
            fhResponse = open(fileActualResponse, "w")
            try:

                if platform.system() == 'Windows':
                    env = {
                        'SystemRoot':
                        os.environ[
                            'SystemRoot'],  # SystemRoot is required for SxS c runtime
                        'PATH':
                        ";".join(
                            [os.path.abspath(p) for p in self.__libraryPath])
                    }
                elif platform.system() == 'Darwin':
                    env = {
                        'DYLD_INSERT_LIBRARIES':
                        os.path.abspath(self.__mallocInterposer),
                        'DYLD_LIBRARY_PATH':
                        ":".join(
                            [os.path.abspath(p) for p in self.__libraryPath])
                    }
                else:
                    env = {
                        'LD_PRELOAD':
                        os.path.abspath(self.__mallocInterposer),
                        'LD_LIBRARY_PATH':
                        ":".join(
                            [os.path.abspath(p) for p in self.__libraryPath])
                    }

                proc = subprocess.Popen(args=args,
                                        stdout=fhResponse,
                                        cwd=self.__dirActual,
                                        env=env)
                returnCode = proc.wait()
                if returnCode != 0:
                    self.fail("Test failed with return code %s!\n%s" %
                              (returnCode, cmd))
            except:
                fhResponse.close()
                raise
            fhResponse.close()

            # Diff the response file
            if testCase["diff-response"].lower() == "true":
                result = ActualDiffers(fileActualResponse,
                                       fileExpectedResponse,
                                       self.__bUpdateExpected,
                                       self.__bIgnoreMallocStats)
                if result:
                    self.fail("\n".join((cmd, result)))

            # Diff the output state file
            if testCase["diff-state"].lower() == "true":
                result = ActualDiffers(fileActualEndState,
                                       fileExpectedEndState,
                                       self.__bUpdateExpected,
                                       self.__bIgnoreMallocStats)
                if result:
                    self.fail("\n".join((cmd, result)))