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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]