From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/2] ioctl_sg01: Print buffer contents on failure
Date: Wed, 22 Oct 2025 11:57:38 +0200 [thread overview]
Message-ID: <20251022095740.8747-2-mdoucha@suse.cz> (raw)
In-Reply-To: <20251022095740.8747-1-mdoucha@suse.cz>
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
This patch is a convenience feature. Feel free to reject it.
testcases/kernel/syscalls/ioctl/ioctl_sg01.c | 24 +++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_sg01.c b/testcases/kernel/syscalls/ioctl/ioctl_sg01.c
index 66ff980ce..dada174e0 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_sg01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_sg01.c
@@ -36,7 +36,7 @@
#define CMD_SIZE 6
static int devfd = -1;
-static char buffer[BUF_SIZE];
+static char buffer[BUF_SIZE + 1];
static unsigned char command[CMD_SIZE];
static struct sg_io_hdr query;
@@ -100,6 +100,25 @@ static const char *find_generic_scsi_device(int access_flags, int skip_usb)
return NULL;
}
+static void dump_hex(const char *str, size_t size)
+{
+ size_t i;
+
+ for (; size && !str[size - 1]; size--)
+ ;
+
+ for (i = 0; i < size; i++) {
+ if (i && (i % 32) == 0)
+ printf("\n");
+ else if (i && (i % 4) == 0)
+ printf(" ");
+
+ printf("%02x", (unsigned int)str[i]);
+ }
+
+ printf("\n");
+}
+
static void setup(void)
{
const char *devpath = find_generic_scsi_device(O_RDONLY, 1);
@@ -135,6 +154,7 @@ static void run(void)
for (i = 0; i < 100; i++) {
TEST(ioctl(devfd, SG_IO, &query));
+ buffer[BUF_SIZE] = '\0';
if (TST_RET != 0 && TST_RET != -1)
tst_brk(TBROK|TTERRNO, "Invalid ioctl() return value");
@@ -143,6 +163,8 @@ static void run(void)
for (j = 0; j < BUF_SIZE; j++) {
if (buffer[j]) {
tst_res(TFAIL, "Kernel memory leaked");
+ tst_res(TINFO, "Buffer contents: %s", buffer);
+ dump_hex(buffer, BUF_SIZE);
return;
}
}
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-10-22 9:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-22 9:57 [LTP] [PATCH 1/2] ioctl_sg01: Skip USB devices Martin Doucha
2025-10-22 9:57 ` Martin Doucha [this message]
2025-10-22 13:31 ` [LTP] [PATCH 2/2] ioctl_sg01: Print buffer contents on failure Petr Vorel
2025-10-24 8:57 ` Petr Vorel
2025-10-29 9:54 ` Cyril Hrubis
2025-11-03 12:49 ` Martin Doucha
2025-11-03 14:58 ` Cyril Hrubis
2025-10-22 13:13 ` [LTP] [PATCH 1/2] ioctl_sg01: Skip USB devices Petr Vorel
2025-10-22 13:37 ` Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251022095740.8747-2-mdoucha@suse.cz \
--to=mdoucha@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox