diff mbox

[v2,3/4] validation: odp_init: add replace log test

Message ID 1421797078-14262-3-git-send-email-mike.holmes@linaro.org
State Accepted
Commit b7396a0d66a0dcccff748014703551fd356543a9
Headers show

Commit Message

Mike Holmes Jan. 20, 2015, 11:37 p.m. UTC
Add a test for the ability to replace the logging function via
init_global

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 test/validation/odp_init.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
diff mbox

Patch

diff --git a/test/validation/odp_init.c b/test/validation/odp_init.c
index 5277d68..c8e5a11 100644
--- a/test/validation/odp_init.c
+++ b/test/validation/odp_init.c
@@ -4,12 +4,17 @@ 
  * SPDX-License-Identifier:     BSD-3-Clause
  */
 
+#include <stdarg.h>
 #include <odp.h>
 #include <CUnit/Basic.h>
 
 #define DEFAULT_MSG_POOL_SIZE	(4*1024*1024)
 #define DEFAULT_MSG_SIZE	(8)
 
+int replacement_logging_used;
+
+static int odp_init_log(odp_log_level_e level , const char *fmt, ...);
+
 static void test_odp_init_global(void)
 {
 	int status;
@@ -20,8 +25,27 @@  static void test_odp_init_global(void)
 	CU_ASSERT(status == 0);
 }
 
+static void test_odp_init_global_replace_log(void)
+{
+	int status;
+	struct odp_init_t init_data;
+
+	init_data.log_fn = &odp_init_log;
+
+	replacement_logging_used = 0;
+
+	status = odp_init_global(&init_data, NULL);
+	CU_ASSERT_FATAL(status == 0);
+
+	CU_ASSERT_TRUE(replacement_logging_used);
+
+	status = odp_term_global();
+	CU_ASSERT(status == 0);
+}
+
 CU_TestInfo test_odp_init[] = {
 	{"test_odp_init_global",  test_odp_init_global},
+	{"replace log",  test_odp_init_global_replace_log},
 	CU_TEST_INFO_NULL,
 };
 
@@ -50,3 +74,19 @@  int main(void)
 
 	return ret;
 }
+
+int odp_init_log(odp_log_level_e level __attribute__((unused)),
+		 const char *fmt, ...)
+{
+	va_list args;
+	int r;
+
+	/* just set a flag to be sure the replacement fn was used */
+	replacement_logging_used = 1;
+
+	va_start(args, fmt);
+	r = vfprintf(stderr, fmt, args);
+	va_end(args);
+
+	return r;
+}