[LTP] [PATCH 4/4] scripts/coccinelle: Helper for converting CGroup selftests
Richard Palethorpe
rpalethorpe@suse.com
Tue Dec 14 10:06:48 CET 2021
Helps with bulk rewriting.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
.../coccinelle/kselftest-cgroup-to-ltp.cocci | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 scripts/coccinelle/kselftest-cgroup-to-ltp.cocci
diff --git a/scripts/coccinelle/kselftest-cgroup-to-ltp.cocci b/scripts/coccinelle/kselftest-cgroup-to-ltp.cocci
new file mode 100644
index 000000000..f91c2c467
--- /dev/null
+++ b/scripts/coccinelle/kselftest-cgroup-to-ltp.cocci
@@ -0,0 +1,40 @@
+@@
+expression cgn, cgns;
+@@
+
+- cgn = cg_name(..., cgns);
++ cgn = tst_cgroup_group_mk(cg_test, cgns);
+
+@@
+expression cg, fname, data;
+@@
+
+- if (cg_write(cg, fname, data)) {
+- ...
+- }
++ SAFE_CGROUP_PRINT(cg, fname, data);
+
+@@
+expression cg;
+@@
+
+... when != TST_CGROUP_VER(...)
+
+- SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory");
++ if (TST_CGROUP_VER(cg, "memory") != TST_CGROUP_V1)
++ SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory");
+
+@@
+expression cg, fname, needle;
+@@
+
+- cg_read_strstr(cg, fname, needle)
++ !SAFE_CGROUP_OCCURSIN(cg, fname, needle)
+
+@@
+identifier l;
+expression cg, fname;
+@@
+
+- l = cg_read_long(cg, fname);
++ SAFE_CGROUP_SCANF(cg, fname, "%ld", &l);
--
2.34.0
More information about the ltp
mailing list