Skip to contentSkip to conversation

Add common.h utilities for aiodio tests

PATCH Superseded Andrea Cervesato via ltp 2 participants 2 messages Nov 30, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add common.h utilities for aiodio tests

---
 testcases/kernel/io/ltp-aiodio/common.h | 55 +++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 testcases/kernel/io/ltp-aiodio/common.h
testcases/kernel/io/ltp-aiodio/common.h new file +55 -0
new file mode 100644
index 000000000..230d9d392
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Common utilities for aiodio tests.
+ */
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+static 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 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);
+}
Signature · 5 lines
2.34.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

testcases/kernel/io/ltp-aiodio/common.h line 10

Quoted 10 lines
testcases/kernel/io/ltp-aiodio/common.h new file +10 -0
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Common utilities for aiodio tests.
+ */

There is no point in using the docparse comments in headers, these are only parsed in tests.

Also the header should include guards here:

#ifndef AIODIO_COMMON_H__
#define AIODIO_COMMON_H__

Quoted 34 lines
testcases/kernel/io/ltp-aiodio/common.h new file +34 -0
+#include <stdlib.h>
+#include "tst_test.h"
+
+static 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 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);

testcases/kernel/io/ltp-aiodio/common.h line 55

Quoted 10 lines
testcases/kernel/io/ltp-aiodio/common.h new file +10 -0
+	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);
+}

And the guards should end here with:

#endif /* AIODIO_COMMON_H__ */

Signature · 5 lines
Cyril Hrubis
[email protected]

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