[23/33] cocci: Split out igt_assert() comparison rules

Submitted by Lyude Paul on June 10, 2019, 3:03 p.m.

Details

Message ID 20190610150321.512-23-lyude@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in IGT - Trybot

Not browsing as part of any series.

Commit Message

Lyude Paul June 10, 2019, 3:03 p.m.
From: Lyude Paul <lyude@redhat.com>

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 scripts/cocci/igt.cocci                    | 182 --------------------
 scripts/cocci/igt_assert_comparisons.cocci | 185 +++++++++++++++++++++
 2 files changed, 185 insertions(+), 182 deletions(-)
 create mode 100644 scripts/cocci/igt_assert_comparisons.cocci

Patch hide | download patch | download mbox

diff --git a/scripts/cocci/igt.cocci b/scripts/cocci/igt.cocci
index 7a369a6a..42609da6 100644
--- a/scripts/cocci/igt.cocci
+++ b/scripts/cocci/igt.cocci
@@ -6,188 +6,6 @@ 
 virtual report
 virtual patch
 
-@initialize:python@
-@@
-op_str_map = {
-    '==': 'eq',
-    '!=': 'neq',
-    '<': 'lt',
-    '<=': 'lte',
-    '>': 'lt',
-    '>=': 'lte',
-}
-
-def warn_cmp_macro(p, type_prefix, op, e1, e2):
-    op = op.strip()
-    op_str = op_str_map[op]
-    if type_prefix != '':
-        type_prefix = type_prefix + '_'
-
-    if op.startswith('>'):
-        args = type_prefix, op_str, e2, e1
-    else:
-        args = type_prefix, op_str, e1, e2
-
-    msg = 'WARNING: igt_assert_%s%s(%s, %s) should be used instead' % args
-    coccilib.report.print_report(p[0], msg)
-
-// Use comparison macros instead of raw igt_assert when possible
-@depends on patch@
-typedef uint32_t;
-typedef uint64_t;
-typedef int64_t;
-int int_1, int_2;
-double double_1, double_2;
-uint32_t u32_1, u32_2;
-uint64_t u64_1, u64_2;
-int64_t s64_1, s64_2;
-@@
-(
-- igt_assert(int_1 == int_2);
-+ igt_assert_eq(int_1, int_2);
-|
-- igt_assert(u32_1 == u32_2);
-+ igt_assert_eq_u32(u32_1, u32_2);
-|
-- igt_assert(s64_1 == s64_2);
-+ igt_assert_eq_s64(s64_1, s64_2);
-|
-- igt_assert(u64_1 == u64_2);
-+ igt_assert_eq_u64(u64_1, u64_2);
-|
-- igt_assert(double_1 == double_2);
-+ igt_assert_eq_double(double_1, double_2);
-|
-- igt_assert(int_1 != int_2);
-+ igt_assert_neq(int_1, int_2);
-|
-- igt_assert(u32_1 != u32_2);
-+ igt_assert_neq_u32(u32_1, u32_2);
-|
-- igt_assert(s64_1 != s64_2);
-+ igt_assert_neq_s64(s64_1, s64_2);
-|
-- igt_assert(u64_1 != u64_2);
-+ igt_assert_neq_u64(u64_1, u64_2);
-|
-- igt_assert(double_1 != double_2);
-+ igt_assert_neq_double(double_1, double_2);
-|
-- igt_assert(int_1 < int_2);
-+ igt_assert_lt(int_1, int_2);
-|
-- igt_assert(s64_1 < s64_2);
-+ igt_assert_lt_s64(s64_1, s64_2);
-|
-- igt_assert(u64_1 < u64_2);
-+ igt_assert_lt_u64(u64_1, u64_2);
-|
-- igt_assert(int_1 <= int_2);
-+ igt_assert_lte(int_1, int_2);
-|
-- igt_assert(s64_1 <= s64_2);
-+ igt_assert_lte_s64(s64_1, s64_2);
-|
-- igt_assert(u64_1 <= u64_2);
-+ igt_assert_lte_u64(u64_1, u64_2);
-|
-- igt_assert(int_1 > int_2);
-+ igt_assert_lt(int_2, int_1);
-|
-- igt_assert(s64_1 > s64_2);
-+ igt_assert_lt_s64(s64_2, s64_1);
-|
-- igt_assert(u64_1 > u64_2);
-+ igt_assert_lt_u64(u64_2, u64_1);
-|
-- igt_assert(int_1 >= int_2);
-+ igt_assert_lte(int_2, int_1);
-|
-- igt_assert(s64_1 >= s64_2);
-+ igt_assert_lte_s64(s64_2, s64_1);
-|
-- igt_assert(u64_1 >= u64_2);
-+ igt_assert_lte_u64(u64_2, u64_1);
-)
-
-@igt_assert_cmp_report depends on report@
-position p;
-int e1, e2;
-binary operator op = {==,!=,<,<=,>,>=};
-@@
-igt_assert@p(e1 op e2);
-
-@script:python depends on report@
-p << igt_assert_cmp_report.p;
-op << igt_assert_cmp_report.op;
-e1 << igt_assert_cmp_report.e1;
-e2 << igt_assert_cmp_report.e2;
-@@
-warn_cmp_macro(p, '', op, e1, e2)
-
-@igt_assert_cmp_u32_report depends on report@
-position p;
-typedef uint32_t;
-uint32_t e1, e2;
-binary operator op = {==,!=};
-@@
-igt_assert@p(e1 op e2);
-
-@script:python depends on report@
-p << igt_assert_cmp_u32_report.p;
-op << igt_assert_cmp_u32_report.op;
-e1 << igt_assert_cmp_u32_report.e1;
-e2 << igt_assert_cmp_u32_report.e2;
-@@
-warn_cmp_macro(p, 'u32', op, e1, e2)
-
-@igt_assert_cmp_u64_report depends on report@
-position p;
-typedef uint64_t;
-uint64_t e1, e2;
-binary operator op = {==,!=,<,<=,>,>=};
-@@
-igt_assert@p(e1 op e2);
-
-@script:python depends on report@
-p << igt_assert_cmp_u64_report.p;
-op << igt_assert_cmp_u64_report.op;
-e1 << igt_assert_cmp_u64_report.e1;
-e2 << igt_assert_cmp_u64_report.e2;
-@@
-warn_cmp_macro(p, 'u64', op, e1, e2)
-
-@igt_assert_cmp_s64_report depends on report@
-position p;
-typedef int64_t;
-int64_t e1, e2;
-binary operator op = {==,!=,<,<=,>,>=};
-@@
-igt_assert@p(e1 op e2);
-
-@script:python depends on report@
-p << igt_assert_cmp_s64_report.p;
-op << igt_assert_cmp_s64_report.op;
-e1 << igt_assert_cmp_s64_report.e1;
-e2 << igt_assert_cmp_s64_report.e2;
-@@
-warn_cmp_macro(p, 's64', op, e1, e2)
-
-@igt_assert_cmp_double_report depends on report@
-position p;
-double e1, e2;
-binary operator op = {==,!=};
-@@
-igt_assert@p(e1 op e2);
-
-@script:python depends on report@
-p << igt_assert_cmp_double_report.p;
-op << igt_assert_cmp_double_report.op;
-e1 << igt_assert_cmp_double_report.e1;
-e2 << igt_assert_cmp_double_report.e2;
-@@
-warn_cmp_macro(p, "double", op, e1, e2)
-
 // avoid unused-result warnings when compiling with _FORTIFY_SOURCE defined
 @depends on patch@
 identifier func =~ "^(read|write)$";
diff --git a/scripts/cocci/igt_assert_comparisons.cocci b/scripts/cocci/igt_assert_comparisons.cocci
new file mode 100644
index 00000000..8388bcb2
--- /dev/null
+++ b/scripts/cocci/igt_assert_comparisons.cocci
@@ -0,0 +1,185 @@ 
+// Use comparison macros instead of raw igt_assert when possible
+
+virtual report
+virtual patch
+
+@initialize:python@
+@@
+op_str_map = {
+    '==': 'eq',
+    '!=': 'neq',
+    '<': 'lt',
+    '<=': 'lte',
+    '>': 'lt',
+    '>=': 'lte',
+}
+
+def warn_cmp_macro(p, type_prefix, op, e1, e2):
+    op = op.strip()
+    op_str = op_str_map[op]
+    if type_prefix != '':
+        type_prefix = type_prefix + '_'
+
+    if op.startswith('>'):
+        args = type_prefix, op_str, e2, e1
+    else:
+        args = type_prefix, op_str, e1, e2
+
+    msg = 'WARNING: igt_assert_%s%s(%s, %s) should be used instead' % args
+    coccilib.report.print_report(p[0], msg)
+
+@depends on patch@
+typedef uint32_t;
+typedef uint64_t;
+typedef int64_t;
+int int_1, int_2;
+double double_1, double_2;
+uint32_t u32_1, u32_2;
+uint64_t u64_1, u64_2;
+int64_t s64_1, s64_2;
+@@
+(
+- igt_assert(int_1 == int_2);
++ igt_assert_eq(int_1, int_2);
+|
+- igt_assert(u32_1 == u32_2);
++ igt_assert_eq_u32(u32_1, u32_2);
+|
+- igt_assert(s64_1 == s64_2);
++ igt_assert_eq_s64(s64_1, s64_2);
+|
+- igt_assert(u64_1 == u64_2);
++ igt_assert_eq_u64(u64_1, u64_2);
+|
+- igt_assert(double_1 == double_2);
++ igt_assert_eq_double(double_1, double_2);
+|
+- igt_assert(int_1 != int_2);
++ igt_assert_neq(int_1, int_2);
+|
+- igt_assert(u32_1 != u32_2);
++ igt_assert_neq_u32(u32_1, u32_2);
+|
+- igt_assert(s64_1 != s64_2);
++ igt_assert_neq_s64(s64_1, s64_2);
+|
+- igt_assert(u64_1 != u64_2);
++ igt_assert_neq_u64(u64_1, u64_2);
+|
+- igt_assert(double_1 != double_2);
++ igt_assert_neq_double(double_1, double_2);
+|
+- igt_assert(int_1 < int_2);
++ igt_assert_lt(int_1, int_2);
+|
+- igt_assert(s64_1 < s64_2);
++ igt_assert_lt_s64(s64_1, s64_2);
+|
+- igt_assert(u64_1 < u64_2);
++ igt_assert_lt_u64(u64_1, u64_2);
+|
+- igt_assert(int_1 <= int_2);
++ igt_assert_lte(int_1, int_2);
+|
+- igt_assert(s64_1 <= s64_2);
++ igt_assert_lte_s64(s64_1, s64_2);
+|
+- igt_assert(u64_1 <= u64_2);
++ igt_assert_lte_u64(u64_1, u64_2);
+|
+- igt_assert(int_1 > int_2);
++ igt_assert_lt(int_2, int_1);
+|
+- igt_assert(s64_1 > s64_2);
++ igt_assert_lt_s64(s64_2, s64_1);
+|
+- igt_assert(u64_1 > u64_2);
++ igt_assert_lt_u64(u64_2, u64_1);
+|
+- igt_assert(int_1 >= int_2);
++ igt_assert_lte(int_2, int_1);
+|
+- igt_assert(s64_1 >= s64_2);
++ igt_assert_lte_s64(s64_2, s64_1);
+|
+- igt_assert(u64_1 >= u64_2);
++ igt_assert_lte_u64(u64_2, u64_1);
+)
+
+@igt_assert_cmp_report depends on report@
+position p;
+int e1, e2;
+binary operator op = {==,!=,<,<=,>,>=};
+@@
+igt_assert@p(e1 op e2);
+
+@script:python depends on report@
+p << igt_assert_cmp_report.p;
+op << igt_assert_cmp_report.op;
+e1 << igt_assert_cmp_report.e1;
+e2 << igt_assert_cmp_report.e2;
+@@
+warn_cmp_macro(p, '', op, e1, e2)
+
+@igt_assert_cmp_u32_report depends on report@
+position p;
+typedef uint32_t;
+uint32_t e1, e2;
+binary operator op = {==,!=};
+@@
+igt_assert@p(e1 op e2);
+
+@script:python depends on report@
+p << igt_assert_cmp_u32_report.p;
+op << igt_assert_cmp_u32_report.op;
+e1 << igt_assert_cmp_u32_report.e1;
+e2 << igt_assert_cmp_u32_report.e2;
+@@
+warn_cmp_macro(p, 'u32', op, e1, e2)
+
+@igt_assert_cmp_u64_report depends on report@
+position p;
+typedef uint64_t;
+uint64_t e1, e2;
+binary operator op = {==,!=,<,<=,>,>=};
+@@
+igt_assert@p(e1 op e2);
+
+@script:python depends on report@
+p << igt_assert_cmp_u64_report.p;
+op << igt_assert_cmp_u64_report.op;
+e1 << igt_assert_cmp_u64_report.e1;
+e2 << igt_assert_cmp_u64_report.e2;
+@@
+warn_cmp_macro(p, 'u64', op, e1, e2)
+
+@igt_assert_cmp_s64_report depends on report@
+position p;
+typedef int64_t;
+int64_t e1, e2;
+binary operator op = {==,!=,<,<=,>,>=};
+@@
+igt_assert@p(e1 op e2);
+
+@script:python depends on report@
+p << igt_assert_cmp_s64_report.p;
+op << igt_assert_cmp_s64_report.op;
+e1 << igt_assert_cmp_s64_report.e1;
+e2 << igt_assert_cmp_s64_report.e2;
+@@
+warn_cmp_macro(p, 's64', op, e1, e2)
+
+@igt_assert_cmp_double_report depends on report@
+position p;
+double e1, e2;
+binary operator op = {==,!=};
+@@
+igt_assert@p(e1 op e2);
+
+@script:python depends on report@
+p << igt_assert_cmp_double_report.p;
+op << igt_assert_cmp_double_report.op;
+e1 << igt_assert_cmp_double_report.e1;
+e2 << igt_assert_cmp_double_report.e2;
+@@
+warn_cmp_macro(p, "double", op, e1, e2)