summaryrefslogtreecommitdiff
path: root/lib/qemu-wrapper.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-07-06 19:11:26 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-07-07 23:52:08 -0400
commit51e977fcbcc8c32af5c3741c53c265ed91d1040d (patch)
tree5799580cf8d5d8f59ad978222cbb6e7e224c74d8 /lib/qemu-wrapper.c
parent75abe03bfcaedd96a2d60e07fb6b06c0a46dcc2e (diff)
Restart VM if necessary until tests are complete
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'lib/qemu-wrapper.c')
-rw-r--r--lib/qemu-wrapper.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/qemu-wrapper.c b/lib/qemu-wrapper.c
index 08d3726..8b6223a 100644
--- a/lib/qemu-wrapper.c
+++ b/lib/qemu-wrapper.c
@@ -53,6 +53,7 @@ static unsigned long timeout;
static char *logdir;
static char *test_basename;
+static char *full_log;
static char *current_test;
static struct timespec current_test_start;
@@ -98,7 +99,7 @@ static FILE *test_file_open(const char *fname)
static FILE *log_open()
{
- char *path = mprintf("%s/%s", logdir, test_basename);
+ char *path = mprintf("%s/%s", logdir, full_log);
FILE *f = fopen(path, "w");
if (!f)
die("error opening %s: %m", path);
@@ -195,11 +196,15 @@ static void update_watchdog(const char *line)
}
}
-static void write_test_status(const char *status)
+static void write_test_file(const char *file, const char *fmt, ...)
{
- FILE *f = test_file_open("status");
+ va_list args;
+ FILE *f = test_file_open(file);
+
+ va_start(args, fmt);
+ vfprintf(f, fmt, args);
+ va_end(args);
- fputs(status, f);
fclose(f);
}
@@ -210,14 +215,12 @@ static void test_start(char *new_test, struct timespec now)
current_test_start = now;
current_test_log = test_file_open("log");
- write_test_status("TEST FAILED");
+ write_test_file("status", "TEST FAILED");
}
static void test_end(struct timespec now)
{
- FILE *duration = test_file_open("duration");
- fprintf(duration, "%li", now.tv_sec - current_test_start.tv_sec);
- fclose(duration);
+ write_test_file("duration", "%li", now.tv_sec - current_test_start.tv_sec);
fclose(current_test_log);
current_test_log = NULL;
@@ -236,7 +239,7 @@ int main(int argc, char *argv[])
if (clock_gettime(CLOCK_MONOTONIC, &start))
die("clock_gettime error: %m");
- while ((opt = getopt(argc, argv, "SFT:b:o:h")) != -1) {
+ while ((opt = getopt(argc, argv, "SFT:b:o:f:h")) != -1) {
switch (opt) {
case 'S':
exit_on_success = true;
@@ -253,6 +256,9 @@ int main(int argc, char *argv[])
case 'b':
test_basename = strdup(optarg);
break;
+ case 'f':
+ full_log = strdup(optarg);
+ break;
case 'o':
logdir = strdup(optarg);
break;
@@ -310,7 +316,7 @@ again:
fputs(output, stdout);
if (current_test_log && test_is_ending(line)) {
- write_test_status(line);
+ write_test_file("status", "%s", line);
test_end(now);
}