def test_scanner_driver_7sp1ent_x64_project_config(self): """Test x64 driver project creation.""" target, cls = target_from_file(SCANNER_INF_PATH) project = monkey_patch_project(cls(), 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.assertCountEqual(config['target'].files, [SCANNER_INF_PATH, SCANNER_SYS_PATH, SCANNER_USER_EXE_PATH]) self.assertCountEqual(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'])
def test_myputs_dll_7sp1ent_x64_project_config(self): """Test x64 DLL project creation.""" target, cls = target_from_file(MYPUTS_DLL_PATH) target.args = ['MyPuts'] project = monkey_patch_project(cls(), WINDOWS_7SP1_X64_IMAGE_DESC) config = project._configure(target) # 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.get_resolved_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'])
def test_cat_x86_symbolic_project_config(self): """ Test Linux project creation given a x86 binary (``cat``) and a symbolic file argument. """ target, cls = target_from_file(CAT_X86_PATH) target.args = ['-T', '@@'] project = monkey_patch_project(cls(), LINUX_IMAGE_DESC) config = project._configure(target) self._assert_cat_x86_common(config) # Verify symbolic arguments self.assertListEqual(config['target'].args.raw_args, ['-T', 'input-0']) self.assertListEqual(config['target'].args.get_resolved_args(''), ['-T', 'input-0']) self.assertFalse(config['sym_args']) self.assertTrue(config['target'].args.symbolic_files) # 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'])
def test_windows_x86_64_sys_target(self): """Test Windows x86_64 SYS driver target.""" target_path = os.path.join(DATA_DIR, 'scanner.sys') target, cls = 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(cls(), WindowsDriverProject) self.assertFalse(target.is_empty())
def test_windows_x86_64_dll_target(self): """Test Windows x86_64 DLL target.""" target_path = os.path.join(DATA_DIR, 'myputs.dll') target, cls = 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(cls(), WindowsDLLProject) self.assertFalse(target.is_empty())
def test_linux_i386_target(self): """Test Linux i386 executable target.""" target_path = os.path.join(DATA_DIR, 'cat') target, cls = 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(cls(), LinuxProject) self.assertFalse(target.is_empty())
def test_cgc_target(self): """Test CGC executable target.""" target_path = os.path.join(DATA_DIR, 'CADET_00001') target, cls = 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(cls(), CGCProject) self.assertFalse(target.is_empty())
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, cls = target_from_file(CAT_X86_PATH) project = monkey_patch_project(cls(), LINUX_IMAGE_DESC) config = project._configure(target) self._assert_cat_x86_common(config) # No target arguments specified self.assertFalse(config['target'].args.get_resolved_args('')) self.assertFalse(config['target'].args.symbolic_files) self.assertFalse(config['sym_args']) # 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'])
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, cls = target_from_file(CADET_00001_PATH) project = monkey_patch_project(cls(), 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.raw_args) self.assertFalse(config['target'].args.symbolic_files) self.assertFalse(config['sym_args']) 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'])
def _handle_test(self, test_root, test, test_config): ts_dir = self.source_path('s2e', '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', [])) target_images = self._get_translated_images(target_images) # We have a list of target images, use it without guessing from the binary if target_images and _need_target_path_resolution(test_config): for image_name in target_images: if image_name in blacklisted_images: logger.warning( '%s is blacklisted, skipping tests for that image', image_name) continue guestfs_dirs = self._select_guestfs(image_name) for target_name in test_config['targets']: try: target_path = _resolve_target_path( test_root, target_name, guestfs_dirs) except CommandError as e: logger.warning(e) continue arg_batches = _parse_target_arguments( test_root, test_config) for arg_idx, arg_batch in enumerate(arg_batches): target, proj_class = target_from_file(target_path) target.args = arg_batch project = proj_class() self._gen_project(ts_dir, test_config, test_root, test, target, target_path, image_name, project, arg_idx) else: for target_name in test_config['targets']: target_path = _resolve_target_path(test_root, target_name, []) arg_batches = _parse_target_arguments(test_root, test_config) for arg_idx, args in enumerate(arg_batches): target, proj_class = target_from_file(target_path) target.args = args project = proj_class() images = project.get_usable_images(target, self._img_templates) logger.info(images) for image_name in images: if image_name in blacklisted_images: logger.warning( '%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 self._gen_project(ts_dir, test_config, test_root, test, target, target_path, image_name, project, arg_idx)