def test_ignore_file_pattern(self): # write dec and inf sample files to tempdir with open(os.path.join(self.test_dir, "test.dec"), "w") as f: f.write(TestGuidList.SAMPLE_DEC_FILE) with open(os.path.join(self.test_dir, "test.inf"), "w") as f: f.write(TestGuidList.SAMPLE_INF_FILE) ResultList = GuidList.guidlist_from_filesystem(self.test_dir, ["*.inf"]) self.assertEqual(len(ResultList), 7)
def test_incomplete_dec_contents(self): # write dec and inf sample files to tempdir with open(os.path.join(self.test_dir, "test.dec"), "w") as f: f.write(TestGuidList.SAMPLE_DEC_FILE.replace("PACKAGE_NAME", "GARBAGE")) with open(os.path.join(self.test_dir, "test.inf"), "w") as f: f.write(TestGuidList.SAMPLE_INF_FILE) ResultList = GuidList.guidlist_from_filesystem(self.test_dir) self.assertEqual(len(ResultList), 7)
def test_unsupported_file_type(self): # write dec and inf sample files to tempdir with open(os.path.join(self.test_dir, "test.unsupported_dec"), "w") as f: f.write(TestGuidList.SAMPLE_DEC_FILE) with open(os.path.join(self.test_dir, "test.unsupported_inf"), "w") as f: f.write(TestGuidList.SAMPLE_INF_FILE) ResultList = GuidList.guidlist_from_filesystem(self.test_dir) self.assertEqual(len(ResultList), 0)
def test_valid_input_recursive_filesystem(self): # write dec and inf sample files to tempdir os.makedirs(os.path.join(self.test_dir, "Build")) with open(os.path.join(self.test_dir, "Build", "test.dec"), "w") as f: f.write(TestGuidList.SAMPLE_DEC_FILE) with open(os.path.join(self.test_dir, "test.inf"), "w") as f: f.write(TestGuidList.SAMPLE_INF_FILE) ResultList = GuidList.guidlist_from_filesystem(self.test_dir) self.assertEqual(len(ResultList), 8)
def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None): Errors = [] abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSystemFromEdk2RelativePath( packagename) if abs_pkg_path is None: tc.SetSkipped() tc.LogStdError("No package {0}".format(packagename)) return -1 All_Ignores = ["/Build", "/Conf"] # Parse the config for other ignores if "IgnoreFoldersAndFiles" in pkgconfig: All_Ignores.extend(pkgconfig["IgnoreFoldersAndFiles"]) # Parse the workspace for all GUIDs gs = GuidList.guidlist_from_filesystem(Edk2pathObj.WorkspacePath, ignore_lines=All_Ignores) # Remove ignored guidvalue if "IgnoreGuidValue" in pkgconfig: for a in pkgconfig["IgnoreGuidValue"]: try: tc.LogStdOut("Ignoring Guid {0}".format(a.upper())) for b in gs[:]: if b.guid == a.upper(): gs.remove(b) except: tc.LogStdError( "GuidCheck.IgnoreGuid -> {0} not found. Invalid ignore guid" .format(a.upper())) logging.info( "GuidCheck.IgnoreGuid -> {0} not found. Invalid ignore guid" .format(a.upper())) # Remove ignored guidname if "IgnoreGuidName" in pkgconfig: for a in pkgconfig["IgnoreGuidName"]: entry = a.split("=") if (len(entry) > 2): tc.LogStdError( "GuidCheck.IgnoreGuidName -> {0} Invalid Format.". format(a)) logging.info( "GuidCheck.IgnoreGuidName -> {0} Invalid Format.". format(a)) continue try: tc.LogStdOut("Ignoring Guid {0}".format(a)) for b in gs[:]: if b.name == entry[0]: if (len(entry) == 1): gs.remove(b) elif (len(entry) == 2 and b.guid.upper() == entry[1].upper()): gs.remove(b) else: c.LogStdError( "GuidCheck.IgnoreGuidName -> {0} incomplete match. Invalid ignore guid" .format(a)) except: tc.LogStdError( "GuidCheck.IgnoreGuidName -> {0} not found. Invalid ignore name" .format(a)) logging.info( "GuidCheck.IgnoreGuidName -> {0} not found. Invalid ignore name" .format(a)) # Find conflicting Guid Values Errors.extend(self._FindConflictingGuidValues(gs)) # Check if there are expected duplicates and remove it from the error list if "IgnoreDuplicates" in pkgconfig: for a in pkgconfig["IgnoreDuplicates"]: names = a.split("=") if len(names) < 2: tc.LogStdError( "GuidCheck.IgnoreDuplicates -> {0} invalid format". format(a)) logging.info( "GuidCheck.IgnoreDuplicates -> {0} invalid format". format(a)) continue for b in Errors[:]: if b.type != "guid": continue ## Make a list of the names that are not in the names list. If there ## are any in the list then this error should not be ignored. t = [x for x in b.entries if x.name not in names] if (len(t) == len(b.entries)): ## did not apply to any entry continue elif (len(t) == 0): ## full match - ignore duplicate tc.LogStdOut( "GuidCheck.IgnoreDuplicates -> {0}".format(a)) Errors.remove(b) elif (len(t) < len(b.entries)): ## partial match tc.LogStdOut( "GuidCheck.IgnoreDuplicates -> {0} incomplete match" .format(a)) logging.info( "GuidCheck.IgnoreDuplicates -> {0} incomplete match" .format(a)) else: tc.LogStdOut( "GuidCheck.IgnoreDuplicates -> {0} unknown error.". format(a)) logging.info( "GuidCheck.IgnoreDuplicates -> {0} unknown error". format(a)) # Find conflicting Guid Names Errors.extend(self._FindConflictingGuidNames(gs)) # Log errors for anything within the package under test for er in Errors[:]: InMyPackage = False for a in er.entries: if abs_pkg_path in a.absfilepath: InMyPackage = True break if (not InMyPackage): Errors.remove(er) else: logging.error(str(er)) tc.LogStdError(str(er)) # add result to test case overall_status = len(Errors) if overall_status != 0: tc.SetFailed( "GuidCheck {0} Failed. Errors {1}".format( packagename, overall_status), "CHECK_FAILED") else: tc.SetSuccess() return overall_status