root/user/uw-testbin/writeread/writeread.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Tim Brecht
   2  * Added :Sat  5 Jan 2013 15:19:15 EST
   3  */
   4 
   5 #include <stdio.h>
   6 #include <stdlib.h>
   7 #include <assert.h>
   8 #include <sys/types.h>
   9 #include <sys/stat.h>
  10 #include <fcntl.h>
  11 #include "../lib/testutils.h"
  12 
  13 #define NUM_TIMES   (1)
  14 #define NUM_INTS    (4*1024) 
  15 
  16 int
  17 main()
  18 {
  19    int i, rc, fd;
  20    int write_array[NUM_INTS];
  21    int read_array[NUM_INTS];
  22 
  23    /* Uncomment this when having failures and for debugging */
  24    // TEST_VERBOSE_ON();
  25 
  26    /* Initialize the array */
  27    for (i=0; i<NUM_INTS; i++) {
  28      write_array[i] = i;
  29    }
  30 
  31    /* Open the file for writing */
  32    fd = open("WRITE_READ_FILE", O_WRONLY | O_CREAT);
  33    TEST_POSITIVE(fd, "Open file named WRITE_READ_FILE failed\n");
  34 
  35    for (i=0; i<NUM_TIMES; i++) {
  36                  rc = write(fd, write_array, sizeof(write_array));
  37      TEST_EQUAL(rc, sizeof(write_array), "Failed to write all of the array");
  38    }
  39 
  40    close(fd);
  41 
  42    /* Open the file */
  43    fd = open("WRITE_READ_FILE", O_RDONLY);
  44    TEST_POSITIVE(fd, "Open file named WRITE_READ_FILE failed\n");
  45 
  46    for (i=0; i<NUM_TIMES; i++) {
  47                  rc = read(fd, read_array, sizeof(read_array));
  48      TEST_EQUAL(rc, sizeof(read_array), "Failed to read all of the array");
  49      for (i=0; i<NUM_INTS; i++) { 
  50        TEST_EQUAL(read_array[i], write_array[i], "Value read not equal to value written");
  51      }
  52    }
  53 
  54    TEST_STATS();
  55 
  56    exit(0);
  57 }

/* [<][>][^][v][top][bottom][index][help] */