1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include "bonnie.h"
#include <unistd.h>
#include <stdlib.h>
#include <cstring>
#include "duration.h"
#include <vector>
#include "getc_putc.h"
int main(int argc, char *argv[])
{
if(argc != 2)
{
fprintf(stderr, "Error - don't run this yourself, run getc_putc!\n");
return 1;
}
int size = atoi(argv[1]);
bool quiet = false;
if(argv[1][strlen(argv[1]) - 1] == 'q')
quiet = true;
volatile char c;
int i;
Duration dur;
double res[2];
FILE *fp = fdopen(FILE_FD, "w+");
if(!fp)
{
fprintf(stderr, "Can't reopen for putc.\n");
return 1;
}
if(fseek(fp, 0, SEEK_SET) != 0)
{
fprintf(stderr, "Can't seek.\n");
return 1;
}
fflush(NULL);
TEST_FUNC_WRITE("putc(c, fp) no thread", if(putc(c, fp) == EOF), res[0]);
if(fseek(fp, 0, SEEK_SET) != 0)
{
fprintf(stderr, "Can't seek.\n");
return 1;
}
fflush(NULL);
TEST_FUNC_READ("getc() no thread", if( (c = getc(fp)) == EOF), res[1]);
if(fseek(fp, 0, SEEK_SET) != 0)
{
fprintf(stderr, "Can't seek.\n");
return 1;
}
fflush(NULL);
if(write(1, res, sizeof(res)) != sizeof(res))
{
fprintf(stderr, "Can't write results to parent process.\n");
return 1;
}
return 0;
}
|