Пример #1
0
 def _get_test_vector(self, test):
     test_vector = utils.TestVector(test.name, test.origin)
     for line in test.content.split('\n'):
         value = line.strip()
         if value:
             test_vector.add(value)
     return test_vector
Пример #2
0
    def get_test_vector(self, test_case):
        test_info = [t for t in test_case.content.split('\n') if t]
        vector = utils.TestVector(test_case.name, test_case.origin)
        for idx, line in enumerate(test_info):
            # is in C hex notation, e.g. '0xffffff' (WITH the ''!)
            value = line.split(':')[1].strip()
            vector.add(value)

        return vector
Пример #3
0
 def _get_test_vector(self, test):
     assert len(test.content.split('\n')) == 1
     assert test.content.startswith('[') and test.content.endswith(']')
     test_vector = utils.TestVector(test.name, test.origin)
     processed_line = test.content[1:-1]
     test_values = processed_line.split(', ')
     for value in test_values:
         test_vector.add(value)
     return test_vector
Пример #4
0
    def get_test_vector(self, test):
        def _get_value(single_line):
            var_name = single_line.split(':')[2].strip()
            prefix_end = var_name.find("'")
            var_name = var_name[prefix_end + 1:-1]
            return var_name

        def _convert_bytestring_to_hex(bytestring):
            bytes = bytestring.split(r'\x')
            value = ''.join(reversed(bytes))
            value = '0x' + value
            return value

        def _get_var_number(test_info_line):
            assert 'object' in test_info_line
            # Object number should be at end, e.g. 'object  1: ...'
            return test_info_line.split(':')[0].split(' ')[-1]

        ktest_tool = [os.path.join(bin_dir, 'ktest-tool')]
        exec_output = utils.execute(ktest_tool + [test.origin],
                                    err_to_output=False,
                                    quiet=True)
        test_info = exec_output.stdout.split('\n')
        vector = utils.TestVector(test.name, test.origin)
        last_number = -1
        last_nondet_method = None
        last_value = None
        for line in [l for l in test_info if l.startswith('object')]:
            logging.debug("Looking at line: %s", line)
            if 'name:' in line:
                # assert len(line.split(':')) == 3
                var_number = int(_get_var_number(line))
                assert var_number > last_number
                last_number = var_number
                var_name = _get_value(line)
                assert last_nondet_method is None, \
                    "Last nondet method already or still assigned: %s" % last_nondet_method
                assert "'" not in var_name, \
                    "Variable name contains \"'\": %s" % var_name
                last_nondet_method = utils.get_corresponding_method_name(
                    var_name)
            elif 'data:' in line:
                # assert len(line.split(':')) == 3
                var_number = _get_var_number(line)
                assert last_nondet_method is not None
                # we get the value in bytestring notation, so we have to convert it afterwards
                value = _get_value(line)
                value = _convert_bytestring_to_hex(value)
                assert last_value is None
                last_value = str(value)
            if last_nondet_method is not None and last_value is not None:
                vector.add(last_value, last_nondet_method)
                last_nondet_method = None
                last_value = None

        return vector
Пример #5
0
    def _get_test_vector(self, test):
        test_info = [t for t in test.content.split('\n') if t]
        vector = utils.TestVector(test.name, test.origin)
        for idx, line in enumerate(test_info):
            var_name = line.split(':')[0].strip()  # Line format is var: value
            nondet_method_name = utils.get_corresponding_method_name(var_name)
            value = line.split(':')[1].strip(
            )  # is in C hex notation, e.g. '\x00\x00' (WITH the ''!)
            vector.add(value, nondet_method_name)

        return vector
Пример #6
0
    def _get_test_vector(self, test):
        def _get_value(single_line):
            var_name = single_line.split(':')[2].strip()
            prefix_end = var_name.find("'")
            var_name = var_name[prefix_end + 1:-1]
            return var_name

        ktest_tool = [os.path.join(bin_dir, 'ktest-tool')]
        exec_output = utils.execute(ktest_tool + [test.origin],
                                    err_to_output=False,
                                    quiet=True)
        test_info = exec_output.stdout.split('\n')
        vector = utils.TestVector(test.name, test.origin)
        last_number = -1
        last_nondet_method = None
        last_value = None
        for line in [l for l in test_info if l.startswith('object')]:
            logging.debug("Looking at line: %s", line)
            if 'name:' in line:
                #assert len(line.split(':')) == 3
                var_number = int(self._get_var_number(line))
                assert var_number > last_number
                last_number = var_number
                var_name = _get_value(line)
                assert last_nondet_method is None, \
                        "Last nondet method already or still assigned: %s" % last_nondet_method
                assert "'" not in var_name, \
                        "Variable name contains \"'\": %s" % var_name
                last_nondet_method = utils.get_corresponding_method_name(
                    var_name)
            elif 'data:' in line:
                #assert len(line.split(':')) == 3
                var_number = self._get_var_number(line)
                assert last_nondet_method is not None
                value = _get_value(line)
                value, = utils.convert_to_int(value, last_nondet_method)
                assert last_value is None
                last_value = str(value)
            if last_nondet_method is not None and last_value is not None:
                vector.add(last_value, last_nondet_method)
                last_nondet_method = None
                last_value = None

        return vector
Пример #7
0
 def create_all_witnesses(self, program_file, new_test_cases):
     created_content = []
     nondet_methods = utils.get_nondet_methods()
     if len(new_test_cases) > 0:
         logging.info("Looking at %s new test files.", len(new_test_cases))
     empty_case_handled = False
     for test_case in new_test_cases:
         logging.debug('Looking at test case %s .', test_case)
         test_vector = self.get_test_vector(test_case)
         if test_vector or not empty_case_handled:
             if not test_vector:
                 test_vector = utils.TestVector(test_case.name,
                                                test_case.origin)
                 empty_case_handled = True
             new_content = self.create_witness(program_file, test_case.name,
                                               test_vector, nondet_methods)
             new_content['vector'] = test_vector
             new_content['origin'] = test_case.origin
             created_content.append(new_content)
         else:
             logging.info("Test vector was not generated for %s", test_case)
     return created_content
Пример #8
0
    def _get_test_vector(self, test):
        vector = utils.TestVector(test.name, test.origin)
        for tv in test.content:
            vector.add(tv)

        return vector
Пример #9
0
    def get_test_vector(self, test_case):
        vector = utils.TestVector(test_case.name, test_case.origin)
        for tv in test_case.content:
            vector.add(tv)

        return vector
Пример #10
0
 def get_test_vector(self, test_case):
     vector = utils.TestVector(test_case.name, test_case.origin)
     for line in test_case.content.split(b'\n'):
         vector.add(line)
     return vector