Beispiel #1
0
    def test_all_svgs_were_created_diff(self):
        outName1, outList1, errorCode1 = flaminglog.make_json(self.INPUTFILE1)
        outName2, outList2, errorCode2 = flaminglog.make_json(self.INPUTFILE2)
        exitCode, fileDict = flaminglog.make_svg(outList1, outList2)

        for key in fileDict:
            self.assertTrue(os.path.exists(key))
Beispiel #2
0
    def test_all_occurrences_in_svgs_diff(self):

        outName1, outList1, errorCode1 = flaminglog.make_json(self.INPUTFILE1)
        outName2, outList2, errorCode2 = flaminglog.make_json(self.INPUTFILE2)
        exitCode, fileDict = flaminglog.make_svg(outList1, outList2)

        rList1 = testframe.get_all_occ_names(outList1)
        rList2 = testframe.get_all_occ_names(outList2)

        file1List = [
            'static/myflame1Combined.svg', 'static/myflame1Separate.svg',
            'static/diff1.svg'
        ]

        file2List = [
            'static/myflame2Combined.svg', 'static/myflame2Separate.svg',
            'static/diff2.svg'
        ]

        for item in file1List:
            resultBool = testframe.check_names_in_svg(rList1, item)
            self.assertTrue(resultBool,
                            "Not all occurrences were found in" + item)

        for item in file2List:
            resultBool = testframe.check_names_in_svg(rList2, item)
            self.assertTrue(resultBool,
                            "Not all occurrences were found in" + item)
Beispiel #3
0
    def test_expected_outputs_diff(self):
        outName1, outList1, errorCode1 = flaminglog.make_json(self.INPUTFILE1)
        outName2, outList2, errorCode2 = flaminglog.make_json(self.INPUTFILE2)
        exitCode, fileDict = flaminglog.make_svg(outList1, outList2)
        self.assertTrue(exitCode, "exitCode is not True")

        for key in fileDict:
            self.assertTrue(fileDict[key] is not None)
Beispiel #4
0
    def generate_files(self):
        testLog1 = 'apitests/TestLogs/beforelog.txt'
        testLog2 = 'apitests/TestLogs/afterlog.txt'

        outName1, outList1, err1 = flaminglog.make_json(testLog1)
        outName2, outList2, err2 = flaminglog.make_json(testLog2)

        exitBool, fileDict = flaminglog.make_svg(outList1, outList2)
    def generate_files(self, folder=''):

        testLog1 = 'apitests/TestLogs/beforelog.txt'
        testLog2 = 'apitests/TestLogs/afterlog.txt'

        outName1, outList1, err1 = flaminglog.make_json(testLog1)
        outName2, outList2, err2 = flaminglog.make_json(testLog2)

        exitBool, fileDict = flaminglog.make_svg(outList1, outList2)

        for key in fileDict:
            if key is not None:
                flaminglog.svg_to_png(key, key[:-3] + 'png')
Beispiel #6
0
    def test_file_not_found(self):
        testFile = 'apitests/TestLogs/does_not_exist.txt'

        with self.assertRaises(Exception) as context:
            outName, outList, errorCode = flaminglog.make_json(testFile)
        errstr = ':was not found'
        self.assertTrue(errstr in str(context.exception))
Beispiel #7
0
    def test_bytecode_top_level(self):
        testFile = 'apitests/TestLogs/rawlog.txt'
        filterList = ['BYTECODE', 'CMDVM', 'CMD']
        outName, outList, errorCode = flaminglog.make_json(
            testFile, filterList)

        self.do_error_subtests(outName, outList, errorCode, None, None, 1004)
Beispiel #8
0
 def test_invalid_occ_list(self):
     testFile = 'apitests/TestLogs/rawlog.txt'
     filterList = ['EVENT', 'RULE', 'RULEVM', 'INVALID']
     with self.assertRaises(Exception) as context:
         outName, outList, errorCode = flaminglog.make_json(
             testFile, filterList)
     errstr = ':is not a valid entry in wantedOccList'
     self.assertTrue(errstr in str(context.exception))
Beispiel #9
0
def make_verified_json(inputFile, valueDict):

    goodLog, badLog = filter_log(inputFile, valueDict)
    goodName, goodList, goodErrorCode = flaminglog.make_json(goodLog)
    #badName, badList, badErrorCode = flaminglog.make_json(badLog)

    countDict = get_count(goodName)
    levelDict = get_levels(goodLog)

    return goodName, countDict, levelDict
Beispiel #10
0
    def test_expected_outputs(self):
        outName, outList, errorCode = flaminglog.make_json(self.INPUTFILE1)
        exitCode, fileDict = flaminglog.make_svg(outList)
        self.assertTrue(exitCode, "exitCode is not True")

        for key in fileDict:
            if (key == 'static/myflame1Combined.svg'
                    or key == 'static/myflame1Separate.svg'):
                self.assertTrue(fileDict[key] is not None)
            else:
                self.assertTrue(fileDict[key] is None)
Beispiel #11
0
    def test_empty_file(self):

        testfile = 'apitests/TestLogs/empty.txt'
        outName, outList, errorCode = flaminglog.make_json(testfile)

        with self.subTest("Length of output List"):
            self.assertEqual(len(outList), 0)

        with open(outName, 'r') as f:
            fileList = json.load(f)

        with self.subTest("Length of output file"):
            self.assertEqual(len(fileList), 0)
Beispiel #12
0
    def test_all_occurrences_in_svg(self):

        outName, outList, errorCode = flaminglog.make_json(self.INPUTFILE1)
        exitCode, fileDict = flaminglog.make_svg(outList)

        rList = testframe.get_all_occ_names(outList)
        resultBoolCom = testframe.check_names_in_svg(
            rList, 'static/myflame1Combined.svg')
        resultBoolSep = testframe.check_names_in_svg(
            rList, 'static/myflame1Separate.svg')

        self.assertTrue(resultBoolSep,
                        "Not all occurrences were found in separate svg file")
        self.assertTrue(resultBoolCom,
                        "Not all occurrences were found in combined svg file")
Beispiel #13
0
    def run_occ_filter_test(self, failList, inputFile, randomFilter):

        testPass = True
        outNameExp, outListExp, errorCodeExp, testLog = testframe.get_test_json(
            inputFile, randomFilter)

        exp = testframe.ExpectedData()
        exp.level = testframe.get_levels(testLog)
        exp.count = testframe.get_log_count(testLog)

        if (exp.level['BYTECODE'] != 1):
            testframe.adjust_event_rule(inputFile, outListExp, randomFilter)

        exp.dataList = outListExp

        outNameR, outListR, errorCodeR = flaminglog.make_json(
            inputFile, randomFilter)

        results = testframe.ResultData()
        results.dataList = outListR

        #if the log file is invalid, e.g. only bytecode
        if (errorCodeExp != 0):

            #add tests for error code/msg here
            testPass = self.do_error_subtests(outNameR, outListR, errorCodeR,
                                              None, None, 1004)

        else:
            checkHelper = testframe.CheckStruct(results, exp)
            levelCheck, dataCheck, countCheck, lenCheck = checkHelper.fullCheck(
            )

            #keeps track of which filters failed
            boolList = [levelCheck, dataCheck, countCheck, lenCheck]
            for item in boolList:
                if not item:
                    testPass = False
                    failList.append(randomFilter.copy())

            self.do_sub_tests(results, exp, countCheck, levelCheck, dataCheck,
                              lenCheck)

        return testPass
Beispiel #14
0
    def test_base_functionality(self):

        testLog = 'apitests/TestLogs/mainlog2.txt'
        verifiedJson = 'apitests/VerifiedJSON/verifiedmainlog2.json'

        exp = testframe.ExpectedData()

        exp.count = {
            'EVENT': 9,
            'RULE': 5,
            'RULEVM': 5,
            'BYTECODE': 90,
            'CMDVM': 12,
            'CMD': 9,
            'VAR_MOD': 8
        }

        exp.level = {
            'EVENT': 1,
            'RULE': 2,
            'RULEVM': 3,
            'BYTECODE': 4,
            'CMDVM': 5,
            'CMD': 6,
            'VAR_MOD': 5
        }

        with open(verifiedJson, 'r') as f:
            exp.dataList = json.load(f)

        outName, outList, errorCode = flaminglog.make_json(testLog)
        results = testframe.ResultData()
        results.dataList = outList

        checkHelper = testframe.CheckStruct(results, exp)
        levelCheck, dataCheck, countCheck, lenCheck = checkHelper.fullCheck()

        self.do_sub_tests(results, exp, countCheck, levelCheck, dataCheck,
                          lenCheck)
Beispiel #15
0
def create_verified_log(rawlog, filterList):

    traceFile = isolate_trace(rawlog)

    filterLogName = 'tempfilterlog.txt'
    traceHandle = open(traceFile, 'r')
    filteredLog = open(filterLogName, 'w+')
    for line in traceHandle:
        splitLine = line.split(',')
        for item in filterList:
            if (item == trim_str(splitLine[1])):
                filteredLog.write(line)

    traceHandle.close()
    filteredLog.close()

    levels = get_levels(filterLogName)
    count = get_log_count(filterLogName)

    outName, outList, errcode = flaminglog.make_json('tempfilterlog.txt')

    return outList, levels, count
Beispiel #16
0
    def test_missing_exit_cmd(self):

        testFile = 'apitests/TestLogs/missing_exit_cmd.txt'
        outName, outList, errorCode = flaminglog.make_json(testFile)

        self.do_error_subtests(outName, outList, errorCode, None, None, 1000)
Beispiel #17
0
 def test_invalid_type_input(self):
     testFile = 'apitests/TestLogs/rawlog.txt'
     with self.assertRaises(Exception) as context:
         outName, outList, errorCode = flaminglog.make_json(testFile, 2)
     errstr = "object is not of type list or str:"
     self.assertTrue(errstr in str(context.exception))
Beispiel #18
0
    def test_too_few_fields(self):
        testFile = 'apitests/TestLogs/too_few_fields.txt'
        outName, outList, errorCode = flaminglog.make_json(testFile)

        self.do_error_subtests(outName, outList, errorCode, None, None, 1003)
Beispiel #19
0
    def test_bytecode_only_trace(self):

        testfile = 'apitests/TestLogs/only_bytecode_trace.txt'
        outName, outList, errorCode = flaminglog.make_json(testfile)

        self.do_error_subtests(outName, outList, errorCode, None, None, 1004)
Beispiel #20
0
    def test_cmdvm_found_low(self):
        testFile = 'apitests/TestLogs/cmdvm_lower.txt'
        outName, outList, errorCode = flaminglog.make_json(testFile)

        self.do_error_subtests(outName, outList, errorCode, None, None, 1001)
Beispiel #21
0
    def test_varmod_found_high(self):
        testFile = 'apitests/TestLogs/varmod_higher.txt'
        outName, outList, errorCode = flaminglog.make_json(testFile)

        self.do_error_subtests(outName, outList, errorCode, None, None, 1001)
Beispiel #22
0
def get_test_json(inputFile, typeFilter):
    tempName = 'apitests/tempfiles/tempout.txt'
    goodLog = remove_unwanted_lines(inputFile, tempName, typeFilter)
    outName, outList, errCode = flaminglog.make_json(goodLog)

    return outName, outList, errCode, goodLog
Beispiel #23
0
 def test_svg_was_created(self):
     outName, outList, errorCode = flaminglog.make_json(self.INPUTFILE1)
     exitCode, fileDict = flaminglog.make_svg(outList)
     self.assertTrue(os.path.exists('static/myflame1Combined.svg'))
     self.assertTrue(os.path.exists('static/myflame1Separate.svg'))