Skip to contentSkip to conversation

Replace compilation time options with log level

PATCH Superseded Dharmik Thakkar 4 participants 21 messages Nov 29, 2018 – Mar 28, 2019

lore
Share & tools
lore
#0 lore raw

cover Replace compilation time options with log level

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

 test/test/test_efd.c            | 24 ++++++++----------------
 test/test/test_hash.c           |  3 +--
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 3 files changed, 19 insertions(+), 31 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 test/hash: replace macro with log-level approach

Need to set hash log type to debug to print debug information, using following eal parameter: --log-type=hash,8

---
 test/test/test_hash.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
test/test/test_hash.c +1 -2
index fe607fadf262..67b8e54bdf13 100644
@@ -80,14 +80,13 @@ 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.
  */
 static void print_key_info(const char *msg, const struct flow_key *key,
 								int32_t pos)
 {
-	if (UNIT_TEST_HASH_VERBOSE) {
+	if (rte_log_get_level(RTE_LOGTYPE_HASH) == RTE_LOG_DEBUG) {
 		const uint8_t *p = (const uint8_t *)key;
 		unsigned int i;
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/3 test/efd: enable unit test compilation always

In reply to Dharmik Thakkar

This patch enables compilation of print_key_info() always using log-level based approach instead of a macro. Need to set efd log type to debug to print debug information, using the following eal parameter:
--log-type=efd,8

---
 test/test/test_efd.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
test/test/test_efd.c +8 -16
index ced091aab63d..3b6f9db13565 100644
@@ -34,28 +34,20 @@ struct flow_key {
 /*
  * Print out result of unit test efd operation.
  */
-#if defined(UNIT_TEST_EFD_VERBOSE)
-
 static void print_key_info(const char *msg, const struct flow_key *key,
 		efd_value_t val)
 {
-	const uint8_t *p = (const uint8_t *) key;
-	unsigned int i;
+	if (rte_log_get_level(RTE_LOGTYPE_EFD) == RTE_LOG_DEBUG) {
+		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(" @ val %d\n", val);
-}
-#else
+		printf("%s key:0x", msg);
+		for (i = 0; i < sizeof(struct flow_key); i++)
+			printf("%02X", p[i]);
 
-static void print_key_info(__attribute__((unused)) const char *msg,
-		__attribute__((unused)) const struct flow_key *key,
-		__attribute__((unused)) efd_value_t val)
-{
+		printf(" @ val %d\n", val);
+	}
 }
-#endif
 
 /* Keys used by unit test functions */
 static struct flow_key keys[5] = {
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/3 test/timer: enable unit test compilation always

In reply to Dharmik Thakkar

This patch replaces macro with log-level based approach to print debug information. Need to set timer log type to debug using the following eal parameter: --log-level=timer,8

---
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
test/test/test_timer_racecond.c +10 -13
index d29048eaf1bf..5ac248b2d90b 100644
@@ -44,8 +44,6 @@
 #include <rte_malloc.h>
 #include <rte_pause.h>
 
-#undef TEST_TIMER_RACECOND_VERBOSE
-
 #ifdef RTE_EXEC_ENV_LINUXAPP
 #define usec_delay(us) usleep(us)
 #else
@@ -70,13 +68,12 @@ timer_cb(struct rte_timer *tim, void *arg __rte_unused)
 {
 	/* Simulate slow callback function, 100 us. */
 	rte_delay_us(100);
-
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-	if (tim == &timer[0])
-		printf("------------------------------------------------\n");
-	printf("timer_cb: core %u timer %lu\n",
-		rte_lcore_id(), tim - timer);
-#endif
+	if (rte_log_get_level(RTE_LOGTYPE_TIMER) == RTE_LOG_DEBUG) {
+		if (tim == &timer[0])
+			printf("------------------------------------------------\n");
+		printf("%s: core %u timer %lu\n", __func__,
+			rte_lcore_id(), tim - timer);
+	}
 	(void)reload_timer(tim);
 }
 
@@ -96,10 +93,10 @@ reload_timer(struct rte_timer *tim)
 
 	ret = rte_timer_reset(tim, ticks, PERIODICAL, master, timer_cb, NULL);
 	if (ret != 0) {
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-		printf("- core %u failed to reset timer %lu (OK)\n",
-			rte_lcore_id(), tim - timer);
-#endif
+		if (rte_log_get_level(RTE_LOGTYPE_TIMER) == RTE_LOG_DEBUG) {
+			printf("- core %u failed to reset timer %lu (OK)\n",
+				rte_lcore_id(), tim - timer);
+		}
 		RTE_PER_LCORE(n_reset_collisions) += 1;
 	}
 	return ret;
Signature · 1 line
2.17.1
Reviewed-by on the v1 series
#4 lore raw
In reply to Dharmik Thakkar
Quoted 4 lines · Dharmik Thakkar

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

Quoted 8 lines

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

For series,

#5 lore raw

v2 cover Replace compilation time options with log level

In reply to Dharmik Thakkar

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

 test/test/test_efd.c            | 24 ++++++++----------------
 test/test/test_hash.c           |  3 +--
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 3 files changed, 19 insertions(+), 31 deletions(-)
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 1/3 test/hash: replace macro with log-level approach

Need to set hash log type to debug to print debug information, using following eal parameter: --log-type=hash,8

---
v2:
* Add Reviewed-by tag

---
 test/test/test_hash.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
test/test/test_hash.c +1 -2
index fe607fadf262..67b8e54bdf13 100644
@@ -80,14 +80,13 @@ 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.
  */
 static void print_key_info(const char *msg, const struct flow_key *key,
 								int32_t pos)
 {
-	if (UNIT_TEST_HASH_VERBOSE) {
+	if (rte_log_get_level(RTE_LOGTYPE_HASH) == RTE_LOG_DEBUG) {
 		const uint8_t *p = (const uint8_t *)key;
 		unsigned int i;
 
Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 2/3 test/efd: enable unit test compilation always

In reply to Dharmik Thakkar

This patch enables compilation of print_key_info() always using log-level based approach instead of a macro. Need to set efd log type to debug to print debug information, using the following eal parameter:
--log-type=efd,8

---
v2:
* Add Reviewed-by tag

---
 test/test/test_efd.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
test/test/test_efd.c +8 -16
index ced091aab63d..3b6f9db13565 100644
@@ -34,28 +34,20 @@ struct flow_key {
 /*
  * Print out result of unit test efd operation.
  */
-#if defined(UNIT_TEST_EFD_VERBOSE)
-
 static void print_key_info(const char *msg, const struct flow_key *key,
 		efd_value_t val)
 {
-	const uint8_t *p = (const uint8_t *) key;
-	unsigned int i;
+	if (rte_log_get_level(RTE_LOGTYPE_EFD) == RTE_LOG_DEBUG) {
+		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(" @ val %d\n", val);
-}
-#else
+		printf("%s key:0x", msg);
+		for (i = 0; i < sizeof(struct flow_key); i++)
+			printf("%02X", p[i]);
 
-static void print_key_info(__attribute__((unused)) const char *msg,
-		__attribute__((unused)) const struct flow_key *key,
-		__attribute__((unused)) efd_value_t val)
-{
+		printf(" @ val %d\n", val);
+	}
 }
-#endif
 
 /* Keys used by unit test functions */
 static struct flow_key keys[5] = {
Signature · 1 line
2.17.1
#8 lore raw

PATCH v2 3/3 test/timer: enable unit test compilation always

In reply to Dharmik Thakkar

This patch replaces macro with log-level based approach to print debug information. Need to set timer log type to debug using the following eal parameter: --log-level=timer,8

---
v2:
* Add Reviewed-by tag

---
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
test/test/test_timer_racecond.c +10 -13
index d29048eaf1bf..5ac248b2d90b 100644
@@ -44,8 +44,6 @@
 #include <rte_malloc.h>
 #include <rte_pause.h>
 
-#undef TEST_TIMER_RACECOND_VERBOSE
-
 #ifdef RTE_EXEC_ENV_LINUXAPP
 #define usec_delay(us) usleep(us)
 #else
@@ -70,13 +68,12 @@ timer_cb(struct rte_timer *tim, void *arg __rte_unused)
 {
 	/* Simulate slow callback function, 100 us. */
 	rte_delay_us(100);
-
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-	if (tim == &timer[0])
-		printf("------------------------------------------------\n");
-	printf("timer_cb: core %u timer %lu\n",
-		rte_lcore_id(), tim - timer);
-#endif
+	if (rte_log_get_level(RTE_LOGTYPE_TIMER) == RTE_LOG_DEBUG) {
+		if (tim == &timer[0])
+			printf("------------------------------------------------\n");
+		printf("%s: core %u timer %lu\n", __func__,
+			rte_lcore_id(), tim - timer);
+	}
 	(void)reload_timer(tim);
 }
 
@@ -96,10 +93,10 @@ reload_timer(struct rte_timer *tim)
 
 	ret = rte_timer_reset(tim, ticks, PERIODICAL, master, timer_cb, NULL);
 	if (ret != 0) {
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-		printf("- core %u failed to reset timer %lu (OK)\n",
-			rte_lcore_id(), tim - timer);
-#endif
+		if (rte_log_get_level(RTE_LOGTYPE_TIMER) == RTE_LOG_DEBUG) {
+			printf("- core %u failed to reset timer %lu (OK)\n",
+				rte_lcore_id(), tim - timer);
+		}
 		RTE_PER_LCORE(n_reset_collisions) += 1;
 	}
 	return ret;
Signature · 1 line
2.17.1
#9 lore raw

v3 cover Replace compilation time options with log level

In reply to Dharmik Thakkar

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

 test/test/test_efd.c            | 24 ++++++++----------------
 test/test/test_hash.c           |  3 +--
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 3 files changed, 19 insertions(+), 31 deletions(-)
Signature · 1 line
2.17.1
#10 lore raw

PATCH v3 1/3 test/hash: replace macro with log-level approach

Need to set hash log type to debug to print debug information, using following eal parameter: --log-type=hash,8

---
v3:
* Resolve coding style issues
---
v2:
* Add Reviewed-by tag

---
 test/test/test_hash.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
test/test/test_hash.c +1 -2
index fe607fadf262..67b8e54bdf13 100644
@@ -80,14 +80,13 @@ 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.
  */
 static void print_key_info(const char *msg, const struct flow_key *key,
 								int32_t pos)
 {
-	if (UNIT_TEST_HASH_VERBOSE) {
+	if (rte_log_get_level(RTE_LOGTYPE_HASH) == RTE_LOG_DEBUG) {
 		const uint8_t *p = (const uint8_t *)key;
 		unsigned int i;
 
Signature · 1 line
2.17.1
#11 lore raw

PATCH v3 2/3 test/efd: enable unit test compilation always

In reply to Dharmik Thakkar

This patch enables compilation of print_key_info() always using log-level based approach instead of a macro. Need to set efd log type to debug to print debug information, using the following eal parameter:
--log-type=efd,8

---
v3:
* Resolve coding style issues
---
v2:
* Add Reviewed-by tag

---
 test/test/test_efd.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
test/test/test_efd.c +8 -16
index ced091aab63d..3b6f9db13565 100644
@@ -34,28 +34,20 @@ struct flow_key {
 /*
  * Print out result of unit test efd operation.
  */
-#if defined(UNIT_TEST_EFD_VERBOSE)
-
 static void print_key_info(const char *msg, const struct flow_key *key,
 		efd_value_t val)
 {
-	const uint8_t *p = (const uint8_t *) key;
-	unsigned int i;
+	if (rte_log_get_level(RTE_LOGTYPE_EFD) == RTE_LOG_DEBUG) {
+		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(" @ val %d\n", val);
-}
-#else
+		printf("%s key:0x", msg);
+		for (i = 0; i < sizeof(struct flow_key); i++)
+			printf("%02X", p[i]);
 
-static void print_key_info(__attribute__((unused)) const char *msg,
-		__attribute__((unused)) const struct flow_key *key,
-		__attribute__((unused)) efd_value_t val)
-{
+		printf(" @ val %d\n", val);
+	}
 }
-#endif
 
 /* Keys used by unit test functions */
 static struct flow_key keys[5] = {
Signature · 1 line
2.17.1
#12 lore raw

PATCH v3 3/3 test/timer: enable unit test compilation always

In reply to Dharmik Thakkar

This patch replaces macro with log-level based approach to print debug information. Need to set timer log type to debug using the following eal parameter: --log-level=timer,8

---
v3:
* Resolve coding style issues
---
v2:
* Add Reviewed-by tag

---
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
test/test/test_timer_racecond.c +10 -13
index d29048eaf1bf..5ac248b2d90b 100644
@@ -44,8 +44,6 @@
 #include <rte_malloc.h>
 #include <rte_pause.h>
 
-#undef TEST_TIMER_RACECOND_VERBOSE
-
 #ifdef RTE_EXEC_ENV_LINUXAPP
 #define usec_delay(us) usleep(us)
 #else
@@ -70,13 +68,12 @@ timer_cb(struct rte_timer *tim, void *arg __rte_unused)
 {
 	/* Simulate slow callback function, 100 us. */
 	rte_delay_us(100);
-
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-	if (tim == &timer[0])
-		printf("------------------------------------------------\n");
-	printf("timer_cb: core %u timer %lu\n",
-		rte_lcore_id(), tim - timer);
-#endif
+	if (rte_log_get_level(RTE_LOGTYPE_TIMER) == RTE_LOG_DEBUG) {
+		if (tim == &timer[0])
+			printf("------------------------------------------------\n");
+		printf("%s: core %u timer %lu\n", __func__,
+			rte_lcore_id(), tim - timer);
+	}
 	(void)reload_timer(tim);
 }
 
@@ -96,10 +93,10 @@ reload_timer(struct rte_timer *tim)
 
 	ret = rte_timer_reset(tim, ticks, PERIODICAL, master, timer_cb, NULL);
 	if (ret != 0) {
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-		printf("- core %u failed to reset timer %lu (OK)\n",
-			rte_lcore_id(), tim - timer);
-#endif
+		if (rte_log_get_level(RTE_LOGTYPE_TIMER) == RTE_LOG_DEBUG) {
+			printf("- core %u failed to reset timer %lu (OK)\n",
+				rte_lcore_id(), tim - timer);
+		}
 		RTE_PER_LCORE(n_reset_collisions) += 1;
 	}
 	return ret;
Signature · 1 line
2.17.1
#13 lore raw
In reply to Dharmik Thakkar
Quoted 13 lines · On Wed, 20 Feb 2019 17:00:20 -0600 Dharmik Thakkar <[email protected]>…

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

Quoted 5 lines
 test/test/test_efd.c            | 24 ++++++++----------------
 test/test/test_hash.c           |  3 +--
 test/test/test_timer_racecond.c | 23 ++++++++++-------------
 3 files changed, 19 insertions(+), 31 deletions(-)

Maybe the tests should use their own dynamic logging (i.e. --log-level=test.hash:debug)

#14 lore raw
Quoted 20 lines · Stephen Hemminger
Quoted 13 lines · On Wed, 20 Feb 2019 17:00:20 -0600 Dharmik Thakkar <[email protected]>…

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach
test/efd: enable unit test compilation always
test/timer: enable unit test compilation always

Quoted 7 lines
Quoted 5 lines
test/test/test_efd.c            | 24 ++++++++----------------
test/test/test_hash.c           |  3 +--
test/test/test_timer_racecond.c | 23 ++++++++++-------------
3 files changed, 19 insertions(+), 31 deletions(-)

Maybe the tests should use their own dynamic logging (i.e. --log-level=test.hash:debug)

Updated. Thank you!

#15 lore raw

v4 cover Replace compilation time options with log level

In reply to Dharmik Thakkar

Currently, in test code, for printing extra information, compilation time options are used. This approach does not compile the code always. Macro needs to be set for the code to compile.

This patchset replaces compilation time option with log level based approach, thus enabling compilation of code always. Log levels can be set using eal parameters.

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

 test/test/test_efd.c            | 24 +++++++++++-------------
 test/test/test_hash.c           | 24 ++++++++++++++----------
 test/test/test_timer_racecond.c | 24 +++++++++++++-----------
 3 files changed, 38 insertions(+), 34 deletions(-)
Signature · 1 line
2.17.1
#16 lore raw

PATCH v4 1/3 test/hash: replace macro with log-level approach

Need to set hash log type to debug to print debug information, using following eal parameter: --log-level=test.hash:debug

---
v4:
* change to dynamic logging (Stephen Hemminger)
---
v3:
* Resolve coding style issues
---
v2:
* Add Reviewed-by tag

---
 test/test/test_hash.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
test/test/test_hash.c +14 -10
index fe607fadf262..390fbef87f42 100644
@@ -69,6 +69,8 @@ struct flow_key {
 	uint8_t proto;
 } __attribute__((packed));
 
+int hash_logtype_test;
+
 /*
  * Hash function that always returns the same value, to easily test what
  * happens when a bucket is full.
@@ -80,22 +82,24 @@ static uint32_t pseudo_hash(__attribute__((unused)) const void *keys,
 	return 3;
 }
 
-#define UNIT_TEST_HASH_VERBOSE	0
+RTE_INIT(test_hash_init_log)
+{
+	hash_logtype_test = rte_log_register("test.hash");
+}
+
 /*
  * Print out result of unit test hash operation.
  */
 static void print_key_info(const char *msg, const struct flow_key *key,
 								int32_t pos)
 {
-	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);
-	}
+	const uint8_t *p = (const uint8_t *)key;
+	unsigned int i;
+
+	rte_log(RTE_LOG_DEBUG, hash_logtype_test, "%s key:0x", msg);
+	for (i = 0; i < sizeof(struct flow_key); i++)
+		rte_log(RTE_LOG_DEBUG, hash_logtype_test, "%02X", p[i]);
+	rte_log(RTE_LOG_DEBUG, hash_logtype_test, " @ pos %d\n", pos);
 }
 
 /* Keys used by unit test functions */
Signature · 1 line
2.17.1
#17 lore raw

PATCH v4 2/3 test/efd: enable unit test compilation always

In reply to Dharmik Thakkar

This patch enables compilation of print_key_info() always using log-level based approach instead of a macro. Need to set efd log type to debug to print debug information, using the following eal parameter:
--log-level=test.efd:debug

---
v4:
* change to dynamic logging (Stephen Hemminger)
---
v3:
* Resolve coding style issues
---
v2:
* Add Reviewed-by tag

---
 test/test/test_efd.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
test/test/test_efd.c +11 -13
index ced091aab63d..93e8f1cbb8bd 100644
@@ -31,31 +31,29 @@ struct flow_key {
 	uint16_t port_dst;
 	uint8_t proto;
 } __attribute__((packed));
+
+int efd_logtype_test;
+
+RTE_INIT(test_efd_init_log)
+{
+	efd_logtype_test = rte_log_register("test.efd");
+}
+
 /*
  * Print out result of unit test efd operation.
  */
-#if defined(UNIT_TEST_EFD_VERBOSE)
-
 static void print_key_info(const char *msg, const struct flow_key *key,
 		efd_value_t val)
 {
 	const uint8_t *p = (const uint8_t *) key;
 	unsigned int i;
 
-	printf("%s key:0x", msg);
+	rte_log(RTE_LOG_DEBUG, efd_logtype_test, "%s key:0x", msg);
 	for (i = 0; i < sizeof(struct flow_key); i++)
-		printf("%02X", p[i]);
+		rte_log(RTE_LOG_DEBUG, efd_logtype_test, "%02X", p[i]);
 
-	printf(" @ val %d\n", val);
+	rte_log(RTE_LOG_DEBUG, efd_logtype_test, " @ val %d\n", val);
 }
-#else
-
-static void print_key_info(__attribute__((unused)) const char *msg,
-		__attribute__((unused)) const struct flow_key *key,
-		__attribute__((unused)) efd_value_t val)
-{
-}
-#endif
 
 /* Keys used by unit test functions */
 static struct flow_key keys[5] = {
Signature · 1 line
2.17.1
#18 lore raw

PATCH v4 3/3 test/timer: enable unit test compilation always

In reply to Dharmik Thakkar

This patch replaces macro with log-level based approach to print debug information. Need to set timer log type to debug using the following eal parameter: --log-level=test.timer:debug

---
v4:
* change to dynamic logging (Stephen Hemminger)
---
v3:
* Resolve coding style issues
---
v2:
* Add Reviewed-by tag

---
 test/test/test_timer_racecond.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
test/test/test_timer_racecond.c +13 -11
index d29048eaf1bf..62b73f886a1f 100644
@@ -44,8 +44,6 @@
 #include <rte_malloc.h>
 #include <rte_pause.h>
 
-#undef TEST_TIMER_RACECOND_VERBOSE
-
 #ifdef RTE_EXEC_ENV_LINUXAPP
 #define usec_delay(us) usleep(us)
 #else
@@ -65,18 +63,23 @@ static volatile unsigned stop_slaves;
 
 static int reload_timer(struct rte_timer *tim);
 
+int timer_logtype_test;
+
+RTE_INIT(test_timer_init_log)
+{
+	timer_logtype_test = rte_log_register("test.timer");
+}
+
 static void
 timer_cb(struct rte_timer *tim, void *arg __rte_unused)
 {
 	/* Simulate slow callback function, 100 us. */
 	rte_delay_us(100);
-
-#ifdef TEST_TIMER_RACECOND_VERBOSE
 	if (tim == &timer[0])
-		printf("------------------------------------------------\n");
-	printf("timer_cb: core %u timer %lu\n",
-		rte_lcore_id(), tim - timer);
-#endif
+		rte_log(RTE_LOG_DEBUG, timer_logtype_test,
+			"------------------------------------------------\n");
+	rte_log(RTE_LOG_DEBUG, timer_logtype_test, "%s: core %u timer %lu\n",
+		__func__, rte_lcore_id(), tim - timer);
 	(void)reload_timer(tim);
 }
 
@@ -96,10 +99,9 @@ reload_timer(struct rte_timer *tim)
 
 	ret = rte_timer_reset(tim, ticks, PERIODICAL, master, timer_cb, NULL);
 	if (ret != 0) {
-#ifdef TEST_TIMER_RACECOND_VERBOSE
-		printf("- core %u failed to reset timer %lu (OK)\n",
+		rte_log(RTE_LOG_DEBUG, timer_logtype_test,
+			"- core %u failed to reset timer %lu (OK)\n",
 			rte_lcore_id(), tim - timer);
-#endif
 		RTE_PER_LCORE(n_reset_collisions) += 1;
 	}
 	return ret;
Signature · 1 line
2.17.1
#19 lore raw
In reply to Dharmik Thakkar
Quoted 4 lines

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

Applied, thanks

#20 lore raw

28/03/2019 19:26, Thomas Monjalon:

Quoted 6 lines
Quoted 4 lines

Dharmik Thakkar (3):
test/hash: replace macro with log-level approach test/efd: enable unit test compilation always test/timer: enable unit test compilation always

Applied, thanks

PS: for 32-bit build, I had to replace "%lu" by "%"PRIuPTR. in third patch (app/test/test_timer_racecond.c).