Module Name:    src
Committed By:   christos
Date:           Fri Apr 12 17:13:55 UTC 2013

Modified Files:
        src/tests/lib/libc/gen: t_fpsetmask.c t_siginfo.c t_sleep.c
Added Files:
        src/tests/lib/libc/gen: isqemu.h

Log Message:
easier way to find if we are on qemu.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/gen/isqemu.h
cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/gen/t_fpsetmask.c
cvs rdiff -u -r1.18 -r1.19 src/tests/lib/libc/gen/t_siginfo.c
cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/gen/t_sleep.c

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/t_fpsetmask.c
diff -u src/tests/lib/libc/gen/t_fpsetmask.c:1.9 src/tests/lib/libc/gen/t_fpsetmask.c:1.10
--- src/tests/lib/libc/gen/t_fpsetmask.c:1.9	Fri Apr 13 02:10:55 2012
+++ src/tests/lib/libc/gen/t_fpsetmask.c	Fri Apr 12 13:13:54 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_fpsetmask.c,v 1.9 2012/04/13 06:10:55 jruoho Exp $ */
+/*	$NetBSD: t_fpsetmask.c,v 1.10 2013/04/12 17:13:54 christos Exp $ */
 
 /*-
  * Copyright (c) 1995 The NetBSD Foundation, Inc.
@@ -36,6 +36,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "isqemu.h"
+
 #ifndef _FLOAT_IEEE754
 
 ATF_TC(no_test);
@@ -296,7 +298,7 @@ sigfpe(int s, siginfo_t *si, void *c)
 		if (strcmp(atf_config_get("atf_arch"), "macppc") == 0)	\
 			atf_tc_expect_fail("PR port-macppc/46319");	\
 									\
-		if (system("cpuctl identify 0 | grep -q QEMU") == 0)	\
+		if (isQEMU())						\
 			atf_tc_expect_fail("PR misc/44767");		\
 									\
 		m(t##_ops);						\

Index: src/tests/lib/libc/gen/t_siginfo.c
diff -u src/tests/lib/libc/gen/t_siginfo.c:1.18 src/tests/lib/libc/gen/t_siginfo.c:1.19
--- src/tests/lib/libc/gen/t_siginfo.c:1.18	Wed Jun 13 07:45:17 2012
+++ src/tests/lib/libc/gen/t_siginfo.c	Fri Apr 12 13:13:55 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: t_siginfo.c,v 1.18 2012/06/13 11:45:17 njoly Exp $ */
+/* $NetBSD: t_siginfo.c,v 1.19 2013/04/12 17:13:55 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -49,6 +49,8 @@
 #include <ieeefp.h>
 #endif
 
+#include "isqemu.h"
+
 /* for sigbus */
 volatile char *addr;
 
@@ -303,7 +305,7 @@ ATF_TC_BODY(sigfpe_flt, tc)
 	struct sigaction sa;
 	double d = strtod("0", NULL);
 
-	if (system("cpuctl identify 0 | grep -q QEMU") == 0)
+	if (isQEMU())
 		atf_tc_skip("Test does not run correctly under qemu");
 	if (system("cpuctl identify 0 | grep -q "
 	    "'cpu0: Intel Pentium II (Klamath) (686-class), id 0x633'") == 0)
@@ -472,12 +474,8 @@ ATF_TC_BODY(sigbus_adraln, tc)
 	addr = calloc(2, sizeof(int));
 	ATF_REQUIRE(addr != NULL);
 
-	if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-		if (system("cpuctl identify 0 | grep -q QEMU") == 0) {
-			atf_tc_expect_fail("QEMU fails to trap unaligned "
-			    "accesses");
-		}
-	}
+	if (isQEMU())
+		atf_tc_expect_fail("QEMU fails to trap unaligned accesses");
 
 	/* Force an unaligned access */
 	addr++;

Index: src/tests/lib/libc/gen/t_sleep.c
diff -u src/tests/lib/libc/gen/t_sleep.c:1.6 src/tests/lib/libc/gen/t_sleep.c:1.7
--- src/tests/lib/libc/gen/t_sleep.c:1.6	Sun Mar 17 01:47:48 2013
+++ src/tests/lib/libc/gen/t_sleep.c	Fri Apr 12 13:13:55 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sleep.c,v 1.6 2013/03/17 05:47:48 jmmv Exp $ */
+/* $NetBSD: t_sleep.c,v 1.7 2013/04/12 17:13:55 christos Exp $ */
 
 /*-
  * Copyright (c) 2006 Frank Kardel
@@ -39,6 +39,8 @@
 #include <sys/event.h>
 #include <sys/signal.h>
 
+#include "isqemu.h"
+
 #define BILLION		1000000000LL	/* nano-seconds per second */
 #define MILLION		1000000LL	/* nano-seconds per milli-second */
 
@@ -157,7 +159,7 @@ do_kevent(struct timespec *delay, struct
 	 * under QEMU, make sure the delay is long enough to account
 	 * for the effects of PR kern/43997 !
 	 */
-	if (system("cpuctl identify 0 | grep -q QEMU") == 0 &&
+	if (isQEMU() &&
 	    tmo/1000 < delay->tv_sec && tmo/500 > delay->tv_sec)
 		delay->tv_sec = MAXSLEEP;
 

Added files:

Index: src/tests/lib/libc/gen/isqemu.h
diff -u /dev/null src/tests/lib/libc/gen/isqemu.h:1.1
--- /dev/null	Fri Apr 12 13:13:55 2013
+++ src/tests/lib/libc/gen/isqemu.h	Fri Apr 12 13:13:54 2013
@@ -0,0 +1,59 @@
+/*	$NetBSD: isqemu.h,v 1.1 2013/04/12 17:13:54 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+#include <err.h>
+
+static bool
+isQEMU(void) {
+	char name[1024];
+	size_t len = sizeof(name);
+
+	if (sysctlbyname("machdep.cpu_brand", name, &len, NULL, 0) == -1) {
+		if (errno == ENOENT)
+			return false;
+		err(EXIT_FAILURE, "sysctl");
+	}
+	return strstr(name, "QEMU") != NULL;
+}
+
+#ifdef TEST
+int
+main(void) {
+	return isQEMU();
+}
+#endif

Reply via email to