[libvirt] [PATCH 3/4] virnetdevbandwidthtest: Introduce mocking

Eric Blake eblake at redhat.com
Fri Jan 24 22:02:25 UTC 2014


On 01/23/2014 06:44 AM, Michal Privoznik wrote:
> The mocking will be used in later commits to mock all calls to the
> virCommandRun(). This is easier to do than cutting off the command
> creation and run into two separate pieces.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  tests/Makefile.am              |   9 ++++
>  tests/virnetdevbandwidthmock.c | 106 +++++++++++++++++++++++++++++++++++++++++
>  tests/virnetdevbandwidthtest.c |  21 +++++++-
>  3 files changed, 135 insertions(+), 1 deletion(-)
>  create mode 100644 tests/virnetdevbandwidthmock.c

> +
> +    if ((fd = open(outfile, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR)) == -1) {
> +        STDERR("unable to open file: %s %d", outfile, errno);
> +        goto cleanup;
> +    }
> +
> +    if (safewrite(fd, buf, strlen(buf)) < 0 ||
> +        safewrite(fd, "\n", 1) < 0) {
> +        STDERR("unable to write to file: %s %d", outfile, errno);
> +        goto cleanup;
> +    }

This could be simplified with virFileWriteStr().

> +
> +    if (VIR_STRDUP_QUIET(outfile, OUTFILETEMPLATE) < 0) {
> +        fprintf(stderr, "Out of memory\n");
> +        abort();
> +    }
> +
> +    if (!mktemp(outfile)) {

I'd prefer mkstemp(), for safety.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140124/02ce45c0/attachment-0001.sig>


More information about the libvir-list mailing list