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().
This commit is contained in:
parent
1d2b0401af
commit
8b2a560acf
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue