igt/drv_hangman: Fix clear_error_state
PATCH 1/1 igt/drv_hangman: Fix clear_error_state
clear_error_state was not doing anything (igt_sysfs_set was not writing to the error file).
Also fix assert_entry to catch this issue; strcasecmp returns 0 when there's a match, or an integer in a mismatch.
Finally, only print part of the error string when the assert fails.
--- tests/drv_hangman.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
tests/drv_hangman.c +10 -4
@@ -58,9 +58,15 @@ static void assert_entry(const char *s, bool expect) error =igt_sysfs_get (sysfs,"error" );igt_assert (error); -igt_assert_f (strcasecmp (error, s) != expect, -"contents of error: '%s' (expected %s '%s')\n" , - error, expect ?"" :"not" , s); +if (expect) { +igt_assert_f (strcasecmp (error, s) ==0 , +"contents of error: '%.24s' (expected %s '%s')\n" , + error, expect ?"" :"not" , s); + }else { +igt_assert_f (strcasecmp (error, s) !=0 , +"contents of error: '%.24s' (expected %s '%s')\n" , + error, expect ?"" :"not" , s); + }free (error); }
@@ -77,7 +83,7 @@ static void assert_error_state_collected(void)static void clear_error_state (void ) { -igt_sysfs_set (sysfs,"error" ,"" ); +igt_sysfs_set (sysfs,"error" ," " ); }static void test_error_state_basic (void )
Signature · 6 lines
2.11.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 20 lines · Michel Thierry
clear_error_statewas not doing anything (igt_sysfs_setwas not writing to the error file).Also fix
assert_entryto catch this issue; strcasecmp returns 0 when there's a match, or an integer in a mismatch.Finally, only print part of the error string when the assert fails.
Cc Chris Wilson <[email protected]>Fixes 79c6a84ca85b ("igt/drv_hangman: Migrate to sysfs")Signed-off-by Michel Thierry <[email protected]>--- tests/drv_hangman.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)tests/drv_hangman.c +0
-0
tests/drv_hangman.c static void assert_entry(const char *s, bool expect) · line 61
Quoted 4 lines
tests/drv_hangman.c +0
-1@@ -58,9 +58,15 @@ static void assert_entry(const char *s, bool expect) error =igt_sysfs_get (sysfs,"error" );igt_assert (error); - igt_assert_f(strcasecmp(error, s) != expect,
!!strcasecmp != expect
or (bool)strcasecmp != expect, type promotion working in the opposite direction.
tests/drv_hangman.c static void assert_entry(const char *s, bool expect) · line 64
Quoted 6 lines
tests/drv_hangman.c +4
-2-"contents of error: '%s' (expected %s '%s')\n" , - error, expect ? "": "not", s); +if (expect) { +igt_assert_f (strcasecmp (error, s) ==0 , +"contents of error: '%.24s' (expected %s '%s')\n" , + error, expect ?"" :"not" , s);
Keep the full error state, it can be very informative. 24 characters isn't enough to determine what.
Quoted 9 lines
tests/drv_hangman.c +5
-0+ }else { +igt_assert_f (strcasecmp (error, s) !=0 , +"contents of error: '%.24s' (expected %s '%s')\n" , + error, expect ?"" :"not" , s); + }free (error); }
tests/drv_hangman.c static void assert_error_state_collected(void) · line 86
Quoted 5 lines
tests/drv_hangman.c +1
-1@@ -77,7 +83,7 @@ static void assert_error_state_collected(void)static void clear_error_state (void ) { -igt_sysfs_set (sysfs,"error" ,"" ); +igt_sysfs_set (sysfs,"error" ," " );
My bad, I was expecting it write the nul character. "\0" would be my preference
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 8 lines · Chris Wilson
tests/drv_hangman.c static void assert_error_state_collected(void) · line 86
Quoted 4 lines · Michel Thierry
static void
clear_error_state(void)
{tests/drv_hangman.c +1
-1-igt_sysfs_set (sysfs,"error" ,"" ); +igt_sysfs_set (sysfs,"error" ," " );My bad, I was expecting it write the nul character. "\0" would be my preference
Still needs an explicit igt_sysfs_write() to avoid strlen. -Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 10 lines · Chris Wilson
Quoted 8 lines · Chris Wilson
tests/drv_hangman.c static void assert_error_state_collected(void) · line 86
Quoted 4 lines · Michel Thierry
static void
clear_error_state(void)
{tests/drv_hangman.c +1
-1-igt_sysfs_set (sysfs,"error" ,"" ); +igt_sysfs_set (sysfs,"error" ," " );My bad, I was expecting it write the nul character. "\0" would be my preference
Quoted 3 lines
Still needs an explicit
igt_sysfs_write()to avoid strlen. -Chris
Yes, strlen(\0) is 0, which at the end is write(x, 0) and ignored.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/1 igt/drv_hangman: Fix clear_error_state
clear_error_state was not doing anything (igt_sysfs_set was not writing to the error file because strlen was 0).
Also fix assert_entry to catch this issue; strcasecmp returns 0 when there's a match, or an integer in a mismatch.
v2: Use new igt_sysfs_write, add len > 0 assert in igt_sysfs_set to catch future errors, clean-up strcasecmp logic (Chris).
--- lib/igt_sysfs.c | 26 ++++++++++++++++++++++++++ lib/igt_sysfs.h | 1 + tests/drv_hangman.c | 4 ++-- 3 files changed, 29 insertions(+), 2 deletions(-)
lib/igt_sysfs.c +26 -0
@@ -172,6 +172,31 @@ int igt_sysfs_open_parameters(int device)return params; } + +/** +* igt_sysfs_write: +* @dir: directory for the device from igt_sysfs_open() +* @attr: name of the sysfs node to open +* +* This writes a single byte to the sysfs file. +* +* Returns: +* True on success, false on failure. +*/ +bool igt_sysfs_write (int dir,const char *attr) +{ +int fd, ret; + + fd =openat (dir, attr,O_WRONLY ); +if (fd <0 ) +return false; + + ret =write (fd,"\0" ,1 ); +close (fd); + +return ret; +} +/** * igt_sysfs_set: * @dir: directory for the device from igt_sysfs_open()
@@ -192,6 +217,7 @@ bool igt_sysfs_set(int dir, const char *attr, const char *value)return false; len =strlen (value); +igt_assert (len >0 ); ret =writeN (fd, value, len);close (fd);
lib/igt_sysfs.h +1 -0
@@ -29,6 +29,7 @@int igt_sysfs_open (int device,int *idx);int igt_sysfs_open_parameters (int device); +bool igt_sysfs_write (int dir,const char *attr);bool igt_sysfs_set (int dir,const char *attr,const char *value);char *igt_sysfs_get (int dir,const char *attr);
tests/drv_hangman.c +2 -2
@@ -58,7 +58,7 @@ static void assert_entry(const char *s, bool expect) error =igt_sysfs_get (sysfs,"error" );igt_assert (error); -igt_assert_f (strcasecmp (error, s) != expect, +igt_assert_f (!!strcasecmp (error, s) != expect,"contents of error: '%s' (expected %s '%s')\n" , error, expect ?"" :"not" , s);
@@ -77,7 +77,7 @@ static void assert_error_state_collected(void)static void clear_error_state (void ) { -igt_sysfs_set (sysfs,"error" ,"" ); +igt_sysfs_write (sysfs,"error" ); }static void test_error_state_basic (void )
Signature · 6 lines
2.11.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 2 lines · Michel Thierry
v2: Use new
igt_sysfs_write, add len > 0 assert inigt_sysfs_setto catch future errors, clean-up strcasecmp logic (Chris).
Nevermind, didn't see you were faster than me...
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx