[PATCH v1] Testing HDIO_GETGEO Output Mismatch Error

Bran S archsbran at gmail.com
Fri Mar 27 11:34:35 UTC 2020


>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


More information about the Strace-devel mailing list