Commit f732563f authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

fix MLD corridor re-generation

parent fe4ff03a
Loading
Loading
Loading
Loading
Loading
+83 −68
Original line number Diff line number Diff line
@@ -967,21 +967,25 @@ class MLDConformance:
                    errorDetails,
                    executedCommand,
                ) in pool.imap_unordered(self.analyseOneCommandFromTuple, args):
                    if self.args.verbose:
                        if runStatus == "OK":
                            if not analysisResult:
                                print(
                        f"{testPrefix} Running test: {pyTestsTag} ... {runStatus}",
                                    f"{testPrefix} Analyzing test: {pyTestsTag} ... Command executed successfully but MLD analysis failed!",
                                    flush=True,
                                )
                    if self.args.verbose and executedCommand:
                            else:
                                print(
                            f"{testPrefix} Executing command: {executedCommand}",
                                    f"{testPrefix} Analyzing test: {pyTestsTag} ... {analysisResult}",
                                    flush=True,
                                )
                    if runStatus == "OK":
                        else:
                            print(
                            f"{testPrefix} Analyzing test: {analysisResult}",
                                f"{testPrefix} Analyzing test: {pyTestsTag} ... {runStatus}",
                                flush=True,
                            )
                    elif errorDetails:
   
                            if errorDetails:
                                cmd, err_output = errorDetails
                                print(f"{testPrefix} Failed command: {cmd}", flush=True)
                                if err_output:
@@ -1000,21 +1004,25 @@ class MLDConformance:
                    errorDetails,
                    executedCommand,
                ) = self.analyseOneCommand(tag, pyTestsTag, idx, self.totalTests)
                if self.args.verbose:
                    if runStatus == "OK":
                        if not analysisResult:
                            print(
                    f"{testPrefix} Running test: {pyTestsTag} ... {runStatus}",
                                f"{testPrefix} Analyzing test: {pyTestsTag} ... Command executed successfully but MLD analysis failed!",
                                flush=True,
                            )
                if self.args.verbose and executedCommand:
                        else:
                            print(
                        f"{testPrefix} Executing command: {executedCommand}",
                                f"{testPrefix} Analyzing test: {pyTestsTag} ... {analysisResult}",
                                flush=True,
                            )
                if runStatus == "OK":
                    else:
                        print(
                        f"{testPrefix} Analyzing test: {analysisResult}",
                            f"{testPrefix} Analyzing test: {pyTestsTag} ... {runStatus}",
                            flush=True,
                        )
                elif errorDetails:

                        if errorDetails:
                            cmd, err_output = errorDetails
                            print(f"{testPrefix} Failed command: {cmd}", flush=True)
                            if err_output:
@@ -1267,38 +1275,45 @@ class MLDConformance:
                    print(f"<{tag}> PASSED BE TEST")

    def computeCorridor(self, mldRefWithTags, mldCutWithTags, tag, threshold=0.1):
        mldDict = dict[str, list]()
        failed = False

        #intersection, indRef, indDut = np.intersect1d(
        #    mldRefWithTags["pyTestTag"],
        #    mldCutWithTags["pyTestTag"],
        #    assume_unique=True,
        #    return_indices=True,
        #)
        
        indRef = np.argsort(mldRefWithTags["pyTestTag"])
        indDut = np.argsort(mldCutWithTags["pyTestTag"])
        intersection = mldRefWithTags["pyTestTag"][indRef]
       
        refTags = mldRefWithTags["pyTestTag"][indRef]
        dutTags = mldCutWithTags["pyTestTag"][indDut]
        refMLD = mldRefWithTags["MLD"][indRef]
        dutMLD = mldCutWithTags["MLD"][indDut]

        diff = dutMLD - refMLD
        same_shape = refMLD.shape == dutMLD.shape
        same_tags = same_shape and np.array_equal(refTags, dutTags)

        if diff.max() > threshold:
            print(
                f"\033[91mMLD Corridor failed for {tag} with max MLD diff of {diff.max()} \033[00m"
            )
        if same_tags:
            diff = dutMLD - refMLD
            maxDiff = float(diff.max()) if diff.size else 0.0
            corridor_failed = maxDiff > threshold
            maxMLD = np.maximum(dutMLD, refMLD)
            mldWithTags = np.column_stack(
                (
                    maxMLD,
                    intersection,
            mldWithTags = np.column_stack((maxMLD, refTags))
        else:
            # For any mismatch, emit mld_ref2 directly from DUT values/tags.
            maxDiff = float("nan")
            mldWithTags = np.column_stack((dutMLD, dutTags))
            corridor_failed = True

        if corridor_failed:
            mismatch_reason = []
            if not same_shape:
                mismatch_reason.append(
                    f"shape mismatch REF={refMLD.shape}, DUT={dutMLD.shape}"
                )
            if same_shape and not same_tags:
                mismatch_reason.append("pyTestTag mismatch")
            mismatch_suffix = (
                f" ({'; '.join(mismatch_reason)})" if mismatch_reason else ""
            )
            print(
                f"\033[91mMLD Corridor failed for {tag} with max MLD diff of {maxDiff}{mismatch_suffix} \033[00m"
            )
            new_mld_dir = os.path.join(
                        self.testvDir, "mld_ref2")
                self.testvDir, "mld_ref2"
            )
            if not os.path.exists(new_mld_dir):
                os.makedirs(new_mld_dir, exist_ok=True)

@@ -1309,7 +1324,7 @@ class MLDConformance:
                np.savetxt(f, mldWithTags, fmt="%s", delimiter=",")
        else:
            print(
                f"\033[92mMLD Corridor passed for {tag} with max MLD diff of {diff.max()} \033[00m"
                f"\033[92mMLD Corridor passed for {tag} with max MLD diff of {maxDiff} \033[00m"
            )

    def doAnalysis(self, selectTag="all", corridor=False):