summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-02-07 07:58:27 -0600
committerLouis Burda <quent.burda@gmail.com>2023-02-07 07:58:27 -0600
commit32331c7f421411bccb87ea818a2a0198b8cf88aa (patch)
treec1168e406640acf1a6dbca60dfb046bedaaab533 /test
parenta2cdd64c6f915d969dfa21e23049ff4b3836b13d (diff)
downloadcachepc-32331c7f421411bccb87ea818a2a0198b8cf88aa.tar.gz
cachepc-32331c7f421411bccb87ea818a2a0198b8cf88aa.zip
Add syscall to deinit events to prevent blocking on send
Diffstat (limited to 'test')
-rw-r--r--test/eviction.c3
-rw-r--r--test/kvm-eviction.c12
-rw-r--r--test/kvm-pagestep.c31
-rw-r--r--test/kvm-step.c22
-rw-r--r--test/kvm-targetstep.c27
-rw-r--r--test/kvm.c8
6 files changed, 54 insertions, 49 deletions
diff --git a/test/eviction.c b/test/eviction.c
index ca404b9..3a6f801 100644
--- a/test/eviction.c
+++ b/test/eviction.c
@@ -40,5 +40,8 @@ main(int argc, const char **argv)
close(fd);
+ ret = ioctl(fd, KVM_CPC_DEINIT, &arg);
+ if (ret == -1) err(1, "KVM_CPC_DEINIT");
+
return arg;
}
diff --git a/test/kvm-eviction.c b/test/kvm-eviction.c
index ceb1abd..1e66182 100644
--- a/test/kvm-eviction.c
+++ b/test/kvm-eviction.c
@@ -45,15 +45,10 @@ main(int argc, const char **argv)
struct cpc_track_cfg cfg;
int i, k, ret, exitcode;
- vmtype = "kvm";
- if (argc > 1) vmtype = argv[1];
- if (strcmp(vmtype, "kvm") && strcmp(vmtype, "sev")
- && strcmp(vmtype, "sev-es")
- && strcmp(vmtype, "sev-snp"))
- errx(1, "invalid vm mode: %s", vmtype);
-
setvbuf(stdout, NULL, _IONBF, 0);
+ parse_vmtype(argc, argv);
+
pin_process(0, TARGET_CORE, true);
kvm_setup_init();
@@ -153,6 +148,9 @@ main(int argc, const char **argv)
vm_deinit(&vms[WITH]);
vm_deinit(&vms[WITHOUT]);
+ ret = ioctl(kvm_dev, KVM_CPC_DEINIT);
+ if (ret == -1) err(1, "KVM_CPC_DEINIT");
+
kvm_setup_deinit();
return exitcode;
diff --git a/test/kvm-pagestep.c b/test/kvm-pagestep.c
index 03cd288..aaecdd8 100644
--- a/test/kvm-pagestep.c
+++ b/test/kvm-pagestep.c
@@ -42,10 +42,13 @@ monitor(struct kvm *kvm, bool baseline)
}
void
-kill_child(void)
+deinit(void)
{
- printf("Killing vm..\n");
+ ioctl(kvm_dev, KVM_CPC_DEINIT);
+
kill(child, SIGKILL);
+
+ kvm_setup_deinit();
}
int
@@ -58,15 +61,10 @@ main(int argc, const char **argv)
uint64_t eventcnt;
int ret;
- vmtype = "kvm";
- if (argc > 1) vmtype = argv[1];
- if (strcmp(vmtype, "kvm") && strcmp(vmtype, "sev")
- && strcmp(vmtype, "sev-es")
- && strcmp(vmtype, "sev-snp"))
- errx(1, "invalid vm mode: %s", vmtype);
-
setvbuf(stdout, NULL, _IONBF, 0);
+ parse_vmtype(argc, argv);
+
kvm_setup_init();
ipc = ipc_alloc();
@@ -100,10 +98,14 @@ main(int argc, const char **argv)
printf("VM exit\n");
vm_deinit(&kvm);
+
+ ipc_free(ipc);
+
+ kvm_setup_deinit();
} else {
pin_process(0, SECONDARY_CORE, true);
- atexit(kill_child);
+ atexit(deinit);
ipc_wait_child(ipc);
@@ -123,13 +125,8 @@ main(int argc, const char **argv)
}
printf("Monitor exit\n");
- }
-
- ipc_free(ipc);
- ret = ioctl(kvm_dev, KVM_CPC_RESET, NULL);
- if (ret < 0) err(1, "KVM_CPC_RESET");
-
- kvm_setup_deinit();
+ ipc_free(ipc);
+ }
}
diff --git a/test/kvm-step.c b/test/kvm-step.c
index 34594ae..99b5dcb 100644
--- a/test/kvm-step.c
+++ b/test/kvm-step.c
@@ -50,10 +50,13 @@ monitor(struct kvm *kvm, bool baseline)
}
void
-kill_child(void)
+deinit(void)
{
- printf("Killing vm..\n");
+ ioctl(kvm_dev, KVM_CPC_DEINIT);
+
kill(child, SIGKILL);
+
+ kvm_setup_deinit();
}
int
@@ -69,6 +72,8 @@ main(int argc, const char **argv)
bool with_data;
int ret;
+ setvbuf(stdout, NULL, _IONBF, 0);
+
with_data = true;
if (argc > 1 && !strcmp(argv[1], "--exec-only")) {
with_data = false;
@@ -78,8 +83,6 @@ main(int argc, const char **argv)
parse_vmtype(argc, argv);
- setvbuf(stdout, NULL, _IONBF, 0);
-
kvm_setup_init();
ipc = ipc_alloc();
@@ -111,10 +114,13 @@ main(int argc, const char **argv)
printf("VM exit\n");
vm_deinit(&kvm);
+
+ ipc_free(ipc);
+ kvm_setup_deinit();
} else {
pin_process(0, SECONDARY_CORE, true);
- atexit(kill_child);
+ atexit(deinit);
ipc_wait_child(ipc);
@@ -178,10 +184,8 @@ main(int argc, const char **argv)
}
printf("Monitor exit\n");
- }
- ipc_free(ipc);
-
- kvm_setup_deinit();
+ ipc_free(ipc);
+ }
}
diff --git a/test/kvm-targetstep.c b/test/kvm-targetstep.c
index f30563c..d7bb81c 100644
--- a/test/kvm-targetstep.c
+++ b/test/kvm-targetstep.c
@@ -53,10 +53,13 @@ monitor(struct kvm *kvm, bool baseline)
}
void
-kill_child(void)
+deinit(void)
{
- printf("Killing vm..\n");
+ ioctl(kvm_dev, KVM_CPC_DEINIT);
+
kill(child, SIGKILL);
+
+ kvm_setup_deinit();
}
int
@@ -73,15 +76,10 @@ main(int argc, const char **argv)
uint32_t arg;
int ret;
- vmtype = "kvm";
- if (argc > 1) vmtype = argv[1];
- if (strcmp(vmtype, "kvm") && strcmp(vmtype, "sev")
- && strcmp(vmtype, "sev-es")
- && strcmp(vmtype, "sev-snp"))
- errx(1, "invalid vm mode: %s", vmtype);
-
setvbuf(stdout, NULL, _IONBF, 0);
+ parse_vmtype(argc, argv);
+
kvm_setup_init();
ipc = ipc_alloc();
@@ -113,10 +111,13 @@ main(int argc, const char **argv)
printf("VM exit\n");
vm_deinit(&kvm);
+
+ ipc_free(ipc);
+ kvm_setup_deinit();
} else {
pin_process(0, SECONDARY_CORE, true);
- atexit(kill_child);
+ atexit(deinit);
ipc_wait_child(ipc);
@@ -218,10 +219,8 @@ main(int argc, const char **argv)
while (monitor(&kvm, false) != 2);
printf("Monitor exit\n");
- }
-
- ipc_free(ipc);
- kvm_setup_deinit();
+ ipc_free(ipc);
+ }
}
diff --git a/test/kvm.c b/test/kvm.c
index d50e4fe..6c888c1 100644
--- a/test/kvm.c
+++ b/test/kvm.c
@@ -28,8 +28,9 @@
#include <stdio.h>
#include <stdlib.h>
-int kvm_dev, sev_dev;
-const char *vmtype;
+int kvm_dev = -1;
+int sev_dev = -1;
+const char *vmtype = NULL;
const char *sev_fwerr_strs[] = {
[0x00] = "Success",
@@ -504,5 +505,8 @@ void
kvm_setup_deinit(void)
{
close(kvm_dev);
+ kvm_dev = -1;
+
close(sev_dev);
+ sev_dev = -1;
}