From b341bce3a52661c8b23ade9a19fcc163cdd61723 Mon Sep 17 00:00:00 2001 From: Spoorthy Priya Yerabolu Date: Thu, 18 Aug 2022 11:50:35 -0700 Subject: [PATCH] tests: lib: sprintf: migrating lib tests to new ZTEST API Migrating sprintf tests to new ZTEST API. Signed-off-by: Spoorthy Priya Yerabolu --- tests/lib/sprintf/prj.conf | 1 + tests/lib/sprintf/prj_new.conf | 1 + tests/lib/sprintf/prj_picolibc.conf | 1 + tests/lib/sprintf/prj_picolibc_new.conf | 2 +- tests/lib/sprintf/src/main.c | 81 ++++++++++--------------- 5 files changed, 35 insertions(+), 51 deletions(-) diff --git a/tests/lib/sprintf/prj.conf b/tests/lib/sprintf/prj.conf index fa9542e0757..b0ec58d5482 100644 --- a/tests/lib/sprintf/prj.conf +++ b/tests/lib/sprintf/prj.conf @@ -1,4 +1,5 @@ CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_FPU=y CONFIG_TEST_USERSPACE=y CONFIG_ZTEST_FATAL_HOOK=y diff --git a/tests/lib/sprintf/prj_new.conf b/tests/lib/sprintf/prj_new.conf index 880d26742b5..0934c7755eb 100644 --- a/tests/lib/sprintf/prj_new.conf +++ b/tests/lib/sprintf/prj_new.conf @@ -1,5 +1,6 @@ CONFIG_STDOUT_CONSOLE=n CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_FPU=y CONFIG_TEST_USERSPACE=y CONFIG_ZTEST_FATAL_HOOK=y diff --git a/tests/lib/sprintf/prj_picolibc.conf b/tests/lib/sprintf/prj_picolibc.conf index 0577be62e7f..2cb424d0b1e 100644 --- a/tests/lib/sprintf/prj_picolibc.conf +++ b/tests/lib/sprintf/prj_picolibc.conf @@ -1,3 +1,4 @@ CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_PICOLIBC=y CONFIG_PICOLIBC_IO_FLOAT=y diff --git a/tests/lib/sprintf/prj_picolibc_new.conf b/tests/lib/sprintf/prj_picolibc_new.conf index da0379e2c21..907cf0bc20d 100644 --- a/tests/lib/sprintf/prj_picolibc_new.conf +++ b/tests/lib/sprintf/prj_picolibc_new.conf @@ -1,6 +1,6 @@ CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y CONFIG_PICOLIBC=y CONFIG_STDOUT_CONSOLE=n -CONFIG_ZTEST=y CONFIG_TEST_USERSPACE=y CONFIG_ZTEST_FATAL_HOOK=y diff --git a/tests/lib/sprintf/src/main.c b/tests/lib/sprintf/src/main.c index 44c3bc92602..0c7578741a5 100644 --- a/tests/lib/sprintf/src/main.c +++ b/tests/lib/sprintf/src/main.c @@ -78,13 +78,26 @@ union raw_double_u { }; #endif +static int WriteFrmtd_vf(FILE *stream, char *format, ...) +{ + int ret; + va_list args; + + va_start(args, format); + ret = vfprintf(stream, format, args); + va_end(args); + + return ret; +} + /** * * @brief Test sprintf with doubles * */ -void test_sprintf_double(void) +#ifdef CONFIG_STDOUT_CONSOLE +ZTEST(sprintf, test_sprintf_double) { char buffer[400]; union raw_double_u var; @@ -400,7 +413,7 @@ int tvsnprintf(char *s, size_t len, const char *format, ...) * */ -void test_vsnprintf(void) +ZTEST(sprintf, test_vsnprintf) { int len; char buffer[100]; @@ -455,7 +468,7 @@ int tvsprintf(char *s, const char *format, ...) * */ -void test_vsprintf(void) +ZTEST(sprintf, test_vsprintf) { int len; char buffer[100]; @@ -481,7 +494,7 @@ void test_vsprintf(void) * */ -void test_snprintf(void) +ZTEST(sprintf, test_snprintf) { #if defined(__GNUC__) && __GNUC__ >= 7 /* @@ -530,7 +543,7 @@ void test_snprintf(void) * */ -void test_sprintf_misc(void) +ZTEST(sprintf, test_sprintf_misc) { int count; char buffer[100]; @@ -597,7 +610,7 @@ void test_sprintf_misc(void) * @brief Test the sprintf() routine with integers * */ -void test_sprintf_integer(void) +ZTEST(sprintf, test_sprintf_integer) { int len; char buffer[100]; @@ -720,7 +733,7 @@ void test_sprintf_integer(void) * */ -void test_sprintf_string(void) +ZTEST(sprintf, test_sprintf_string) { char buffer[400]; @@ -750,7 +763,7 @@ void test_sprintf_string(void) * @see printf(). * */ -void test_print(void) +ZTEST(sprintf, test_print) { int ret; @@ -768,7 +781,7 @@ void test_print(void) * @see fprintf(). * */ -void test_fprintf(void) +ZTEST(sprintf, test_fprintf) { int ret, i = 3; @@ -791,19 +804,7 @@ void test_fprintf(void) * */ -static int WriteFrmtd_vf(FILE *stream, char *format, ...) -{ - int ret; - va_list args; - - va_start(args, format); - ret = vfprintf(stream, format, args); - va_end(args); - - return ret; -} - -void test_vfprintf(void) +ZTEST(sprintf, test_vfprintf) { int ret; @@ -846,7 +847,7 @@ static int WriteFrmtd_v(char *format, ...) return ret; } -void test_vprintf(void) +ZTEST(sprintf, test_vprintf) { int ret; @@ -872,7 +873,7 @@ void test_vprintf(void) * * @see fputs(), puts(), fputc(), putc(). */ -void test_put(void) +ZTEST(sprintf, test_put) { int ret; @@ -918,7 +919,7 @@ void test_put(void) * @brief Test fwrite function * */ -void test_fwrite(void) +ZTEST(sprintf, test_fwrite) { int ret; @@ -942,7 +943,9 @@ void test_fwrite(void) * @details When CONFIG_STDOUT_CONSOLE=n the default * stdout hook function _stdout_hook_default() returns EOF. */ -void test_EOF(void) + +#else +ZTEST(sprintf, test_EOF) { int ret; @@ -958,6 +961,7 @@ void test_EOF(void) ret = WriteFrmtd_vf(stdout, "This %d", 3); zassert_equal(ret, EOF, "vfprintf \"3\" failed"); } +#endif /** * @} @@ -969,27 +973,4 @@ void test_EOF(void) * */ -void test_main(void) -{ -#ifndef CONFIG_STDOUT_CONSOLE - ztest_test_suite(test_sprintf, - ztest_user_unit_test(test_EOF)); - ztest_run_test_suite(test_sprintf); -#else - ztest_test_suite(test_sprintf, - ztest_unit_test(test_sprintf_misc), - ztest_unit_test(test_sprintf_double), - ztest_unit_test(test_sprintf_integer), - ztest_unit_test(test_vsprintf), - ztest_unit_test(test_vsnprintf), - ztest_unit_test(test_sprintf_string), - ztest_unit_test(test_snprintf), - ztest_unit_test(test_print), - ztest_unit_test(test_fprintf), - ztest_unit_test(test_vfprintf), - ztest_unit_test(test_vprintf), - ztest_user_unit_test(test_put), - ztest_user_unit_test(test_fwrite)); - ztest_run_test_suite(test_sprintf); -#endif -} +ZTEST_SUITE(sprintf, NULL, NULL, NULL, NULL, NULL);