Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/gen easier way to find if we are on qemu.



details:   https://anonhg.NetBSD.org/src/rev/b10df65748ae
branches:  trunk
changeset: 786044:b10df65748ae
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Apr 12 17:13:54 2013 +0000

description:
easier way to find if we are on qemu.

diffstat:

 tests/lib/libc/gen/isqemu.h      |  59 ++++++++++++++++++++++++++++++++++++++++
 tests/lib/libc/gen/t_fpsetmask.c |   6 ++-
 tests/lib/libc/gen/t_siginfo.c   |  14 ++++-----
 tests/lib/libc/gen/t_sleep.c     |   6 ++-
 4 files changed, 73 insertions(+), 12 deletions(-)

diffs (159 lines):

diff -r 88a1d1b3cd37 -r b10df65748ae tests/lib/libc/gen/isqemu.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/gen/isqemu.h       Fri Apr 12 17:13:54 2013 +0000
@@ -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
diff -r 88a1d1b3cd37 -r b10df65748ae tests/lib/libc/gen/t_fpsetmask.c
--- a/tests/lib/libc/gen/t_fpsetmask.c  Fri Apr 12 16:59:38 2013 +0000
+++ b/tests/lib/libc/gen/t_fpsetmask.c  Fri Apr 12 17:13:54 2013 +0000
@@ -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 @@
                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);                                             \
diff -r 88a1d1b3cd37 -r b10df65748ae tests/lib/libc/gen/t_siginfo.c
--- a/tests/lib/libc/gen/t_siginfo.c    Fri Apr 12 16:59:38 2013 +0000
+++ b/tests/lib/libc/gen/t_siginfo.c    Fri Apr 12 17:13:54 2013 +0000
@@ -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 @@
        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 @@
        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++;
diff -r 88a1d1b3cd37 -r b10df65748ae tests/lib/libc/gen/t_sleep.c
--- a/tests/lib/libc/gen/t_sleep.c      Fri Apr 12 16:59:38 2013 +0000
+++ b/tests/lib/libc/gen/t_sleep.c      Fri Apr 12 17:13:54 2013 +0000
@@ -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 @@
         * 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;
 



Home | Main Index | Thread Index | Old Index