[BACK]Return to gen_t_subr_prf CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / kernel

File: [cvs.NetBSD.org] / src / tests / kernel / gen_t_subr_prf (download)

Revision 1.4, Sun Aug 10 16:44:37 2014 UTC (5 years, 11 months ago) by tls
Branch: MAIN
CVS Tags: tls-maxphys-base, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan
Branch point for: phil-wifi
Changes since 1.3: +10 -0 lines

Merge tls-earlyentropy branch into HEAD.

#!/bin/sh

cat << _EOF > $2
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <sha2.h>

#include <atf-c.h>

/* Avoid SSP re-definitions */
#undef snprintf
#undef vsnprintf
#undef sprintf
#undef vsprintf

#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;

#if 0
static SHA512_CTX kprnd_sha;
#endif

#define timespec timeval
#define nanotime(ts) gettimeofday(ts, NULL)

#define device_xname(a) ""
int kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0);
void device_printf(device_t, const char *, ...) __printflike(2, 3);

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