[v3] test/hash: solve unit test hash compilation error

Message ID 1540590183-87753-1-git-send-email-dharmik.thakkar@arm.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] test/hash: solve unit test hash compilation error |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Dharmik Thakkar Oct. 26, 2018, 9:43 p.m. UTC
  Enable print_key_info() function compilation always.

Compilation error message:
'test_hash.c: In function ‘print_key_info’:
test_hash.c:90:15: error: cast discards ‘const’ qualifier from pointer
target type [-Werror=cast-qual]
  uint8_t *p = (uint8_t *)key;
               ^
cc1: all warnings being treated as errors'


Fixes: af75078fece36 ("first public release")
Cc: stable@dpdk.org

Suggested-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
---
v3:
* Add compilation error message
---
v2:
* Fix checkpatch coding style issue
* Add "Fixes:" tag
---
 test/test/test_hash.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
  

Comments

Thomas Monjalon Nov. 6, 2018, 2:19 a.m. UTC | #1
26/10/2018 23:43, Dharmik Thakkar:
> Enable print_key_info() function compilation always.
> 
> Compilation error message:
> 'test_hash.c: In function ‘print_key_info’:
> test_hash.c:90:15: error: cast discards ‘const’ qualifier from pointer
> target type [-Werror=cast-qual]
>   uint8_t *p = (uint8_t *)key;
>                ^
> cc1: all warnings being treated as errors'
> 
> 
> Fixes: af75078fece36 ("first public release")
> Cc: stable@dpdk.org
> 
> Suggested-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> Reviewed-by: Gavin Hu <gavin.hu@arm.com>

Applied, thanks
  

Patch

diff --git a/test/test/test_hash.c b/test/test/test_hash.c
index b3db9fd10547..db6442a2b101 100644
--- a/test/test/test_hash.c
+++ b/test/test/test_hash.c
@@ -80,29 +80,23 @@  static uint32_t pseudo_hash(__attribute__((unused)) const void *keys,
 	return 3;
 }
 
+#define UNIT_TEST_HASH_VERBOSE	0
 /*
  * Print out result of unit test hash operation.
  */
-#if defined(UNIT_TEST_HASH_VERBOSE)
 static void print_key_info(const char *msg, const struct flow_key *key,
 								int32_t pos)
 {
-	uint8_t *p = (uint8_t *)key;
-	unsigned i;
-
-	printf("%s key:0x", msg);
-	for (i = 0; i < sizeof(struct flow_key); i++) {
-		printf("%02X", p[i]);
+	if (UNIT_TEST_HASH_VERBOSE) {
+		const uint8_t *p = (const uint8_t *)key;
+		unsigned int i;
+
+		printf("%s key:0x", msg);
+		for (i = 0; i < sizeof(struct flow_key); i++)
+			printf("%02X", p[i]);
+		printf(" @ pos %d\n", pos);
 	}
-	printf(" @ pos %d\n", pos);
-}
-#else
-static void print_key_info(__attribute__((unused)) const char *msg,
-		__attribute__((unused)) const struct flow_key *key,
-		__attribute__((unused)) int32_t pos)
-{
 }
-#endif
 
 /* Keys used by unit test functions */
 static struct flow_key keys[5] = { {