xref: /minix3/tests/kernel/gen_t_subr_prf (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
111be35a1SLionel Sambuc#!/bin/sh
211be35a1SLionel Sambuc
311be35a1SLionel Sambuccat << _EOF > $2
411be35a1SLionel Sambuc#include <sys/types.h>
5*0a6a1f1dSLionel Sambuc#include <sys/time.h>
611be35a1SLionel Sambuc#include <stdio.h>
711be35a1SLionel Sambuc#include <stdarg.h>
811be35a1SLionel Sambuc#include <stdint.h>
911be35a1SLionel Sambuc#include <string.h>
10*0a6a1f1dSLionel Sambuc#include <sha2.h>
1111be35a1SLionel Sambuc
1211be35a1SLionel Sambuc#include <atf-c.h>
1311be35a1SLionel Sambuc
1411be35a1SLionel Sambuc/* Avoid SSP re-definitions */
1511be35a1SLionel Sambuc#undef snprintf
1611be35a1SLionel Sambuc#undef vsnprintf
1711be35a1SLionel Sambuc#undef sprintf
1811be35a1SLionel Sambuc#undef vsprintf
1911be35a1SLionel Sambuc
2011be35a1SLionel Sambuc#define KPRINTF_BUFSIZE 1024
2111be35a1SLionel Sambuc#undef putchar
2211be35a1SLionel Sambuc#define putchar xputchar
23*0a6a1f1dSLionel Sambuc
2411be35a1SLionel Sambucstatic int putchar(char c, int foo, void *b)
2511be35a1SLionel Sambuc{
2611be35a1SLionel Sambuc	return fputc(c, stderr);
2711be35a1SLionel Sambuc}
2811be35a1SLionel Sambuc
2911be35a1SLionel Sambuc#define TOBUFONLY 1
3011be35a1SLionel Sambucstatic const char HEXDIGITS[] = "0123456789ABCDEF";
3111be35a1SLionel Sambucstatic const char hexdigits[] = "0123456789abcdef";
3211be35a1SLionel Sambuc
3311be35a1SLionel Sambuctypedef int device_t;
3411be35a1SLionel Sambuc
35*0a6a1f1dSLionel Sambuc#if 0
36*0a6a1f1dSLionel Sambucstatic SHA512_CTX kprnd_sha;
37*0a6a1f1dSLionel Sambuc#endif
38*0a6a1f1dSLionel Sambuc
39*0a6a1f1dSLionel Sambuc#define timespec timeval
40*0a6a1f1dSLionel Sambuc#define nanotime(ts) gettimeofday(ts, NULL)
41*0a6a1f1dSLionel Sambuc
4211be35a1SLionel Sambuc#define device_xname(a) ""
4311be35a1SLionel Sambucint kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0);
4411be35a1SLionel Sambucvoid device_printf(device_t, const char *, ...) __printflike(2, 3);
4511be35a1SLionel Sambuc
4611be35a1SLionel Sambucstatic void
4711be35a1SLionel Sambucempty(void)
4811be35a1SLionel Sambuc{
4911be35a1SLionel Sambuc}
5011be35a1SLionel Sambuc
5111be35a1SLionel Sambucstatic void (*v_flush)(void) = empty;
5211be35a1SLionel Sambuc
5311be35a1SLionel SambucATF_TC(snprintf_print);
5411be35a1SLionel SambucATF_TC_HEAD(snprintf_print, tc)
5511be35a1SLionel Sambuc{
5611be35a1SLionel Sambuc        atf_tc_set_md_var(tc, "descr", "checks snprintf print");
5711be35a1SLionel Sambuc}
5811be35a1SLionel Sambuc 
5911be35a1SLionel SambucATF_TC_BODY(snprintf_print, tc)
6011be35a1SLionel Sambuc{
6111be35a1SLionel Sambuc	char buf[10];
6211be35a1SLionel Sambuc	int i;
6311be35a1SLionel Sambuc
6411be35a1SLionel Sambuc	memset(buf, 'x', sizeof(buf));
6511be35a1SLionel Sambuc	i = snprintf(buf, sizeof(buf), "number %d", 10);
6611be35a1SLionel Sambuc	ATF_CHECK_EQ(i, 9);
6711be35a1SLionel Sambuc	ATF_CHECK_STREQ(buf, "number 10");
6811be35a1SLionel Sambuc}
6911be35a1SLionel Sambuc
7011be35a1SLionel SambucATF_TC(snprintf_print_overflow);
7111be35a1SLionel SambucATF_TC_HEAD(snprintf_print_overflow, tc)
7211be35a1SLionel Sambuc{
7311be35a1SLionel Sambuc        atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow");
7411be35a1SLionel Sambuc}
7511be35a1SLionel Sambuc 
7611be35a1SLionel SambucATF_TC_BODY(snprintf_print_overflow, tc)
7711be35a1SLionel Sambuc{
7811be35a1SLionel Sambuc	char buf[10];
7911be35a1SLionel Sambuc	int i;
8011be35a1SLionel Sambuc
8111be35a1SLionel Sambuc	memset(buf, 'x', sizeof(buf));
8211be35a1SLionel Sambuc	i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10);
8311be35a1SLionel Sambuc	ATF_CHECK_EQ(i, 16);
8411be35a1SLionel Sambuc	ATF_CHECK_STREQ(buf, "fjsdfsdjf");
8511be35a1SLionel Sambuc}
8611be35a1SLionel Sambuc
8711be35a1SLionel SambucATF_TC(snprintf_count);
8811be35a1SLionel SambucATF_TC_HEAD(snprintf_count, tc)
8911be35a1SLionel Sambuc{
9011be35a1SLionel Sambuc        atf_tc_set_md_var(tc, "descr", "checks snprintf count");
9111be35a1SLionel Sambuc}
9211be35a1SLionel Sambuc 
9311be35a1SLionel SambucATF_TC_BODY(snprintf_count, tc)
9411be35a1SLionel Sambuc{
9511be35a1SLionel Sambuc	int i;
9611be35a1SLionel Sambuc	
9711be35a1SLionel Sambuc	i = snprintf(NULL, 20, "number %d", 10);
9811be35a1SLionel Sambuc	ATF_CHECK_EQ(i, 9);
9911be35a1SLionel Sambuc}
10011be35a1SLionel Sambuc
10111be35a1SLionel SambucATF_TC(snprintf_count_overflow);
10211be35a1SLionel SambucATF_TC_HEAD(snprintf_count_overflow, tc)
10311be35a1SLionel Sambuc{
10411be35a1SLionel Sambuc        atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow");
10511be35a1SLionel Sambuc}
10611be35a1SLionel Sambuc 
10711be35a1SLionel SambucATF_TC_BODY(snprintf_count_overflow, tc)
10811be35a1SLionel Sambuc{
10911be35a1SLionel Sambuc	int i;
11011be35a1SLionel Sambuc
11111be35a1SLionel Sambuc	i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10);
11211be35a1SLionel Sambuc	ATF_CHECK_EQ(i, 16);
11311be35a1SLionel Sambuc}
11411be35a1SLionel Sambuc
11511be35a1SLionel SambucATF_TP_ADD_TCS(tp)
11611be35a1SLionel Sambuc{
11711be35a1SLionel Sambuc        ATF_TP_ADD_TC(tp, snprintf_print);
11811be35a1SLionel Sambuc        ATF_TP_ADD_TC(tp, snprintf_print_overflow);
11911be35a1SLionel Sambuc        ATF_TP_ADD_TC(tp, snprintf_count);
12011be35a1SLionel Sambuc        ATF_TP_ADD_TC(tp, snprintf_count_overflow);
12111be35a1SLionel Sambuc
12211be35a1SLionel Sambuc        return atf_no_error();
12311be35a1SLionel Sambuc}
12411be35a1SLionel Sambuc_EOF
12511be35a1SLionel Sambuc
12611be35a1SLionel Sambucawk '
12711be35a1SLionel Sambuc/^snprintf\(/ {
12811be35a1SLionel Sambuc	print prevline
12911be35a1SLionel Sambuc	out = 1
13011be35a1SLionel Sambuc}
13111be35a1SLionel Sambuc{
13211be35a1SLionel Sambuc	if (out) print
13311be35a1SLionel Sambuc	else prevline = $0
13411be35a1SLionel Sambuc}' $1 >>$2
135