1) Moved tprintf and related functions to their own file in common/libc/printf/tprintf.c.

This file is included by both libc and hostcompat.

2) Changed printf -> tprintf in all testbin programs
This commit is contained in:
Scott Haseley 2016-01-15 13:33:11 -05:00
parent 98ff530afb
commit 0ab862abfa
49 changed files with 501 additions and 478 deletions

View File

@ -0,0 +1,63 @@
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <kern/secret.h>
#ifdef HOST
#include "hostcompat.h"
#endif
/* printf variant that is quiet during automated testing */
int
tprintf(const char *fmt, ...)
{
int chars;
va_list ap;
if (strcmp(KERNEL_SECRET, "") != 0) {
return 0;
}
va_start(ap, fmt);
chars = vprintf(fmt, ap);
va_end(ap);
return chars;
}
/* printf variant that is loud during automated testing */
int
nprintf(const char *fmt, ...)
{
int chars;
va_list ap;
if (strcmp(KERNEL_SECRET, "") == 0) {
return 0;
}
va_start(ap, fmt);
chars = vprintf(fmt, ap);
va_end(ap);
return chars;
}
/* printf variant that prepends the kernel secret */
int
printsf(const char *fmt, ...)
{
int chars;
va_list ap;
if (strcmp(KERNEL_SECRET, "") != 0) {
printf("%s: ", KERNEL_SECRET);
}
va_start(ap, fmt);
chars = vprintf(fmt, ap);
va_end(ap);
return chars;
}

View File

@ -22,6 +22,11 @@ TOP=../../..
LIB=hostcompat LIB=hostcompat
SRCS=err.c ntohll.c time.c hostcompat.c SRCS=err.c ntohll.c time.c hostcompat.c
# printf
COMMON=$(TOP)/common/libc
SRCS+=\
$(COMMON)/printf/tprintf.c
HOST_CFLAGS+=$(COMPAT_CFLAGS) HOST_CFLAGS+=$(COMPAT_CFLAGS)
MKDIRS=$(INSTALLTOP)/hostinclude MKDIRS=$(INSTALLTOP)/hostinclude

View File

@ -35,6 +35,13 @@ void hostcompat_init(int argc, char **argv);
time_t __time(time_t *secs, unsigned long *nsecs); time_t __time(time_t *secs, unsigned long *nsecs);
/* Automated testing extensions. */
int tprintf(const char *fmt, ...);
int nprintf(const char *fmt, ...);
int printsf(const char *fmt, ...);
#ifdef DECLARE_NTOHLL #ifdef DECLARE_NTOHLL
uint64_t ntohll(uint64_t); uint64_t ntohll(uint64_t);
#define htonll(x) (ntohll(x)) #define htonll(x) (ntohll(x))

View File

@ -10,7 +10,8 @@ COMMON=$(TOP)/common/libc
# printf # printf
SRCS+=\ SRCS+=\
$(COMMON)/printf/__printf.c \ $(COMMON)/printf/__printf.c \
$(COMMON)/printf/snprintf.c $(COMMON)/printf/snprintf.c \
$(COMMON)/printf/tprintf.c
# stdio # stdio
SRCS+=\ SRCS+=\

View File

@ -78,56 +78,3 @@ vprintf(const char *fmt, va_list ap)
} }
return chars; return chars;
} }
/* printf variant that is quiet during automated testing */
int
tprintf(const char *fmt, ...)
{
int chars;
va_list ap;
if (strcmp(KERNEL_SECRET, "") != 0) {
return 0;
}
va_start(ap, fmt);
chars = vprintf(fmt, ap);
va_end(ap);
return chars;
}
/* printf variant that is loud during automated testing */
int
nprintf(const char *fmt, ...)
{
int chars;
va_list ap;
if (strcmp(KERNEL_SECRET, "") == 0) {
return 0;
}
va_start(ap, fmt);
chars = vprintf(fmt, ap);
va_end(ap);
return chars;
}
/* printf variant that prepends the kernel secret */
int
printsf(const char *fmt, ...)
{
int chars;
va_list ap;
if (strcmp(KERNEL_SECRET, "") != 0) {
printf("%s: ", KERNEL_SECRET);
}
va_start(ap, fmt);
chars = vprintf(fmt, ap);
va_end(ap);
return chars;
}

View File

@ -51,7 +51,7 @@ main(int argc, char *argv[])
i = atoi(argv[1]); i = atoi(argv[1]);
j = atoi(argv[2]); j = atoi(argv[2]);
printf("Answer: %d\n", i+j); tprintf("Answer: %d\n", i+j);
return 0; return 0;
} }

View File

@ -43,14 +43,14 @@ main(int argc, char *argv[])
const char *tmp; const char *tmp;
int i; int i;
printf("argc: %d\n", argc); tprintf("argc: %d\n", argc);
for (i=0; i<=argc; i++) { for (i=0; i<=argc; i++) {
tmp = argv[i]; tmp = argv[i];
if (tmp==NULL) { if (tmp==NULL) {
tmp = "[NULL]"; tmp = "[NULL]";
} }
printf("argv[%d]: %s\n", i, tmp); tprintf("argv[%d]: %s\n", i, tmp);
} }
return 0; return 0;

View File

@ -49,7 +49,7 @@ reboot_badflags(void)
{ {
int rv; int rv;
printf("(This should not kill the system...)\n"); tprintf("(This should not kill the system...)\n");
report_begin("reboot with invalid flags"); report_begin("reboot with invalid flags");
rv = reboot(15353); rv = reboot(15353);
report_check(rv, errno, EINVAL); report_check(rv, errno, EINVAL);

View File

@ -198,20 +198,20 @@ menu(void)
{ {
int i; int i;
for (i=0; ops[i].name; i++) { for (i=0; ops[i].name; i++) {
printf("[%c] %-24s", ops[i].ch, ops[i].name); tprintf("[%c] %-24s", ops[i].ch, ops[i].name);
if (i%2==1) { if (i%2==1) {
printf("\n"); tprintf("\n");
} }
} }
if (i%2==1) { if (i%2==1) {
printf("\n"); tprintf("\n");
} }
printf("[1] %-24s", "asst1"); tprintf("[1] %-24s", "asst1");
printf("[2] %-24s\n", "asst2"); tprintf("[2] %-24s\n", "asst2");
printf("[3] %-24s", "asst3"); tprintf("[3] %-24s", "asst3");
printf("[4] %-24s\n", "asst4"); tprintf("[4] %-24s\n", "asst4");
printf("[*] %-24s", "all"); tprintf("[*] %-24s", "all");
printf("[!] %-24s\n", "quit"); tprintf("[!] %-24s\n", "quit");
} }
static static
@ -231,7 +231,7 @@ runit(int op)
if (op=='*') { if (op=='*') {
for (i=0; ops[i].name; i++) { for (i=0; ops[i].name; i++) {
printf("[%s]\n", ops[i].name); tprintf("[%s]\n", ops[i].name);
ops[i].f(); ops[i].f();
} }
return; return;
@ -241,7 +241,7 @@ runit(int op)
k = op-'0'; k = op-'0';
for (i=0; ops[i].name; i++) { for (i=0; ops[i].name; i++) {
if (ops[i].asst <= k) { if (ops[i].asst <= k) {
printf("[%s]\n", ops[i].name); tprintf("[%s]\n", ops[i].name);
ops[i].f(); ops[i].f();
} }
} }
@ -249,7 +249,7 @@ runit(int op)
} }
if (op < LOWEST || op > HIGHEST) { if (op < LOWEST || op > HIGHEST) {
printf("Invalid request %c\n", op); tprintf("Invalid request %c\n", op);
return; return;
} }
@ -261,12 +261,12 @@ main(int argc, char **argv)
{ {
int op, i, j; int op, i, j;
printf("[%c-%c, 1-4, *, ?=menu, !=quit]\n", LOWEST, HIGHEST); tprintf("[%c-%c, 1-4, *, ?=menu, !=quit]\n", LOWEST, HIGHEST);
if (argc > 1) { if (argc > 1) {
for (i=1; i<argc; i++) { for (i=1; i<argc; i++) {
for (j=0; argv[i][j]; j++) { for (j=0; argv[i][j]; j++) {
printf("Choose: %c\n", tprintf("Choose: %c\n",
argv[i][j]); argv[i][j]);
runit(argv[i][j]); runit(argv[i][j]);
} }
@ -275,12 +275,12 @@ main(int argc, char **argv)
else { else {
menu(); menu();
while (1) { while (1) {
printf("Choose: "); tprintf("Choose: ");
op = getchar(); op = getchar();
if (op==EOF) { if (op==EOF) {
break; break;
} }
printf("%c\n", op); tprintf("%c\n", op);
runit(op); runit(op);
} }
} }

View File

@ -78,7 +78,7 @@ main(int argc, char *argv[])
/* round size up */ /* round size up */
size = ((size + chunksize - 1) / chunksize) * chunksize; size = ((size + chunksize - 1) / chunksize) * chunksize;
printf("Creating a file of size %d in %d-byte chunks\n", tprintf("Creating a file of size %d in %d-byte chunks\n",
size, chunksize); size, chunksize);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC);

View File

@ -223,10 +223,10 @@ dotest(void)
dowait(pids[i]); dowait(pids[i]);
} }
if (failures > 0) { if (failures > 0) {
printf("%u failures.\n", failures); tprintf("%u failures.\n", failures);
} }
else { else {
printf("Done.\n"); tprintf("Done.\n");
} }
} }

View File

@ -182,7 +182,7 @@ static
void void
try_seeking(int fd, off_t pos, off_t cursize) try_seeking(int fd, off_t pos, off_t cursize)
{ {
printf("Seeking to (and near) 0x%llx\n", pos); tprintf("Seeking to (and near) 0x%llx\n", pos);
/* Go to the place. */ /* Go to the place. */
dolseek(fd, pos, SEEK_SET, "SEEK_SET", pos); dolseek(fd, pos, SEEK_SET, "SEEK_SET", pos);
@ -215,30 +215,30 @@ main(void)
off_t cursize; off_t cursize;
int fd; int fd;
printf("Creating file...\n"); tprintf("Creating file...\n");
fd = open(TESTFILE, O_RDWR|O_CREAT|O_TRUNC, 0664); fd = open(TESTFILE, O_RDWR|O_CREAT|O_TRUNC, 0664);
if (fd < 0) { if (fd < 0) {
err(1, "%s", TESTFILE); err(1, "%s", TESTFILE);
} }
printf("Writing something at offset 0\n"); tprintf("Writing something at offset 0\n");
write_slogan(fd, 0, false); write_slogan(fd, 0, false);
cursize = strlen(slogans[0]); cursize = strlen(slogans[0]);
try_seeking(fd, (off_t)0x1000LL, cursize); try_seeking(fd, (off_t)0x1000LL, cursize);
printf("Writing something else\n"); tprintf("Writing something else\n");
write_slogan(fd, 1, false); write_slogan(fd, 1, false);
cursize = (off_t)0x1000LL + strlen(slogans[1]); cursize = (off_t)0x1000LL + strlen(slogans[1]);
try_seeking(fd, (off_t)0, cursize); try_seeking(fd, (off_t)0, cursize);
/* If seek is totally bust, this will fail. */ /* If seek is totally bust, this will fail. */
printf("Checking what we wrote\n"); tprintf("Checking what we wrote\n");
check_slogan(fd, 0); check_slogan(fd, 0);
try_seeking(fd, (off_t)0x1000LL, cursize); try_seeking(fd, (off_t)0x1000LL, cursize);
printf("Checking the other thing we wrote\n"); tprintf("Checking the other thing we wrote\n");
check_slogan(fd, 1); check_slogan(fd, 1);
try_seeking(fd, (off_t)0x20LL, cursize); try_seeking(fd, (off_t)0x20LL, cursize);
@ -250,19 +250,19 @@ main(void)
try_seeking(fd, (off_t)0x180000000LL, cursize); try_seeking(fd, (off_t)0x180000000LL, cursize);
try_seeking(fd, (off_t)0x180000020LL, cursize); try_seeking(fd, (off_t)0x180000020LL, cursize);
printf("Now trying to read (should get EOF)\n"); tprintf("Now trying to read (should get EOF)\n");
try_reading(fd); try_reading(fd);
printf("Now trying to write (should get EFBIG)\n"); tprintf("Now trying to write (should get EFBIG)\n");
try_writing(fd); try_writing(fd);
try_seeking(fd, (off_t)0x100000000LL, cursize); try_seeking(fd, (off_t)0x100000000LL, cursize);
/* If seek truncates to 32 bits, this might read the slogan instead */ /* If seek truncates to 32 bits, this might read the slogan instead */
printf("Trying to read again (should get EOF)\n"); tprintf("Trying to read again (should get EOF)\n");
try_reading(fd); try_reading(fd);
printf("Passed.\n"); tprintf("Passed.\n");
close(fd); close(fd);
remove(TESTFILE); remove(TESTFILE);

View File

@ -131,11 +131,11 @@ static
void void
printsettings(void) printsettings(void)
{ {
printf("Page size: %u\n", PAGE_SIZE); tprintf("Page size: %u\n", PAGE_SIZE);
printf("Allocating %u pages and touching %u pages on each cycle.\n", tprintf("Allocating %u pages and touching %u pages on each cycle.\n",
allocs, touchpages); allocs, touchpages);
printf("Page selection bias: %u\n", bias); tprintf("Page selection bias: %u\n", bias);
printf("\n"); tprintf("\n");
} }
static static

View File

@ -292,7 +292,7 @@ runop(int op)
/* intentionally don't check if op is in bounds :) */ /* intentionally don't check if op is in bounds :) */
opindex = op-'a'; opindex = op-'a';
printf("Running: [%c] %s\n", ops[opindex].ch, ops[opindex].name); tprintf("Running: [%c] %s\n", ops[opindex].ch, ops[opindex].name);
if (forking) { if (forking) {
pid = fork(); pid = fork();
@ -307,25 +307,25 @@ runop(int op)
} }
ok = 0; ok = 0;
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
printf("Signal %d\n", WTERMSIG(status)); tprintf("Signal %d\n", WTERMSIG(status));
if (WTERMSIG(status) == ops[opindex].sig) { if (WTERMSIG(status) == ops[opindex].sig) {
ok = 1; ok = 1;
} }
} }
else { else {
printf("Exit %d\n", WEXITSTATUS(status)); tprintf("Exit %d\n", WEXITSTATUS(status));
if (WEXITSTATUS(status) == MAGIC) { if (WEXITSTATUS(status) == MAGIC) {
ok = 1; ok = 1;
} }
} }
if (ok) { if (ok) {
printf("Ok.\n"); tprintf("Ok.\n");
} }
else { else {
printf("FAILED: expected signal %d\n", tprintf("FAILED: expected signal %d\n",
ops[opindex].sig); ops[opindex].sig);
} }
printf("\n"); tprintf("\n");
return; return;
} }
} }
@ -351,14 +351,14 @@ ask(void)
while (1) { while (1) {
for (i=0; ops[i].name; i++) { for (i=0; ops[i].name; i++) {
printf("[%c] %s\n", ops[i].ch, ops[i].name); tprintf("[%c] %s\n", ops[i].ch, ops[i].name);
} }
printf("[-] Disable forking\n"); tprintf("[-] Disable forking\n");
printf("[+] Enable forking (default)\n"); tprintf("[+] Enable forking (default)\n");
printf("[*] Run everything\n"); tprintf("[*] Run everything\n");
printf("[!] Quit\n"); tprintf("[!] Quit\n");
printf("Choose: "); tprintf("Choose: ");
op = getchar(); op = getchar();
if (op == '!') { if (op == '!') {

View File

@ -64,12 +64,12 @@ main(int argc, char **argv)
stride = atoi(argv[1]); stride = atoi(argv[1]);
} }
if (stride <= 0 || argc > 2) { if (stride <= 0 || argc > 2) {
printf("Usage: ctest [stridesize]\n"); tprintf("Usage: ctest [stridesize]\n");
printf(" stridesize should not be a multiple of 2.\n"); tprintf(" stridesize should not be a multiple of 2.\n");
return 1; return 1;
} }
printf("Starting ctest: stride %d\n", stride); tprintf("Starting ctest: stride %d\n", stride);
/* /*
* Generate a huge linked list, with each entry pointing to * Generate a huge linked list, with each entry pointing to
@ -96,6 +96,6 @@ main(int argc, char **argv)
e = e->e; e = e->e;
} }
printf("\nDone!\n"); tprintf("\nDone!\n");
return 0; return 0;
} }

View File

@ -84,7 +84,7 @@ choose_name(char *buf, size_t len)
/* /*
* The purpose of this is to be atomic. In our world, straight * The purpose of this is to be atomic. In our world, straight
* printf tends not to be. * tprintf tends not to be.
*/ */
static static
void void

View File

@ -205,7 +205,7 @@ firstread(void)
errx(1, ".: File position after open not 0"); errx(1, ".: File position after open not 0");
} }
printf("Scanning directory...\n"); tprintf("Scanning directory...\n");
readit(); readit();
} }
@ -216,7 +216,7 @@ doreadat0(void)
{ {
off_t pos; off_t pos;
printf("Rewinding directory and reading it again...\n"); tprintf("Rewinding directory and reading it again...\n");
pos = lseek(dirfd, 0, SEEK_SET); pos = lseek(dirfd, 0, SEEK_SET);
if (pos < 0) { if (pos < 0) {
@ -274,7 +274,7 @@ readallonebyone(void)
{ {
int i; int i;
printf("Trying to read each entry again...\n"); tprintf("Trying to read each entry again...\n");
for (i=0; testfiles[i].name; i++) { for (i=0; testfiles[i].name; i++) {
doreadone(i); doreadone(i);
} }
@ -286,7 +286,7 @@ readallrandomly(void)
{ {
int n, i, x; int n, i, x;
printf("Trying to read a bunch of entries randomly...\n"); tprintf("Trying to read a bunch of entries randomly...\n");
for (i=0; testfiles[i].name; i++); for (i=0; testfiles[i].name; i++);
n = i; n = i;
@ -327,7 +327,7 @@ doreadateof(void)
off_t pos; off_t pos;
int i; int i;
printf("Trying to read after going to EOF...\n"); tprintf("Trying to read after going to EOF...\n");
pos = lseek(dirfd, 0, SEEK_END); pos = lseek(dirfd, 0, SEEK_END);
if (pos<0) { if (pos<0) {
@ -364,7 +364,7 @@ dobadreads(void)
off_t pos, pos2, eof; off_t pos, pos2, eof;
int valid, i, k=0; int valid, i, k=0;
printf("Trying some possibly invalid reads...\n"); tprintf("Trying some possibly invalid reads...\n");
eof = lseek(dirfd, 0, SEEK_END); eof = lseek(dirfd, 0, SEEK_END);
if (eof < 0) { if (eof < 0) {
@ -394,13 +394,13 @@ dobadreads(void)
} }
if (k>0) { if (k>0) {
printf("Survived %d invalid reads...\n", k); tprintf("Survived %d invalid reads...\n", k);
} }
else { else {
printf("Couldn't find any invalid offsets to try...\n"); tprintf("Couldn't find any invalid offsets to try...\n");
} }
printf("Trying to read beyond EOF...\n"); tprintf("Trying to read beyond EOF...\n");
pos2 = lseek(dirfd, eof + 1000, SEEK_SET); pos2 = lseek(dirfd, eof + 1000, SEEK_SET);
if (pos2 < 0) { if (pos2 < 0) {
/* this is ok */ /* this is ok */
@ -414,10 +414,10 @@ static
void void
dotest(void) dotest(void)
{ {
printf("Opening directory...\n"); tprintf("Opening directory...\n");
openit(); openit();
printf("Running tests...\n"); tprintf("Running tests...\n");
/* read the whole directory */ /* read the whole directory */
firstread(); firstread();
@ -443,7 +443,7 @@ dotest(void)
/* rewind again to make sure the invalid attempts didn't break it */ /* rewind again to make sure the invalid attempts didn't break it */
doreadat0(); doreadat0();
printf("Closing directory...\n"); tprintf("Closing directory...\n");
closeit(); closeit();
} }
@ -489,7 +489,7 @@ setup(void)
{ {
int i; int i;
printf("Making directory %s...\n", TESTDIR); tprintf("Making directory %s...\n", TESTDIR);
/* Create a directory */ /* Create a directory */
if (mkdir(TESTDIR, 0775)<0) { if (mkdir(TESTDIR, 0775)<0) {
@ -501,7 +501,7 @@ setup(void)
err(1, "%s: chdir", TESTDIR); err(1, "%s: chdir", TESTDIR);
} }
printf("Making some files...\n"); tprintf("Making some files...\n");
/* Populate it */ /* Populate it */
for (i=0; testfiles[i].name; i++) { for (i=0; testfiles[i].name; i++) {
@ -518,7 +518,7 @@ cleanup(void)
{ {
int i; int i;
printf("Cleaning up...\n"); tprintf("Cleaning up...\n");
/* Remove the files */ /* Remove the files */
for (i=0; testfiles[i].name; i++) { for (i=0; testfiles[i].name; i++) {

View File

@ -58,7 +58,7 @@ main(void)
strcpy(dirname, onename); strcpy(dirname, onename);
for (i=0; i<MAXLEVELS; i++) { for (i=0; i<MAXLEVELS; i++) {
printf("Creating directory: %s\n", dirname); tprintf("Creating directory: %s\n", dirname);
if (mkdir(dirname, 0755)) { if (mkdir(dirname, 0755)) {
err(1, "%s: mkdir", dirname); err(1, "%s: mkdir", dirname);
@ -68,18 +68,18 @@ main(void)
strcat(dirname, onename); strcat(dirname, onename);
} }
printf("Passed directory creation test.\n"); tprintf("Passed directory creation test.\n");
for (i=0; i<MAXLEVELS; i++) { for (i=0; i<MAXLEVELS; i++) {
dirname[strlen(dirname) - strlen(onename) - 1] = 0; dirname[strlen(dirname) - strlen(onename) - 1] = 0;
printf("Removing directory: %s\n", dirname); tprintf("Removing directory: %s\n", dirname);
if (rmdir(dirname)) { if (rmdir(dirname)) {
err(1, "%s: rmdir", dirname); err(1, "%s: rmdir", dirname);
} }
} }
printf("Passed directory removal test.\n"); tprintf("Passed directory removal test.\n");
return 0; return 0;
} }

View File

@ -79,7 +79,7 @@ subproc_read(void)
int fd; int fd;
int i, res; int i, res;
printf("File Reader starting ...\n\n"); tprintf("File Reader starting ...\n\n");
fd = open(FNAME, O_RDONLY); fd = open(FNAME, O_RDONLY);
if (fd < 0) { if (fd < 0) {
@ -102,5 +102,5 @@ subproc_read(void)
close(fd); close(fd);
printf("File Read exited successfully!\n"); tprintf("File Read exited successfully!\n");
} }

View File

@ -124,8 +124,8 @@ big_file(int size)
{ {
int i, j, fileid; int i, j, fileid;
printf("[BIGFILE] test starting :\n"); tprintf("[BIGFILE] test starting :\n");
printf("\tCreating a file of size: %d\n", size); tprintf("\tCreating a file of size: %d\n", size);
fileid = open(BIGFILE_NAME, O_WRONLY|O_CREAT|O_TRUNC, 0664); fileid = open(BIGFILE_NAME, O_WRONLY|O_CREAT|O_TRUNC, 0664);
if (fileid < 0) { if (fileid < 0) {
@ -136,16 +136,16 @@ big_file(int size)
fbuffer[i] = LETTER(i); fbuffer[i] = LETTER(i);
} }
printf("\tWriting to file.\n"); tprintf("\tWriting to file.\n");
for (i = 0; i < size; i += BUFFER_SIZE) { for (i = 0; i < size; i += BUFFER_SIZE) {
write(fileid, fbuffer, BUFFER_SIZE); write(fileid, fbuffer, BUFFER_SIZE);
if (!(i % (10 * BUFFER_SIZE))) { if (!(i % (10 * BUFFER_SIZE))) {
printf("\rBW : %d", i); tprintf("\rBW : %d", i);
} }
} }
printf("\n\tReading from file.\n"); tprintf("\n\tReading from file.\n");
close(fileid); close(fileid);
fileid = open(BIGFILE_NAME, O_RDONLY); fileid = open(BIGFILE_NAME, O_RDONLY);
@ -164,7 +164,7 @@ big_file(int size)
} }
if (!(i % (10 * BUFFER_SIZE))) { if (!(i % (10 * BUFFER_SIZE))) {
printf("\rBR : %d", i); tprintf("\rBR : %d", i);
} }
/* Check to see that the data is consistent : */ /* Check to see that the data is consistent : */
@ -181,7 +181,7 @@ big_file(int size)
err(1, "[BIGFILE]: %s: remove", BIGFILE_NAME); err(1, "[BIGFILE]: %s: remove", BIGFILE_NAME);
} }
printf("\n[BIGFILE] : Success!\n"); tprintf("\n[BIGFILE] : Success!\n");
} }
/* =================================================== /* ===================================================
@ -195,7 +195,7 @@ concur(void)
int i, fd; int i, fd;
int r1, r2, w1; int r1, r2, w1;
printf("Spawning 2 readers, 1 writer.\n"); tprintf("Spawning 2 readers, 1 writer.\n");
fd = open(FNAME, O_WRONLY|O_CREAT|O_TRUNC, 0664); fd = open(FNAME, O_WRONLY|O_CREAT|O_TRUNC, 0664);
@ -203,7 +203,7 @@ concur(void)
err(1, "[CONCUR]: %s: open", FNAME); err(1, "[CONCUR]: %s: open", FNAME);
} }
printf("Initializing test file: "); tprintf("Initializing test file: ");
for (i = 0; i < SECTOR_SIZE + 1; i++) { for (i = 0; i < SECTOR_SIZE + 1; i++) {
cbuffer[i] = READCHAR; cbuffer[i] = READCHAR;
@ -216,13 +216,13 @@ concur(void)
close(fd); close(fd);
printf("Done initializing. Starting processes...\n"); tprintf("Done initializing. Starting processes...\n");
r1 = forkoff(subproc_read); r1 = forkoff(subproc_read);
w1 = forkoff(subproc_write); w1 = forkoff(subproc_write);
r2 = forkoff(subproc_read); r2 = forkoff(subproc_read);
printf("Waiting for processes.\n"); tprintf("Waiting for processes.\n");
dowait(r1); dowait(r1);
dowait(r2); dowait(r2);
@ -232,7 +232,7 @@ concur(void)
err(1, "[CONCUR]: %s: remove", FNAME); err(1, "[CONCUR]: %s: remove", FNAME);
} }
printf("[CONCUR] Done!\n"); tprintf("[CONCUR] Done!\n");
} }
/* =================================================== /* ===================================================
@ -253,14 +253,14 @@ dir_test(int depth)
for (i = 0; i < depth; i++) { for (i = 0; i < depth; i++) {
strcat(dirname, tmp); strcat(dirname, tmp);
printf("\tCreating dir : %s\n", dirname); tprintf("\tCreating dir : %s\n", dirname);
if (mkdir(dirname, 0775) < 0) { if (mkdir(dirname, 0775) < 0) {
err(1, "[DIRTEST]: %s: mkdir", dirname); err(1, "[DIRTEST]: %s: mkdir", dirname);
} }
strcat(dirname, fmp); strcat(dirname, fmp);
printf("\tCreating file: %s\n", dirname); tprintf("\tCreating file: %s\n", dirname);
fd = open(dirname, O_WRONLY|O_CREAT|O_TRUNC, 0664); fd = open(dirname, O_WRONLY|O_CREAT|O_TRUNC, 0664);
if (fd<0) { if (fd<0) {
@ -270,19 +270,19 @@ dir_test(int depth)
dirname[strlen(dirname) - strlen(fmp)] = '\0'; dirname[strlen(dirname) - strlen(fmp)] = '\0';
} }
printf("[DIRTEST] : Passed directory creation test.\n"); tprintf("[DIRTEST] : Passed directory creation test.\n");
for (i = 0; i < depth; i++) { for (i = 0; i < depth; i++) {
strcat(dirname, fmp); strcat(dirname, fmp);
printf("\tDeleting file: %s\n", dirname); tprintf("\tDeleting file: %s\n", dirname);
if (remove(dirname)) { if (remove(dirname)) {
err(1, "[DIRTEST]: %s: remove", dirname); err(1, "[DIRTEST]: %s: remove", dirname);
} }
dirname[strlen(dirname) - strlen(fmp)] = '\0'; dirname[strlen(dirname) - strlen(fmp)] = '\0';
printf("\tRemoving dir : %s\n", dirname); tprintf("\tRemoving dir : %s\n", dirname);
if (rmdir(dirname)) { if (rmdir(dirname)) {
err(1, "[DIRTEST]: %s: rmdir", dirname); err(1, "[DIRTEST]: %s: rmdir", dirname);
@ -291,8 +291,8 @@ dir_test(int depth)
dirname[strlen(dirname) - strlen(tmp)] = '\0'; dirname[strlen(dirname) - strlen(tmp)] = '\0';
} }
printf("[DIRTEST] : Passed directory removal test.\n"); tprintf("[DIRTEST] : Passed directory removal test.\n");
printf("[DIRTEST] : Success!\n"); tprintf("[DIRTEST] : Success!\n");
} }
/* =================================================== /* ===================================================
@ -325,21 +325,21 @@ main(int argc, char * argv[])
} }
if (tv & RUNBIGFILE) { if (tv & RUNBIGFILE) {
printf("[BIGFILE] : Run #1\n"); tprintf("[BIGFILE] : Run #1\n");
big_file(BIGFILE_SIZE); big_file(BIGFILE_SIZE);
printf("[BIGFILE] : Run #2\n"); tprintf("[BIGFILE] : Run #2\n");
big_file(BIGFILE_SIZE); big_file(BIGFILE_SIZE);
} }
if (tv & RUNDIRTEST) { if (tv & RUNDIRTEST) {
printf("[DIRTEST] : Run #1\n"); tprintf("[DIRTEST] : Run #1\n");
dir_test(DIR_DEPTH); dir_test(DIR_DEPTH);
printf("[DIRTEST] : Run #2\n"); tprintf("[DIRTEST] : Run #2\n");
dir_test(DIR_DEPTH); dir_test(DIR_DEPTH);
} }
if (tv & RUNCONCUR) { if (tv & RUNCONCUR) {
printf("[CONCUR]\n"); tprintf("[CONCUR]\n");
concur(); concur();
} }
return 0; return 0;

View File

@ -67,7 +67,7 @@ subproc_write(void)
buffer[i] = WRITECHAR; buffer[i] = WRITECHAR;
} }
printf("File Writer starting ...\n"); tprintf("File Writer starting ...\n");
fd = open(FNAME, O_WRONLY); fd = open(FNAME, O_WRONLY);
if (fd < 0) { if (fd < 0) {
@ -81,5 +81,5 @@ subproc_write(void)
close(fd); close(fd);
printf("File Write exited successfully!\n"); tprintf("File Write exited successfully!\n");
} }

View File

@ -245,7 +245,7 @@ main(int argc, char *argv[])
} }
else if (argc == 3) { else if (argc == 3) {
if (!strcmp(argv[1], "1") || !strcmp(argv[1], "0")) { if (!strcmp(argv[1], "1") || !strcmp(argv[1], "0")) {
printf("%s\n", argv[2]); tprintf("%s\n", argv[2]);
} }
else { else {
number_init(&n1, argv[1]); number_init(&n1, argv[1]);

View File

@ -45,12 +45,12 @@ main(void)
{ {
volatile int i; volatile int i;
printf("\nEntering the faulter program - I should die immediately\n"); tprintf("\nEntering the faulter program - I should die immediately\n");
i = *(int *)REALLY_BIG_ADDRESS; i = *(int *)REALLY_BIG_ADDRESS;
// gcc 4.8 improperly demands this // gcc 4.8 improperly demands this
(void)i; (void)i;
printf("I didn't get killed! Program has a bug\n"); tprintf("I didn't get killed! Program has a bug\n");
return 0; return 0;
} }

View File

@ -66,14 +66,14 @@ main(int argc, char **argv)
// 23 Mar 2012 : GWA : Test that open works. // 23 Mar 2012 : GWA : Test that open works.
printf("Opening %s\n", filename); tprintf("Opening %s\n", filename);
fh = open(filename, O_RDWR|O_CREAT|O_TRUNC); fh = open(filename, O_RDWR|O_CREAT|O_TRUNC);
if (fh < 0) { if (fh < 0) {
err(1, "create failed"); err(1, "create failed");
} }
printf("Writing %d bytes.\n", BUFFER_SIZE * BUFFER_COUNT); tprintf("Writing %d bytes.\n", BUFFER_SIZE * BUFFER_COUNT);
// 23 Mar 2012 : GWA : Do the even-numbered writes. Test read() and // 23 Mar 2012 : GWA : Do the even-numbered writes. Test read() and
// lseek(SEEK_END). // lseek(SEEK_END).
@ -127,7 +127,7 @@ main(int argc, char **argv)
// 23 Mar 2012 : GWA : Read the test data back and make sure what we wrote // 23 Mar 2012 : GWA : Read the test data back and make sure what we wrote
// ended up where we wrote it. Tests read() and lseek(SEEK_SET). // ended up where we wrote it. Tests read() and lseek(SEEK_SET).
printf("Verifying write.\n"); tprintf("Verifying write.\n");
for (i = BUFFER_COUNT - 1; i >= 0; i--) { for (i = BUFFER_COUNT - 1; i >= 0; i--) {
target = i * sizeof(writebuf); target = i * sizeof(writebuf);
@ -148,7 +148,7 @@ main(int argc, char **argv)
// 23 Mar 2012 : GWA : Close the file. // 23 Mar 2012 : GWA : Close the file.
printf("Closing %s\n", filename); tprintf("Closing %s\n", filename);
close(fh); close(fh);
// 23 Mar 2012 : GWA : Make sure the file is actually closed. // 23 Mar 2012 : GWA : Make sure the file is actually closed.
@ -160,7 +160,7 @@ main(int argc, char **argv)
// 23 Mar 2012 : GWA : FIXME : Spin until exit() works. // 23 Mar 2012 : GWA : FIXME : Spin until exit() works.
printf("Spinning in case exit() doesn't work.\n"); tprintf("Spinning in case exit() doesn't work.\n");
while (1) {}; while (1) {};
return 0; return 0;

View File

@ -103,6 +103,6 @@ main(int argc, char *argv[])
if (rv<0) { if (rv<0) {
err(1, "%s: remove", file); err(1, "%s: remove", file);
} }
printf("Passed filetest.\n"); tprintf("Passed filetest.\n");
return 0; return 0;
} }

View File

@ -2148,7 +2148,7 @@ doindent(unsigned depth)
unsigned i; unsigned i;
for (i=0; i<depth; i++) { for (i=0; i<depth; i++) {
printf(" "); tprintf(" ");
} }
} }
@ -2174,17 +2174,17 @@ printdiffs(unsigned indent, struct fsobject *obja, struct fsobject *objb)
entb = entb->next) { entb = entb->next) {
if (enta->name == entb->name) { if (enta->name == entb->name) {
doindent(indent); doindent(indent);
printf("%s", name_get(enta->name)); tprintf("%s", name_get(enta->name));
if (enta->obj->isdir && if (enta->obj->isdir &&
!entb->obj->isdir) { !entb->obj->isdir) {
printf(": expected dir, found file;"); tprintf(": expected dir, found file;");
printf(" %u names missing.\n", tprintf(" %u names missing.\n",
count_subtree(enta->obj) - 1); count_subtree(enta->obj) - 1);
} }
else if (!enta->obj->isdir && else if (!enta->obj->isdir &&
entb->obj->isdir) { entb->obj->isdir) {
printf(": expected file, found dir;"); tprintf(": expected file, found dir;");
printf(" %u extra names.\n", tprintf(" %u extra names.\n",
count_subtree(entb->obj) - 1); count_subtree(entb->obj) - 1);
} }
else if (!enta->obj->isdir && else if (!enta->obj->isdir &&
@ -2194,18 +2194,18 @@ printdiffs(unsigned indent, struct fsobject *obja, struct fsobject *objb)
alen = enta->obj->obj_file.len; alen = enta->obj->obj_file.len;
blen = entb->obj->obj_file.len; blen = entb->obj->obj_file.len;
if (alen == blen) { if (alen == blen) {
printf("\t\t%lld bytes (ok)\n", tprintf("\t\t%lld bytes (ok)\n",
alen); alen);
} }
else { else {
printf(": found %lld bytes, " tprintf(": found %lld bytes, "
"expected %lld " "expected %lld "
"bytes.\n", "bytes.\n",
blen, alen); blen, alen);
} }
} }
else { else {
printf("/\n"); tprintf("/\n");
printdiffs(indent + 1, printdiffs(indent + 1,
enta->obj, entb->obj); enta->obj, entb->obj);
} }
@ -2215,13 +2215,13 @@ printdiffs(unsigned indent, struct fsobject *obja, struct fsobject *objb)
} }
if (!found) { if (!found) {
doindent(indent); doindent(indent);
printf("%s: missing ", name_get(enta->name)); tprintf("%s: missing ", name_get(enta->name));
if (enta->obj->isdir) { if (enta->obj->isdir) {
printf("subtree with %u names.\n", tprintf("subtree with %u names.\n",
count_subtree(enta->obj) - 1); count_subtree(enta->obj) - 1);
} }
else { else {
printf("file\n"); tprintf("file\n");
} }
} }
} }
@ -2238,13 +2238,13 @@ printdiffs(unsigned indent, struct fsobject *obja, struct fsobject *objb)
} }
if (!found) { if (!found) {
doindent(indent); doindent(indent);
printf("%s: extra ", name_get(entb->name)); tprintf("%s: extra ", name_get(entb->name));
if (entb->obj->isdir) { if (entb->obj->isdir) {
printf("subtree with %u names.\n", tprintf("subtree with %u names.\n",
count_subtree(entb->obj) - 1); count_subtree(entb->obj) - 1);
} }
else { else {
printf("file\n"); tprintf("file\n");
} }
} }
} }
@ -2326,7 +2326,7 @@ checkfilezeros(int fd, const char *namestr, off_t start, off_t end)
unsigned poison = 0, trash = 0; unsigned poison = 0, trash = 0;
off_t origstart = start; off_t origstart = start;
printf(" %lld - %lld (expecting zeros)\n", start, end); tprintf(" %lld - %lld (expecting zeros)\n", start, end);
if (lseek(fd, start, SEEK_SET) == -1) { if (lseek(fd, start, SEEK_SET) == -1) {
err(1, "%s: lseek to %lld", namestr, start); err(1, "%s: lseek to %lld", namestr, start);
@ -2356,19 +2356,19 @@ checkfilezeros(int fd, const char *namestr, off_t start, off_t end)
start += ret; start += ret;
} }
if (poison > 0 || trash > 0) { if (poison > 0 || trash > 0) {
printf("ERROR: File %s: expected zeros from %lld to %lld; " tprintf("ERROR: File %s: expected zeros from %lld to %lld; "
"found", "found",
namestr, origstart, end); namestr, origstart, end);
if (poison > 0) { if (poison > 0) {
printf(" %u poison bytes", poison); tprintf(" %u poison bytes", poison);
if (trash > 0) { if (trash > 0) {
printf(" and"); tprintf(" and");
} }
} }
if (trash > 0) { if (trash > 0) {
printf(" %u trash bytes", trash); tprintf(" %u trash bytes", trash);
} }
printf("\n"); tprintf("\n");
} }
} }
@ -2440,7 +2440,7 @@ checkfiledata(int fd, const char *namestr, unsigned code, unsigned seq,
checkend = regionend; checkend = regionend;
} }
printf(" %lld - %lld\n", checkstart, checkend); tprintf(" %lld - %lld\n", checkstart, checkend);
readfiledata(fd, namestr, readfiledata(fd, namestr,
regionstart, checkstart, checkend, regionend); regionstart, checkstart, checkend, regionend);
@ -2695,7 +2695,7 @@ checkonefilecontents(const char *namestr, struct fsobject *file,
return; return;
} }
assert(change->type == FC_WRITE); assert(change->type == FC_WRITE);
printf("ERROR: File %s is zero length but was expected to " tprintf("ERROR: File %s is zero length but was expected to "
"contain at least %lld bytes at offset %lld!\n", "contain at least %lld bytes at offset %lld!\n",
namestr, change->fc_write.pos, change->fc_write.len); namestr, change->fc_write.pos, change->fc_write.len);
close(fd); close(fd);
@ -2704,7 +2704,7 @@ checkonefilecontents(const char *namestr, struct fsobject *file,
/* XXX: this check is wrong too. */ /* XXX: this check is wrong too. */
if (change->type == FC_CREAT) { if (change->type == FC_CREAT) {
printf("ERROR: File %s was never written to but has " tprintf("ERROR: File %s was never written to but has "
"length %lld\n", "length %lld\n",
namestr, file->obj_file.len); namestr, file->obj_file.len);
close(fd); close(fd);
@ -2741,12 +2741,12 @@ checkonefilecontents(const char *namestr, struct fsobject *file,
*/ */
while (!change_is_present(fd, namestr, file->obj_file.len, change)) { while (!change_is_present(fd, namestr, file->obj_file.len, change)) {
if (change->version < okversion) { if (change->version < okversion) {
printf("File %s: change for version %u is missing\n", tprintf("File %s: change for version %u is missing\n",
namestr, change->version); namestr, change->version);
} }
change = backup_for_file(change->prev,file->obj_file.identity); change = backup_for_file(change->prev,file->obj_file.identity);
if (change == NULL) { if (change == NULL) {
printf("File %s: no matching version found\n", tprintf("File %s: no matching version found\n",
namestr); namestr);
close(fd); close(fd);
return; return;
@ -2781,18 +2781,18 @@ checkallfilecontents(struct fsobject *dir, struct fschange *change)
for (de = dir->obj_dir.entries; de != NULL; de = de->next) { for (de = dir->obj_dir.entries; de != NULL; de = de->next) {
namestr = name_get(de->name); namestr = name_get(de->name);
if (de->obj->isdir) { if (de->obj->isdir) {
printf(" >>> Entering %s\n", namestr); tprintf(" >>> Entering %s\n", namestr);
if (chdir(namestr)) { if (chdir(namestr)) {
err(1, "%s: chdir", namestr); err(1, "%s: chdir", namestr);
} }
checkallfilecontents(de->obj, change); checkallfilecontents(de->obj, change);
printf(" <<< Leaving %s\n", namestr); tprintf(" <<< Leaving %s\n", namestr);
if (chdir("..")) { if (chdir("..")) {
err(1, "..: chdir"); err(1, "..: chdir");
} }
} }
else { else {
printf("%s...\n", namestr); tprintf("%s...\n", namestr);
checkonefilecontents(namestr, de->obj, change); checkonefilecontents(namestr, de->obj, change);
} }
} }
@ -2813,7 +2813,7 @@ checkfs(void)
/* /*
* We just built the model; talk about it. * We just built the model; talk about it.
*/ */
printf("Established %u versions across %u directories and %u files\n", tprintf("Established %u versions across %u directories and %u files\n",
changes->version + 1, nextdirnum, nextfilenum); changes->version + 1, nextdirnum, nextfilenum);
/* /*
@ -2821,7 +2821,7 @@ checkfs(void)
* FOUND holding the found volume state. * FOUND holding the found volume state.
*/ */
inspectfs(); inspectfs();
printf("Found %u subdirs and %u files on the volume\n", tprintf("Found %u subdirs and %u files on the volume\n",
found_subdirs, found_files); found_subdirs, found_files);
/* /*
@ -2856,7 +2856,7 @@ checkfs(void)
best = change; best = change;
bestscore = score; bestscore = score;
} }
//printf("version %u score %u\n", change->version, score); //tprintf("version %u score %u\n", change->version, score);
change = change->next; change = change->next;
} }
assert(best != NULL); assert(best != NULL);
@ -2874,9 +2874,9 @@ checkfs(void)
* differences. XXX: this results in not checking file * differences. XXX: this results in not checking file
* data... * data...
*/ */
printf("FAILURE: Directory tree does not match on any " tprintf("FAILURE: Directory tree does not match on any "
"version.\n"); "version.\n");
printf("Best version is %u; describing differences:\n", tprintf("Best version is %u; describing differences:\n",
best->version); best->version);
printdiffs(1, state, found); printdiffs(1, state, found);
return; return;
@ -2886,9 +2886,9 @@ checkfs(void)
* Ok, we did get an exact match. Print it. * Ok, we did get an exact match. Print it.
*/ */
printf("Directory tree matched in version %u.\n", best->version); tprintf("Directory tree matched in version %u.\n", best->version);
if (best->partial) { if (best->partial) {
printf("WARNING: this is a version from a partially committed " tprintf("WARNING: this is a version from a partially committed "
"operation.\n"); "operation.\n");
} }
@ -2905,7 +2905,7 @@ checkfs(void)
/* now check the file contents */ /* now check the file contents */
printf("Checking file contents...\n"); tprintf("Checking file contents...\n");
checkallfilecontents(state, best); checkallfilecontents(state, best);
printf("Done.\n"); tprintf("Done.\n");
} }

View File

@ -165,7 +165,7 @@ data_matches(const char *namestr, off_t regionoffset,
} }
else if (zero_at(where, howmuch)) { else if (zero_at(where, howmuch)) {
if (where >= zerostart) { if (where >= zerostart) {
printf("WARNING: file %s range %lld-%lld is " tprintf("WARNING: file %s range %lld-%lld is "
"zeroed\n", "zeroed\n",
namestr, regionoffset + where, namestr, regionoffset + where,
regionoffset + where + howmuch); regionoffset + where + howmuch);
@ -176,7 +176,7 @@ data_matches(const char *namestr, off_t regionoffset,
} }
else if (poison_at(where, howmuch)) { else if (poison_at(where, howmuch)) {
if (where >= zerostart) { if (where >= zerostart) {
printf("ERROR: file %s range %lld-%lld is " tprintf("ERROR: file %s range %lld-%lld is "
"poisoned\n", "poisoned\n",
namestr, regionoffset + where, namestr, regionoffset + where,
regionoffset + where + howmuch); regionoffset + where + howmuch);
@ -205,7 +205,7 @@ data_check(const char *namestr, off_t regionoffset,
if (!data_matches(namestr, regionoffset, if (!data_matches(namestr, regionoffset,
code, seq, zerostart, len, checkstart, checklen)) { code, seq, zerostart, len, checkstart, checklen)) {
printf("ERROR: file %s range %lld-%lld contains garbage\n", tprintf("ERROR: file %s range %lld-%lld contains garbage\n",
namestr, regionoffset + checkstart, namestr, regionoffset + checkstart,
regionoffset + checkstart + checklen); regionoffset + checkstart + checklen);
} }

View File

@ -72,7 +72,7 @@ do_createfile(unsigned name)
if (fd < 0) { if (fd < 0) {
err(1, "%s: create", namestr); err(1, "%s: create", namestr);
} }
printf("create %s\n", namestr); tprintf("create %s\n", namestr);
return fd; return fd;
} }
@ -122,7 +122,7 @@ do_write(int fd, unsigned name, unsigned code, unsigned seq,
done += ret; done += ret;
} }
printf("write %s: %lld at %lld\n", namestr, len, pos); tprintf("write %s: %lld at %lld\n", namestr, len, pos);
} }
void void
@ -134,7 +134,7 @@ do_truncate(int fd, unsigned name, off_t len)
if (ftruncate(fd, len) == -1) { if (ftruncate(fd, len) == -1) {
err(1, "%s: truncate to %lld", namestr, len); err(1, "%s: truncate to %lld", namestr, len);
} }
printf("truncate %s: to %lld\n", namestr, len); tprintf("truncate %s: to %lld\n", namestr, len);
} }
void void
@ -146,7 +146,7 @@ do_mkdir(unsigned name)
if (mkdir(namestr, 0775) == -1) { if (mkdir(namestr, 0775) == -1) {
err(1, "%s: mkdir", namestr); err(1, "%s: mkdir", namestr);
} }
printf("mkdir %s\n", namestr); tprintf("mkdir %s\n", namestr);
} }
void void
@ -158,7 +158,7 @@ do_rmdir(unsigned name)
if (rmdir(namestr) == -1) { if (rmdir(namestr) == -1) {
err(1, "%s: rmdir", namestr); err(1, "%s: rmdir", namestr);
} }
printf("rmdir %s\n", namestr); tprintf("rmdir %s\n", namestr);
} }
void void
@ -170,7 +170,7 @@ do_unlink(unsigned name)
if (remove(namestr) == -1) { if (remove(namestr) == -1) {
err(1, "%s: remove", namestr); err(1, "%s: remove", namestr);
} }
printf("remove %s\n", namestr); tprintf("remove %s\n", namestr);
} }
void void
@ -183,7 +183,7 @@ do_link(unsigned from, unsigned to)
if (link(fromstr, tostr) == -1) { if (link(fromstr, tostr) == -1) {
err(1, "link %s to %s", fromstr, tostr); err(1, "link %s to %s", fromstr, tostr);
} }
printf("link %s %s\n", fromstr, tostr); tprintf("link %s %s\n", fromstr, tostr);
} }
void void
@ -196,7 +196,7 @@ do_rename(unsigned from, unsigned to)
if (rename(fromstr, tostr) == -1) { if (rename(fromstr, tostr) == -1) {
err(1, "rename %s to %s", fromstr, tostr); err(1, "rename %s to %s", fromstr, tostr);
} }
printf("rename %s %s\n", fromstr, tostr); tprintf("rename %s %s\n", fromstr, tostr);
} }
void void
@ -216,7 +216,7 @@ do_renamexd(unsigned fromdir, unsigned from, unsigned todir, unsigned to)
if (rename(frombuf, tobuf) == -1) { if (rename(frombuf, tobuf) == -1) {
err(1, "rename %s to %s", frombuf, tobuf); err(1, "rename %s to %s", frombuf, tobuf);
} }
printf("rename %s %s\n", frombuf, tobuf); tprintf("rename %s %s\n", frombuf, tobuf);
} }
void void
@ -228,7 +228,7 @@ do_chdir(unsigned name)
if (chdir(namestr) == -1) { if (chdir(namestr) == -1) {
err(1, "chdir: %s", namestr); err(1, "chdir: %s", namestr);
} }
printf("chdir %s\n", namestr); tprintf("chdir %s\n", namestr);
} }
void void
@ -237,7 +237,7 @@ do_chdirup(void)
if (chdir("..") == -1) { if (chdir("..") == -1) {
err(1, "chdir: .."); err(1, "chdir: ..");
} }
printf("chdir ..\n"); tprintf("chdir ..\n");
} }
void void
@ -246,6 +246,6 @@ do_sync(void)
if (sync()) { if (sync()) {
warn("sync"); warn("sync");
} }
printf("sync\n"); tprintf("sync\n");
printf("----------------------------------------\n"); tprintf("----------------------------------------\n");
} }

View File

@ -132,13 +132,13 @@ printworkloads(void)
{ {
unsigned i; unsigned i;
printf("Supported workloads:\n"); tprintf("Supported workloads:\n");
for (i=0; i<numworkloads; i++) { for (i=0; i<numworkloads; i++) {
printf(" %s", workloads[i].name); tprintf(" %s", workloads[i].name);
if (workloads[i].argname) { if (workloads[i].argname) {
printf(" %s", workloads[i].argname); tprintf(" %s", workloads[i].argname);
} }
printf("\n"); tprintf("\n");
} }
} }

View File

@ -77,7 +77,7 @@ main(int argc, char *argv[])
close(fd); close(fd);
printf("Hash : %d\n", j); tprintf("Hash : %d\n", j);
return 0; return 0;
} }

View File

@ -50,34 +50,34 @@ main(void)
{ {
int i,j; int i,j;
printf("Entering the huge program - I will stress test your VM\n"); tprintf("Entering the huge program - I will stress test your VM\n");
/* move number in so that sparse[i][0]=i */ /* move number in so that sparse[i][0]=i */
for (i=0; i<NumPages; i++) { for (i=0; i<NumPages; i++) {
sparse[i][0]=i; sparse[i][0]=i;
} }
printf("stage [1] done\n"); tprintf("stage [1] done\n");
/* increment each location 5 times */ /* increment each location 5 times */
for (j=0; j<5; j++) { for (j=0; j<5; j++) {
for (i=0; i<NumPages; i++) { for (i=0; i<NumPages; i++) {
sparse[i][0]++; sparse[i][0]++;
} }
printf("stage [2.%d] done\n", j); tprintf("stage [2.%d] done\n", j);
} }
printf("stage [2] done\n"); tprintf("stage [2] done\n");
/* check if the numbers are sane */ /* check if the numbers are sane */
for (i=NumPages-1; i>=0; i--) { for (i=NumPages-1; i>=0; i--) {
if (sparse[i][0]!=i+5) { if (sparse[i][0]!=i+5) {
printf("BAD NEWS!!! - your VM mechanism has a bug!\n"); tprintf("BAD NEWS!!! - your VM mechanism has a bug!\n");
exit(1); exit(1);
} }
} }
printf("You passed!\n"); tprintf("You passed!\n");
return 0; return 0;
} }

View File

@ -77,7 +77,7 @@ geti(void)
break; break;
} }
else if ((ch=='\b' || ch==127) && digits>0) { else if ((ch=='\b' || ch==127) && digits>0) {
printf("\b \b"); tprintf("\b \b");
val = val/10; val = val/10;
digits--; digits--;
} }
@ -117,11 +117,11 @@ markblock(volatile void *ptr, size_t size, unsigned bias, int doprint)
val = ((unsigned long)i ^ (unsigned long)bias); val = ((unsigned long)i ^ (unsigned long)bias);
pl[i] = val; pl[i] = val;
if (doprint && (i%64==63)) { if (doprint && (i%64==63)) {
printf("."); tprintf(".");
} }
} }
if (doprint) { if (doprint) {
printf("\n"); tprintf("\n");
} }
} }
@ -143,9 +143,9 @@ checkblock(volatile void *ptr, size_t size, unsigned bias, int doprint)
val = ((unsigned long)i ^ (unsigned long)bias); val = ((unsigned long)i ^ (unsigned long)bias);
if (pl[i] != val) { if (pl[i] != val) {
if (doprint) { if (doprint) {
printf("\n"); tprintf("\n");
} }
printf("FAILED: data mismatch at offset %lu of block " tprintf("FAILED: data mismatch at offset %lu of block "
"at 0x%lx: %lu vs. %lu\n", "at 0x%lx: %lu vs. %lu\n",
(unsigned long) (i*sizeof(unsigned long)), (unsigned long) (i*sizeof(unsigned long)),
(unsigned long)(uintptr_t)pl, (unsigned long)(uintptr_t)pl,
@ -153,11 +153,11 @@ checkblock(volatile void *ptr, size_t size, unsigned bias, int doprint)
return -1; return -1;
} }
if (doprint && (i%64==63)) { if (doprint && (i%64==63)) {
printf("."); tprintf(".");
} }
} }
if (doprint) { if (doprint) {
printf("\n"); tprintf("\n");
} }
return 0; return 0;
@ -178,23 +178,23 @@ test1(void)
{ {
volatile unsigned *x; volatile unsigned *x;
printf("*** Malloc test 1 ***\n"); tprintf("*** Malloc test 1 ***\n");
printf("Allocating %u bytes\n", BIGSIZE); tprintf("Allocating %u bytes\n", BIGSIZE);
x = malloc(BIGSIZE); x = malloc(BIGSIZE);
if (x==NULL) { if (x==NULL) {
printf("FAILED: malloc failed\n"); tprintf("FAILED: malloc failed\n");
return; return;
} }
markblock(x, BIGSIZE, 0, 0); markblock(x, BIGSIZE, 0, 0);
if (checkblock(x, BIGSIZE, 0, 0)) { if (checkblock(x, BIGSIZE, 0, 0)) {
printf("FAILED: data corrupt\n"); tprintf("FAILED: data corrupt\n");
return; return;
} }
free((void *)x); free((void *)x);
printf("Passed malloc test 1.\n"); tprintf("Passed malloc test 1.\n");
} }
@ -237,43 +237,43 @@ test2(void)
volatile unsigned *x; volatile unsigned *x;
size_t size; size_t size;
printf("Entering malloc test 2.\n"); tprintf("Entering malloc test 2.\n");
printf("Make sure you read and understand the comment in malloctest.c " tprintf("Make sure you read and understand the comment in malloctest.c "
"that\nexplains the conditions this test assumes.\n\n"); "that\nexplains the conditions this test assumes.\n\n");
printf("Testing how much memory we can allocate:\n"); tprintf("Testing how much memory we can allocate:\n");
for (size = HUGESIZE; (x = malloc(size))==NULL; size = size/2) { for (size = HUGESIZE; (x = malloc(size))==NULL; size = size/2) {
printf(" %9lu bytes: failed\n", (unsigned long) size); tprintf(" %9lu bytes: failed\n", (unsigned long) size);
} }
printf(" %9lu bytes: succeeded\n", (unsigned long) size); tprintf(" %9lu bytes: succeeded\n", (unsigned long) size);
printf("Passed part 1\n"); tprintf("Passed part 1\n");
printf("Touching all the words in the block.\n"); tprintf("Touching all the words in the block.\n");
markblock(x, size, 0, 1); markblock(x, size, 0, 1);
printf("Validating the words in the block.\n"); tprintf("Validating the words in the block.\n");
if (checkblock(x, size, 0, 1)) { if (checkblock(x, size, 0, 1)) {
printf("FAILED: data corrupt\n"); tprintf("FAILED: data corrupt\n");
return; return;
} }
printf("Passed part 2\n"); tprintf("Passed part 2\n");
printf("Freeing the block\n"); tprintf("Freeing the block\n");
free((void *)x); free((void *)x);
printf("Passed part 3\n"); tprintf("Passed part 3\n");
printf("Allocating another block\n"); tprintf("Allocating another block\n");
x = malloc(size); x = malloc(size);
if (x==NULL) { if (x==NULL) {
printf("FAILED: free didn't return the memory?\n"); tprintf("FAILED: free didn't return the memory?\n");
return; return;
} }
free((void *)x); free((void *)x);
printf("Passed malloc test 2.\n"); tprintf("Passed malloc test 2.\n");
} }
@ -304,11 +304,11 @@ test3(void)
int ct=0, failed=0; int ct=0, failed=0;
void *x; void *x;
printf("Entering malloc test 3.\n"); tprintf("Entering malloc test 3.\n");
printf("Make sure you read and understand the comment in malloctest.c " tprintf("Make sure you read and understand the comment in malloctest.c "
"that\nexplains the conditions this test assumes.\n\n"); "that\nexplains the conditions this test assumes.\n\n");
printf("Testing how much memory we can allocate:\n"); tprintf("Testing how much memory we can allocate:\n");
while ((tmp = malloc(sizeof(struct test3))) != NULL) { while ((tmp = malloc(sizeof(struct test3))) != NULL) {
@ -322,33 +322,33 @@ test3(void)
ct++; ct++;
if (ct%128==0) { if (ct%128==0) {
printf("."); tprintf(".");
} }
} }
printf("Allocated %lu bytes\n", (unsigned long) tot); tprintf("Allocated %lu bytes\n", (unsigned long) tot);
printf("Trying some more allocations which I expect to fail...\n"); tprintf("Trying some more allocations which I expect to fail...\n");
x = malloc(SMALLSIZE); x = malloc(SMALLSIZE);
if (x != NULL) { if (x != NULL) {
printf("FAILED: malloc(%u) succeeded\n", SMALLSIZE); tprintf("FAILED: malloc(%u) succeeded\n", SMALLSIZE);
return; return;
} }
x = malloc(MEDIUMSIZE); x = malloc(MEDIUMSIZE);
if (x != NULL) { if (x != NULL) {
printf("FAILED: malloc(%u) succeeded\n", MEDIUMSIZE); tprintf("FAILED: malloc(%u) succeeded\n", MEDIUMSIZE);
return; return;
} }
x = malloc(BIGSIZE); x = malloc(BIGSIZE);
if (x != NULL) { if (x != NULL) {
printf("FAILED: malloc(%u) succeeded\n", BIGSIZE); tprintf("FAILED: malloc(%u) succeeded\n", BIGSIZE);
return; return;
} }
printf("Ok, now I'm going to free everything...\n"); tprintf("Ok, now I'm going to free everything...\n");
while (list != NULL) { while (list != NULL) {
tmp = list->next; tmp = list->next;
@ -363,20 +363,20 @@ test3(void)
} }
if (failed) { if (failed) {
printf("FAILED: data corruption\n"); tprintf("FAILED: data corruption\n");
return; return;
} }
printf("Let me see if I can allocate some more now...\n"); tprintf("Let me see if I can allocate some more now...\n");
x = malloc(MEDIUMSIZE); x = malloc(MEDIUMSIZE);
if (x == NULL) { if (x == NULL) {
printf("FAIL: Nope, I couldn't.\n"); tprintf("FAIL: Nope, I couldn't.\n");
return; return;
} }
free(x); free(x);
printf("Passed malloc test 3\n"); tprintf("Passed malloc test 3\n");
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -397,34 +397,34 @@ test4(void)
void *x, *y, *z; void *x, *y, *z;
unsigned long lx, ly, lz, overhead, zsize; unsigned long lx, ly, lz, overhead, zsize;
printf("Entering malloc test 4.\n"); tprintf("Entering malloc test 4.\n");
printf("This test is intended for first/best-fit based mallocs.\n"); tprintf("This test is intended for first/best-fit based mallocs.\n");
printf("This test may not work correctly if run after other tests.\n"); tprintf("This test may not work correctly if run after other tests.\n");
printf("Testing free list coalescing:\n"); tprintf("Testing free list coalescing:\n");
x = malloc(SMALLSIZE); x = malloc(SMALLSIZE);
if (x==NULL) { if (x==NULL) {
printf("FAILED: malloc(%u) failed\n", SMALLSIZE); tprintf("FAILED: malloc(%u) failed\n", SMALLSIZE);
return; return;
} }
y = malloc(MEDIUMSIZE); y = malloc(MEDIUMSIZE);
if (y==NULL) { if (y==NULL) {
printf("FAILED: malloc(%u) failed\n", MEDIUMSIZE); tprintf("FAILED: malloc(%u) failed\n", MEDIUMSIZE);
return; return;
} }
if (sizeof(unsigned long) < sizeof(void *)) { if (sizeof(unsigned long) < sizeof(void *)) {
printf("Buh? I can't fit a void * in an unsigned long\n"); tprintf("Buh? I can't fit a void * in an unsigned long\n");
printf("ENVIRONMENT FAILED...\n"); tprintf("ENVIRONMENT FAILED...\n");
return; return;
} }
lx = (unsigned long)x; lx = (unsigned long)x;
ly = (unsigned long)y; ly = (unsigned long)y;
printf("x is 0x%lx; y is 0x%lx\n", lx, ly); tprintf("x is 0x%lx; y is 0x%lx\n", lx, ly);
/* /*
* The memory should look something like this: * The memory should look something like this:
@ -436,7 +436,7 @@ test4(void)
/* This is obviously wrong. */ /* This is obviously wrong. */
if (lx == ly) { if (lx == ly) {
printf("FAIL: x == y\n"); tprintf("FAIL: x == y\n");
return; return;
} }
@ -447,11 +447,11 @@ test4(void)
* or the other block's start is within the first block.) * or the other block's start is within the first block.)
*/ */
if (lx < ly && lx + SMALLSIZE > ly) { if (lx < ly && lx + SMALLSIZE > ly) {
printf("FAIL: y starts within x\n"); tprintf("FAIL: y starts within x\n");
return; return;
} }
if (ly < lx && ly + MEDIUMSIZE > lx) { if (ly < lx && ly + MEDIUMSIZE > lx) {
printf("FAIL: x starts within y\n"); tprintf("FAIL: x starts within y\n");
return; return;
} }
@ -461,7 +461,7 @@ test4(void)
* free list. * free list.
*/ */
if (ly < lx) { if (ly < lx) {
printf("TEST UNSUITABLE: y is below x\n"); tprintf("TEST UNSUITABLE: y is below x\n");
return; return;
} }
@ -469,39 +469,39 @@ test4(void)
* Compute the space used by index structures. * Compute the space used by index structures.
*/ */
overhead = ly - (lx + SMALLSIZE); overhead = ly - (lx + SMALLSIZE);
printf("Apparent block overhead: %lu\n", overhead); tprintf("Apparent block overhead: %lu\n", overhead);
if (overhead > ABSURD_OVERHEAD) { if (overhead > ABSURD_OVERHEAD) {
printf("TEST UNSUITABLE: block overhead absurdly large.\n"); tprintf("TEST UNSUITABLE: block overhead absurdly large.\n");
return; return;
} }
if (overhead > OVERHEAD) { if (overhead > OVERHEAD) {
printf("FAIL: block overhead is too large.\n"); tprintf("FAIL: block overhead is too large.\n");
return; return;
} }
printf("Freeing blocks...\n"); tprintf("Freeing blocks...\n");
free(x); free(x);
free(y); free(y);
zsize = SMALLSIZE + MEDIUMSIZE + overhead; zsize = SMALLSIZE + MEDIUMSIZE + overhead;
printf("Now allocating %lu bytes... should reuse the space.\n", zsize); tprintf("Now allocating %lu bytes... should reuse the space.\n", zsize);
z = malloc(zsize); z = malloc(zsize);
if (z == NULL) { if (z == NULL) {
printf("FAIL: Allocation failed...\n"); tprintf("FAIL: Allocation failed...\n");
return; return;
} }
lz = (unsigned long) z; lz = (unsigned long) z;
printf("z is 0x%lx (x was 0x%lx, y 0x%lx)\n", lz, lx, ly); tprintf("z is 0x%lx (x was 0x%lx, y 0x%lx)\n", lz, lx, ly);
if (lz==lx) { if (lz==lx) {
printf("Passed.\n"); tprintf("Passed.\n");
} }
else { else {
printf("Failed.\n"); tprintf("Failed.\n");
} }
free(z); free(z);
@ -530,7 +530,7 @@ test567(int testno, unsigned long seed)
int i, n, size, failed=0; int i, n, size, failed=0;
srandom(seed); srandom(seed);
printf("Seeded random number generator with %lu.\n", seed); tprintf("Seeded random number generator with %lu.\n", seed);
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
ptrs[i] = NULL; ptrs[i] = NULL;
@ -544,7 +544,7 @@ test567(int testno, unsigned long seed)
ptrs[n] = malloc(size); ptrs[n] = malloc(size);
psizes[n] = size; psizes[n] = size;
if (ptrs[n] == NULL) { if (ptrs[n] == NULL) {
printf("\nmalloc %u failed\n", size); tprintf("\nmalloc %u failed\n", size);
failed = 1; failed = 1;
break; break;
} }
@ -561,10 +561,10 @@ test567(int testno, unsigned long seed)
psizes[n] = 0; psizes[n] = 0;
} }
if (i%256==0) { if (i%256==0) {
printf("."); tprintf(".");
} }
} }
printf("\n"); tprintf("\n");
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
if (ptrs[i] != NULL) { if (ptrs[i] != NULL) {
@ -573,10 +573,10 @@ test567(int testno, unsigned long seed)
} }
if (failed) { if (failed) {
printf("FAILED malloc test %d\n", testno); tprintf("FAILED malloc test %d\n", testno);
} }
else { else {
printf("Passed malloc test %d\n", testno); tprintf("Passed malloc test %d\n", testno);
} }
} }
@ -584,7 +584,7 @@ static
void void
test5(void) test5(void)
{ {
printf("Beginning malloc test 5\n"); tprintf("Beginning malloc test 5\n");
test567(5, 0); test567(5, 0);
} }
@ -595,7 +595,7 @@ test6(void)
int fd, len; int fd, len;
unsigned long seed; unsigned long seed;
printf("Beginning malloc test 6\n"); tprintf("Beginning malloc test 6\n");
fd = open(_PATH_RANDOM, O_RDONLY); fd = open(_PATH_RANDOM, O_RDONLY);
if (fd < 0) { if (fd < 0) {
@ -619,9 +619,9 @@ test7(void)
{ {
unsigned long seed; unsigned long seed;
printf("Beginning malloc test 7\n"); tprintf("Beginning malloc test 7\n");
printf("Enter random seed: "); tprintf("Enter random seed: ");
seed = geti(); seed = geti();
test567(7, seed); test567(7, seed);
@ -673,12 +673,12 @@ main(int argc, char *argv[])
while (1) { while (1) {
if (menu) { if (menu) {
for (i=0; tests[i].num>=0; i++) { for (i=0; tests[i].num>=0; i++) {
printf(" %2d %s\n", tests[i].num, tprintf(" %2d %s\n", tests[i].num,
tests[i].desc); tests[i].desc);
} }
menu = 0; menu = 0;
} }
printf("malloctest: "); tprintf("malloctest: ");
tn = geti(); tn = geti();
if (tn < 0) { if (tn < 0) {
break; break;

View File

@ -75,14 +75,14 @@ main(void)
for (k = 0; k < Dim; k++) for (k = 0; k < Dim; k++)
C[i][j] += A[i][k] * B[k][j]; C[i][j] += A[i][k] * B[k][j];
printf("matmult-orig finished.\n"); tprintf("matmult-orig finished.\n");
r = C[Dim-1][Dim-1]; r = C[Dim-1][Dim-1];
printf("answer is: %d (should be %d)\n", r, RIGHT); tprintf("answer is: %d (should be %d)\n", r, RIGHT);
if (r != RIGHT) { if (r != RIGHT) {
printf("FAILED\n"); tprintf("FAILED\n");
} }
else { else {
printf("Passed.\n"); tprintf("Passed.\n");
} }
return 0; return 0;
} }

View File

@ -79,12 +79,12 @@ main(void)
for (i = 0; i < Dim; i++) for (i = 0; i < Dim; i++)
r += C[i][i]; r += C[i][i];
printf("matmult finished.\n"); tprintf("matmult finished.\n");
printf("answer is: %d (should be %d)\n", r, RIGHT); tprintf("answer is: %d (should be %d)\n", r, RIGHT);
if (r != RIGHT) { if (r != RIGHT) {
printf("FAILED\n"); tprintf("FAILED\n");
return 1; return 1;
} }
printf("Passed.\n"); tprintf("Passed.\n");
return 0; return 0;
} }

View File

@ -169,7 +169,7 @@ spawn(int njobs)
semcreate("1", &s1); semcreate("1", &s1);
semcreate("2", &s2); semcreate("2", &s2);
printf("Forking %d child processes...\n", njobs); tprintf("Forking %d child processes...\n", njobs);
for (i=0; i<njobs; i++) { for (i=0; i<njobs; i++) {
pids[i] = fork(); pids[i] = fork();
@ -193,9 +193,9 @@ spawn(int njobs)
semopen(&s1); semopen(&s1);
semopen(&s2); semopen(&s2);
printf("Waiting for fork...\n"); tprintf("Waiting for fork...\n");
semP(&s1, njobs); semP(&s1, njobs);
printf("Starting the execs...\n"); tprintf("Starting the execs...\n");
semV(&s2, njobs); semV(&s2, njobs);
failed = 0; failed = 0;
@ -219,7 +219,7 @@ spawn(int njobs)
warnx("%d children failed", failed); warnx("%d children failed", failed);
} }
else { else {
printf("Succeeded\n"); tprintf("Succeeded\n");
} }
semclose(&s1); semclose(&s1);

View File

@ -175,12 +175,12 @@ main(void)
{ {
char *start, *end; char *start, *end;
printf("Welcome to the palindrome tester!\n"); tprintf("Welcome to the palindrome tester!\n");
printf("I will take a large palindrome and test it.\n"); tprintf("I will take a large palindrome and test it.\n");
printf("Here it is:\n"); tprintf("Here it is:\n");
printf("%s\n", palindrome); tprintf("%s\n", palindrome);
printf("Testing..."); tprintf("Testing...");
/* skip to end */ /* skip to end */
end = palindrome+strlen(palindrome); end = palindrome+strlen(palindrome);
end--; end--;
@ -188,11 +188,11 @@ main(void)
for (start = palindrome; start <= end; start++, end--) { for (start = palindrome; start <= end; start++, end--) {
putchar('.'); putchar('.');
if (*start != *end) { if (*start != *end) {
printf("NOT a palindrome\n"); tprintf("NOT a palindrome\n");
return 0; return 0;
} }
} }
printf("IS a palindrome\n"); tprintf("IS a palindrome\n");
return 0; return 0;
} }

View File

@ -88,7 +88,7 @@ struct matrix {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/* /*
* Use this instead of just calling printf so we know each printout * Use this instead of just calling tprintf so we know each printout
* is atomic; this prevents the lines from getting intermingled. * is atomic; this prevents the lines from getting intermingled.
*/ */
static static
@ -329,8 +329,8 @@ makeprocs(bool dowait)
semcreate("2", &s2); semcreate("2", &s2);
} }
printf("Job size approximately %lu bytes\n", (unsigned long) JOBSIZE); tprintf("Job size approximately %lu bytes\n", (unsigned long) JOBSIZE);
printf("Forking %d jobs; total load %luk\n", NJOBS, tprintf("Forking %d jobs; total load %luk\n", NJOBS,
(unsigned long) (NJOBS * JOBSIZE)/1024); (unsigned long) (NJOBS * JOBSIZE)/1024);
for (i=0; i<NJOBS; i++) { for (i=0; i<NJOBS; i++) {
@ -378,10 +378,10 @@ makeprocs(bool dowait)
} }
if (failcount>0) { if (failcount>0) {
printf("%d subprocesses failed\n", failcount); tprintf("%d subprocesses failed\n", failcount);
exit(1); exit(1);
} }
printf("Test complete\n"); tprintf("Test complete\n");
semclose(&s1); semclose(&s1);
semclose(&s2); semclose(&s2);
@ -404,7 +404,7 @@ main(int argc, char *argv[])
dowait = true; dowait = true;
} }
else { else {
printf("Usage: parallelvm [-w]\n"); tprintf("Usage: parallelvm [-w]\n");
return 1; return 1;
} }
makeprocs(dowait); makeprocs(dowait);

View File

@ -113,10 +113,10 @@ static
void void
usage(void) usage(void)
{ {
printf("Usage: randcall [-f] [-c count] [-r seed] 2|3|4|all\n"); tprintf("Usage: randcall [-f] [-c count] [-r seed] 2|3|4|all\n");
printf(" -f suppress forking\n"); tprintf(" -f suppress forking\n");
printf(" -c set iteration count (default 100)\n"); tprintf(" -c set iteration count (default 100)\n");
printf(" -r set pseudorandom seed (default 0)\n"); tprintf(" -r set pseudorandom seed (default 0)\n");
exit(1); exit(1);
} }

View File

@ -181,16 +181,16 @@ cat(void)
int int
main(void) main(void)
{ {
printf("Creating %s...\n", INFILE); tprintf("Creating %s...\n", INFILE);
mkfile(); mkfile();
printf("Running cat < %s > %s\n", INFILE, OUTFILE); tprintf("Running cat < %s > %s\n", INFILE, OUTFILE);
cat(); cat();
printf("Checking %s...\n", OUTFILE); tprintf("Checking %s...\n", OUTFILE);
chkfile(); chkfile();
printf("Passed.\n"); tprintf("Passed.\n");
(void)remove(INFILE); (void)remove(INFILE);
(void)remove(OUTFILE); (void)remove(OUTFILE);
return 0; return 0;

View File

@ -116,13 +116,13 @@ static
void void
test1(void) test1(void)
{ {
printf("Making %s\n", testdir); tprintf("Making %s\n", testdir);
startup(); startup();
printf("Removing %s while in it\n", testdir); tprintf("Removing %s while in it\n", testdir);
killdir(); killdir();
printf("Leaving the test directory\n"); tprintf("Leaving the test directory\n");
finish(); finish();
} }
@ -136,7 +136,7 @@ test2(void)
{ {
int fd; int fd;
printf("Now trying with the directory open...\n"); tprintf("Now trying with the directory open...\n");
startup(); startup();
fd = open(".", O_RDONLY); fd = open(".", O_RDONLY);
if (fd<0) { if (fd<0) {
@ -162,7 +162,7 @@ test3(void)
char buf[PATH_MAX]; char buf[PATH_MAX];
int fd; int fd;
printf("Checking if . exists after rmdir\n"); tprintf("Checking if . exists after rmdir\n");
startup(); startup();
killdir(); killdir();
@ -230,7 +230,7 @@ test4(void)
char buf[4096]; char buf[4096];
int fd; int fd;
printf("Checking if creating files works after rmdir...\n"); tprintf("Checking if creating files works after rmdir...\n");
startup(); startup();
killdir(); killdir();
@ -272,7 +272,7 @@ static
void void
test5(void) test5(void)
{ {
printf("Checking if creating subdirs works after rmdir...\n"); tprintf("Checking if creating subdirs works after rmdir...\n");
startup(); startup();
killdir(); killdir();
@ -315,7 +315,7 @@ test6(void)
char buf[PATH_MAX]; char buf[PATH_MAX];
int fd, len; int fd, len;
printf("Now trying to list the directory...\n"); tprintf("Now trying to list the directory...\n");
startup(); startup();
fd = open(".", O_RDONLY); fd = open(".", O_RDONLY);
if (fd<0) { if (fd<0) {
@ -399,6 +399,6 @@ main(void)
test6(); test6();
test7(); test7();
printf("Whew... survived.\n"); tprintf("Whew... survived.\n");
return 0; return 0;
} }

View File

@ -157,7 +157,7 @@ main(void)
err(1, "Unexpected error reopening the file"); err(1, "Unexpected error reopening the file");
} }
printf("Succeeded!\n"); tprintf("Succeeded!\n");
return 0; return 0;
} }

View File

@ -62,7 +62,7 @@ geti(void)
break; break;
} }
else if ((ch=='\b' || ch==127) && digits>0) { else if ((ch=='\b' || ch==127) && digits>0) {
printf("\b \b"); tprintf("\b \b");
val = val/10; val = val/10;
digits--; digits--;
} }
@ -141,7 +141,7 @@ static
void void
say(const char *msg) say(const char *msg)
{ {
/* Use one write so it's atomic (printf usually won't be) */ /* Use one write so it's atomic (tprintf usually won't be) */
write(STDOUT_FILENO, msg, strlen(msg)); write(STDOUT_FILENO, msg, strlen(msg));
} }
@ -194,9 +194,9 @@ checkpage(volatile void *baseptr, unsigned pageoffset, bool neednl)
val = ((unsigned long)i ^ (unsigned long)pageoffset); val = ((unsigned long)i ^ (unsigned long)pageoffset);
if (pl[i] != val) { if (pl[i] != val) {
if (neednl) { if (neednl) {
printf("\n"); tprintf("\n");
} }
printf("FAILED: data mismatch at offset %lu of page " tprintf("FAILED: data mismatch at offset %lu of page "
"at 0x%lx: %lu vs. %lu\n", "at 0x%lx: %lu vs. %lu\n",
(unsigned long) (i*sizeof(unsigned long)), (unsigned long) (i*sizeof(unsigned long)),
(unsigned long)(uintptr_t)pl, (unsigned long)(uintptr_t)pl,
@ -241,9 +241,9 @@ checkpagelight(volatile void *baseptr, unsigned pageoffset, bool neednl)
pl = (volatile unsigned long *)pageptr; pl = (volatile unsigned long *)pageptr;
if (pl[0] != pageoffset) { if (pl[0] != pageoffset) {
if (neednl) { if (neednl) {
printf("\n"); tprintf("\n");
} }
printf("FAILED: data mismatch at offset 0 of page " tprintf("FAILED: data mismatch at offset 0 of page "
"at 0x%lx: %lu vs. %u\n", "at 0x%lx: %lu vs. %u\n",
(unsigned long)(uintptr_t)pl, (unsigned long)(uintptr_t)pl,
pl[0], pageoffset); pl[0], pageoffset);
@ -317,14 +317,14 @@ test1(void)
{ {
void *p; void *p;
printf("Allocating a page...\n"); tprintf("Allocating a page...\n");
p = dosbrk(PAGE_SIZE); p = dosbrk(PAGE_SIZE);
markpage(p, 0); markpage(p, 0);
if (checkpage(p, 0, false)) { if (checkpage(p, 0, false)) {
errx(1, "FAILED: data corrupt"); errx(1, "FAILED: data corrupt");
} }
printf("Passed sbrk test 1.\n"); tprintf("Passed sbrk test 1.\n");
} }
/* /*
@ -338,7 +338,7 @@ test2(void)
op = dosbrk(0); op = dosbrk(0);
printf("Allocating a page...\n"); tprintf("Allocating a page...\n");
p = dosbrk(PAGE_SIZE); p = dosbrk(PAGE_SIZE);
if (p != op) { if (p != op) {
errx(1, "FAILED: sbrk grow didn't return the old break " errx(1, "FAILED: sbrk grow didn't return the old break "
@ -351,7 +351,7 @@ test2(void)
p = dosbrk(0); p = dosbrk(0);
printf("Freeing the page...\n"); tprintf("Freeing the page...\n");
q = dosbrk(-PAGE_SIZE); q = dosbrk(-PAGE_SIZE);
if (q != p) { if (q != p) {
errx(1, "FAILED: sbrk shrink didn't return the old break " errx(1, "FAILED: sbrk shrink didn't return the old break "
@ -363,7 +363,7 @@ test2(void)
"(got %p, expected %p", q, op); "(got %p, expected %p", q, op);
} }
printf("Passed sbrk test 2.\n"); tprintf("Passed sbrk test 2.\n");
} }
/* /*
@ -382,7 +382,7 @@ test3(void)
op = dosbrk(0); op = dosbrk(0);
printf("Allocating %u pages...\n", num); tprintf("Allocating %u pages...\n", num);
p = dosbrk(PAGE_SIZE * num); p = dosbrk(PAGE_SIZE * num);
if (p != op) { if (p != op) {
errx(1, "FAILED: sbrk grow didn't return the old break " errx(1, "FAILED: sbrk grow didn't return the old break "
@ -403,7 +403,7 @@ test3(void)
p = dosbrk(0); p = dosbrk(0);
printf("Freeing the pages...\n"); tprintf("Freeing the pages...\n");
q = dosbrk(-PAGE_SIZE * num); q = dosbrk(-PAGE_SIZE * num);
if (q != p) { if (q != p) {
errx(1, "FAILED: sbrk shrink didn't return the old break " errx(1, "FAILED: sbrk shrink didn't return the old break "
@ -415,7 +415,7 @@ test3(void)
"(got %p, expected %p", q, op); "(got %p, expected %p", q, op);
} }
printf("Passed sbrk test 3.\n"); tprintf("Passed sbrk test 3.\n");
} }
/* /*
@ -435,7 +435,7 @@ test4(void)
op = dosbrk(0); op = dosbrk(0);
printf("Allocating %u pages...\n", num); tprintf("Allocating %u pages...\n", num);
p = dosbrk(PAGE_SIZE * num); p = dosbrk(PAGE_SIZE * num);
if (p != op) { if (p != op) {
errx(1, "FAILED: sbrk grow didn't return the old break " errx(1, "FAILED: sbrk grow didn't return the old break "
@ -454,7 +454,7 @@ test4(void)
exit(1); exit(1);
} }
printf("Freeing the pages one at a time...\n"); tprintf("Freeing the pages one at a time...\n");
for (i=num; i-- > 0; ) { for (i=num; i-- > 0; ) {
(void)dosbrk(-PAGE_SIZE); (void)dosbrk(-PAGE_SIZE);
for (j=0; j<i; j++) { for (j=0; j<i; j++) {
@ -475,7 +475,7 @@ test4(void)
"(got %p, expected %p", q, op); "(got %p, expected %p", q, op);
} }
printf("Passed sbrk test 4.\n"); tprintf("Passed sbrk test 4.\n");
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -492,7 +492,7 @@ test5(void)
void *p; void *p;
p = dosbrk(0); p = dosbrk(0);
printf("This should produce fatal signal 11 (SIGSEGV).\n"); tprintf("This should produce fatal signal 11 (SIGSEGV).\n");
((long *)p)[10] = 0; ((long *)p)[10] = 0;
errx(1, "FAILED: I didn't crash"); errx(1, "FAILED: I didn't crash");
} }
@ -509,7 +509,7 @@ test6(void)
(void)dosbrk(PAGE_SIZE); (void)dosbrk(PAGE_SIZE);
p = dosbrk(0); p = dosbrk(0);
printf("This should produce fatal signal 11 (SIGSEGV).\n"); tprintf("This should produce fatal signal 11 (SIGSEGV).\n");
((long *)p)[10] = 0; ((long *)p)[10] = 0;
errx(1, "FAILED: I didn't crash"); errx(1, "FAILED: I didn't crash");
} }
@ -527,7 +527,7 @@ test7(void)
(void)dosbrk(PAGE_SIZE); (void)dosbrk(PAGE_SIZE);
(void)dosbrk(-PAGE_SIZE); (void)dosbrk(-PAGE_SIZE);
p = dosbrk(0); p = dosbrk(0);
printf("This should produce fatal signal 11 (SIGSEGV).\n"); tprintf("This should produce fatal signal 11 (SIGSEGV).\n");
((long *)p)[10] = 0; ((long *)p)[10] = 0;
errx(1, "FAILED: I didn't crash"); errx(1, "FAILED: I didn't crash");
} }
@ -546,7 +546,7 @@ test8(void)
(void)dosbrk(PAGE_SIZE * 12); (void)dosbrk(PAGE_SIZE * 12);
(void)dosbrk(-PAGE_SIZE * 6); (void)dosbrk(-PAGE_SIZE * 6);
p = dosbrk(0); p = dosbrk(0);
printf("This should produce fatal signal 11 (SIGSEGV).\n"); tprintf("This should produce fatal signal 11 (SIGSEGV).\n");
((long *)p)[10] = 0; ((long *)p)[10] = 0;
errx(1, "FAILED: I didn't crash"); errx(1, "FAILED: I didn't crash");
} }
@ -588,59 +588,59 @@ test9(void)
#define HUGESIZE (1024 * 1024 * 1024) /* 1G */ #define HUGESIZE (1024 * 1024 * 1024) /* 1G */
printf("Checking how much memory we can allocate:\n"); tprintf("Checking how much memory we can allocate:\n");
for (size = HUGESIZE; (p = sbrk(size)) == (void *)-1; size = size/2) { for (size = HUGESIZE; (p = sbrk(size)) == (void *)-1; size = size/2) {
printf(" %9lu bytes: failed\n", (unsigned long) size); tprintf(" %9lu bytes: failed\n", (unsigned long) size);
} }
printf(" %9lu bytes: succeeded\n", (unsigned long) size); tprintf(" %9lu bytes: succeeded\n", (unsigned long) size);
printf("Passed sbrk test 9 (part 1/5)\n"); tprintf("Passed sbrk test 9 (part 1/5)\n");
printf("Touching each page.\n"); tprintf("Touching each page.\n");
pages = size / PAGE_SIZE; pages = size / PAGE_SIZE;
dot = pages / 64; dot = pages / 64;
for (i=0; i<pages; i++) { for (i=0; i<pages; i++) {
markpagelight(p, i); markpagelight(p, i);
if (dot > 0 && i % dot == 0) { if (dot > 0 && i % dot == 0) {
printf("."); tprintf(".");
} }
} }
if (dot > 0) { if (dot > 0) {
printf("\n"); tprintf("\n");
} }
printf("Testing each page.\n"); tprintf("Testing each page.\n");
bad = false; bad = false;
for (i=0; i<pages; i++) { for (i=0; i<pages; i++) {
if (checkpagelight(p, i, dot > 0)) { if (checkpagelight(p, i, dot > 0)) {
if (dot > 0) { if (dot > 0) {
printf("\n"); tprintf("\n");
} }
warnx("FAILED: data corrupt"); warnx("FAILED: data corrupt");
bad = true; bad = true;
} }
if (dot > 0 && i % dot == 0) { if (dot > 0 && i % dot == 0) {
printf("."); tprintf(".");
} }
} }
if (dot > 0) { if (dot > 0) {
printf("\n"); tprintf("\n");
} }
if (bad) { if (bad) {
exit(1); exit(1);
} }
printf("Passed sbrk test 9 (part 2/5)\n"); tprintf("Passed sbrk test 9 (part 2/5)\n");
printf("Freeing the memory.\n"); tprintf("Freeing the memory.\n");
(void)dosbrk(-size); (void)dosbrk(-size);
printf("Passed sbrk test 9 (part 3/5)\n"); tprintf("Passed sbrk test 9 (part 3/5)\n");
printf("Allocating the memory again.\n"); tprintf("Allocating the memory again.\n");
(void)dosbrk(size); (void)dosbrk(size);
printf("Passed sbrk test 9 (part 4/5)\n"); tprintf("Passed sbrk test 9 (part 4/5)\n");
printf("And really freeing it.\n"); tprintf("And really freeing it.\n");
(void)dosbrk(-size); (void)dosbrk(-size);
printf("Passed sbrk test 9 (all)\n"); tprintf("Passed sbrk test 9 (all)\n");
} }
/* /*
@ -655,16 +655,16 @@ test10(void)
unsigned i, n; unsigned i, n;
bool bad; bool bad;
printf("Allocating all of memory one page at a time:\n"); tprintf("Allocating all of memory one page at a time:\n");
op = dosbrk(0); op = dosbrk(0);
n = 0; n = 0;
while ((p = sbrk(PAGE_SIZE)) != (void *)-1) { while ((p = sbrk(PAGE_SIZE)) != (void *)-1) {
markpagelight(op, n); markpagelight(op, n);
n++; n++;
} }
printf("Got %u pages (%zu bytes).\n", n, (size_t)PAGE_SIZE * n); tprintf("Got %u pages (%zu bytes).\n", n, (size_t)PAGE_SIZE * n);
printf("Now freeing them.\n"); tprintf("Now freeing them.\n");
bad = false; bad = false;
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
if (checkpagelight(op, n - i - 1, false)) { if (checkpagelight(op, n - i - 1, false)) {
@ -676,14 +676,14 @@ test10(void)
if (bad) { if (bad) {
exit(1); exit(1);
} }
printf("Freed %u pages.\n", n); tprintf("Freed %u pages.\n", n);
p = dosbrk(0); p = dosbrk(0);
if (p != op) { if (p != op) {
errx(1, "FAILURE: break did not return to original value"); errx(1, "FAILURE: break did not return to original value");
} }
printf("Now let's see if I can allocate another page.\n"); tprintf("Now let's see if I can allocate another page.\n");
p = dosbrk(PAGE_SIZE); p = dosbrk(PAGE_SIZE);
markpage(p, 0); markpage(p, 0);
if (checkpage(p, 0, false)) { if (checkpage(p, 0, false)) {
@ -691,7 +691,7 @@ test10(void)
} }
(void)dosbrk(-PAGE_SIZE); (void)dosbrk(-PAGE_SIZE);
printf("Passed sbrk test 10.\n"); tprintf("Passed sbrk test 10.\n");
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -707,20 +707,20 @@ test11(void)
unsigned i; unsigned i;
bool bad; bool bad;
printf("Allocating %u pages (%zu bytes).\n", num, tprintf("Allocating %u pages (%zu bytes).\n", num,
(size_t)PAGE_SIZE * num); (size_t)PAGE_SIZE * num);
p = dosbrk(num * PAGE_SIZE); p = dosbrk(num * PAGE_SIZE);
printf("Touching the pages.\n"); tprintf("Touching the pages.\n");
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
markpagelight(p, i); markpagelight(p, i);
if (i % 4 == 0) { if (i % 4 == 0) {
printf("."); tprintf(".");
} }
} }
printf("\n"); tprintf("\n");
printf("Checking the pages.\n"); tprintf("Checking the pages.\n");
bad = false; bad = false;
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
if (checkpagelight(p, i, true)) { if (checkpagelight(p, i, true)) {
@ -728,16 +728,16 @@ test11(void)
bad = true; bad = true;
} }
if (i % 4 == 0) { if (i % 4 == 0) {
printf("."); tprintf(".");
} }
} }
printf("\n"); tprintf("\n");
if (bad) { if (bad) {
exit(1); exit(1);
} }
printf("Now NOT freeing the pages. They should get freed on exit.\n"); tprintf("Now NOT freeing the pages. They should get freed on exit.\n");
printf("If not, you'll notice pretty quickly.\n"); tprintf("If not, you'll notice pretty quickly.\n");
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -756,7 +756,7 @@ test12(void)
pid_t pid; pid_t pid;
void *p; void *p;
printf("Forking...\n"); tprintf("Forking...\n");
pid = dofork(); pid = dofork();
if (pid == 0) { if (pid == 0) {
/* child */ /* child */
@ -778,7 +778,7 @@ test12(void)
} }
say("Parent done.\n"); say("Parent done.\n");
dowait(pid); dowait(pid);
printf("Passed sbrk test 12.\n"); tprintf("Passed sbrk test 12.\n");
} }
/* /*
@ -791,14 +791,14 @@ test13(void)
pid_t pid; pid_t pid;
void *p; void *p;
printf("Allocating a page...\n"); tprintf("Allocating a page...\n");
p = dosbrk(PAGE_SIZE); p = dosbrk(PAGE_SIZE);
markpage(p, 0); markpage(p, 0);
if (checkpage(p, 0, false)) { if (checkpage(p, 0, false)) {
errx(1, "FAILED: data corrupt before forking"); errx(1, "FAILED: data corrupt before forking");
} }
printf("Forking...\n"); tprintf("Forking...\n");
pid = dofork(); pid = dofork();
if (pid == 0) { if (pid == 0) {
/* child */ /* child */
@ -811,7 +811,7 @@ test13(void)
errx(1, "FAILED: data corrupt in parent"); errx(1, "FAILED: data corrupt in parent");
} }
dowait(pid); dowait(pid);
printf("Passed sbrk test 13.\n"); tprintf("Passed sbrk test 13.\n");
} }
/* /*
@ -824,21 +824,21 @@ test14(void)
pid_t pid; pid_t pid;
void *p; void *p;
printf("Allocating a page...\n"); tprintf("Allocating a page...\n");
p = dosbrk(PAGE_SIZE); p = dosbrk(PAGE_SIZE);
markpage(p, 0); markpage(p, 0);
if (checkpage(p, 0, false)) { if (checkpage(p, 0, false)) {
errx(1, "FAILED: data corrupt before forking"); errx(1, "FAILED: data corrupt before forking");
} }
printf("Forking...\n"); tprintf("Forking...\n");
pid = dofork(); pid = dofork();
if (pid == 0) { if (pid == 0) {
/* child */ /* child */
if (checkpage(p, 0, false)) { if (checkpage(p, 0, false)) {
errx(1, "FAILED: data corrupt in child"); errx(1, "FAILED: data corrupt in child");
} }
printf("Child freeing a page...\n"); tprintf("Child freeing a page...\n");
dosbrk(-PAGE_SIZE); dosbrk(-PAGE_SIZE);
exit(0); exit(0);
} }
@ -846,7 +846,7 @@ test14(void)
if (checkpage(p, 0, false)) { if (checkpage(p, 0, false)) {
errx(1, "FAILED: data corrupt in parent after child ran"); errx(1, "FAILED: data corrupt in parent after child ran");
} }
printf("Passed sbrk test 14.\n"); tprintf("Passed sbrk test 14.\n");
} }
/* /*
@ -863,7 +863,7 @@ test15(void)
unsigned i; unsigned i;
void *p; void *p;
printf("Allocating %u pages...\n", num); tprintf("Allocating %u pages...\n", num);
p = dosbrk(PAGE_SIZE * num); p = dosbrk(PAGE_SIZE * num);
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
markpage(p, i); markpage(p, i);
@ -874,7 +874,7 @@ test15(void)
} }
} }
printf("Freeing one page...\n"); tprintf("Freeing one page...\n");
(void)dosbrk(-PAGE_SIZE); (void)dosbrk(-PAGE_SIZE);
num--; num--;
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
@ -883,7 +883,7 @@ test15(void)
} }
} }
printf("Allocating two pages...\n"); tprintf("Allocating two pages...\n");
(void)dosbrk(PAGE_SIZE * 2); (void)dosbrk(PAGE_SIZE * 2);
markpage(p, num++); markpage(p, num++);
markpage(p, num++); markpage(p, num++);
@ -893,7 +893,7 @@ test15(void)
} }
} }
printf("Forking...\n"); tprintf("Forking...\n");
pid = dofork(); pid = dofork();
if (pid == 0) { if (pid == 0) {
/* child */ /* child */
@ -947,7 +947,7 @@ test15(void)
} }
(void)dosbrk(-PAGE_SIZE * num); (void)dosbrk(-PAGE_SIZE * num);
printf("Passed sbrk test 15.\n"); tprintf("Passed sbrk test 15.\n");
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -967,7 +967,7 @@ stresstest(unsigned long seed, bool large)
bool bad, neg; bool bad, neg;
srandom(seed); srandom(seed);
printf("Seeded random number generator with %lu.\n", seed); tprintf("Seeded random number generator with %lu.\n", seed);
op = dosbrk(0); op = dosbrk(0);
@ -999,23 +999,23 @@ stresstest(unsigned long seed, bool large)
} }
for (j=0; j<num; j++) { for (j=0; j<num; j++) {
if (checkpagelight(op, j, true)) { if (checkpagelight(op, j, true)) {
printf("\n"); tprintf("\n");
warnx("FAILED: data corrupt on page %u", j); warnx("FAILED: data corrupt on page %u", j);
bad = true; bad = true;
} }
} }
if (i % dot == 0) { if (i % dot == 0) {
printf("."); tprintf(".");
} }
} }
printf("\n"); tprintf("\n");
if (bad) { if (bad) {
warnx("FAILED"); warnx("FAILED");
exit(1); exit(1);
} }
dosbrk(-(num * PAGE_SIZE)); dosbrk(-(num * PAGE_SIZE));
printf("Passed sbrk %s stress test.\n", large ? "large" : "small"); tprintf("Passed sbrk %s stress test.\n", large ? "large" : "small");
} }
static static
@ -1036,7 +1036,7 @@ static
void void
test18(void) test18(void)
{ {
printf("Enter random seed: "); tprintf("Enter random seed: ");
stresstest(geti(), false); stresstest(geti(), false);
} }
@ -1058,7 +1058,7 @@ static
void void
test21(void) test21(void)
{ {
printf("Enter random seed: "); tprintf("Enter random seed: ");
stresstest(geti(), true); stresstest(geti(), true);
} }
@ -1128,12 +1128,12 @@ main(int argc, char *argv[])
while (1) { while (1) {
if (menu) { if (menu) {
for (j=0; j<numtests; j++) { for (j=0; j<numtests; j++) {
printf(" %2d %s\n", tests[j].num, tprintf(" %2d %s\n", tests[j].num,
tests[j].desc); tests[j].desc);
} }
menu = false; menu = false;
} }
printf("sbrktest: "); tprintf("sbrktest: ");
tn = geti(); tn = geti();
if (tn < 0) { if (tn < 0) {
break; break;

View File

@ -229,7 +229,7 @@ runit(unsigned numthinkers, unsigned numgrinders,
char buf[32]; char buf[32];
unsigned i; unsigned i;
printf("Running with %u thinkers, %u grinders, and %u pong groups " tprintf("Running with %u thinkers, %u grinders, and %u pong groups "
"of size %u each.\n", numthinkers, numgrinders, numponggroups, "of size %u each.\n", numthinkers, numgrinders, numponggroups,
ponggroupsize); ponggroupsize);
@ -242,7 +242,7 @@ runit(unsigned numthinkers, unsigned numgrinders,
&pids[i+2]); &pids[i+2]);
} }
usem_open(&startsem); usem_open(&startsem);
printf("Forking done; starting the workload.\n"); tprintf("Forking done; starting the workload.\n");
__time(&startsecs, &startnsecs); __time(&startsecs, &startnsecs);
Vn(&startsem, numthinkers + numgrinders + Vn(&startsem, numthinkers + numgrinders +
numponggroups * ponggroupsize); numponggroups * ponggroupsize);
@ -252,20 +252,20 @@ runit(unsigned numthinkers, unsigned numgrinders,
openresultsfile(O_RDONLY); openresultsfile(O_RDONLY);
printf("--- Timings ---\n"); tprintf("--- Timings ---\n");
if (numthinkers > 0) { if (numthinkers > 0) {
calcresult(0, startsecs, startnsecs, buf, sizeof(buf)); calcresult(0, startsecs, startnsecs, buf, sizeof(buf));
printf("Thinkers: %s\n", buf); tprintf("Thinkers: %s\n", buf);
} }
if (numgrinders > 0) { if (numgrinders > 0) {
calcresult(1, startsecs, startnsecs, buf, sizeof(buf)); calcresult(1, startsecs, startnsecs, buf, sizeof(buf));
printf("Grinders: %s\n", buf); tprintf("Grinders: %s\n", buf);
} }
for (i=0; i<numponggroups; i++) { for (i=0; i<numponggroups; i++) {
calcresult(i+2, startsecs, startnsecs, buf, sizeof(buf)); calcresult(i+2, startsecs, startnsecs, buf, sizeof(buf));
printf("Pong group %u: %s\n", i, buf); tprintf("Pong group %u: %s\n", i, buf);
} }
closeresultsfile(); closeresultsfile();

View File

@ -100,7 +100,7 @@ pong_cyclic(unsigned id)
P(&sems[id]); P(&sems[id]);
} }
#ifdef VERBOSE_PONG #ifdef VERBOSE_PONG
printf(" %u", id); tprintf(" %u", id);
#else #else
if (nextid == 0 && i % 16 == 0) { if (nextid == 0 && i % 16 == 0) {
putchar('.'); putchar('.');
@ -151,7 +151,7 @@ pong_reciprocating(unsigned id)
P(&sems[id]); P(&sems[id]);
} }
#ifdef VERBOSE_PONG #ifdef VERBOSE_PONG
printf(" %u", id); tprintf(" %u", id);
#else #else
if (id == 0 && i % 16 == 0) { if (id == 0 && i % 16 == 0) {
putchar('.'); putchar('.');
@ -197,11 +197,11 @@ pong(unsigned groupid, unsigned id)
waitstart(); waitstart();
pong_cyclic(id); pong_cyclic(id);
#ifdef VERBOSE_PONG #ifdef VERBOSE_PONG
printf("--------------------------------\n"); tprintf("--------------------------------\n");
#endif #endif
pong_reciprocating(id); pong_reciprocating(id);
#ifdef VERBOSE_PONG #ifdef VERBOSE_PONG
printf("--------------------------------\n"); tprintf("--------------------------------\n");
#endif #endif
pong_cyclic(id); pong_cyclic(id);

View File

@ -131,7 +131,7 @@ readstatus(int status, struct exitinfo *ei)
ei->coredump = 0; ei->coredump = 0;
} }
else { else {
printf("Invalid status code %d", status); tprintf("Invalid status code %d", status);
ei->val = status; ei->val = status;
ei->signaled = 0; ei->signaled = 0;
ei->stopped = 0; ei->stopped = 0;
@ -149,16 +149,16 @@ void
printstatus(const struct exitinfo *ei, int printexitzero) printstatus(const struct exitinfo *ei, int printexitzero)
{ {
if (ei->signaled && ei->coredump) { if (ei->signaled && ei->coredump) {
printf("Signal %d (core dumped)\n", ei->val); tprintf("Signal %d (core dumped)\n", ei->val);
} }
else if (ei->signaled) { else if (ei->signaled) {
printf("Signal %d\n", ei->val); tprintf("Signal %d\n", ei->val);
} }
else if (ei->stopped) { else if (ei->stopped) {
printf("Stopped on signal %d\n", ei->val); tprintf("Stopped on signal %d\n", ei->val);
} }
else if (printexitzero || ei->val != 0) { else if (printexitzero || ei->val != 0) {
printf("Exit %d\n", ei->val); tprintf("Exit %d\n", ei->val);
} }
} }
@ -177,7 +177,7 @@ dowait(pid_t pid)
warn("pid %d", pid); warn("pid %d", pid);
} }
else { else {
printf("pid %d: ", pid); tprintf("pid %d: ", pid);
readstatus(status, &ei); readstatus(status, &ei);
printstatus(&ei, 1); printstatus(&ei, 1);
} }
@ -201,7 +201,7 @@ dowaitpoll(pid_t pid)
warn("pid %d", pid); warn("pid %d", pid);
} }
else if (foundpid != 0) { else if (foundpid != 0) {
printf("pid %d: ", pid); tprintf("pid %d: ", pid);
readstatus(status, &ei); readstatus(status, &ei);
printstatus(&ei, 1); printstatus(&ei, 1);
return 1; return 1;
@ -262,7 +262,7 @@ cmd_wait(int ac, char *av[], struct exitinfo *ei)
exitinfo_exit(ei, 0); exitinfo_exit(ei, 0);
return; return;
} }
printf("Usage: wait [pid]\n"); tprintf("Usage: wait [pid]\n");
exitinfo_exit(ei, 1); exitinfo_exit(ei, 1);
} }
@ -284,7 +284,7 @@ cmd_chdir(int ac, char *av[], struct exitinfo *ei)
exitinfo_exit(ei, 0); exitinfo_exit(ei, 0);
return; return;
} }
printf("Usage: chdir dir\n"); tprintf("Usage: chdir dir\n");
exitinfo_exit(ei, 1); exitinfo_exit(ei, 1);
} }
@ -306,7 +306,7 @@ cmd_exit(int ac, char *av[], struct exitinfo *ei)
code = atoi(av[1]); code = atoi(av[1]);
} }
else { else {
printf("Usage: exit [code]\n"); tprintf("Usage: exit [code]\n");
exitinfo_exit(ei, 1); exitinfo_exit(ei, 1);
return; return;
} }
@ -352,7 +352,7 @@ docommand(char *buf, struct exitinfo *ei)
nargs = 0; nargs = 0;
for (s = strtok(buf, " \t\r\n"); s; s = strtok(NULL, " \t\r\n")) { for (s = strtok(buf, " \t\r\n"); s; s = strtok(NULL, " \t\r\n")) {
if (nargs >= NARG_MAX) { if (nargs >= NARG_MAX) {
printf("%s: Too many arguments " tprintf("%s: Too many arguments "
"(exceeds system limit)\n", "(exceeds system limit)\n",
args[0]); args[0]);
exitinfo_exit(ei, 1); exitinfo_exit(ei, 1);
@ -380,7 +380,7 @@ docommand(char *buf, struct exitinfo *ei)
if (nargs > 0 && !strcmp(args[nargs-1], "&")) { if (nargs > 0 && !strcmp(args[nargs-1], "&")) {
/* background */ /* background */
if (!can_bg()) { if (!can_bg()) {
printf("%s: Too many background jobs; wait for " tprintf("%s: Too many background jobs; wait for "
"some to finish before starting more\n", "some to finish before starting more\n",
args[0]); args[0]);
exitinfo_exit(ei, 1); exitinfo_exit(ei, 1);
@ -422,7 +422,7 @@ docommand(char *buf, struct exitinfo *ei)
if (bg) { if (bg) {
/* background this command */ /* background this command */
remember_bg(pid); remember_bg(pid);
printf("[%d] %s ... &\n", pid, args[0]); tprintf("[%d] %s ... &\n", pid, args[0]);
exitinfo_exit(ei, 0); exitinfo_exit(ei, 0);
return; return;
} }
@ -537,8 +537,8 @@ static
void void
usage(void) usage(void)
{ {
printf("Usage: shll [-p percent]\n"); tprintf("Usage: shll [-p percent]\n");
printf(" -p percent of characters to drop (default 5)\n"); tprintf(" -p percent of characters to drop (default 5)\n");
exit(1); exit(1);
} }

View File

@ -63,7 +63,7 @@ main(int argc, char *argv[])
err(1, "Sparse files of length zero are not meaningful"); err(1, "Sparse files of length zero are not meaningful");
} }
printf("Creating a sparse file of size %d\n", size); tprintf("Creating a sparse file of size %d\n", size);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC); fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC);
if (fd < 0) { if (fd < 0) {

View File

@ -92,7 +92,7 @@ main(void)
win = do_move(player); win = do_move(player);
print_board(); print_board();
if (win) { if (win) {
printf("Player %d, you WON!\n\n", player); tprintf("Player %d, you WON!\n\n", player);
break; /* out of for loop */ break; /* out of for loop */
} }
} }
@ -101,7 +101,7 @@ main(void)
* tie game. * tie game.
*/ */
if (!win) if (!win)
printf("Tie Game!\n\n"); tprintf("Tie Game!\n\n");
if (!ask_yesno("Do you wish to play again?")) if (!ask_yesno("Do you wish to play again?"))
break; /* out of while loop */ break; /* out of while loop */
} }
@ -121,9 +121,9 @@ main(void)
void void
print_instructions(void) print_instructions(void)
{ {
printf("Welcome to tic-tac-toe!\n"); tprintf("Welcome to tic-tac-toe!\n");
printf("Player 1 always plays X and player 2 always play O\n"); tprintf("Player 1 always plays X and player 2 always play O\n");
printf("Good luck!\n\n\n"); tprintf("Good luck!\n\n\n");
} }
void void
@ -142,22 +142,22 @@ print_board(void)
int i, j; int i, j;
/* Print labels across the top */ /* Print labels across the top */
printf("\n 0 1 2\n"); tprintf("\n 0 1 2\n");
for (i = 0; i < DIM; i++) { for (i = 0; i < DIM; i++) {
/* Print row labels */ /* Print row labels */
printf(" %d ", i); tprintf(" %d ", i);
for (j = 0; j < DIM; j++) { for (j = 0; j < DIM; j++) {
switch (board[i][j]) { switch (board[i][j]) {
case EMPTY: printf(" "); break; case EMPTY: tprintf(" "); break;
case X_MARKER: printf(" X "); break; case X_MARKER: tprintf(" X "); break;
case O_MARKER: printf(" O "); break; case O_MARKER: tprintf(" O "); break;
default: printf("???"); break; default: tprintf("???"); break;
} }
} }
printf("\n"); tprintf("\n");
} }
printf("\n"); tprintf("\n");
} }
/* /*
@ -181,7 +181,7 @@ ask_yesno(const char *msg)
char answer[MAXSTRING]; char answer[MAXSTRING];
while (TRUE) { while (TRUE) {
printf("%s [yes/no] ", msg); tprintf("%s [yes/no] ", msg);
if (read_string(answer, MAXSTRING) < 0) if (read_string(answer, MAXSTRING) < 0)
return(FALSE); return(FALSE);
if (Strcmp(answer, "yes")) if (Strcmp(answer, "yes"))
@ -189,7 +189,7 @@ ask_yesno(const char *msg)
else if (Strcmp(answer, "no")) else if (Strcmp(answer, "no"))
return(FALSE); return(FALSE);
else else
printf("Please answer either yes or no\n"); tprintf("Please answer either yes or no\n");
} }
} }
@ -216,32 +216,32 @@ do_move(int player)
char answer[MAXSTRING]; char answer[MAXSTRING];
char cx; char cx;
printf("Player %d (%c), your move\n", player, tprintf("Player %d (%c), your move\n", player,
player == X_PLAYER ? 'X' : 'O'); player == X_PLAYER ? 'X' : 'O');
while (TRUE) { while (TRUE) {
printf("Which row [0-%d]: ", DIM-1); tprintf("Which row [0-%d]: ", DIM-1);
if (read_string(answer, MAXSTRING) < 0) if (read_string(answer, MAXSTRING) < 0)
return(FALSE); return(FALSE);
cx = answer[0]; cx = answer[0];
x = cx - '0'; x = cx - '0';
if (x < 0 || x >= DIM) { if (x < 0 || x >= DIM) {
printf("Invalid row; must be >= 0 and < %d\n", DIM-1); tprintf("Invalid row; must be >= 0 and < %d\n", DIM-1);
continue; continue;
} }
printf("Which column [0-%d]: ", DIM-1); tprintf("Which column [0-%d]: ", DIM-1);
if (read_string(answer, MAXSTRING) < 0) if (read_string(answer, MAXSTRING) < 0)
return(FALSE); return(FALSE);
cx = answer[0]; cx = answer[0];
y = cx - '0'; y = cx - '0';
if (y < 0 || y >= DIM) { if (y < 0 || y >= DIM) {
printf("Invalid column; must be >= 0 and < %d\n", tprintf("Invalid column; must be >= 0 and < %d\n",
DIM-1); DIM-1);
continue; continue;
} }
if (board[x][y] != EMPTY) { if (board[x][y] != EMPTY) {
printf("That location is occupied; please try again\n"); tprintf("That location is occupied; please try again\n");
print_board(); print_board();
} else } else
break; break;

View File

@ -79,7 +79,7 @@ main(int argc, char *argv[])
threadfork(BladeRunner); threadfork(BladeRunner);
} }
printf("Parent has left.\n"); tprintf("Parent has left.\n");
return 0; return 0;
} }
@ -93,7 +93,7 @@ BladeRunner()
{ {
while (count < MAX) { while (count < MAX) {
if (count % 500 == 0) if (count % 500 == 0)
printf("Blade "); tprintf("Blade ");
count++; count++;
} }
} }
@ -103,7 +103,7 @@ ThreadRunner()
{ {
while (count < MAX) { while (count < MAX) {
if (count % 513 == 0) if (count % 513 == 0)
printf(" Runner\n"); tprintf(" Runner\n");
count++; count++;
} }
} }

View File

@ -112,7 +112,7 @@ check_sbrk(void)
base = sbrk(SBRK_SIZE); base = sbrk(SBRK_SIZE);
if (base == (void *)-1) { if (base == (void *)-1) {
if (errno == ENOSYS) { if (errno == ENOSYS) {
printf("I guess you haven't implemented sbrk yet.\n"); tprintf("I guess you haven't implemented sbrk yet.\n");
return; return;
} }
err(1, "sbrk"); err(1, "sbrk");
@ -133,13 +133,13 @@ check_sbrk(void)
int int
main(void) main(void)
{ {
printf("zero: phase 1: checking .bss\n"); tprintf("zero: phase 1: checking .bss\n");
check_data(); check_data();
check_bss(); check_bss();
printf("zero: phase 2: checking sbrk()\n"); tprintf("zero: phase 2: checking sbrk()\n");
check_sbrk(); check_sbrk();
printf("zero: passed\n"); tprintf("zero: passed\n");
return 0; return 0;
} }