Home | History | Annotate | Download | only in tests
      1 #include <string.h>
      2 #include <stdlib.h>
      3 #include <unistd.h>
      4 #include <sys/types.h>
      5 #include <sys/stat.h>
      6 #include <fcntl.h>
      7 #include <sys/time.h>
      8 
      9 // For some reason, the stack frame below __GI_write is disappearing.
     10 // Therefore, if I don't want the write errors to be merged, I have to
     11 // ensure they have a different stack trace.  I do this by using this
     12 // function.  Weird.
     13 __attribute__((noinline))
     14 void mywrite(char* buf, int len)
     15 {
     16    write(-1, buf, len);
     17 }
     18 
     19 __attribute__((noinline))
     20 void mygetitimer(long arg1, struct itimerval* itval)
     21 {
     22    getitimer(arg1, itval);
     23 }
     24 
     25 __attribute__((noinline))
     26 void myopen(char* name, long flags)
     27 {
     28    open(name, flags);
     29 }
     30 
     31 int main(void)
     32 {
     33    char *buf = malloc(sizeof(char)*6), *buf2 = malloc(sizeof(char)*6);
     34    struct itimerval* itval = malloc(sizeof(struct itimerval) - 1);
     35    int diff = buf2 - buf;
     36    buf[0] = 'h';
     37    buf[1] = 'e';
     38    buf[2] = 'l';
     39    buf[3] = 'l';
     40    buf[4] = 'o';
     41    buf[5] = 'x';
     42 
     43    // error (read)  (will fail due to -1, as we want -- don't want any
     44    // unpredictable output to foul up the test)
     45    mywrite(buf+3, 5);      // error (read)
     46    mywrite(buf-1, 5);      // error (read)
     47    mywrite(buf+1, diff);   // error (read)
     48    myopen(buf+3, 0x0);     // error (read_asciiz)
     49 
     50    mygetitimer(0, itval);    // error (write)
     51 
     52    //----
     53    free(buf);
     54    mywrite(buf,   5);      // error
     55    mywrite(buf+3, 5);      // error
     56    mywrite(buf+1, diff);   // error (read)
     57 
     58    return 0;
     59 }
     60