Example #1
0
    def test(self):
        instance = os.path.join(self.aux_root, "contains_error.c")
        cex_count = 2  # Will only produce one, checking the output though.
        aa_file = os.path.join(self.aux_root, "dummy_aa.spc")

        with patch.object(self.logger, "error") as mock_logger, patch.object(
            self.logger, "info"
        ) as mock_info:
            try:
                g = generate_coverage.GenerateFirstThenCollect(
                    instance=instance,
                    output_dir=self.temp_folder,
                    cex_count=cex_count,
                    spec=self.default_spec,
                    heap_size=None,
                    timelimit=self.default_timelimit,
                    logger=self.logger,
                    aa_file=aa_file,
                    start_time=self.start_time,
                    timer=generate_coverage.Timer(),
                )
                list(g.generate_executions())
                self.fail("Should have raised FoundBugError.")
            except generate_coverage.FoundBugError:
                pass
            mock_logger.assert_called_once_with(
                "Found an assertion violation. "
                "Inspect counterexamples before collecting a "
                "coverage measure."
            )
            mock_info.assert_called_once_with("Generated 2 executions.")

        self.assertTrue(os.path.exists(self.temp_folder))
        self.assertEqual(len(os.listdir(self.temp_folder)), 2)
Example #2
0
    def test(self):
        """
        This is known behavior that is worth to document. We will only get
        a single execution for each return statement due to how states
        are merged.
        """
        instance = os.path.join(self.aux_root, "one_per_return.c")
        cex_count = 10
        aa_file = os.path.join(self.aux_root, "dummy_aa.spc")
        with patch.object(self.logger, "info") as mock_info:
            g = generate_coverage.GenerateFirstThenCollect(
                instance=instance,
                output_dir=self.temp_folder,
                cex_count=cex_count,
                spec=self.default_spec,
                heap_size=None,
                timelimit=self.default_timelimit,
                logger=self.logger,
                aa_file=aa_file,
                start_time=self.start_time,
                timer=generate_coverage.Timer(),
            )
            cex_generated = len(list(g.generate_executions()))
            mock_info.assert_called_once_with("Generated 1 executions.")

        self.assertTrue(os.path.exists(self.temp_folder))
        self.assertEqual(len(os.listdir(self.temp_folder)), 1)
        self.assertEqual(cex_generated, 1)
Example #3
0
    def test(self):
        instance = os.path.join(self.aux_root, 'contains_error.c')
        cex_count = 2  # Will only produce one, checking the output though.
        aa_file = os.path.join(self.aux_root, 'dummy_aa.spc')

        with patch.object(self.logger, 'error') as mock_logger, \
             patch.object(self.logger, 'info') as mock_info:
            try:
                g = generate_coverage.GenerateFirstThenCollect(
                    instance=instance,
                    output_dir=self.temp_folder,
                    cex_count=cex_count,
                    spec=self.default_spec,
                    heap_size=None,
                    timelimit=self.default_timelimit,
                    logger=self.logger,
                    aa_file=aa_file,
                    start_time=self.start_time)
                cex_generated = len(list(g.generate_executions()))
                self.fail('Should have raised FoundBugException.')
            except generate_coverage.FoundBugException as e:
                pass
            mock_logger.assert_called_once_with(
                'Found an assertion violation. '
                'Inspect counterexamples before collecting a '
                'coverage measure.')
            mock_info.assert_called_once_with('Generated 2 executions.')

        self.assertTrue(os.path.exists(self.temp_folder))
        self.assertEqual(len(os.listdir(self.temp_folder)), 2)
Example #4
0
    def test(self):
        instance = os.path.join(self.aux_root, 'two_loop_iterations.c')
        cex_count = 2  # Will only produce one, checking the output though.
        aa_file = os.path.join(self.aux_root, 'dummy_aa.spc')
        with patch.object(self.logger, 'info') as mock_logger:
            g = generate_coverage.GenerateFirstThenCollect(
                instance=instance,
                output_dir=self.temp_folder,
                cex_count=cex_count,
                spec=self.default_spec,
                heap_size=None,
                timelimit=self.default_timelimit,
                logger=self.logger,
                aa_file=aa_file,
                start_time=self.start_time)
            cex_generated = len(list(g.generate_executions()))
            mock_logger.assert_called_once_with('Generated 1 executions.')

        self.assertTrue(os.path.exists(self.temp_folder))
        self.assertEqual(len(os.listdir(self.temp_folder)), 1)
        self.assertEqual(cex_generated, 1)
    def test(self):
        instance = os.path.join(self.aux_root, 'three_paths.c')
        cex_count = 10  # There are only 3 paths though, checking the output.
        aa_file = os.path.join(self.aux_root, 'dummy_aa.spc')
        with patch.object(self.logger, 'info') as mock_info:
            g = generate_coverage.GenerateFirstThenCollect(
                instance=instance,
                output_dir=self.temp_folder,
                cex_count=cex_count,
                spec=self.default_spec,
                heap_size=None,
                timelimit=self.default_timelimit,
                logger=self.logger,
                aa_file=aa_file,
                start_time=self.start_time,
                timer=generate_coverage.Timer())
            cex_generated = len(list(g.generate_executions()))
            mock_info.assert_called_once_with('Generated 3 executions.')

        self.assertTrue(os.path.exists(self.temp_folder))
        self.assertEqual(len(os.listdir(self.temp_folder)), 3)
        self.assertEqual(cex_generated, 3)