diff mbox

[i-g-t,v2] tests/psr: Don't strcmp CRCs that are not NULL terminated.

Message ID 20170919224749.11161-1-dhinakaran.pandiyan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dhinakaran Pandiyan Sept. 19, 2017, 10:47 p.m. UTC
Switched to strncmp.
v2: increased buffer size to account for NULL character.

Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
---
 tests/kms_psr_sink_crc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Sripada, Radhakrishna Sept. 22, 2017, 1:01 a.m. UTC | #1
> -----Original Message-----

> From: Intel-gfx [mailto:intel-gfx-bounces@lists.freedesktop.org] On Behalf

> Of Dhinakaran Pandiyan

> Sent: Tuesday, September 19, 2017 3:48 PM

> To: intel-gfx@lists.freedesktop.org

> Cc: Pandiyan, Dhinakaran <dhinakaran.pandiyan@intel.com>; Vivi, Rodrigo

> <rodrigo.vivi@intel.com>

> Subject: [Intel-gfx] [PATCH i-g-t v2] tests/psr: Don't strcmp CRCs that are not

> NULL terminated.

> 

> Switched to strncmp.

> v2: increased buffer size to account for NULL character.

> 

> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>

> Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>

Reviewed-by: Radhakrishna Sripada <radhakrishna.sripada@intel.com>

> ---

>  tests/kms_psr_sink_crc.c | 13 +++++++------

>  1 file changed, 7 insertions(+), 6 deletions(-)

> 

> diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c

> index 1c25f2c8..ff257698 100644

> --- a/tests/kms_psr_sink_crc.c

> +++ b/tests/kms_psr_sink_crc.c

> @@ -34,6 +34,7 @@

>  bool running_with_psr_disabled;

> 

>  #define CRC_BLACK "000000000000"

> +#define CRC_LEN 12

> 

>  enum operations {

>  	PAGE_FLIP,

> @@ -243,7 +244,7 @@ static void get_sink_crc(data_t *data, char *crc) {

>  	usleep(300000);

> 

>  	/* Black screen is always invalid */

> -	igt_assert(strcmp(crc, CRC_BLACK) != 0);

> +	igt_assert(strncmp(crc, CRC_BLACK, CRC_LEN + 1) != 0);

>  }

> 

>  static bool is_green(char *crc)

> @@ -298,8 +299,8 @@ static void run_test(data_t *data)

>  	uint32_t handle = data->fb_white.gem_handle;

>  	igt_plane_t *test_plane;

>  	void *ptr;

> -	char ref_crc[12];

> -	char crc[12];

> +	char ref_crc[CRC_LEN + 1] = {0};

> +	char crc[CRC_LEN + 1] = {0};

>  	const char *expected = "";

> 

>  	/* Confirm that screen became Green */

> @@ -356,9 +357,9 @@ static void run_test(data_t *data)

>  		memset(ptr, 0xff, data->mod_size);

>  		get_sink_crc(data, crc);

>  		if (data->test_plane == DRM_PLANE_TYPE_PRIMARY)

> -			assert_or_manual(strcmp(ref_crc, crc) == 0, "screen

> WHITE");

> +			assert_or_manual(strncmp(ref_crc, crc, CRC_LEN + 1)

> == 0, "screen WHITE");

>  		else

> -			assert_or_manual(strcmp(ref_crc, crc) == 0,

> +			assert_or_manual(strncmp(ref_crc, crc, CRC_LEN + 1)

> == 0,

>  			       "GREEN background with WHITE box");

> 

>  		igt_info("Waiting 10s...\n");

> @@ -401,7 +402,7 @@ static void run_test(data_t *data)

>  		break;

>  	}

>  	get_sink_crc(data, crc);

> -	assert_or_manual(strcmp(ref_crc, crc) != 0, expected);

> +	assert_or_manual(strncmp(ref_crc, crc, CRC_LEN + 1) != 0,

> expected);

>  }

> 

>  static void test_cleanup(data_t *data) {

> --

> 2.11.0

> 

> _______________________________________________

> Intel-gfx mailing list

> Intel-gfx@lists.freedesktop.org

> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
index 1c25f2c8..ff257698 100644
--- a/tests/kms_psr_sink_crc.c
+++ b/tests/kms_psr_sink_crc.c
@@ -34,6 +34,7 @@ 
 bool running_with_psr_disabled;
 
 #define CRC_BLACK "000000000000"
+#define CRC_LEN 12
 
 enum operations {
 	PAGE_FLIP,
@@ -243,7 +244,7 @@  static void get_sink_crc(data_t *data, char *crc) {
 	usleep(300000);
 
 	/* Black screen is always invalid */
-	igt_assert(strcmp(crc, CRC_BLACK) != 0);
+	igt_assert(strncmp(crc, CRC_BLACK, CRC_LEN + 1) != 0);
 }
 
 static bool is_green(char *crc)
@@ -298,8 +299,8 @@  static void run_test(data_t *data)
 	uint32_t handle = data->fb_white.gem_handle;
 	igt_plane_t *test_plane;
 	void *ptr;
-	char ref_crc[12];
-	char crc[12];
+	char ref_crc[CRC_LEN + 1] = {0};
+	char crc[CRC_LEN + 1] = {0};
 	const char *expected = "";
 
 	/* Confirm that screen became Green */
@@ -356,9 +357,9 @@  static void run_test(data_t *data)
 		memset(ptr, 0xff, data->mod_size);
 		get_sink_crc(data, crc);
 		if (data->test_plane == DRM_PLANE_TYPE_PRIMARY)
-			assert_or_manual(strcmp(ref_crc, crc) == 0, "screen WHITE");
+			assert_or_manual(strncmp(ref_crc, crc, CRC_LEN + 1) == 0, "screen WHITE");
 		else
-			assert_or_manual(strcmp(ref_crc, crc) == 0,
+			assert_or_manual(strncmp(ref_crc, crc, CRC_LEN + 1) == 0,
 			       "GREEN background with WHITE box");
 
 		igt_info("Waiting 10s...\n");
@@ -401,7 +402,7 @@  static void run_test(data_t *data)
 		break;
 	}
 	get_sink_crc(data, crc);
-	assert_or_manual(strcmp(ref_crc, crc) != 0, expected);
+	assert_or_manual(strncmp(ref_crc, crc, CRC_LEN + 1) != 0, expected);
 }
 
 static void test_cleanup(data_t *data) {