Пример #1
0
 def test_from_args(self):
     host = MockHost()
     parser = ArgParser('description')
     parser.require_name(False)
     # netaddr should get called with 'just-four-random-words', and fail
     with self.assertRaises(RuntimeError):
         args = parser.parse_args(['--device', 'just-four-random-words'])
         device = Device.from_args(host, args)
Пример #2
0
    def test_parse_args_missing_value(self):
        parser = ArgParser('test_parse_args_missing_value')
        parser.require_name(False)

        with self.assertRaises(SystemExit):
            parser.parse_args(['--device'])

        with self.assertRaises(SystemExit):
            parser.parse_args(['--output'])

        with self.assertRaises(SystemExit):
            parser.parse_args(['--staging'])
Пример #3
0
    def test_parse_args_unrecognized(self):
        parser = ArgParser('test_parse_args_unrecognized')
        parser.require_name(False)

        with self.assertRaises(SystemExit):
            parser.parse_args(['--unknown'])

        with self.assertRaises(SystemExit):
            parser.parse_args(['-help=1'])

        parser.require_name(True)
        parser.allow_label(True)
        with self.assertRaises(SystemExit):
            parser.parse_args(['one', 'two', 'three'])
Пример #4
0
    def test_parse_args_label(self):
        parser = ArgParser('test_parse_args_label')

        # Error if label present when not allowed.
        with self.assertRaises(SystemExit):
            parser.parse_args(['name', 'label'])

        # label not allowed if name is optional.
        parser.require_name(False)
        with self.assertRaises(AssertionError):
            parser.allow_label(True)

        parser.require_name(True)
        parser.allow_label(True)
        args = parser.parse_args(['name', 'label'])
        self.assertArgsEqual(args, name='name', label='label')
Пример #5
0
def main():
    parser = ArgParser(
        'Lists fuzzers matching NAME if provided, or all fuzzers.')
    parser.require_name(False)
    args = parser.parse_args()

    host = Host.from_build()

    fuzzers = Fuzzer.filter(host.fuzzers, args.name)
    if len(fuzzers) == 0:
        print('No matching fuzzers.')
        return 1
    print('Found %d matching fuzzers:' % len(fuzzers))
    for fuzzer in fuzzers:
        print('  %s/%s' % fuzzer)
    return 0
Пример #6
0
    def test_parse_args_name(self):
        parser = ArgParser('test_parse_args_name')

        # By default, 'name' is required
        parser.require_name(True)
        with self.assertRaises(SystemExit):
            parser.parse_args([])

        args = parser.parse_args(['name'])
        self.assertArgsEqual(args, name='name')

        # 'name' can be made optional.
        parser.require_name(False)
        args = parser.parse_args([])
        self.assertArgsEqual(args)

        args = parser.parse_args(['name'])
        self.assertArgsEqual(args, name='name')
Пример #7
0
def main():
    parser = ArgParser(
        'Reports status for the fuzzer matching NAME if ' +
        'provided, or for all running fuzzers.  Status includes execution ' +
        'state, corpus size, and number of artifacts.')
    parser.require_name(False)
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzers = Fuzzer.filter(host.fuzzers, args.name)

    pids = device.getpids()
    silent = True
    for pkg, tgt in fuzzers:
        fuzzer = Fuzzer(device, pkg, tgt)
        if not args.name and tgt not in pids:
            continue
        silent = False
        if tgt in pids:
            print(str(fuzzer) + ': RUNNING')
        else:
            print(str(fuzzer) + ': STOPPED')
        print('    Output path:  ' + fuzzer.data_path())
        print('    Corpus size:  %d inputs / %d bytes' %
              fuzzer.measure_corpus())
        artifacts = fuzzer.list_artifacts()
        if len(artifacts) == 0:
            print('    Artifacts:    None')
        else:
            print('    Artifacts:    ' + artifacts[0])
            for artifact in artifacts[1:]:
                print('                  ' + artifact)
    if silent:
        print('No fuzzers are running.  Include \'name\' to check specific ' +
              'fuzzers.')
        return 1
    return 0