lib/igt_core: Add igt_assert_eq
PATCH 1/3 lib/igt_core: Add igt_assert_eq
Suggested by Chris Wilson. Not yet rolled out since I'm trying to use cocci for this.
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt_core.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/igt_core.h +13 -0
@@ -253,6 +253,19 @@ void igt_exit(void) __attribute__((noreturn)); }while (0 )/** +* igt_assert_eq: +* @n1: first integer +* @n2: second integer +* +* Fails (sub-)test if the two integers are not equal. Beware that for now this +* only works on integers. +* +* Like igt_assert(), but displays the values being compared on failure instead +* of simply printing the stringified expression. + */ +#define igt_assert_eq (n1, n2) igt_assert_cmpint(n1, ==, n2) + +/** * igt_require: * @expr: condition to test *
Signature · 1 line
2.0.0
PATCH 2/3 lib: add igt.cocci
Small start but useful to collect refactorings/simplifications for common igt patterns. Please add more if you stumble over some so that we can occasionally run this to clean up the tests.
I haven't figured out yet how to do the assert_cmpint->assert_eq transformation.
Run this with
spatch --sp-file lib/igt.cocci --in-place tests/*.c
Signed-off-by Daniel Vetter <[email protected]>
--- lib/igt.cocci | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/igt.cocci
lib/igt.cocci new file +17 -0
@@ -0,0 +1,17 @@ +@@ +expression Ec; +expression list[n] Ep; +@@ +- if (Ec) { +- fprintf( stderr, Ep ); +- igt_fail(...); +- } ++ igt_assert_f(Ec, Ep); +@@ +expression Ec; +expression list[n] Ep; +@@ +- if (Ec) { +- igt_skip(Ep); +- } ++ igt_skip_on_f(Ec, Ep);
Signature · 1 line
2.0.0
PATCH 3/3 tests: Run igt.cocci over tests
In reply to Daniel VetterCocci is awesome
Signed-off-by Daniel Vetter <[email protected]>
--- tests/drv_hangman.c | 14 ++++---------- tests/kms_psr_sink_crc.c | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-)
tests/drv_hangman.c +4 -10
@@ -118,17 +118,11 @@ static void _assert_dfs_entry(const char *fname, const char *s, bool inverse)read_dfs (fname, tmp, l +1 );if (!inverse) { -if (strncmp (tmp, s, l) !=0 ) { -fprintf (stderr,"contents of %s: '%s' (expected '%s')\n" , - fname, tmp, s); -igt_fail (1 ); - } +igt_assert_f (strncmp (tmp, s, l) !=0 , +"contents of %s: '%s' (expected '%s')\n" , fname, tmp, s); }else { -if (strncmp (tmp, s, l) ==0 ) { -fprintf (stderr,"contents of %s: '%s' (expected not '%s'\n" , - fname, tmp, s); -igt_fail (1 ); - } +igt_assert_f (strncmp (tmp, s, l) ==0 , +"contents of %s: '%s' (expected not '%s'\n" , fname, tmp, s); } }
tests/kms_psr_sink_crc.c +2 -2
@@ -269,8 +269,8 @@ static bool psr_sink_support(data_t *data)igt_require (file); ret =fscanf (file,"Sink_Support: %s\n" , str); -if (ret ==0 ) -igt_skip ("i915_edp_psr_status format not supported by this test case\n" ); +igt_skip_on_f (ret ==0 , +"i915_edp_psr_status format not supported by this test case\n" );fclose (file);return strcmp (str,"yes" ) ==0 ;
Signature · 1 line
2.0.0
PATCH 1/1 Revert "tests: Run igt.cocci over tests"
This reverts commit 6903ab04e5f9048e3932eb3225e94b6a228681ba.
The igt_assert conversion rule is broken and doesn't invert the check as it should.
Signed-off-by Daniel Vetter <[email protected]>
--- tests/drv_hangman.c | 14 ++++++++++---- tests/kms_psr_sink_crc.c | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-)
tests/drv_hangman.c +10 -4
@@ -118,11 +118,17 @@ static void _assert_dfs_entry(const char *fname, const char *s, bool inverse)read_dfs (fname, tmp, l +1 );if (!inverse) { -igt_assert_f (strncmp (tmp, s, l) !=0 , -"contents of %s: '%s' (expected '%s')\n" , fname, tmp, s); +if (strncmp (tmp, s, l) !=0 ) { +fprintf (stderr,"contents of %s: '%s' (expected '%s')\n" , + fname, tmp, s); +igt_fail (1 ); + } }else { -igt_assert_f (strncmp (tmp, s, l) ==0 , -"contents of %s: '%s' (expected not '%s'\n" , fname, tmp, s); +if (strncmp (tmp, s, l) ==0 ) { +fprintf (stderr,"contents of %s: '%s' (expected not '%s'\n" , + fname, tmp, s); +igt_fail (1 ); + } } }
tests/kms_psr_sink_crc.c +2 -2
@@ -269,8 +269,8 @@ static bool psr_sink_support(data_t *data)igt_require (file); ret =fscanf (file,"Sink_Support: %s\n" , str); -igt_skip_on_f (ret ==0 , -"i915_edp_psr_status format not supported by this test case\n" ); +if (ret ==0 ) +igt_skip ("i915_edp_psr_status format not supported by this test case\n" );fclose (file);return strcmp (str,"yes" ) ==0 ;
Signature · 1 line
2.0.0