00001
00002
00003
00004
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <assert.h>
00008 #include <sys/types.h>
00009 #include <sys/stat.h>
00010 #include <fcntl.h>
00011 #include "../lib/testutils.h"
00012
00013 #define NUM_TIMES (1)
00014 #define NUM_INTS (4*1024)
00015
00016 int
00017 main()
00018 {
00019 int i, rc, fd;
00020 int write_array[NUM_INTS];
00021 int read_array[NUM_INTS];
00022
00023
00024
00025
00026
00027 for (i=0; i<NUM_INTS; i++) {
00028 write_array[i] = i;
00029 }
00030
00031
00032 fd = open("WRITE_READ_FILE", O_WRONLY | O_CREAT);
00033 TEST_POSITIVE(fd, "Open file named WRITE_READ_FILE failed\n");
00034
00035 for (i=0; i<NUM_TIMES; i++) {
00036 rc = write(fd, write_array, sizeof(write_array));
00037 TEST_EQUAL(rc, sizeof(write_array), "Failed to write all of the array");
00038 }
00039
00040 close(fd);
00041
00042
00043 fd = open("WRITE_READ_FILE", O_RDONLY);
00044 TEST_POSITIVE(fd, "Open file named WRITE_READ_FILE failed\n");
00045
00046 for (i=0; i<NUM_TIMES; i++) {
00047 rc = read(fd, read_array, sizeof(read_array));
00048 TEST_EQUAL(rc, sizeof(read_array), "Failed to read all of the array");
00049 for (i=0; i<NUM_INTS; i++) {
00050 TEST_EQUAL(read_array[i], write_array[i], "Value read not equal to value written");
00051 }
00052 }
00053
00054 TEST_STATS();
00055
00056 exit(0);
00057 }