public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] API/cgroup: Add safe_cgroup_lines_scanf
@ 2021-12-20 13:10 Richard Palethorpe via ltp
  2021-12-20 13:10 ` [LTP] [PATCH 2/3] API/cgroup: Add memory.stat Richard Palethorpe via ltp
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Richard Palethorpe via ltp @ 2021-12-20 13:10 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

Similar to file_lines_scanf. Allows us to read a particular key-value
pair from a controller file. Can replace kselftest's cg_read_key_*
when converting tests.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 include/tst_cgroup.h | 12 +++++++++++-
 lib/tst_cgroup.c     | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
index 632050e86..561216296 100644
--- a/include/tst_cgroup.h
+++ b/include/tst_cgroup.h
@@ -188,9 +188,19 @@ void safe_cgroup_printf(const char *const file, const int lineno,
 void safe_cgroup_scanf(const char *file, const int lineno,
 		       const struct tst_cgroup_group *const cg,
 		       const char *const file_name,
-		       const char *fmt, ...)
+		       const char *const fmt, ...)
 		       __attribute__ ((format (scanf, 5, 6), nonnull));
 
+#define SAFE_CGROUP_LINES_SCANF(cg, file_name, fmt, ...)		\
+	safe_cgroup_lines_scanf(__FILE__, __LINE__,			\
+				(cg), (file_name), (fmt), __VA_ARGS__)
+
+void safe_cgroup_lines_scanf(const char *const file, const int lineno,
+			     const struct tst_cgroup_group *const cg,
+			     const char *const file_name,
+			     const char *const fmt, ...)
+			__attribute__ ((format (scanf, 5, 6), nonnull));
+
 #define SAFE_CGROUP_OCCURSIN(cg, file_name, needle)		\
 	safe_cgroup_occursin(__FILE__, __LINE__,		\
 			     (cg), (file_name), (needle))
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index c08ff2f20..961596256 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -1161,6 +1161,39 @@ void safe_cgroup_scanf(const char *const file, const int lineno,
 		 file_name, buf, fmt, ret, conv_cnt);
 }
 
+void safe_cgroup_lines_scanf(const char *const file, const int lineno,
+			     const struct tst_cgroup_group *const cg,
+			     const char *const file_name,
+			     const char *const fmt, ...)
+{
+	va_list va;
+	char buf[BUFSIZ];
+	ssize_t len = safe_cgroup_read(file, lineno,
+				       cg, file_name, buf, sizeof(buf));
+	const int conv_cnt = tst_count_scanf_conversions(fmt);
+	int ret = 0;
+	char *line;
+
+	if (len < 1)
+		return;
+
+	line = strtok(buf, "\n");
+	while (line && ret != conv_cnt) {
+		va_start(va, fmt);
+		ret = vsscanf(line, fmt, va);
+		va_end(va);
+
+		line = strtok(NULL, "\n");
+	}
+
+	if (conv_cnt == ret)
+		return;
+
+	tst_brk_(file, lineno, TBROK,
+		 "'%s': vsscanf('%s', '%s', ..): Less conversions than expected: %d != %d",
+		 file_name, buf, fmt, ret, conv_cnt);
+}
+
 int safe_cgroup_occursin(const char *const file, const int lineno,
 			 const struct tst_cgroup_group *const cg,
 			 const char *const file_name,
-- 
2.34.0


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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-01-03  9:51 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-20 13:10 [LTP] [PATCH 1/3] API/cgroup: Add safe_cgroup_lines_scanf Richard Palethorpe via ltp
2021-12-20 13:10 ` [LTP] [PATCH 2/3] API/cgroup: Add memory.stat Richard Palethorpe via ltp
2021-12-20 15:15   ` Cyril Hrubis
2021-12-20 13:10 ` [LTP] [PATCH 3/3] cgroup: Add memcontrol02 Richard Palethorpe via ltp
2021-12-20 15:44   ` Cyril Hrubis
2021-12-21  8:38     ` Richard Palethorpe
2021-12-21 11:14       ` Cyril Hrubis
2021-12-20 15:08 ` [LTP] [PATCH 1/3] API/cgroup: Add safe_cgroup_lines_scanf Cyril Hrubis
2021-12-30 10:37 ` [LTP] [PATCH v2 1/5] " Richard Palethorpe via ltp
2021-12-30 10:37   ` [LTP] [PATCH v2 2/5] API/cgroup: Add memory.stat Richard Palethorpe via ltp
2021-12-30 10:37   ` [LTP] [PATCH v2 3/5] API/fs: Add exfat magic Richard Palethorpe via ltp
2021-12-30 10:37   ` [LTP] [PATCH v2 4/5] API: Add TST_EXP_EXPR macro Richard Palethorpe via ltp
2021-12-30 10:37   ` [LTP] [PATCH v2 5/5] cgroup: Add memcontrol02 Richard Palethorpe via ltp
2022-01-03  9:45     ` Petr Vorel
2022-01-03  9:51   ` [LTP] [PATCH v2 1/5] API/cgroup: Add safe_cgroup_lines_scanf Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox