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