[PATCH v1] Testing HDIO_GETGEO Output Mismatch Error

Bran S archsbran at gmail.com
Fri Mar 27 11:40:22 UTC 2020


On Fri, 27 Mar 2020 at 17:04, Bran S <archsbran at gmail.com> wrote:
>
> From 1f942268d428be68d276876b11623820acf1a66c Mon Sep 17 00:00:00 2001
> From: archsbran <archsbran at gmail.com>
> Date: Fri, 27 Mar 2020 17:02:46 +0530
> Subject: [PATCH v1] Testing HDIO_GETGEO Output Mismatch Error
>
> ---
>  tests/Makefile.am              |  2 ++
>  tests/gen_tests.in             |  1 +
>  tests/hdio_getgeo-success.c    | 52 ++++++++++++++++++++++++++++++++++
>  tests/hdio_getgeo-success.test | 20 +++++++++++++
>  4 files changed, 75 insertions(+)
>  create mode 100644 tests/hdio_getgeo-success.c
>  create mode 100755 tests/hdio_getgeo-success.test
>
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index f2a5bc6d..77826f3a 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -114,6 +114,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
>      getpid    \
>      getppid    \
>      gettid \
> +    hdio_getgeo-success \
>      inject-nf \
>      int_0x80 \
>      ioctl_dm-v \
> @@ -280,6 +281,7 @@ DECODER_TESTS = \
>      fadvise64.test \
>      futex.test \
>      getuid.test \
> +    hdio_getgeo-success.test \
>      int_0x80.test \
>      inotify_init-y.test \
>      ioctl.test \
> diff --git a/tests/gen_tests.in b/tests/gen_tests.in
> index ae090d6d..a49ebcba 100644
> --- a/tests/gen_tests.in
> +++ b/tests/gen_tests.in
> @@ -148,6 +148,7 @@ getuid32    +getuid.test
>  getuid32-creds    +getuid.test
>  getxxid    -a10 -e trace=getxpid,getxuid,getxgid
>  group_req    -e trace=setsockopt
> +hdio_getgeo-success +ioctl.test
>  inet-cmsg    -e trace=recvmsg
>  init_module    -a27
>  inotify    -a23 -e trace=inotify_add_watch,inotify_rm_watch
> diff --git a/tests/hdio_getgeo-success.c b/tests/hdio_getgeo-success.c
> new file mode 100644
> index 00000000..35e4a3cb
> --- /dev/null
> +++ b/tests/hdio_getgeo-success.c
> @@ -0,0 +1,52 @@
> +/*
> + * Check HDIO_GETGEO ioctl syscall.
> + *
> + * Copyright (c) 2020 The strace developers.
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "tests.h"
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/ioctl.h>
> +#include <linux/hdreg.h>
> +
> +int
> +main(int argc, char **argv)
> +{
> +    long inject_retval;
> +    long ret;
> +    struct hd_geometry geom;
> +
> +    if (argc == 1)
> +        return 0;
> +
> +    if (argc < 3)
> +        error_msg_and_fail("Usage: %s NUM_SKIP INJECT_RETVAL", argv[0]);
> +
> +    inject_retval = strtol(argv[2], NULL, 0);
> +
> +    if (inject_retval < 0)
> +        error_msg_and_fail("Expected non-negative INJECT_RETVAL, "
> +                   "but got %ld", inject_retval);
> +
> +    ret = ioctl(-1, HDIO_GETGEO, NULL);
> +    // ioctl(-1, HDIO_GETGEO, NULL);
> +    printf("ioctl(-1, HDIO_GETGEO, NULL) = %s%s\n",
> +            sprintrc(ret),
> +            ret == inject_retval ? " (INJECTED)" : "");
> +
> +    ret = ioctl(-1, HDIO_GETGEO, &geom);
> +    // ioctl(-1, HDIO_GETGEO, &geom);
> +    printf("ioctl(-1, HDIO_GETGEO, %p) = %s%s\n",
> +            &geom,
> +            sprintrc(ret),
> +            ret == inject_retval ? " (INJECTED)" : "");
> +
> +    puts("+++ exited with 0 +++");
> +    return 0;
> +}
> diff --git a/tests/hdio_getgeo-success.test b/tests/hdio_getgeo-success.test
> new file mode 100755
> index 00000000..034c48b0
> --- /dev/null
> +++ b/tests/hdio_getgeo-success.test
> @@ -0,0 +1,20 @@
> +#!/bin/sh -efu
> +#
> +# Check decoding of successful HDIO_GETGEO ioctl.
> +#
> +# Copyright (c) 2020 The strace developers.
> +# All rights reserved.
> +#
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +. "${srcdir=.}/scno_tampering.sh"
> +
> +: ${IOCTL_INJECT_START=1}
> +: ${IOCTL_INJECT_RETVAL=42}
> +
> +run_prog
> +run_strace -a35 -e trace=ioctl \
> +    -e inject=ioctl:retval="${IOCTL_INJECT_RETVAL}":when="${IOCTL_INJECT_START}+"
> \
> +    ../hdio_getgeo-success "${IOCTL_INJECT_START}"
> "${IOCTL_INJECT_RETVAL}" > "$EXP"
> +grep -v '^ioctl([012][,<]' < "$LOG" > "$OUT"
> +match_diff "$OUT" "$EXP"
> --
> 2.20.1

I have tried to implement the test using the success injection
technique as suggested. But I am facing an output mismatch error.
Below are the relevant file contents which might better represent the problem.

----
$ cat tests/hdio_getgeo-success.log

--- exp    2020-03-27 16:59:53.422799968 +0530
+++ out    2020-03-27 16:59:53.428799965 +0530
@@ -1,3 +1,3 @@
-ioctl(-1, HDIO_GETGEO, NULL) = 42 (INJECTED)
-ioctl(-1, HDIO_GETGEO, 0x7ffdc9699010) = 42 (INJECTED)
+ioctl(-1, HDIO_GETGEO, NULL)       = 42 (INJECTED)
+ioctl(-1, HDIO_GETGEO, {heads=192, sectors=174, cylinders=635,
start=0}) = 42 (INJECTED)
 +++ exited with 0 +++
hdio_getgeo-success.test: failed test: ../../strace -a35 -e
trace=ioctl -e inject=ioctl:retval=42:when=1+ ../hdio_getgeo-success 1
42 output mismatch
FAIL hdio_getgeo-success.test (exit status: 1)
----

----
$ cat tests/hdio_getgeo-success.dir/exp
ioctl(-1, HDIO_GETGEO, NULL) = 42 (INJECTED)
ioctl(-1, HDIO_GETGEO, 0x7ffdc9699010) = 42 (INJECTED)
+++ exited with 0 +++
----

----
$ cat tests/hdio_getgeo-success.dir/log
ioctl(-1, HDIO_GETGEO, NULL)       = 42 (INJECTED)
ioctl(-1, HDIO_GETGEO, {heads=192, sectors=174, cylinders=635,
start=0}) = 42 (INJECTED)
+++ exited with 0 +++
----

----
$ cat tests/hdio_getgeo-success.dir/out
ioctl(-1, HDIO_GETGEO, NULL)       = 42 (INJECTED)
ioctl(-1, HDIO_GETGEO, {heads=192, sectors=174, cylinders=635,
start=0}) = 42 (INJECTED)
+++ exited with 0 +++
----

The output that is written into `tests/hdio_getgeo-success.dir/out` is
what we want right ?
How can I correct the expected output in `tests/hdio_getgeo-success.dir/out` ?
Please let me know what I am doing wrong.

Thanks


More information about the Strace-devel mailing list