diff options
author | Cristian Cadar <c.cadar@imperial.ac.uk> | 2019-08-09 11:07:48 +0100 |
---|---|---|
committer | MartinNowack <martin.nowack@gmail.com> | 2019-08-14 16:26:48 +0100 |
commit | 49b5a873008ac96c927b254ee746dbd96f2f1a9d (patch) | |
tree | b79f48f4fb3b20a3ce45bb30c4ad8d391ef69037 /tools | |
parent | 64508909bcbd52d6a06ec0f299b3752368d10e31 (diff) | |
download | klee-49b5a873008ac96c927b254ee746dbd96f2f1a9d.tar.gz |
Changed klee-replay to create a temporary directory with a random name in /tmp instead of using a fixed name in the current directory.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/klee-replay/file-creator.c | 37 | ||||
-rw-r--r-- | tools/klee-replay/klee-replay.c | 15 | ||||
-rw-r--r-- | tools/klee-replay/klee-replay.h | 5 |
3 files changed, 43 insertions, 14 deletions
diff --git a/tools/klee-replay/file-creator.c b/tools/klee-replay/file-creator.c index a218e6b0..58580f94 100644 --- a/tools/klee-replay/file-creator.c +++ b/tools/klee-replay/file-creator.c @@ -12,6 +12,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <ftw.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -431,18 +432,21 @@ static void create_file(int target_fd, } } +char replay_dir[] = "/tmp/klee-replay-XXXXXX"; + void replay_create_files(exe_file_system_t *exe_fs) { - char tmpdir[PATH_MAX]; unsigned k; - if (!getcwd(tmpdir, PATH_MAX)) { - perror("getcwd"); - exit(1); + // Create a temporary directory to place files involved in replay + strcpy(replay_dir, "/tmp/klee-replay-XXXXXX"); // new template for each replayed file + char* tmpdir = mkdtemp(replay_dir); + + if (tmpdir == NULL) { + perror("mkdtemp: could not create temporary directory"); + exit(EXIT_FAILURE); } - strcat(tmpdir, ".temps"); - delete_file(tmpdir, 1); - mkdir(tmpdir, 0755); + fprintf(stderr, "note: storing KLEE replay files in %s\n", tmpdir); umask(0); for (k=0; k < exe_fs->n_sym_files; k++) { @@ -467,6 +471,25 @@ void replay_create_files(exe_file_system_t *exe_fs) { check_file(k, &exe_fs->sym_files[k]); } + +/* Used by nftw() in replay_delete_files() */ +int remove_callback(const char *fpath, + __attribute__((unused)) const struct stat *sb, + __attribute__((unused)) int typeflag, + __attribute__((unused)) struct FTW *ftwbuf) { + return remove(fpath); +} + +void replay_delete_files() { + fprintf(stderr, "removing %s\n", replay_dir); + + if (nftw(replay_dir, remove_callback, FOPEN_MAX, + FTW_DEPTH | FTW_PHYS) == -1) { + perror("nftw"); + exit(EXIT_FAILURE); + } +} + static void check_file(int index, exe_disk_file_t *dfile) { struct stat s; int res; diff --git a/tools/klee-replay/klee-replay.c b/tools/klee-replay/klee-replay.c index 9261535a..1399985d 100644 --- a/tools/klee-replay/klee-replay.c +++ b/tools/klee-replay/klee-replay.c @@ -18,11 +18,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/wait.h> #include <time.h> #include <unistd.h> -#include <sys/wait.h> - #if defined(__APPLE__) || defined(__FreeBSD__) #include <signal.h> #define fgetc_unlocked(x) fgetc (x) @@ -348,7 +347,6 @@ int main(int argc, char** argv) { prg_argv = input->args; prg_argv[0] = argv[optind]; klee_init_env(&prg_argc, &prg_argv); - if (idx > 2) fprintf(stderr, "\n"); fprintf(stderr, "%s: TEST CASE: %s\n", progname, input_fname); @@ -360,6 +358,9 @@ int main(int argc, char** argv) { } fprintf(stderr, "\n"); + /* Create the input files, pipes, etc. */ + replay_create_files(&__exe_fs); + /* Run the test case machinery in a subprocess, eventually this parent process should be a script or something which shells out to the actual execution tool. */ @@ -368,18 +369,20 @@ int main(int argc, char** argv) { perror("fork"); _exit(66); } else if (pid == 0) { - /* Create the input files, pipes, etc., and run the process. */ - replay_create_files(&__exe_fs); + /* Run the executable */ run_monitored(executable, prg_argc, prg_argv); _exit(0); } else { - /* Wait for the test case. */ + /* Wait for the executable to finish. */ int res, status; do { res = waitpid(pid, &status, 0); } while (res < 0 && errno == EINTR); + // Delete all files in the replay directory + replay_delete_files(); + if (res < 0) { perror("waitpid"); _exit(66); diff --git a/tools/klee-replay/klee-replay.h b/tools/klee-replay/klee-replay.h index b4d0f248..8dc3b872 100644 --- a/tools/klee-replay/klee-replay.h +++ b/tools/klee-replay/klee-replay.h @@ -18,7 +18,11 @@ #include "../../runtime/POSIX/fd.h" #include <sys/time.h> +// temporary directory used for replay +extern char replay_dir[]; + void replay_create_files(exe_file_system_t *exe_fs); +void replay_delete_files(); void process_status(int status, time_t elapsed, @@ -26,4 +30,3 @@ void process_status(int status, __attribute__((noreturn)); #endif - |