Module Name: src
Committed By: kre
Date: Tue May 21 03:46:45 UTC 2019
Modified Files:
src/tests/kernel: gen_t_subr_prf
Log Message:
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().
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/kernel/gen_t_subr_prf
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/kernel/gen_t_subr_prf
diff -u src/tests/kernel/gen_t_subr_prf:1.5 src/tests/kernel/gen_t_subr_prf:1.6
--- src/tests/kernel/gen_t_subr_prf:1.5 Sun Feb 3 10:48:47 2019
+++ src/tests/kernel/gen_t_subr_prf Tue May 21 03:46:45 2019
@@ -6,6 +6,7 @@ cat << _EOF > $2
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
#include <sha2.h>
@@ -16,11 +17,14 @@ cat << _EOF > $2
#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_TC_BODY(snprintf_count_overflow, tc)
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();
}