gen_t_subr_prf revision 1.3.6.1 1 #!/bin/sh
2
3 cat << _EOF > $2
4 #include <sys/types.h>
5 #include <sys/time.h>
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <sha2.h>
11
12 #include <atf-c.h>
13
14 /* Avoid SSP re-definitions */
15 #undef snprintf
16 #undef vsnprintf
17 #undef sprintf
18 #undef vsprintf
19
20 #define KPRINTF_BUFSIZE 1024
21 #undef putchar
22 #define putchar xputchar
23
24 static int putchar(char c, int foo, void *b)
25 {
26 return fputc(c, stderr);
27 }
28
29 #define TOBUFONLY 1
30 static const char HEXDIGITS[] = "0123456789ABCDEF";
31 static const char hexdigits[] = "0123456789abcdef";
32
33 typedef int device_t;
34
35 static SHA512_CTX kprnd_sha;
36
37 #define timespec timeval
38 #define nanotime(ts) gettimeofday(ts, NULL)
39
40 #define device_xname(a) ""
41 int kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0);
42 void device_printf(device_t, const char *, ...) __printflike(2, 3);
43
44 static void
45 empty(void)
46 {
47 }
48
49 static void (*v_flush)(void) = empty;
50
51 ATF_TC(snprintf_print);
52 ATF_TC_HEAD(snprintf_print, tc)
53 {
54 atf_tc_set_md_var(tc, "descr", "checks snprintf print");
55 }
56
57 ATF_TC_BODY(snprintf_print, tc)
58 {
59 char buf[10];
60 int i;
61
62 memset(buf, 'x', sizeof(buf));
63 i = snprintf(buf, sizeof(buf), "number %d", 10);
64 ATF_CHECK_EQ(i, 9);
65 ATF_CHECK_STREQ(buf, "number 10");
66 }
67
68 ATF_TC(snprintf_print_overflow);
69 ATF_TC_HEAD(snprintf_print_overflow, tc)
70 {
71 atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow");
72 }
73
74 ATF_TC_BODY(snprintf_print_overflow, tc)
75 {
76 char buf[10];
77 int i;
78
79 memset(buf, 'x', sizeof(buf));
80 i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10);
81 ATF_CHECK_EQ(i, 16);
82 ATF_CHECK_STREQ(buf, "fjsdfsdjf");
83 }
84
85 ATF_TC(snprintf_count);
86 ATF_TC_HEAD(snprintf_count, tc)
87 {
88 atf_tc_set_md_var(tc, "descr", "checks snprintf count");
89 }
90
91 ATF_TC_BODY(snprintf_count, tc)
92 {
93 int i;
94
95 i = snprintf(NULL, 20, "number %d", 10);
96 ATF_CHECK_EQ(i, 9);
97 }
98
99 ATF_TC(snprintf_count_overflow);
100 ATF_TC_HEAD(snprintf_count_overflow, tc)
101 {
102 atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow");
103 }
104
105 ATF_TC_BODY(snprintf_count_overflow, tc)
106 {
107 int i;
108
109 i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10);
110 ATF_CHECK_EQ(i, 16);
111 }
112
113 ATF_TP_ADD_TCS(tp)
114 {
115 ATF_TP_ADD_TC(tp, snprintf_print);
116 ATF_TP_ADD_TC(tp, snprintf_print_overflow);
117 ATF_TP_ADD_TC(tp, snprintf_count);
118 ATF_TP_ADD_TC(tp, snprintf_count_overflow);
119
120 return atf_no_error();
121 }
122 _EOF
123
124 awk '
125 /^snprintf\(/ {
126 print prevline
127 out = 1
128 }
129 {
130 if (out) print
131 else prevline = $0
132 }' $1 >>$2
133