Example #1
0
class TestWorkerRunner(unittest.TestCase):
    def setUp(self):
        self.runner = WorkerRunner('test', pipeline=[KleeRunProcessor])
        self.runner.__enter__()

    def tearDown(self):
        self.runner.__exit__(None, None, None)

    def run_klee_test(self,
                      fixture_name,
                      run_configuration=None,
                      expect_failure=False):
        if not run_configuration:
            run_configuration = {}

        test_fixtures = os.path.join(FIXTURE_DIR, fixture_name)

        with codecs.open(os.path.join(test_fixtures, 'input.c'),
                         encoding='utf-8') as f:
            code = f.read()

        with codecs.open(os.path.join(test_fixtures, 'expected.stdout'),
                         'U',
                         encoding='utf-8') as f:
            expected_out = f.read()

        flags = re.M | re.DOTALL | re.UNICODE
        expected_regex = re.compile(u"{}$".format(expected_out), flags)
        if expect_failure:
            self.assertRaisesRegexp(KleeRunFailure, expected_regex,
                                    self.runner.execute_pipeline, code,
                                    run_configuration)
        else:
            result = self.runner.execute_pipeline(code, run_configuration)
            stdout = result['klee_run']['output']
            self.assertRegexpMatches(stdout, expected_regex)

    def test_simple_run(self):
        self.run_klee_test('simple')

    def test_simple_unicode_run(self):
        self.run_klee_test('simple_unicode')

    def test_symargs(self):
        self.run_klee_test('symargs',
                           {'sym_args': {
                               'range': [1, 1],
                               'size': 1
                           }})

    def test_symfiles(self):
        self.run_klee_test('symfiles', {
            'stdin_enabled': True,
            'num_files': 0,
            'size_files': 1
        })

    def test_fail_on_invalid_syntax(self):
        self.run_klee_test('invalid_syntax', expect_failure=True)
Example #2
0
class TestWorkerRunner(unittest.TestCase):
    def setUp(self):
        self.runner = WorkerRunner('test', pipeline=[KleeRunProcessor])
        self.runner.__enter__()

    def tearDown(self):
        self.runner.__exit__(None, None, None)

    def run_klee_test(self, fixture_name, run_configuration=None,
                      expect_failure=False):
        if not run_configuration:
            run_configuration = {}

        test_fixtures = os.path.join(FIXTURE_DIR, fixture_name)

        with codecs.open(os.path.join(test_fixtures, 'input.c'),
                         encoding='utf-8') as f:
            code = f.read()

        with codecs.open(os.path.join(test_fixtures, 'expected.stdout'), 'U',
                         encoding='utf-8') as f:
            expected_out = f.read()

        flags = re.M | re.DOTALL | re.UNICODE
        expected_regex = re.compile(u"{}$".format(expected_out), flags)
        if expect_failure:
            self.assertRaisesRegexp(KleeRunFailure, expected_regex,
                                    self.runner.execute_pipeline, code,
                                    run_configuration)
        else:
            result = self.runner.execute_pipeline(code, run_configuration)
            stdout = result['klee_run']['output']
            self.assertRegexpMatches(stdout, expected_regex)

    def test_simple_run(self):
        self.run_klee_test('simple')

    def test_simple_unicode_run(self):
        self.run_klee_test('simple_unicode')

    def test_symargs(self):
        self.run_klee_test('symargs', {
            'sym_args': {
                'range': [1, 1],
                'size': 1
            }
        })

    def test_symfiles(self):
        self.run_klee_test('symfiles', {
            'stdin_enabled': True,
            'num_files': 0,
            'size_files': 1
        })

    def test_fail_on_invalid_syntax(self):
        self.run_klee_test('invalid_syntax', expect_failure=True)
Example #3
0
class TestWorkerRunner(unittest.TestCase):
    def setUp(self):
        self.runner = WorkerRunner('test', pipeline=[KleeRunProcessor])
        self.runner.__enter__()

    def tearDown(self):
        self.runner.__exit__(None, None, None)

    def run_klee_test(self,
                      fixture_name,
                      run_configuration=None,
                      expect_failure=False):
        if not run_configuration:
            run_configuration = {}

        test_fixtures = os.path.join(FIXTURE_DIR, fixture_name)

        with codecs.open(os.path.join(test_fixtures, 'input.c'),
                         encoding='utf-8') as f:
            code = f.read()

        with codecs.open(os.path.join(test_fixtures, 'expected.stdout'),
                         encoding='utf-8') as f:
            expected_out = f.read()

        flags = re.M | re.DOTALL | re.UNICODE
        expected_regex = re.compile(u"{}$".format(expected_out), flags)
        if expect_failure:
            self.assertRaisesRegex(KleeRunFailure, expected_regex,
                                   self.runner.execute_pipeline, code,
                                   run_configuration)
        else:
            result = self.runner.execute_pipeline(code, run_configuration)
            stdout = result['klee_run']['output']
            self.assertRegex(stdout, expected_regex)

    def test_simple_run(self):
        self.run_klee_test('simple')

    def test_simple_unicode_run(self):
        self.run_klee_test('simple_unicode')

    def test_symargs(self):
        self.run_klee_test('symargs',
                           {'sym_args': {
                               'range': [1, 1],
                               'size': 1
                           }})

    def test_symin(self):
        self.run_klee_test('symin', {'sym_in': {'size': 1}})

    def test_fail_on_invalid_syntax(self):
        self.run_klee_test('invalid_syntax', expect_failure=True)

    def test_timeout_container(self):
        try:
            self.runner.run_with_docker(['/bin/sleep', '10'], timeout=1)
        except KleeRunFailure as ex:
            self.assertIn('Timeout error after 1', str(ex))
            return
        self.assertTrue(False)