def test_scanner_driver_7sp1ent_x64_project_config(self):
        """Test x64 driver project creation."""
        target = Target.from_file(SCANNER_INF_PATH)
        project = monkey_patch_project(target.initialize_project(),
                                       WINDOWS_7SP1_X64_IMAGE_DESC)

        config = project._configure(target)

        # Assert that we've actually created a Windows project
        self.assertEqual(config['project_type'], 'windows')

        # Assert that the target is the one given
        self.assertEqual(config['target_path'], SCANNER_INF_PATH)
        self.assertEqual(config['target_arch'], 'x86_64')
        self.assertItemsEqual(config['target_files'],
                              [SCANNER_INF_PATH, SCANNER_SYS_PATH,
                               SCANNER_USER_EXE_PATH])
        self.assertItemsEqual(config['modules'], [(SCANNER_SYS, True)])

        # Assert that the x86_64 Windows 7 image was selected
        self.assertDictEqual(config['image'], WINDOWS_7SP1_X64_IMAGE_DESC)

        # Enabled by default for drivers
        self.assertTrue(config['use_fault_injection'])

        # Disabled by default
        self.assertFalse(config['enable_pov_generation'])
        self.assertFalse(config['use_seeds'])
        self.assertFalse(config['use_recipes'])
        self.assertFalse(config['processes'])
Exemple #2
0
    def test_cat_x86_symbolic_project_config(self):
        """
        Test Linux project creation given a x86 binary (``cat``) and a symbolic
        file argument.
        """
        target = Target.from_file(CAT_X86_PATH)
        project = monkey_patch_project(target.initialize_project(),
                                       LINUX_IMAGE_DESC)
        options = {
            'target_args': ['-T', '@@'],
        }

        config = project._configure(target, **options)

        self._assert_cat_x86_common(config)

        # Verify symbolic arguments
        self.assertListEqual(config['target_args'], ['-T', '@@'])
        self.assertFalse(config['sym_args'])
        self.assertTrue(config['use_symb_input_file'])

        # Disabled by default
        self.assertFalse(config['enable_pov_generation'])
        self.assertFalse(config['use_seeds'])
        self.assertFalse(config['use_recipes'])
        self.assertFalse(config['use_fault_injection'])
Exemple #3
0
    def test_myputs_dll_7sp1ent_x64_project_config(self):
        """Test x64 DLL project creation."""
        target = Target.from_file(MYPUTS_DLL_PATH)
        project = monkey_patch_project(target.initialize_project(),
                                       WINDOWS_7SP1_X64_IMAGE_DESC)
        options = {
            'target_args': ['MyPuts'],
        }

        config = project._configure(target, **options)

        # Assert that we have actually created a Windows project
        self.assertEqual(config['project_type'], 'windows')

        # Assert that the target is the one given
        self.assertEqual(config['target_path'], MYPUTS_DLL_PATH)
        self.assertEqual(config['target_arch'], 'x86_64')
        self.assertCountEqual(config['target_files'], [MYPUTS_DLL_PATH])
        self.assertListEqual(config['modules'], [(MYPUTS_DLL, False)])

        # Assert that the x86_64 Windows 7 image was selected
        self.assertDictEqual(config['image'], WINDOWS_7SP1_X64_IMAGE_DESC)

        # Assert that the DLL entry point is the one that we provided
        self.assertEqual(config['target_args'], ['MyPuts'])

        # Verify static analysis results
        self.assertCountEqual(config['dll_exports'], [b'MyPuts'])

        # Disabled by default
        self.assertFalse(config['processes'])
        self.assertFalse(config['use_seeds'])
Exemple #4
0
    def test_windows_x86_64_dll_target(self):
        """Test Windows x86_64 DLL target."""
        target_path = os.path.join(DATA_DIR, 'myputs.dll')
        target = Target.from_file(target_path)

        self.assertEqual(target.path, target_path)
        self.assertEqual(target.arch, 'x86_64')
        self.assertEqual(target.operating_system, 'windows')
        self.assertFalse(target.aux_files)
        self.assertIsInstance(target.initialize_project(), WindowsDLLProject)
        self.assertFalse(target.is_empty())
Exemple #5
0
    def test_linux_i386_target(self):
        """Test Linux i386 executable target."""
        target_path = os.path.join(DATA_DIR, 'cat')
        target = Target.from_file(target_path)

        self.assertEqual(target.path, target_path)
        self.assertEqual(target.arch, 'i386')
        self.assertEqual(target.operating_system, 'linux')
        self.assertFalse(target.aux_files)
        self.assertIsInstance(target.initialize_project(), LinuxProject)
        self.assertFalse(target.is_empty())
Exemple #6
0
    def test_cgc_target(self):
        """Test CGC executable target."""
        target_path = os.path.join(DATA_DIR, 'CADET_00001')
        target = Target.from_file(target_path)

        self.assertEqual(target.path, target_path)
        self.assertEqual(target.arch, 'i386')
        self.assertEqual(target.operating_system, 'decree')
        self.assertFalse(target.aux_files)
        self.assertIsInstance(target.initialize_project(), CGCProject)
        self.assertFalse(target.is_empty())
Exemple #7
0
    def _handle_test(self, test_root, test, test_config, img_templates):
        ts_dir = self.source_path('testsuite')

        if os.path.exists(os.path.join(test_root, 'Makefile')):
            _build_test(self._config, self.source_path('s2e'), test_root)

        blacklisted_images = set(test_config.get('blacklisted-images', []))
        target_images = set(test_config.get('target-images', []))

        for target_name in test_config['targets']:
            target_path = os.path.join(test_root, target_name)
            target = Target.from_file(target_path)
            project = target.initialize_project()
            images = project.get_usable_images(target, img_templates)

            for image_name in images:
                if image_name in blacklisted_images:
                    logger.warn(
                        '%s is blacklisted, skipping tests for that image',
                        image_name)
                    continue

                if target_images and image_name not in target_images:
                    logger.debug('%s is not in target-images, skipping',
                                 image_name)
                    continue

                options = {
                    'image':
                    image_name,
                    'name':
                    'testsuite_%s_%s_%s' %
                    (test, os.path.basename(target_name), image_name),
                    'target':
                    target,
                    'target_args':
                    test_config.get('target_arguments', []),
                    'force':
                    True
                }
                options.update(test_config.get('options', []))

                call_command(project, *[], **options)

                scripts = test_config.get('scripts', {})
                run_tests_template = scripts.get('run_tests', 'run-tests.tpl')
                self._generate_run_tests(ts_dir, test, run_tests_template,
                                         options)
                _call_post_project_gen_script(
                    test_root, test_config,
                    self.projects_path(options['name']))
Exemple #8
0
    def test_windows_x86_64_inf_target(self):
        """Test Windows x86_64 INF driver target."""
        target_path = os.path.join(DATA_DIR, 'scanner.inf')
        target = Target.from_file(target_path)

        self.assertEqual(target.path, target_path)
        self.assertEqual(target.arch, 'x86_64')
        self.assertEqual(target.operating_system, 'windows')
        self.assertItemsEqual(target.aux_files, [
            os.path.join(DATA_DIR, 'scanner.sys'),
            os.path.join(DATA_DIR, 'scanuser.exe')
        ])
        self.assertIsInstance(target.initialize_project(),
                              WindowsDriverProject)
        self.assertFalse(target.is_empty())
Exemple #9
0
    def test_cadet0001_project_config(self):
        """
        Test CGC project creation given a CGC binary and nothing else. No
        image, project name, etc. is provided.
        """
        target = Target.from_file(CADET_00001_PATH)
        project = monkey_patch_project(target.initialize_project(),
                                       CGC_IMAGE_DESC)

        config = project._configure(target)

        # Assert that we have actually created a CGC project
        self.assertEqual(config['project_type'], 'cgc')

        # Assert that the target is the one given (CADET_00001)
        self.assertEqual(config['target_path'], CADET_00001_PATH)
        self.assertEqual(config['target_arch'], 'i386')
        self.assertListEqual(config['target_files'], [CADET_00001_PATH])
        self.assertListEqual(config['processes'], [CADET_00001])
        self.assertListEqual(config['modules'], [(CADET_00001, False)])

        # Assert that the CGC image has been selected
        self.assertDictEqual(config['image'], CGC_IMAGE_DESC)

        # CGC binaries have no input files
        self.assertFalse(config['target_args'])
        self.assertFalse(config['sym_args'])
        self.assertFalse(config['use_symb_input_file'])
        self.assertFalse(config['warn_input_file'])
        self.assertFalse(config['warn_seeds'])

        # CGC projects should always have POV generation, seeds and recipes
        # enabled
        self.assertTrue(config['enable_pov_generation'])
        self.assertTrue(config['use_seeds'])
        self.assertTrue(config['use_recipes'])

        # CGC has its own test case generation system
        self.assertFalse(config['use_test_case_generator'])
Exemple #10
0
    def test_cat_x86_concrete_project_config(self):
        """
        Test Linux project creation given a x86 binary (``cat``) and nothing
        else. No image, project name, symbolic arguments, etc. are provided.
        """
        target = Target.from_file(CAT_X86_PATH)
        project = monkey_patch_project(target.initialize_project(),
                                       LINUX_IMAGE_DESC)

        config = project._configure(target)

        self._assert_cat_x86_common(config)

        # No target arguments specified
        self.assertFalse(config['target_args'])
        self.assertFalse(config['sym_args'])
        self.assertFalse(config['use_symb_input_file'])

        # Disabled by default
        self.assertFalse(config['enable_pov_generation'])
        self.assertFalse(config['use_seeds'])
        self.assertFalse(config['use_recipes'])
        self.assertFalse(config['use_fault_injection'])
Exemple #11
0
def _handle_with_file(target_path, proj_class, *args, **options):
    target = Target.from_file(target_path, proj_class)
    options['target'] = target

    return call_command(target.initialize_project(), *args, **options)