gen_t_subr_prf revision 1.3
11.1Schristos#!/bin/sh 21.1Schristos 31.1Schristoscat << _EOF > $2 41.1Schristos#include <sys/types.h> 51.1Schristos#include <stdio.h> 61.1Schristos#include <stdarg.h> 71.1Schristos#include <stdint.h> 81.1Schristos#include <string.h> 91.1Schristos 101.1Schristos#include <atf-c.h> 111.1Schristos 121.3Schristos/* Avoid SSP re-definitions */ 131.3Schristos#undef snprintf 141.3Schristos#undef vsnprintf 151.3Schristos#undef sprintf 161.3Schristos#undef vsprintf 171.3Schristos 181.1Schristos#define KPRINTF_BUFSIZE 1024 191.1Schristos#undef putchar 201.1Schristos#define putchar xputchar 211.1Schristosstatic int putchar(char c, int foo, void *b) 221.1Schristos{ 231.1Schristos return fputc(c, stderr); 241.1Schristos} 251.1Schristos 261.1Schristos#define TOBUFONLY 1 271.1Schristosstatic const char HEXDIGITS[] = "0123456789ABCDEF"; 281.1Schristosstatic const char hexdigits[] = "0123456789abcdef"; 291.1Schristos 301.1Schristostypedef int device_t; 311.1Schristos 321.1Schristos#define device_xname(a) "" 331.2Sjoergint kprintf(const char *, int, void *, char *, va_list) __printflike(1, 0); 341.2Sjoergvoid device_printf(device_t, const char *, ...) __printflike(2, 3); 351.1Schristos 361.1Schristosstatic void 371.1Schristosempty(void) 381.1Schristos{ 391.1Schristos} 401.1Schristos 411.1Schristosstatic void (*v_flush)(void) = empty; 421.1Schristos 431.1SchristosATF_TC(snprintf_print); 441.1SchristosATF_TC_HEAD(snprintf_print, tc) 451.1Schristos{ 461.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf print"); 471.1Schristos} 481.1Schristos 491.1SchristosATF_TC_BODY(snprintf_print, tc) 501.1Schristos{ 511.1Schristos char buf[10]; 521.1Schristos int i; 531.1Schristos 541.1Schristos memset(buf, 'x', sizeof(buf)); 551.1Schristos i = snprintf(buf, sizeof(buf), "number %d", 10); 561.1Schristos ATF_CHECK_EQ(i, 9); 571.1Schristos ATF_CHECK_STREQ(buf, "number 10"); 581.1Schristos} 591.1Schristos 601.1SchristosATF_TC(snprintf_print_overflow); 611.1SchristosATF_TC_HEAD(snprintf_print_overflow, tc) 621.1Schristos{ 631.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf print with overflow"); 641.1Schristos} 651.1Schristos 661.1SchristosATF_TC_BODY(snprintf_print_overflow, tc) 671.1Schristos{ 681.1Schristos char buf[10]; 691.1Schristos int i; 701.1Schristos 711.1Schristos memset(buf, 'x', sizeof(buf)); 721.1Schristos i = snprintf(buf, sizeof(buf), "fjsdfsdjfsdf %d\n", 10); 731.1Schristos ATF_CHECK_EQ(i, 16); 741.1Schristos ATF_CHECK_STREQ(buf, "fjsdfsdjf"); 751.1Schristos} 761.1Schristos 771.1SchristosATF_TC(snprintf_count); 781.1SchristosATF_TC_HEAD(snprintf_count, tc) 791.1Schristos{ 801.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf count"); 811.1Schristos} 821.1Schristos 831.1SchristosATF_TC_BODY(snprintf_count, tc) 841.1Schristos{ 851.1Schristos int i; 861.1Schristos 871.1Schristos i = snprintf(NULL, 20, "number %d", 10); 881.1Schristos ATF_CHECK_EQ(i, 9); 891.1Schristos} 901.1Schristos 911.1SchristosATF_TC(snprintf_count_overflow); 921.1SchristosATF_TC_HEAD(snprintf_count_overflow, tc) 931.1Schristos{ 941.1Schristos atf_tc_set_md_var(tc, "descr", "checks snprintf count with overflow"); 951.1Schristos} 961.1Schristos 971.1SchristosATF_TC_BODY(snprintf_count_overflow, tc) 981.1Schristos{ 991.1Schristos int i; 1001.1Schristos 1011.1Schristos i = snprintf(NULL, 10, "fjsdfsdjfsdf %d\n", 10); 1021.1Schristos ATF_CHECK_EQ(i, 16); 1031.1Schristos} 1041.1Schristos 1051.1SchristosATF_TP_ADD_TCS(tp) 1061.1Schristos{ 1071.1Schristos ATF_TP_ADD_TC(tp, snprintf_print); 1081.1Schristos ATF_TP_ADD_TC(tp, snprintf_print_overflow); 1091.1Schristos ATF_TP_ADD_TC(tp, snprintf_count); 1101.1Schristos ATF_TP_ADD_TC(tp, snprintf_count_overflow); 1111.1Schristos 1121.1Schristos return atf_no_error(); 1131.1Schristos} 1141.1Schristos_EOF 1151.1Schristos 1161.1Schristosawk ' 1171.1Schristos/^snprintf\(/ { 1181.1Schristos print prevline 1191.1Schristos out = 1 1201.1Schristos} 1211.1Schristos{ 1221.1Schristos if (out) print 1231.1Schristos else prevline = $0 1241.1Schristos}' $1 >>$2 125