about summary refs log tree commit diff homepage
path: root/test/Runtime
diff options
context:
space:
mode:
authorAndrew Santosa <santosa_1999@yahoo.com>2018-06-22 19:50:46 +0800
committerMartinNowack <martin.nowack@gmail.com>2019-03-31 09:53:16 +0100
commitc2a353355a02d392df7ac3f7c47aa4b950c3b943 (patch)
treebddbcbb4289e918b964992521e6059e7e98d4761 /test/Runtime
parent3c22f088ce92854b9fcb5b41f67bf9a503ec9719 (diff)
downloadklee-c2a353355a02d392df7ac3f7c47aa4b950c3b943.tar.gz
Various updates to gen-random-bout.cpp
* Added handling of --sym-arg
* Resolved the crash when minimum and maximum number of arguments for --sym-args are equal
* Replaced "range" with "n_args" produced by --sym-args
* Added model_version variable (constrained to 1), to prevent klee complaining about insufficient input
* Allow a single dash to prefix an option
* Arrange the elements in the correct order: command-line arguments, files, stdin, stdout
* Added test/Runtime/POSIX/GenRandomBout.c test, with a substitution for %gen-random-bout in test/lit.cfg
Diffstat (limited to 'test/Runtime')
-rw-r--r--test/Runtime/POSIX/GenRandomBout.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/Runtime/POSIX/GenRandomBout.c b/test/Runtime/POSIX/GenRandomBout.c
new file mode 100644
index 00000000..8f1199cb
--- /dev/null
+++ b/test/Runtime/POSIX/GenRandomBout.c
@@ -0,0 +1,81 @@
+// -- Core testing commands
+// RUN: rm -rf %t.out
+// RUN: mkdir -p %t.out && cd %t.out
+// 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
+// RUN: %cc %s -O0 -o %t
+// RUN: %klee-replay %t file.bout 2>&1 | grep "klee-replay: EXIT STATUS: NORMAL"
+//
+// -- 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"
+
+#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;
+
+  printf("All size tests passed\n");
+
+  return 0;
+}