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 3/5] fuzz: Fuzzing functions for qcow2 images
Date: Fri, 18 Jul 2014 10:26:56 +0100 [thread overview]
Message-ID: <20140718092656.GD2685@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <040a32f2f5ebb18bcdfbcb3e6336ae912467370b.1405538416.git.maria.k@catit.be>
[-- Attachment #1: Type: text/plain, Size: 1601 bytes --]
On Wed, Jul 16, 2014 at 11:49:37PM +0400, Maria Kustova wrote:
> +def string_validator(current, strings):
> + """Return a random string value from the list not equal to the current.
> +
> + This function is useful for selection from valid values except current one.
> + """
> + val = random.choice(strings)
> + if val == current:
> + return string_validator(current, strings)
> + else:
> + return val
There is a pattern to these validator functions:
def validator(current, pick, choices):
while True:
val = pick(choices)
if val != current:
return val
int_validator is validator(_, random_from_intervals, _)
bit_validator is validator(_, random_bits, _)
string_validator is validator(_, random.choice, _)
The code duplication in int_validator, bit_validator, and
string_validator can be eliminated.
> +
> +
> +def selector(current, constraints, fmt=None):
> + """Select one value from all defined by constraints
> +
> + Each constraint produces one random value satisfying to it. The function
> + randomly selects one value satisfying at least one constraint (depending on
> + constraints overlaps).
> + """
> + validate = {
> + 'bitmask': bit_validator,
> + 'string': string_validator
> + }.get(fmt, int_validator)
Is the indirection through a string necessary?
def selector(current, constraints, fmt=int_validator):
Callers can pass bit_validator or string_validator if they want. It
makes the code a little simpler and it stays readable since
string_validator's name tells you what it does.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2014-07-18 9:27 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
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 [this message]
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=20140718092656.GD2685@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).