Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/kernel Add a test for the kernel snprintf.
details: https://anonhg.NetBSD.org/src/rev/de92f57388a7
branches: trunk
changeset: 771516:de92f57388a7
user: christos <christos%NetBSD.org@localhost>
date: Thu Nov 24 01:46:40 2011 +0000
description:
Add a test for the kernel snprintf.
diffstat:
tests/kernel/Makefile | 10 ++-
tests/kernel/gen_t_subr_prf | 118 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 126 insertions(+), 2 deletions(-)
diffs (158 lines):
diff -r d0620ec53dc9 -r de92f57388a7 tests/kernel/Makefile
--- a/tests/kernel/Makefile Thu Nov 24 01:45:39 2011 +0000
+++ b/tests/kernel/Makefile Thu Nov 24 01:46:40 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.21 2011/10/15 07:00:49 jruoho Exp $
+# $NetBSD: Makefile,v 1.22 2011/11/24 01:46:40 christos Exp $
NOMAN= # defined
@@ -14,6 +14,7 @@
TESTS_C+= t_rnd
TESTS_C+= t_extattrctl
TESTS_C+= t_filedesc
+TESTS_C+= t_subr_prf
TESTS_SH= t_umount
TESTS_SH+= t_ps_strings
@@ -23,7 +24,7 @@
PROGS+= h_ps_strings2
LDADD.t_rnd+= -lrumpvfs -lrumpdev_rnd -lrumpdev -lrump -lrumpuser -lpthread
-LDADD.t_filedesc+= -lrumpvfs -lrumpdev_rnd -lrumpdev -lrump -lrumpuser -lpthread
+LDADD.t_filedesc+= ${LDADD.t_rnd}
LDADD.t_extattrctl+= -lrumpvfs -lrump -lrumpuser -lpthread
.PATH: ${NETBSDSRCDIR}/sys/kern
@@ -32,4 +33,9 @@
CPPFLAGS.t_extent.c= -D_EXTENT_TESTING -D__POOL_EXPOSE
CPPFLAGS.subr_extent.c= -D_EXTENT_TESTING -D__POOL_EXPOSE
+t_subr_prf.c: gen_t_subr_prf ${NETBSDSRCDIR}/sys/kern/subr_prf.c
+ ${HOST_SH} ${.ALLSRC} ${.TARGET}
+
+CLEANFILES+= t_subr_prf.c
+
.include <bsd.test.mk>
diff -r d0620ec53dc9 -r de92f57388a7 tests/kernel/gen_t_subr_prf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/gen_t_subr_prf Thu Nov 24 01:46:40 2011 +0000
@@ -0,0 +1,118 @@
+#!/bin/sh
+
+cat << _EOF > $2
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#define KPRINTF_BUFSIZE 1024
+#undef putchar
+#define putchar xputchar
+static int putchar(char c, int foo, void *b)
+{
+ return fputc(c, stderr);
+}
+
+#define TOBUFONLY 1
+static const char HEXDIGITS[] = "0123456789ABCDEF";
+static const char hexdigits[] = "0123456789abcdef";
+
+typedef int device_t;
+
+#define device_xname(a) ""
+int kprintf(const char *, int, void *, char *, va_list);
+void device_printf(device_t, const char *, ...);
+
+static void
+empty(void)
+{
+}
+
+static void (*v_flush)(void) = empty;
+
+ATF_TC(snprintf_print);
+ATF_TC_HEAD(snprintf_print, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "checks snprintf print");
+}
+
+ATF_TC_BODY(snprintf_print, tc)
+{
+ char buf[10];
+ int i;
+
+ memset(buf, 'x', sizeof(buf));
+ i = snprintf(buf, sizeof(buf), "number %d", 10);
+ ATF_CHECK_EQ(i, 9);
+ ATF_CHECK_STREQ(buf, "number 10");
+}
+
+ATF_TC(snprintf_print_overflow);
+ATF_TC_HEAD(snprintf_print_overflow, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow");
+}
+
+ATF_TC_BODY(snprintf_print_overflow, tc)
+{
+ char buf[10];
+ int i;
+
+ memset(buf, 'x', sizeof(buf));
+ i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10);
+ ATF_CHECK_EQ(i, 16);
+ ATF_CHECK_STREQ(buf, "fjsdfsdjf");
+}
+
+ATF_TC(snprintf_count);
+ATF_TC_HEAD(snprintf_count, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "checks snprintf count");
+}
+
+ATF_TC_BODY(snprintf_count, tc)
+{
+ int i;
+
+ i = snprintf(NULL, 20, "number %d", 10);
+ ATF_CHECK_EQ(i, 9);
+}
+
+ATF_TC(snprintf_count_overflow);
+ATF_TC_HEAD(snprintf_count_overflow, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow");
+}
+
+ATF_TC_BODY(snprintf_count_overflow, tc)
+{
+ int i;
+
+ i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10);
+ ATF_CHECK_EQ(i, 16);
+}
+
+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);
+
+ return atf_no_error();
+}
+_EOF
+
+awk '
+/^snprintf\(/ {
+ print prevline
+ out = 1
+}
+{
+ if (out) print
+ else prevline = $0
+}' $1 >>$2
Home |
Main Index |
Thread Index |
Old Index