about summary refs log tree commit diff homepage
path: root/test/Replay/klee-replay/GenRandomBout.c
blob: 0620e77838b445e8f354b2b0198a8556f1474e0a (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// -- Core testing commands
// RUN: rm -f %t.bout
// RUN: %gen-random-bout 100 -sym-arg 4 -sym-files 2 20 -sym-arg 5 -sym-stdin 8 -sym-stdout -sym-arg 6 -sym-args 1 4 5 -bout-file %t.bout
// RUN: %cc %s -O0 -o %t
// RUN: %klee-replay %t %t.bout 2> %t.out
// RUN: FileCheck --input-file=%t.out %s
//
// -- Option error handling tests
// RUN: bash -c '%gen-random-bout || :' 2>&1 | grep "Usage"
// RUN: bash -c '%gen-random-bout 0 --unexpected-option || :' 2>&1 | grep "Unexpected"
// RUN: bash -c '%gen-random-bout 100 --sym-args 5 3 || :' 2>&1 | grep "ran out of"
// RUN: bash -c '%gen-random-bout 100 --sym-args 5 3 10 || :' 2>&1 | grep "should be no more"

// CHECK: KLEE-REPLAY: NOTE: EXIT STATUS: NORMAL

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int check_fd(int fd, const int file_size) {
  struct stat fs;

  if (fstat(fd, &fs) < 0)
    return -1;

  if (fs.st_size != file_size)
    return -1;

  return 0;
}

int check_file(const char *file_name, const int file_size) {
  int fd;

  if ((fd = open(file_name, O_RDONLY)) < 0)
    return -1;

  if (check_fd(fd, file_size) < 0)
    return -1;

  close(fd);

  return 0;
}

int main(int argc, char **argv) {
  int i = 0;

  if (argc < 4 || argc > 7)
    return 1;

  if (strlen(argv[1]) > 4)
    return 1;

  if (strlen(argv[2]) > 5)
    return 1;

  if (strlen(argv[3]) > 6)
    return 1;

  for (i = 4; i < argc; ++i)
    if (strlen(argv[i]) > 5)
      return 1;

  if (check_file("A", 20) < 0)
    return 1;

  if (check_file("B", 20) < 0)
    return 1;

  if (check_fd(0, 8) < 0)
    return 1;

  if (check_fd(1, 1024) < 0)
    return 1;

  puts("All size tests passed");

  return 0;
}