Signed-off-by: Jiri Jaburek <jjabu...@redhat.com> --- include/test.h | 1 + lib/tst_virt.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
diff --git a/include/test.h b/include/test.h index 137e6f4..53d6254 100644 --- a/include/test.h +++ b/include/test.h @@ -51,6 +51,7 @@ /* virt types for tst_is_virt() */ #define VIRT_XEN 1 /* xen dom0/domU */ +#define VIRT_KVM 2 /* only default virtual CPU */ /* * Ensure that NUMSIGS is defined. diff --git a/lib/tst_virt.c b/lib/tst_virt.c index d1f1e74..87f73dc 100644 --- a/lib/tst_virt.c +++ b/lib/tst_virt.c @@ -24,6 +24,28 @@ #include <unistd.h> #include "test.h" +#include "safe_macros.h" + +static int is_kvm(void) +{ + FILE *cpuinfo; + char line[64]; + int found; + + /* this doesn't work with custom -cpu values, since there's + * no easy, reasonable or reliable way to work around those */ + cpuinfo = SAFE_FOPEN(NULL, "/proc/cpuinfo", "r"); + found = 0; + while (fgets(line, sizeof(line), cpuinfo) != NULL) { + if (strstr(line, "QEMU Virtual CPU")) { + found = 1; + break; + } + } + + SAFE_FCLOSE(NULL, cpuinfo); + return found; +} static int is_xen(void) { @@ -47,6 +69,8 @@ int tst_is_virt(int virt_type) switch (virt_type) { case VIRT_XEN: return is_xen(); + case VIRT_KVM: + return is_kvm(); } tst_brkm(TBROK, NULL, "invalid virt_type flag: %d", virt_type); } -- 2.1.0 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list