public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] Add common.h utilities for aiodio tests
Date: Tue, 30 Nov 2021 13:10:21 +0100	[thread overview]
Message-ID: <20211130121022.14296-2-andrea.cervesato@suse.com> (raw)
In-Reply-To: <20211130121022.14296-1-andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/io/ltp-aiodio/common.h | 54 +++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 testcases/kernel/io/ltp-aiodio/common.h

diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
new file mode 100644
index 000000000..fefeed2cf
--- /dev/null
+++ b/testcases/kernel/io/ltp-aiodio/common.h
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef AIODIO_COMMON_H__
+#define AIODIO_COMMON_H__
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+static inline char *check_zero(char *buf, int size)
+{
+	char *p;
+
+	p = buf;
+
+	while (size > 0) {
+		if (*buf != 0) {
+			tst_res(TINFO,
+				"non zero buffer at buf[%lu] => 0x%02x,%02x,%02x,%02x",
+				buf - p, (unsigned int)buf[0],
+				size > 1 ? (unsigned int)buf[1] : 0,
+				size > 2 ? (unsigned int)buf[2] : 0,
+				size > 3 ? (unsigned int)buf[3] : 0);
+			tst_res(TINFO, "buf %p, p %p", buf, p);
+			return buf;
+		}
+		buf++;
+		size--;
+	}
+
+	return 0;
+}
+
+static inline void io_append(const char *path, char pattern, int flags, size_t bs, size_t bcount)
+{
+	int fd;
+	size_t i;
+	char *bufptr;
+
+	bufptr = SAFE_MEMALIGN(getpagesize(), bs);
+	memset(bufptr, pattern, bs);
+
+	fd = SAFE_OPEN(path, flags, 0666);
+
+	for (i = 0; i < bcount; i++)
+		SAFE_WRITE(1, fd, bufptr, bs);
+
+	free(bufptr);
+	SAFE_CLOSE(fd);
+}
+
+#endif /* AIODIO_COMMON_H__ */
-- 
2.34.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2021-11-30 12:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 12:10 [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Andrea Cervesato via ltp
2021-11-30 12:10 ` Andrea Cervesato via ltp [this message]
2021-11-30 12:10 ` [LTP] [PATCH 2/2] Use common.h in dio_truncate test Andrea Cervesato via ltp
2021-11-30 14:48 ` [LTP] [PATCH 0/2] Create common.h utilities for aiodio testsuite Cyril Hrubis

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=20211130121022.14296-2-andrea.cervesato@suse.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.com \
    /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