diff mbox

[i-g-t] igt/drv_hangman: Fix clear_error_state

Message ID 20170223012629.13734-1-michel.thierry@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michel Thierry Feb. 23, 2017, 1:26 a.m. UTC
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.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Fixes: 79c6a84ca85b ("igt/drv_hangman: Migrate to sysfs")
Signed-off-by: Michel Thierry <michel.thierry@intel.com>
---
 tests/drv_hangman.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Chris Wilson Feb. 23, 2017, 1:52 a.m. UTC | #1
On Wed, Feb 22, 2017 at 05:26:29PM -0800, Michel Thierry wrote:
> 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.
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Fixes: 79c6a84ca85b ("igt/drv_hangman: Migrate to sysfs")
> Signed-off-by: Michel Thierry <michel.thierry@intel.com>
> ---
>  tests/drv_hangman.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
> index cafdf4c1..43f73661 100644
> --- a/tests/drv_hangman.c
> +++ b/tests/drv_hangman.c
> @@ -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.

> -		     "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.

> +	} 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", " ");

My bad, I was expecting it write the nul character. "\0" would be my
preference
-Chris
Chris Wilson Feb. 23, 2017, 2:04 a.m. UTC | #2
On Thu, Feb 23, 2017 at 01:52:04AM +0000, Chris Wilson wrote:
> On Wed, Feb 22, 2017 at 05:26:29PM -0800, Michel Thierry wrote:
> >  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

Still needs an explicit igt_sysfs_write() to avoid strlen.
-Chris
Michel Thierry Feb. 23, 2017, 2:06 a.m. UTC | #3
On 22/02/17 18:04, Chris Wilson wrote:
> On Thu, Feb 23, 2017 at 01:52:04AM +0000, Chris Wilson wrote:
>> On Wed, Feb 22, 2017 at 05:26:29PM -0800, Michel Thierry wrote:
>>>  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
>
> 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.
diff mbox

Patch

diff --git a/tests/drv_hangman.c b/tests/drv_hangman.c
index cafdf4c1..43f73661 100644
--- a/tests/drv_hangman.c
+++ b/tests/drv_hangman.c
@@ -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)