def test_e2e(self): # Set up hermetic environment. host = Host() host.fd_out = self._stdout host.fd_err = self._stderr with host.temp_dir() as temp_dir: # (Re-)parse the command line arguments, a la main.py. factory = Factory(host=host) parser = factory.parser args = parser.parse_args() # Ensure exactly 1 fuzzer is selected. fuzzer = factory.create_fuzzer(args) self.assertNoErrors() args.name = str(fuzzer) list_args = parser.parse_args(['list', args.name]) list_args.command(list_args, factory) self.assertOut( ['Found 1 matching fuzzer for "{}":'.format(str(fuzzer))], n=1) self.assertNoErrors() start_args = parser.parse_args( ['start', '-o', temp_dir.pathname, args.name]) proc = command.start_fuzzer(start_args, factory) self.assertNoErrors() stop_args = parser.parse_args(['stop', args.name]) command.stop_fuzzer(stop_args, factory) self.assertNoErrors() if proc: proc.wait() check_args = parser.parse_args(['check', args.name]) command.check_fuzzer(check_args, factory) self.assertOut(['{}: STOPPED'.format(args.name)], n=1) self.assertNoErrors() unit = os.path.join(temp_dir.pathname, 'unit') with open(unit, 'w') as opened: opened.write('hello world') repro_args = parser.parse_args(['repro', args.name, unit]) command.repro_units(repro_args, factory) self.assertNoErrors() analyze_args = ['analyze', '-max_total_time=10', args.name] if args.local: analyze_args.append('--local') analyze_args = parser.parse_args(analyze_args) command.analyze_fuzzer(analyze_args, factory) self.assertNoErrors()
def test_single_fuzzer(self): # (Re-)parse the command line arguments, a la main.py. args = self.parser.parse_args() # Ensure exactly 1 fuzzer is selected. fuzzer = self.factory.create_fuzzer(args) self.assertNoErrors() args.name = str(fuzzer) list_args = self.parser.parse_args(['list', args.name]) list_args.command(list_args, self.factory) self.assertOut( ['Found 1 matching fuzzer for "{}":'.format(str(fuzzer))], n=1) self.assertNoErrors() start_args = self.parser.parse_args( ['start', '-o', self.temp_dir, args.name]) proc = command.start_fuzzer(start_args, self.factory) self.assertNoErrors() stop_args = self.parser.parse_args(['stop', args.name]) command.stop_fuzzer(stop_args, self.factory) self.assertNoErrors() if proc: proc.wait() check_args = self.parser.parse_args(['check', args.name]) command.check_fuzzer(check_args, self.factory) self.assertOut(['{}: STOPPED'.format(args.name)], n=1) self.assertNoErrors() unit = os.path.join(self.temp_dir, 'unit') with open(unit, 'w') as opened: opened.write('hello world') repro_args = self.parser.parse_args(['repro', args.name, unit]) command.repro_units(repro_args, self.factory) self.assertNoErrors() analyze_args = ['analyze', '-max_total_time=10', args.name] if args.local: analyze_args.append('--local') analyze_args = self.parser.parse_args(analyze_args) command.analyze_fuzzer(analyze_args, self.factory) self.assertNoErrors()
def test_start_fuzzer(self): name = str(self.fuzzer) # In the foreground output = 'output' self.host.mkdir(output) args = self.parse_args('start', '-f', '-o', output, name) command.start_fuzzer(args, self.factory) self.assertLogged( 'Starting {}.'.format(self.fuzzer), 'Outputs will be written to: {}'.format(output), ) # In the background args = self.parse_args('start', '-o', output, name) command.start_fuzzer(args, self.factory) self.assertLogged( 'Starting {}.'.format(self.fuzzer), 'Outputs will be written to: {}'.format(output), 'Check status with "fx fuzz check {}".'.format(self.fuzzer), 'Stop manually with "fx fuzz stop {}".'.format(self.fuzzer), ) cmd = [ 'python', sys.argv[0], 'start', '--monitor', '--output', output, name, ] self.assertRan(*cmd) args = self.parse_args('start', '-m', '-o', output, name) command.start_fuzzer(args, self.factory) self.assertLogged( '{} has stopped.'.format(self.fuzzer), 'Output written to: {}.'.format(output), )