[PATCH 8/8] tests: check KVM ioctl commands decoding

Dmitry V. Levin ldv at altlinux.org
Fri Dec 1 07:25:09 UTC 2017


On Fri, Dec 01, 2017 at 02:45:58PM +0900, Masatake YAMATO wrote:
> * tests/Makefile.am: Add ioctl_kvm.
> * tests/ioctl_kvm.c: New test target file.
>   Taken from https://lwn.net/Articles/658512/.
> * tests/ioctl_kvm.expected: New expected file.
> * tests/ioctl_kvm.test: New test driver.
> ---
>  tests/Makefile.am        |   1 +
>  tests/ioctl_kvm.c        | 152 +++++++++++++++++++++++++++++++++++++++++++++++
>  tests/ioctl_kvm.expected |  11 ++++
>  tests/ioctl_kvm.test     |  12 ++++
>  4 files changed, 176 insertions(+)
>  create mode 100644 tests/ioctl_kvm.c
>  create mode 100644 tests/ioctl_kvm.expected
>  create mode 100755 tests/ioctl_kvm.test
> 
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index f2109fd4..6aa998e5 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -102,6 +102,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
>  	int_0x80 \
>  	ioctl_dm-v \
>  	ioctl_evdev-v \
> +	ioctl_kvm \
>  	ioctl_loop-nv \
>  	ioctl_loop-v \
>  	ioctl_nsfs \
> diff --git a/tests/ioctl_kvm.c b/tests/ioctl_kvm.c
> new file mode 100644
> index 00000000..95f4e589
> --- /dev/null
> +++ b/tests/ioctl_kvm.c
> @@ -0,0 +1,152 @@
> +/* Based on the program explained on the page, https://lwn.net/Articles/658512/ */
> +
> +/* Sample code for /dev/kvm API
> + *
> + * Copyright (c) 2015 Intel Corporation
> + * Author: Josh Triplett <josh at joshtriplett.org>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
> + * sell copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +#include <err.h>
> +#include <fcntl.h>
> +#include <linux/kvm.h>

Wouldn't the test just fail to compile when linux/kvm.h is not available?

> +#include <stdint.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/ioctl.h>
> +#include <sys/mman.h>
> +#include <sys/stat.h>
> +#include <sys/types.h>

The order of header inclusion is odd.  For example, it's no use to include
<sys/types.h> that late - it's been included several times at this point
by other headers.

> +
> +int main(void)
> +{
> +	int kvm, vmfd, vcpufd, ret;
> +	const uint8_t code[] = {
> +		0xba, 0xf8, 0x03, /* mov $0x3f8, %dx */
> +		0x00, 0xd8,       /* add %bl, %al */
> +		0x04, '0',        /* add $'0', %al */
> +		0xee,             /* out %al, (%dx) */
> +		0xb0, '\n',       /* mov $'\n', %al */
> +		0xee,             /* out %al, (%dx) */
> +		0xf4,             /* hlt */
> +	};
> +	uint8_t *mem;
> +	struct kvm_sregs sregs;
> +	size_t mmap_size;
> +	struct kvm_run *run;
> +
> +	kvm = open("/dev/kvm", O_RDWR | O_CLOEXEC);
> +	if (kvm == -1)
> +		err(1, "/dev/kvm");

Wouldn't the test just fail when /dev/kvm is missing or not accessible?


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20171201/15576b75/attachment.bin>


More information about the Strace-devel mailing list