Skip to content

Commit

Permalink
Split log.Skipped into Not Implemented and Not Applicable
Browse files Browse the repository at this point in the history
Signed-off-by: BrentHoltsclaw <brent.holtsclaw@intel.com>
Signed-off-by: Erik Bjorge <erik.c.bjorge@intel.com>
  • Loading branch information
BrentHoltsclaw authored and ErikBjorge committed Feb 26, 2018
1 parent 9a5e095 commit 3a39ff1
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 105 deletions.
37 changes: 24 additions & 13 deletions chipsec/logger.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
#CHIPSEC: Platform Security Assessment Framework
#Copyright (c) 2010-2016, Intel Corporation
#
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; Version 2.
Expand Down Expand Up @@ -115,22 +115,22 @@ class ColorLogger:
CYAN = 6
WHITE = 7
NORMAL = 8

def log_test(self):
print ColorLogger.BOLD + "BOLD" + ColorLogger.ENDC
print ColorLogger.UNDERLINE + "UNDERLINE" + ColorLogger.ENDC
for color_type in (ColorLogger.LIGHT,ColorLogger.DARK,ColorLogger.BACKGROUND,ColorLogger.LIGHT_BACKGROUND):
for code in xrange(ColorLogger.GRAY, ColorLogger.NORMAL+1):
self.log(color_type+code, color_type, code )


def log(self,msg, color_type=LIGHT,color=8):
print ColorLogger.format(msg, color_type, color)

@staticmethod
def format(msg, color_type=LIGHT,color=8):
return ( '\033[%im%s%s'%(color_type+color,str(msg),ColorLogger.ENDC))
return ( '\033[%im%s%s'%(color_type+color,str(msg),ColorLogger.ENDC))

COLOR_ID = {
BLACK : ColorLogger.NORMAL,
RED : ColorLogger.RED,
Expand All @@ -141,9 +141,9 @@ def format(msg, color_type=LIGHT,color=8):
CYAN : ColorLogger.CYAN,
WHITE : ColorLogger.WHITE
}

def log_color( fg_color, text ):
_text = ColorLogger.format(text, ColorLogger.LIGHT,COLOR_ID[ fg_color ])
_text = ColorLogger.format(text, ColorLogger.LIGHT,COLOR_ID[ fg_color ])
print _text

else:
Expand Down Expand Up @@ -299,8 +299,8 @@ def log_error_check( self, text ):
self.xmlAux.error_check( text )

def log_skipped_check( self, text ):
"""Logs a Test as SKIPPED, this is used for XML output.
If XML file was not specified, then it will just print a SKIPPED test message.
"""Logs a Test as Not Implemented, this is used for XML output.
If XML file was not specified, then it will just print a NOT IMPLEMENTED test message.
"""
self.log_skipped(text)
self.xmlAux.skipped_check( text )
Expand All @@ -317,6 +317,12 @@ def log_information_check( self, text ):
self.log_information(text)
self.xmlAux.information_check(text)

def log_not_applicable_check( self, text):
"""Logs a Test as Not Applicable, this is used for XML output.
If XML file was not specified, then it will just print a NOT APPLICABLE test message """
self.log_not_applicable(text)
self.xmlAux.not_applicable_check()


def log_passed( self, text ):
"""Logs a passed message."""
Expand All @@ -335,8 +341,13 @@ def log_warning( self, text ):
#self.xmlAux.passed_check()

def log_skipped( self, text ):
"""Logs a skipped message."""
text = "[*] SKIPPED: " + text
"""Logs a NOT IMPLEMENTED message."""
text = "[*] NOT IMPLEMENTED: " + text
self._log(text, YELLOW, True)

def log_not_applicable(self, text):
"""Logs a NOT APPLICABLE message."""
text = "[*] NOT APPLICABLE: " + text
self._log(text, YELLOW, True)

def log_heading( self, text ):
Expand Down
34 changes: 18 additions & 16 deletions chipsec/module_common.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
#CHIPSEC: Platform Security Assessment Framework
#Copyright (c) 2010-2015, Intel Corporation
#
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; Version 2.
Expand Down Expand Up @@ -44,23 +44,25 @@
import chipsec.defines

class ModuleResult:
FAILED = 0
PASSED = 1
WARNING = 2
SKIPPED = 3
DEPRECATED = 4
INFORMATION = 5
ERROR = -1
FAILED = 0
PASSED = 1
WARNING = 2
SKIPPED = 3
DEPRECATED = 4
INFORMATION = 5
NOTAPPLICABLE = 6
ERROR = -1


ModuleResultName = {
ModuleResult.FAILED: "Failed",
ModuleResult.PASSED: "Passed",
ModuleResult.WARNING: "Warning",
ModuleResult.SKIPPED: "Skipped",
ModuleResult.DEPRECATED: "Deprecated",
ModuleResult.INFORMATION: "Information",
ModuleResult.ERROR: "Error"
ModuleResult.FAILED: "Failed",
ModuleResult.PASSED: "Passed",
ModuleResult.WARNING: "Warning",
ModuleResult.SKIPPED: "Skipped",
ModuleResult.DEPRECATED: "Deprecated",
ModuleResult.INFORMATION: "Information",
ModuleResult.ERROR: "Error",
ModuleResult.NOTAPPLICABLE: "NotApplicable"
}
def getModuleResultName(res):
return ModuleResultName[res] if res in ModuleResultName else ModuleResultName[ModuleResult.ERROR]
Expand Down Expand Up @@ -92,7 +94,7 @@ def update_res(self, value):
self.res = value
elif self.res == ModuleResult.INFORMATION:
self.res = value
else: # PASSED or SKIPPED or DEPRECATED
else: # PASSED or SKIPPED or DEPRECATED or NOTAPPLICABLE
self.res = value

def run(self, module_argv):
Expand Down
58 changes: 46 additions & 12 deletions chipsec/xmlout.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
#CHIPSEC: Platform Security Assessment Framework
#Copyright (c) 2010-2015, Intel Corporation
#
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; Version 2.
Expand Down Expand Up @@ -97,7 +97,7 @@ def error_check(self, text):
self._end_test()

def skipped_check(self, text):
"""Used when you want to mark a testcase as SKIPPED and add it to the testsuite."""
"""Used when you want to mark a testcase as NOT IMPLEMENTED and add it to the testsuite."""
if self.useXML == True:
self._check_testCase_exist()
self.testCase.add_skipped_info( text, None )
Expand All @@ -109,6 +109,12 @@ def information_check(self, text):
self.testCase.add_information_info( text, None )
self._end_test()

def not_applicable_check(self, text):
"""Used when you want to mark a testcase as NOT IMPLEMENTED and add it to the testsuite."""
if self.useXML == True:
self._check_testCase_exist()
self.testCase.add_not_applicable_info( text, None )
self._end_test()

def start_test(self, test_name):
"""Starts the test/testcase."""
Expand Down Expand Up @@ -147,13 +153,13 @@ def saveXML( self ):
return True

class testCaseType:
"""Used to represent the types of TestCase that can be assigned (FAILURE, ERROR, SKIPPED, PASS, INFORMATION)"""
FAILURE = 1
ERROR = 2
SKIPPED = 3
INFORMATION = 4
PASS = 5

"""Used to represent the types of TestCase that can be assigned (FAILURE, ERROR, SKIPPED, PASS)"""
FAILURE = 1
ERROR = 2
SKIPPED = 3
INFORMATION = 4
PASS = 5
NOTAPPLICABLE = 6

class xmlTestCase():
"""Represents a JUnit test case with a result and possibly some stdout or stderr"""
Expand Down Expand Up @@ -181,6 +187,8 @@ def __init__(self, name, classname, pTime=None, stdout=None, stderr=None, tcType
self.skipped_output = ""
self.information_message = ""
self.information_output = ""
self.not_applicable_message = ""
self.not_applicable_output = ""

if tcType == testCaseType.ERROR:
self.error_message = message
Expand All @@ -194,6 +202,9 @@ def __init__(self, name, classname, pTime=None, stdout=None, stderr=None, tcType
elif tcType == testCaseType.INFORMATION:
self.information_message = message
self.information_output = output
elif tcType == testCasetype.NOTAPPLICABLE:
self.not_applicable_message = message
self.not_applicable_output = output
else:
#Then it should be PASSED.
self.tcType = testCaseType.PASS
Expand All @@ -205,6 +216,13 @@ def is_skipped(self):
else:
False

def is_not_applicable(self):
"""Returns True if the testCase is of Type NOTAPPLICABLE, if not returns False"""
if self.tcType == testCaseType.NOTAPPLICABLE:
return True
else:
False

def is_error(self):
"""Returns True if the testCase is of Type Error, if not returns False"""
if self.tcType == testCaseType.ERROR:
Expand All @@ -221,7 +239,7 @@ def is_failure(self):

def is_pass(self):
"""Returns True if the testCase is of Type Pass, if not returns False."""
if self.tcType not in [testCaseType.ERROR, testCaseType.FAILURE, testCaseType.SKIPPED, testCaseType.INFORMATION] or self.tcType == testCaseType.PASS:
if self.tcType not in [testCaseType.ERROR, testCaseType.FAILURE, testCaseType.SKIPPED, testCaseType.INFORMATION, testCaseType.NOTAPPLICABLE] or self.tcType == testCaseType.PASS:
return True
else:
False
Expand Down Expand Up @@ -253,7 +271,7 @@ def add_error_info(self, message=None, output=None):
self.error_output = output

def add_skipped_info(self, message=None, output=None):
"""Sets the values for the corresponding Type Skipped."""
"""Sets the values for the corresponding Type Not Implemented."""
self.tcType = testCaseType.SKIPPED
self.tcMessage = message
self.tcOutput = output
Expand All @@ -270,6 +288,15 @@ def add_information_info(self, message=None, output=None):
self.information_message = message
self.information_output = output

def add_not_applicable_info(self, message=None, output=None):
"""Sets the values for the corresponding Type Not Applicable."""
self.tcType = testCaseType.NOTAPPLICABLE
self.tcMessage = message
self.tcOutput = output
#To be compatible with junit_xml
self.not_applicable_message = message
self.not_applicable_output = output

def add_stdout_info(self, text):
"""Adds the text that is going to be part of the stdout for the TestCase."""
if self.stdout is not None:
Expand Down Expand Up @@ -380,6 +407,7 @@ def build_xml(self):
ts_attributes['errors'] = str( len( [tc for tc in self.test_cases if tc.is_error()] ) )
ts_attributes['skipped'] = str( len( [tc for tc in self.test_cases if tc.is_skipped()] ) )
ts_attributes['information'] = str( len( [tc for tc in self.test_cases if tc.is_information()] ) )
ts_attributes['notapplicable'] = str( len( [tc for tc in self.test_cases if tc.is_not_applicable()] ) )
#ts_attributes["time"] = str( sum( [tc.time for tc in self.test_cases if tc.time] ) )
ts_attributes["time"] = "%.5f" % sum( [tc.time for tc in self.test_cases if tc.time] )
ts_attributes["tests"] = str( len( self.test_cases ) )
Expand Down Expand Up @@ -426,11 +454,17 @@ def build_xml(self):
if tc.error_output:
error_element.text = tc.error_output
elif tc.is_skipped():
skipped_element = ET.SubElement( tc_element, "skipped", {'type': 'skipped'} )
skipped_element = ET.SubElement( tc_element, "not_implemented", {'type': 'not_implemented'} )
if tc.skipped_message:
skipped_element.set( 'message', tc.skipped_message )
if tc.skipped_output:
skipped_element.text = tc.skipped_output
elif tc.is_not_applicable():
not_applicable_element = ET.SubElement( tc_element, "not_applicable", {'type': 'not_applicable'} )
if tc.not_applicable_message:
not_applicable_element.set( 'message', tc.not_applicable_message )
if tc.not_applicable_output:
not_applicable_element.text = tc.skipped_output

#system-out and system-err are common for all, so here we go.
if tc.stdout:
Expand Down

0 comments on commit 3a39ff1

Please sign in to comment.