Exemple #1
0
    def test_build_report_summary_section(self):
        lExpected = []
        lExpected.append('  Suppression Rules')
        lExpected.append('    Total                  :     6')
        lExpected.append('    Unused                 :     1')
        lExpected.append('')
        lExpected.append('  Warnings')
        lExpected.append('    Total                  :     5')
        lExpected.append('    Suppressed             :     4')
        lExpected.append('    Unsuppressed           :     1')
        lExpected.append('    Under Investigation    :     0')
        lExpected.append('    Multiply Suppressed    :     3')
        lExpected.append('')
        lExpected.append('=' * 80)

        oSupList = utils.create_suppression_list(
            utils.read_suppression_file(
                'tests/subcommand/report/suppress_microsemi_designer_logfile.yaml'
            ))
        oWarnList = utils.create_warning_list(
            utils.read_log_file(
                'tests/vendor/microsemi/designer/warning_messages.log'),
            'tests/vendor/microsemi/designer/warning_messages.log')

        utils.apply_suppression_rules_to_warnings(oWarnList, oSupList)

        lActual = display.build_report_summary_section(oWarnList, oSupList)

        for iIndex, sLine in enumerate(lExpected):
            self.assertEqual(sLine, lActual[iIndex])
def report(cla):

    dSup = utils.read_suppression_file(cla.suppression_file)
    oSupList = utils.create_suppression_list(dSup)

    lLogFile = utils.read_log_file(cla.log_file)

    oWarnList = utils.create_warning_list(lLogFile, cla.log_file)

    utils.apply_suppression_rules_to_warnings(oWarnList, oSupList)

    lReport = []
    build_header(cla, lReport)
    build_section_1(oWarnList, lReport)
    build_section_2(oSupList, lReport)
    build_section_3(oSupList, lReport)
    build_section_4(oSupList, lReport)
    build_section_5(oWarnList, lReport)
    build_summary(oWarnList, oSupList, lReport)

    utils.write_file(cla.report_file, lReport)

    if cla.junit:
        lJUnitFile = generate_junit_xml_file(cla, oWarnList, oSupList)
        utils.write_file(cla.junit, lJUnitFile)
Exemple #3
0
def suppress(cla):

    dSup = utils.read_suppression_file(cla.suppression_file)
    oSupList = utils.create_suppression_list(dSup)

    lLogFile = utils.read_log_file(cla.log_file)

    oWarnList = utils.create_warning_list(lLogFile, cla.log_file)

    utils.apply_suppression_rules_to_warnings(oWarnList, oSupList)
    oNonSuppressedWarnings = oWarnList.get_unsuppressed_warnings()

    display.results(cla.log_file, cla.suppression_file, oSupList, oWarnList)
Exemple #4
0
    def test_create_suppression_list_w_investigates(self):

        dSuppression = utils.read_suppression_file(
            os.path.join(os.path.dirname(__file__),
                         'investigate_suppress.yaml'))

        oActualSuppressionList = utils.create_suppression_list(dSuppression)

        oExpectedSuppressList = suppression_list.create()

        oSuppression = suppression.create('SYN001', 'This is the message',
                                          'jcleary', 'This is fine because...')
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('SYN001', 'This is another message',
                                          '<None>', 'Just ignore this...')
        oSuppression.investigate = True
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('NO_ID',
                                          'Some warning without a proper ID',
                                          '<None>', 'This is fine...')
        oSuppression.investigate = True
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create(
            'NO_ID', 'This is another NO_ID suppression rule', '<None>',
            'Both this and the other NO_ID must be present.')
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('CMP2001',
                                          'This is some compile warning',
                                          'jcleary', 'Just because...')
        oSuppression.investigate = True
        oExpectedSuppressList.suppressions.append(oSuppression)

        self.assertEqual(5, len(oActualSuppressionList.suppressions))
        oExpectedSuppressList.suppressions.append(oSuppression)

        for i in range(5):
            oExpected = oExpectedSuppressList.suppressions[i]
            oActual = oActualSuppressionList.suppressions[i]

            self.assertEqual(oExpected.get_warning_id(),
                             oActual.get_warning_id())
            self.assertEqual(oExpected.get_message(), oActual.get_message())
            self.assertEqual(oExpected.get_author(), oActual.get_author())
            self.assertEqual(oExpected.get_comment(), oActual.get_comment())
            self.assertEqual(oExpected.get_investigate(),
                             oActual.get_investigate())
def create(cla):

    lLogFile = utils.read_log_file(cla.log_file)

    oWarnList = utils.create_warning_list(lLogFile, cla.log_file)

    if cla.suppression_file is not None:
        dSup = utils.read_suppression_file(cla.suppression_file)
        oSupList = utils.create_suppression_list(dSup)
        oWarnList = suppress.extract_non_suppressed_warnings(
            oWarnList, oSupList)

    dSup = create_suppression_dict(oWarnList)

    with open(cla.output_suppression_file, 'w') as file:
        yaml.dump(dSup, file)
Exemple #6
0
    def test_extract_non_suppressed_warnings(self):
        dSup = utils.read_suppression_file(
            file_path('suppress_microsemi_designer_logfile.yaml'))
        oSupList = utils.create_suppression_list(dSup)

        lLogFile = utils.read_log_file(
            'tests/vendor/microsemi/designer/warning_messages.log')
        oWarnList = designer.extract_warnings(lLogFile)

        oActual = suppress.extract_non_suppressed_warnings(oWarnList, oSupList)

        self.assertEqual(1, oActual.get_number_of_warnings())

        self.assertEqual('MULTI546', oActual.warnings[0].get_id())
        self.assertEqual(
            'This is the first line of the warning This is the second line of the warning This is the last line of the warning.',
            oActual.warnings[0].get_message())
Exemple #7
0
    def test_create_suppression_list(self):

        dSuppression = {}
        dSuppression['suppress'] = {}
        dSuppression['suppress']['rules'] = {}

        dSuppression['suppress']['rules']['SYN001'] = []
        dRule = {}
        dRule['msg'] = 'This is the message'
        dRule['author'] = 'jcleary'
        dRule['comment'] = 'This is fine because...'
        dSuppression['suppress']['rules']['SYN001'].append(dRule)
        dRule = {}
        dRule['msg'] = 'This is another message'
        dRule['comment'] = 'Just ignore this...'
        dSuppression['suppress']['rules']['SYN001'].append(dRule)

        dSuppression['suppress']['rules']['NO_ID'] = []
        dRule = {}
        dRule['msg'] = 'Some warning without a proper ID'
        dRule['comment'] = 'This is fine...'
        dSuppression['suppress']['rules']['NO_ID'].append(dRule)

        dSuppression['suppress']['rules']['CMP2001'] = []
        dRule = {}
        dRule['msg'] = 'This is some compile warning'
        dRule['author'] = 'jcleary'
        dRule['comment'] = 'Just because...'
        dSuppression['suppress']['rules']['CMP2001'].append(dRule)

        dSuppression['suppress']['rules']['NO_COMMENT'] = []
        dRule = {}
        dRule['msg'] = 'This rule has no comment'
        dSuppression['suppress']['rules']['NO_COMMENT'].append(dRule)

        oActualSuppressionList = utils.create_suppression_list(dSuppression)

        oExpectedSuppressList = suppression_list.create()

        oSuppression = suppression.create('SYN001', 'This is the message',
                                          'jcleary', 'This is fine because...')
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('SYN001', 'This is another message',
                                          '<None>', 'Just ignore this...')
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('NO_ID',
                                          'Some warning without a proper ID',
                                          '<None>', 'This is fine...')
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('CMP2001',
                                          'This is some compile warning',
                                          'jcleary', 'Just because...')
        oExpectedSuppressList.suppressions.append(oSuppression)

        oSuppression = suppression.create('NO_COMMENT',
                                          'This rule has no comment', '<None>',
                                          '<None>')

        self.assertEqual(5, len(oActualSuppressionList.suppressions))
        oExpectedSuppressList.suppressions.append(oSuppression)

        for i in range(5):
            oExpected = oExpectedSuppressList.suppressions[i]
            oActual = oActualSuppressionList.suppressions[i]

            self.assertEqual(oExpected.get_warning_id(),
                             oActual.get_warning_id())
            self.assertEqual(oExpected.get_message(), oActual.get_message())
            self.assertEqual(oExpected.get_author(), oActual.get_author())
            self.assertEqual(oExpected.get_comment(), oActual.get_comment())
            self.assertEqual(oExpected.get_investigate(),
                             oActual.get_investigate())
Exemple #8
0
    def test_create_suppression_list_w_empty_dictionary(self):
        dSuppression = {}
        oActualSuppressionList = utils.create_suppression_list(dSuppression)
        oExpectedSuppressionList = suppression_list.create()

        self.assertEqual(0, len(oActualSuppressionList.suppressions))