def test(self): instance = os.path.join(self.aux_root, 'three_paths.c') aa_file = os.path.join(self.aux_root, 'aa_three_paths_inner_if_both_blocks.spc') non_existent_dir = self.temp_folder argv = [ str(x) for x in [ '-assumption_automaton_file', aa_file, '-cex_dir', non_existent_dir, '-spec', self.default_spec, '-cex_count', 10, '-generator_type', 'fixpoint', instance ] ] with patch.object(self.logger, 'info') as mock_info: generate_coverage.main(argv, self.logger) expected_calls = [ call('Generated 1 executions.'), call('Coverage after collecting 1 executions:'), call('Lines covered: 1'), call('Total lines to cover: 10'), call(''), call('Generated 1 executions.'), call('Coverage after collecting 2 executions:'), call('Lines covered: 4'), call('Total lines to cover: 10'), call(''), call('Generated 1 executions.'), call('Coverage after collecting 3 executions:'), call('Lines covered: 5'), call('Total lines to cover: 10'), call(''), call('Generated 0 executions.'), call('Total lines covered: 5'), call('Total lines to cover: 10') ] self.assertEqual(mock_info.mock_calls, expected_calls)
def test(self): instance = os.path.join(self.aux_root, "three_paths.c") aa_file = os.path.join(self.aux_root, "aa_three_paths_inner_if_both_blocks.spc") specs_dir = os.path.join(self.aux_root, "cex_three_paths", "inner_both_blocks") argv = [ str(x) for x in [ "-assumption_automaton_file", aa_file, "-cex_dir", specs_dir, "-only_collect_coverage", "-spec", self.default_spec, "-generator_type", "blind", instance, ] ] with patch.object(self.logger, "info") as mock_info: generate_coverage.main(argv, self.logger) expected_calls = [ call("Coverage after collecting 1 executions:"), call("Lines covered: 4"), call("Total lines to cover: 10"), call(""), call("Coverage after collecting 2 executions:"), call("Lines covered: 5"), call("Total lines to cover: 10"), call(""), call("Total lines covered: 5"), call("Total lines to cover: 10"), ] self.assertEqual(mock_info.mock_calls, expected_calls)
def test(self): instance = os.path.join(self.aux_root, 'three_paths.c') aa_file = os.path.join(self.aux_root, 'aa_three_paths_inner_if_both_blocks.spc') specs_dir = os.path.join(self.aux_root, 'cex_three_paths', 'inner_both_blocks') argv = [ str(x) for x in [ '-assumption_automaton_file', aa_file, '-cex_dir', specs_dir, '-only_collect_coverage', '-spec', self.default_spec, '-generator_type', 'blind', instance ] ] with patch.object(self.logger, 'info') as mock_info: generate_coverage.main(argv, self.logger) expected_calls = [ call('Coverage after collecting 1 executions:'), call('Lines covered: 4'), call('Total lines to cover: 10'), call(''), call('Coverage after collecting 2 executions:'), call('Lines covered: 5'), call('Total lines to cover: 10'), call(''), call('Total lines covered: 5'), call('Total lines to cover: 10') ] self.assertEqual(mock_info.mock_calls, expected_calls)
def test(self): instance = os.path.join(self.aux_root, 'loop_many_paths.c') aa_file = os.path.join(self.aux_root, 'true_aa.spc') non_existent_dir = self.temp_folder timelimit = 20 argv = [ str(x) for x in [ '-assumption_automaton_file', aa_file, '-cex_dir', non_existent_dir, '-spec', self.default_spec, '-timelimit', str(timelimit), '-generator_type', 'fixpoint', instance ] ] start_time = time.time() lines_covered = 0 def side_effect(info_msg): import re nonlocal lines_covered m = re.search(pattern="Total lines covered: (.*)", string=info_msg) if m: lines_covered = int(m.group(1)) with patch.object(self.logger, 'info') as mock_info, patch.object( self.logger, 'error') as mock_error: mock_info.side_effect = side_effect generate_coverage.main(argv, self.logger) self.assertEqual(mock_error.mock_calls, []) self.assertGreater(lines_covered, 0) self.assertGreater(25, lines_covered) elapsed_time = time.time() - start_time self.assertGreater(2 * timelimit, elapsed_time)
def test(self): instance = os.path.join(self.aux_root, "loop_many_paths.c") aa_file = os.path.join(self.aux_root, "true_aa.spc") non_existent_dir = self.temp_folder timelimit = 20 argv = [ str(x) for x in [ "-assumption_automaton_file", aa_file, "-cex_dir", non_existent_dir, "-spec", self.default_spec, "-timelimit", str(timelimit), "-generator_type", "fixpoint", instance, ] ] start_time = time.time() lines_covered = 0 log = [] def side_effect(info_msg): log.append(info_msg) import re nonlocal lines_covered m = re.search(pattern="Total lines covered: (.*)", string=info_msg) if m: lines_covered = int(m.group(1)) # Will allow only one terminating execution to be generated, # since the timer adds 10 second for each call to method 'time'. timer = MockAdd10SecTimer(start_time) with patch.object(self.logger, "info") as mock_info, patch.object( self.logger, "error") as mock_error: mock_info.side_effect = side_effect generate_coverage.main(argv, self.logger, timer=timer) self.assertEqual(mock_error.mock_calls, []) elapsed_time = time.time() - start_time self.assertGreater( 2 * timelimit, elapsed_time, msg="Timeout occured, log was:\n" + "\n".join(log), ) self.assertGreater( lines_covered, 0, msg="Unexpected negative number for line coverage, log was:\n" + "\n".join(log), ) self.assertGreater( 25, lines_covered, msg="Unexpectedly low number of covered lines , log was:\n" + "\n".join(log), )
def test(self): instance = os.path.join(self.aux_root, "three_paths.c") aa_file = os.path.join(self.aux_root, "aa_three_paths_inner_if_both_blocks.spc") non_existent_dir = self.temp_folder argv = [ str(x) for x in [ "-assumption_automaton_file", aa_file, "-cex_dir", non_existent_dir, "-spec", self.default_spec, "-timelimit", str(900), "-generator_type", "fixpoint", instance, ] ] # ch = logging.StreamHandler() # ch.setLevel(logging.DEBUG) # self.logger.addHandler(ch) # self.logger.setLevel(logging.DEBUG) with patch.object(self.logger, "info") as mock_info: generate_coverage.main(argv, self.logger) expected_calls = [ call("Generated 1 executions."), call("Coverage after collecting 1 executions:"), call("Lines covered: 1"), call("Total lines to cover: 10"), call(""), call("Generated 1 executions."), call("Coverage after collecting 2 executions:"), call("Lines covered: 4"), call("Total lines to cover: 10"), call(""), call("Generated 1 executions."), call("Coverage after collecting 3 executions:"), call("Lines covered: 5"), call("Total lines to cover: 10"), call(""), call("Generated 0 executions."), call("Total lines covered: 5"), call("Total lines to cover: 10"), ] self.assertEqual(mock_info.mock_calls, expected_calls)
#!/usr/bin/env python3 # This file is part of CPAchecker, # a tool for configurable software verification: # https://cpachecker.sosy-lab.org # # SPDX-FileCopyrightText: 2017 Rodrigo Castano # SPDX-FileCopyrightText: 2017-2020 Dirk Beyer <https://www.sosy-lab.org> # # SPDX-License-Identifier: Apache-2.0 import logging import sys import post_processing.coverage.generate_coverage as generate_coverage if __name__ == "__main__": if sys.version_info[0] < 3: sys.exit("This script requires Python 3.") logging.basicConfig() logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # Excluding argv[0], otherwise it'll be recognized as the positional # argument. generate_coverage.main(sys.argv[1:], logger)