Module Name:    src
Committed By:   gson
Date:           Wed Dec 15 09:19:28 UTC 2021

Modified Files:
        src/tests/lib/libc/gen: isqemu.h

Log Message:
When running the tests under "qemu -accel kvm" on a Linux host,
isQEMU_TCG() should return false.  Fixes multiple test cases that were
failing with "Test case was expecting a failure but none were raised"
on that platform.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/gen/isqemu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/gen/isqemu.h
diff -u src/tests/lib/libc/gen/isqemu.h:1.5 src/tests/lib/libc/gen/isqemu.h:1.6
--- src/tests/lib/libc/gen/isqemu.h:1.5	Sun Aug 23 11:00:18 2020
+++ src/tests/lib/libc/gen/isqemu.h	Wed Dec 15 09:19:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: isqemu.h,v 1.5 2020/08/23 11:00:18 gson Exp $	*/
+/*	$NetBSD: isqemu.h,v 1.6 2021/12/15 09:19:28 gson Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -72,10 +72,18 @@ isQEMU_TCG(void) {
 			return false;
 		err(EXIT_FAILURE, "sysctl");
 	}
-	return strstr(name, "QEMU") != NULL;
-#else
-	return false;
+	if (strstr(name, "QEMU") == NULL)
+		return false;
+	if (sysctlbyname("machdep.hypervisor", name, &len, NULL, 0) == -1) {
+		if (errno == ENOENT)
+			return true;
+		err(EXIT_FAILURE, "sysctl");
+	}
+	if (strcmp(name, "KVM") == 0)
+		return false;
+	return true;
 #endif
+	return false;
 }
 
 #ifdef TEST

Reply via email to