def test_reading_1(self): self.assertTrue(configuration.readConfigFile(os.path.join(self.testsDirectory, "configurationTestReading1.json"))) self.assertEqual(configuration.getLanguage(), "C") self.assertFalse(configuration.getPenaltyFlag()) self.assertEqual(configuration.getErrorsToLookFor(), ['MEMORY LEAK', 'INVALID ACCESS', 'INVALID FREE'])
def test_reading_2(self): # testing penalty configurations self.assertTrue(configuration.readConfigFile(os.path.join(self.testsDirectory, "configurationTestReading2.json"))) self.assertEqual(configuration.getLanguage(), "C") self.assertTrue(configuration.getPenaltyFlag()) self.assertEqual(configuration.getErrorsToLookFor(), ['UNITIALIZED VARIABLE USAGE', 'INVALID ACCESS', 'MEMORY LEAK', 'INVALID FREE']) self.assertEqual(configuration.getPenaltyDictionary(), {'UNITIALIZED VARIABLE USAGE': {'Penalty': 7.0, 'Mode': 'S'},\ 'INVALID ACCESS': {'Penalty': 6.0, 'Mode': 'S'},\ 'MEMORY LEAK': {'Penalty': 5.0, u'Mode': 'S'},\ 'INVALID FREE': {'Penalty': 8.0, 'Mode': 'S'}})
def main(): callerPath = os.getcwd() init(sys.argv[0]) sys.path.insert(0, "platforms") sys.path.insert(0, os.getcwd()) returnPath = os.getcwd() platformInstance = platformhandler.getInstance() if platformInstance is None: print "ERROR: Your OS is not supported by Robocheck" return if len(sys.argv) != 2 or "--help" in sys.argv: helpMessage() exit() configFilePath = os.path.abspath('config.json') if "--config" in sys.argv: configuration.createConfigFile(configFilePath) return cleanUp(platformInstance) couldRead = configuration.readConfigFile(configFilePath) if couldRead is False: return language = configuration.getLanguage() errorsToLookFor = configuration.getErrorsToLookFor() tools = modulehandler.getCompatibleModules(language, errorsToLookFor, platformInstance) os.mkdir(platformInstance.getTempPath() + "current-robocheck-test") os.chdir(callerPath) try: platformInstance.zipExtractAll(sys.argv[1]) except Exception: print "ERROR: Archive was not Zip format or it was corrupted!" exit() platformInstance.cdToTemp() errorJsonList = [] os.chdir("current-robocheck-test") try: sources = os.listdir('src') exes = os.listdir('bins') except Exception: print "ERROR: Archive did not have the expected folders!" cleanUp(platformInstance) exit() exesPath = "bins" srcsPath = 'src' errorList = [] for tool in tools: errors = tool.runToolGetErrors(platformInstance, exes, sources, exesPath, srcsPath, errorsToLookFor) errorsToLookFor = getRemainingErrors(errorsToLookFor, errors) for err in errors: if err not in errorList: errorList.append(err) errorJsonList = configuration.getJson(errorList) errorJsonList = dict([("ErrorsFound",errorJsonList)]) print json.dumps(errorJsonList, indent=2) os.chdir(callerPath) jsonOutput = open('robocheck-output.json', 'w') jsonOutput.write(json.dumps(errorJsonList, indent=2)) jsonOutput.close() cleanUp(platformInstance)