qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Maria Kustova <maxa@catit.be>
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
	Maria Kustova <maria.k@catit.be>
Subject: Re: [Qemu-devel] [PATCH V3 2/5] runner: Tool for fuzz tests execution
Date: Fri, 18 Jul 2014 09:44:04 +0100	[thread overview]
Message-ID: <20140718084404.GC2685@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <f0621dfeacd5ebea6fa69fa00a105df87e06867e.1405538416.git.maria.k@catit.be>

[-- Attachment #1: Type: text/plain, Size: 3914 bytes --]

On Wed, Jul 16, 2014 at 11:49:36PM +0400, Maria Kustova wrote:
> +    def __init__(self, test_id, seed, work_dir, run_log,
> +                 cleanup=True, log_all=False):
> +        """Set test environment in a specified work directory.
> +
> +        Path to qemu-img and qemu-io will be retrieved from 'QEMU_IMG' and
> +        'QEMU_IO' environment variables
> +        """
> +        if seed is not None:
> +            self.seed = seed
> +        else:
> +            self.seed = str(hash(random.randint(0, sys.maxint)))

What is the purpose of hash()?  hash(<int>) == <int>.

> +    def finish(self):
> +        """ Restore environment after a test execution. Remove folders of
> +        passed tests
> +        """
> +        self.log.close()
> +        self.parent_log.close()
> +        os.chdir(self.init_path)
> +        if (False not in self.result) and self.cleanup:
> +            rmtree(self.current_dir)

self.result could simply be a bool:

self.failed = False
...
if self.cleanup and not self.failed:
    rmtree(self.current_dir)

The array seems unnecessary

> +
> +if __name__ == '__main__':
> +
> +    def usage():
> +        print """
> +        Usage: runner.py [OPTION...] TEST_DIR IMG_GENERATOR
> +
> +        Set up test environment in TEST_DIR and run a test in it. A module for
> +        test image generation should be specified via IMG_GENERATOR.
> +        Example:
> +        runner.py -c '[["qemu-img", "info", "$test_img"]]' /tmp/test ../qcow2
> +
> +        Optional arguments:
> +          -h, --help                    display this help and exit
> +          -c, --command=JSON            run tests for all commands specified in
> +                                        the JSON object
> +          -s, --seed=STRING             seed for a test image generation,
> +                                        by default will be generated randomly
> +          --config=JSON                 take fuzzer configuration from the JSON
> +                                        object
> +          -k, --keep_passed             don't remove folders of passed tests
> +          -v, --verbose                 log information about passed tests
> +
> +        JSON objects:
> +
> +        '--command' accepts a JSON object containing a list of commands.
> +        Each command presents an application under test with all its paramaters
> +        as a list of strings, e.g.
> +          ["qemu-io", "$test_img", "-c", "write $off $len"]

[] is not a JSON object.  {} is a JSON object.

Does this mean --command takes a JSON array of commands to invoke, where
each command is a JSON array of argument strings?

> +
> +        Supported application aliases: 'qemu-img' and 'qemu-io'.
> +        Supported argument aliases: $test_img for the fuzzed image, $off
> +        for an offset, $len for length.
> +
> +        Values for $off and $len will be generated based on the virtual disk
> +        size of the fuzzed image
> +        Paths to 'qemu-img' and 'qemu-io' are retrevied from 'QEMU_IMG' and
> +        'QEMU_IO' environment variables
> +
> +        '--config' accepts a JSON object containing a list of fields to be
> +        fuzzed, e.g.
> +          [["header"], ["header", "version"]]

Same thing about JSON "object" terminology.

> +    try:
> +        opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kv',
> +                                       ['command=', 'help', 'seed=', 'config=',
> +                                        'keep_passed', 'verbose'])
> +    except getopt.error:
> +        e = sys.exc_info()[1]

How about the more common except syntax:
except getopt.error, e:

It eliminates sys.exc_info()[1].  The same applies to the other
instances in this file.

> +    if not len(args) == 2:
> +        print "Missed parameter\nTry 'runner.py --help' " \

s/Missed parameter/Expected two parameters/

(More than 2 parameters could have been given.)

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2014-07-18  8:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 19:49 [Qemu-devel] [PATCH V3 0/5] tests: Add the image fuzzer with qcow2 support Maria Kustova
2014-07-16 19:49 ` [Qemu-devel] [PATCH V3 1/5] docs: Specification for the image fuzzer Maria Kustova
2014-07-16 19:49 ` [Qemu-devel] [PATCH V3 2/5] runner: Tool for fuzz tests execution Maria Kustova
2014-07-18  8:44   ` Stefan Hajnoczi [this message]
2014-07-16 19:49 ` [Qemu-devel] [PATCH V3 3/5] fuzz: Fuzzing functions for qcow2 images Maria Kustova
2014-07-18  9:26   ` Stefan Hajnoczi
2014-07-16 19:49 ` [Qemu-devel] [PATCH V3 4/5] layout: Generator of fuzzed " Maria Kustova
2014-07-18 12:11   ` Stefan Hajnoczi
2014-07-16 19:49 ` [Qemu-devel] [PATCH V3 5/5] package: Public API for image-fuzzer/runner/runner.py Maria Kustova

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140718084404.GC2685@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=maria.k@catit.be \
    --cc=maxa@catit.be \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).