Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel Make the t_subr_prf test build after changes to...



details:   https://anonhg.NetBSD.org/src/rev/c8770e65beac
branches:  trunk
changeset: 456636:c8770e65beac
user:      kre <kre%NetBSD.org@localhost>
date:      Tue May 21 03:46:45 2019 +0000

description:
Make the t_subr_prf test build after changes to sys/kern/subr_prf.c
and while here add a simple test for the new kernel vasprintf().

diffstat:

 tests/kernel/gen_t_subr_prf |  38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r 77d3425e3150 -r c8770e65beac tests/kernel/gen_t_subr_prf
--- a/tests/kernel/gen_t_subr_prf       Tue May 21 03:42:52 2019 +0000
+++ b/tests/kernel/gen_t_subr_prf       Tue May 21 03:46:45 2019 +0000
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sha2.h>
 
@@ -16,11 +17,14 @@
 #undef vsnprintf
 #undef sprintf
 #undef vsprintf
+#undef vasprintf
 
 #define KPRINTF_BUFSIZE 1024
 #undef putchar
 #define putchar xputchar
 
+#define        kmem_alloc(n, f)        malloc(n)
+
 static int putchar(char c, int foo, void *b)
 {
        return fputc(c, stderr);
@@ -112,12 +116,46 @@
        ATF_CHECK_EQ(i, 16);
 }
 
+ATF_TC(vasprintf_print);
+ATF_TC_HEAD(vasprintf_print, tc)
+{
+        atf_tc_set_md_var(tc, "descr", "checks vasprintf works");
+}
+
+int vasp_helper(char **, const char *, ...);
+
+int
+vasp_helper(char **buf, const char *fmt, ...)
+{
+       va_list ap;
+       int ret;
+
+       va_start(ap, fmt);
+       ret = vasprintf(buf, fmt, ap);
+       va_end(ap);
+       return ret;
+}
+
+ATF_TC_BODY(vasprintf_print, tc)
+{
+       int i;
+       char *buf;
+
+       buf = NULL;
+       i =  vasp_helper(&buf, "N=%d C=%c S=%s", 7, 'x', "abc");
+       ATF_CHECK_EQ(i, 13);
+       ATF_CHECK(buf != NULL);
+       ATF_CHECK_STREQ(buf, "N=7 C=x S=abc");
+       free(buf);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
         ATF_TP_ADD_TC(tp, snprintf_print);
         ATF_TP_ADD_TC(tp, snprintf_print_overflow);
         ATF_TP_ADD_TC(tp, snprintf_count);
         ATF_TP_ADD_TC(tp, snprintf_count_overflow);
+       ATF_TP_ADD_TC(tp, vasprintf_print);
 
         return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index