gen_t_subr_prf revision 272343
1272343Sngie#!/bin/sh 2272343Sngie 3272343Sngiecat << _EOF > $2 4272343Sngie#include <sys/types.h> 5272343Sngie#include <sys/time.h> 6272343Sngie#include <stdio.h> 7272343Sngie#include <stdarg.h> 8272343Sngie#include <stdint.h> 9272343Sngie#include <string.h> 10272343Sngie#include <sha2.h> 11272343Sngie 12272343Sngie#include <atf-c.h> 13272343Sngie 14272343Sngie/* Avoid SSP re-definitions */ 15272343Sngie#undef snprintf 16272343Sngie#undef vsnprintf 17272343Sngie#undef sprintf 18272343Sngie#undef vsprintf 19272343Sngie 20272343Sngie#define KPRINTF_BUFSIZE 1024 21272343Sngie#undef putchar 22272343Sngie#define putchar xputchar 23272343Sngie 24272343Sngiestatic int putchar(char c, int foo, void *b) 25272343Sngie{ 26272343Sngie return fputc(c, stderr); 27272343Sngie} 28272343Sngie 29272343Sngie#define TOBUFONLY 1 30272343Sngiestatic const char HEXDIGITS[] = "0123456789ABCDEF"; 31272343Sngiestatic const char hexdigits[] = "0123456789abcdef"; 32272343Sngie 33272343Sngietypedef int device_t; 34272343Sngie 35272343Sngie#if 0 36272343Sngiestatic SHA512_CTX kprnd_sha; 37272343Sngie#endif 38272343Sngie 39272343Sngie#define timespec timeval 40272343Sngie#define nanotime(ts) gettimeofday(ts, NULL) 41272343Sngie 42272343Sngie#define device_xname(a) "" 43272343Sngieint kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0); 44272343Sngievoid device_printf(device_t, const char *, ...) __printflike(2, 3); 45272343Sngie 46272343Sngiestatic void 47272343Sngieempty(void) 48272343Sngie{ 49272343Sngie} 50272343Sngie 51272343Sngiestatic void (*v_flush)(void) = empty; 52272343Sngie 53272343SngieATF_TC(snprintf_print); 54272343SngieATF_TC_HEAD(snprintf_print, tc) 55272343Sngie{ 56272343Sngie atf_tc_set_md_var(tc, "descr", "checks snprintf print"); 57272343Sngie} 58272343Sngie 59272343SngieATF_TC_BODY(snprintf_print, tc) 60272343Sngie{ 61272343Sngie char buf[10]; 62272343Sngie int i; 63272343Sngie 64272343Sngie memset(buf, 'x', sizeof(buf)); 65272343Sngie i = snprintf(buf, sizeof(buf), "number %d", 10); 66272343Sngie ATF_CHECK_EQ(i, 9); 67272343Sngie ATF_CHECK_STREQ(buf, "number 10"); 68272343Sngie} 69272343Sngie 70272343SngieATF_TC(snprintf_print_overflow); 71272343SngieATF_TC_HEAD(snprintf_print_overflow, tc) 72272343Sngie{ 73272343Sngie atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow"); 74272343Sngie} 75272343Sngie 76272343SngieATF_TC_BODY(snprintf_print_overflow, tc) 77272343Sngie{ 78272343Sngie char buf[10]; 79272343Sngie int i; 80272343Sngie 81272343Sngie memset(buf, 'x', sizeof(buf)); 82272343Sngie i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10); 83272343Sngie ATF_CHECK_EQ(i, 16); 84272343Sngie ATF_CHECK_STREQ(buf, "fjsdfsdjf"); 85272343Sngie} 86272343Sngie 87272343SngieATF_TC(snprintf_count); 88272343SngieATF_TC_HEAD(snprintf_count, tc) 89272343Sngie{ 90272343Sngie atf_tc_set_md_var(tc, "descr", "checks snprintf count"); 91272343Sngie} 92272343Sngie 93272343SngieATF_TC_BODY(snprintf_count, tc) 94272343Sngie{ 95272343Sngie int i; 96272343Sngie 97272343Sngie i = snprintf(NULL, 20, "number %d", 10); 98272343Sngie ATF_CHECK_EQ(i, 9); 99272343Sngie} 100272343Sngie 101272343SngieATF_TC(snprintf_count_overflow); 102272343SngieATF_TC_HEAD(snprintf_count_overflow, tc) 103272343Sngie{ 104272343Sngie atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow"); 105272343Sngie} 106272343Sngie 107272343SngieATF_TC_BODY(snprintf_count_overflow, tc) 108272343Sngie{ 109272343Sngie int i; 110272343Sngie 111272343Sngie i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10); 112272343Sngie ATF_CHECK_EQ(i, 16); 113272343Sngie} 114272343Sngie 115272343SngieATF_TP_ADD_TCS(tp) 116272343Sngie{ 117272343Sngie ATF_TP_ADD_TC(tp, snprintf_print); 118272343Sngie ATF_TP_ADD_TC(tp, snprintf_print_overflow); 119272343Sngie ATF_TP_ADD_TC(tp, snprintf_count); 120272343Sngie ATF_TP_ADD_TC(tp, snprintf_count_overflow); 121272343Sngie 122272343Sngie return atf_no_error(); 123272343Sngie} 124272343Sngie_EOF 125272343Sngie 126272343Sngieawk ' 127272343Sngie/^snprintf\(/ { 128272343Sngie print prevline 129272343Sngie out = 1 130272343Sngie} 131272343Sngie{ 132272343Sngie if (out) print 133272343Sngie else prevline = $0 134272343Sngie}' $1 >>$2 135