From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 1F4D31F8C6 for ; Sat, 28 Aug 2021 23:06:44 +0000 (UTC) Received: from localhost ([::1]:47118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mK7PO-0003MB-IS for normalperson@yhbt.net; Sat, 28 Aug 2021 19:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mK7PL-0003Lz-7H for bug-gnulib@gnu.org; Sat, 28 Aug 2021 19:06:39 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.217]:32173) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mK7PD-0004Ie-Go for bug-gnulib@gnu.org; Sat, 28 Aug 2021 19:06:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1630191986; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=2ySFXbm0dc3TdppOx6hs1CM20MvinViqHaqSesQvG5Y=; b=rWInarpZgRF+G2Mxk55q/8oif/phDaQUtv5G0VeEeVqUjqbXUSAOSDRskUAZzmUsPY lG47k881H+e0iR2j46MPF8eZAANPoyD3oCs20hmViE6y9oOnJoJGtt/tamOfe1Tql8Ms pJs4KgPbtEhWGRbbD4SjuU6nemwHsIPRrDwxtvRNDNEBjgJqIwwnzOH2T8qYLuF9eLu4 VUlIUU9WjsfAsR8QlViWcBZNYZMRP1XB4ijDH3yIEsKxlqeqNdyBqdPVltLWkaXkITGj jgkG6AzXfLTl55CDdb7vQ7Lh94ZaOmDFhnimOQr+dpMPTl+vPM/4MLzYeoYWJRD2INzM 04mw== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94z26ll5ip689kRYCRMhNyaHrKtI3tZ9C5tre" X-RZG-CLASS-ID: mo00 Received: from omega.localnet by smtp.strato.de (RZmta 47.31.0 AUTH) with ESMTPSA id I0beb9x7SN6PoN1 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sun, 29 Aug 2021 01:06:25 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: Skip some tests when running under QEMU user-mode Date: Sun, 29 Aug 2021 01:06:25 +0200 Message-ID: <10180977.2WqB4rESCP@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.217; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" When a gnulib testdir runs under QEMU user-mode (that is, the executables are being interpreted by qemu-, via binfmt recognition in the kernel), some unit tests (test-dprintf-posix2, test-fprintf-posix3, on Linux/alpha also test-fprintf-posix2 and test-printf-posix2) take a very long time to terminate, and some tests regularly fail. In order to produce reasonable "make check" results, this patch skips some of the tests in this situation. 2021-08-28 Bruno Haible Skip some tests when running under QEMU user-mode. * tests/qemu.h: New file. * tests/test-get-rusage-as.c: Include qemu.h. (main): Skip the test when running under QEMU. * tests/test-get-rusage-data.c: Include qemu.h. (main): Skip the test when running under QEMU. * tests/test-printf-posix2.c: Include qemu.h. (main): Return with code 77 when running under QEMU. * tests/test-fprintf-posix2.c: Include qemu.h. (main): Return with code 77 when running under QEMU. * tests/test-fprintf-posix3.c: Include qemu.h. (main): Return with code 79 when running under QEMU. * tests/test-fprintf-posix3.sh: Skip the test when the return code was 79. * tests/test-dprintf-posix2.c: Include qemu.h. (main): Return with code 79 when running under QEMU. Use return code 80 instead of 78. * tests/test-dprintf-posix2.sh: Skip the test when the return code was 79. Update for changed return code. * modules/get-rusage-as-tests (Files): Add qemu.h. (Depends-on): Add stdbool. * modules/get-rusage-data-tests (Files): Add qemu.h. (Depends-on): Add stdbool. * modules/fprintf-posix-tests (Files): Add qemu.h. (Depends-on): Add stdbool. * modules/dprintf-posix-tests (Files): Add qemu.h. (Depends-on): Add stdbool. diff --git a/modules/dprintf-posix-tests b/modules/dprintf-posix-tests index 0c5a6e8cb..09ebbc06f 100644 --- a/modules/dprintf-posix-tests +++ b/modules/dprintf-posix-tests @@ -5,10 +5,12 @@ tests/test-printf-posix.output tests/test-dprintf-posix2.sh tests/test-dprintf-posix2.c tests/infinity.h +tests/qemu.h tests/signature.h tests/macros.h Depends-on: +stdbool stdint get-rusage-as diff --git a/modules/fprintf-posix-tests b/modules/fprintf-posix-tests index 258e3bfb2..de0a8df79 100644 --- a/modules/fprintf-posix-tests +++ b/modules/fprintf-posix-tests @@ -8,10 +8,12 @@ tests/test-fprintf-posix2.c tests/test-fprintf-posix3.sh tests/test-fprintf-posix3.c tests/infinity.h +tests/qemu.h tests/signature.h tests/macros.h Depends-on: +stdbool stdint get-rusage-as diff --git a/modules/get-rusage-as-tests b/modules/get-rusage-as-tests index 9941009e3..67c011d71 100644 --- a/modules/get-rusage-as-tests +++ b/modules/get-rusage-as-tests @@ -1,8 +1,10 @@ Files: tests/test-get-rusage-as.c +tests/qemu.h tests/macros.h Depends-on: +stdbool configure.ac: diff --git a/modules/get-rusage-data-tests b/modules/get-rusage-data-tests index 109cce53e..d18d30bc2 100644 --- a/modules/get-rusage-data-tests +++ b/modules/get-rusage-data-tests @@ -1,9 +1,11 @@ Files: tests/test-get-rusage-data.c +tests/qemu.h tests/macros.h m4/musl.m4 Depends-on: +stdbool configure.ac: gl_MUSL_LIBC diff --git a/tests/qemu.h b/tests/qemu.h new file mode 100644 index 000000000..403b77928 --- /dev/null +++ b/tests/qemu.h @@ -0,0 +1,99 @@ +/* Determine whether the current process is running under QEMU. + Copyright (C) 2021 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2021. */ + +#include +#ifdef __linux__ +# include +# include +# include +#endif + +/* This function determines whether the current process is running under QEMU + (user-mode). + + It does so by looking at parts of the environment that QEMU does not emulate + 100% perfectly well. + + For comparison, the techniques given in the paper + Thomas Raffetseder, Christopher Kruegel, Engin Kirda + "Detecting System Emulators" + 2007 + https://publik.tuwien.ac.at/files/pub-inf_5317.pdf + apply to both the QEMU system mode and QEMU user mode. */ + +static bool +is_running_under_qemu_user (void) +{ +#ifdef __linux__ + char buf[4096 + 1]; + int fd; + +# if defined __m68k__ + fd = open ("/proc/hardware", O_RDONLY); + if (fd >= 0) + { + int n = read (fd, buf, sizeof (buf) - 1); + close (fd); + if (n > 0) + { + buf[n] = '\0'; + if (strstr (buf, "qemu") != NULL) + return true; + } + } +# endif + + fd = open ("/proc/cpuinfo", O_RDONLY); + if (fd >= 0) + { + int n = read (fd, buf, sizeof (buf) - 1); + close (fd); + if (n > 0) + { + buf[n] = '\0'; +# if defined __hppa__ + if (strstr (buf, "QEMU") != NULL) + return true; +# endif +# if !(defined __i386__ || defined __x86_64__) + if (strstr (buf, "AuthenticAMD") != NULL + || strstr (buf, "GenuineIntel") != NULL) + return true; +# endif +# if !(defined __arm__ || defined __aarch64__) + if (strstr (buf, "ARM") != NULL + || strcasestr (buf, "aarch64") != NULL) + return true; +# endif +# if !defined __sparc__ + if (strcasestr (buf, "SPARC") != NULL) + return true; +# endif +# if !defined __powerpc__ + if (strstr (buf, "POWER") != NULL) + return true; +# endif + } + } + + /* If you need more heuristics, look at system calls that are not perfectly + well emulated in qemu/linux-user/syscall.c. */ +#endif + + return false; +} diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c index bd5997567..67e14f7c8 100644 --- a/tests/test-dprintf-posix2.c +++ b/tests/test-dprintf-posix2.c @@ -31,6 +31,7 @@ # include #endif +#include "qemu.h" #include "resource-ext.h" /* Test against a memory leak in the fprintf replacement. */ @@ -53,6 +54,12 @@ main (int argc, char *argv[]) int arg; int result; + if (is_running_under_qemu_user ()) + { + fprintf (stderr, "Skipping test: cannot trust address space size when running under QEMU\n"); + return 79; + } + /* Limit the amount of malloc()ed memory to MAX_ALLOC_TOTAL or less. */ /* On AIX systems, malloc() is limited by RLIMIT_DATA. */ @@ -85,7 +92,7 @@ main (int argc, char *argv[]) if (memory == NULL) return 1; memset (memory, 17, MAX_ALLOC_TOTAL); - result = 78; + result = 80; } else { diff --git a/tests/test-dprintf-posix2.sh b/tests/test-dprintf-posix2.sh index 0fb38591d..7a548188f 100755 --- a/tests/test-dprintf-posix2.sh +++ b/tests/test-dprintf-posix2.sh @@ -4,7 +4,7 @@ (${CHECKER} ./test-dprintf-posix2${EXEEXT} 0 result=$? - if test $result != 77 && test $result != 78; then result=1; fi + if test $result != 77 && test $result != 79 && test $result != 80; then result=1; fi exit $result ) 2>/dev/null malloc_result=$? @@ -12,6 +12,10 @@ if test $malloc_result = 77; then echo "Skipping test: no way to determine address space size" exit 77 fi +if test $malloc_result = 79; then + echo "Skipping test: cannot trust address space size when running under QEMU" + exit 77 +fi ${CHECKER} ./test-dprintf-posix2${EXEEXT} 1 > /dev/null result=$? @@ -23,7 +27,7 @@ if test $result != 0; then exit 1 fi -if test $malloc_result = 78; then +if test $malloc_result = 80; then echo "Skipping test: get_rusage_as() doesn't work" exit 77 fi diff --git a/tests/test-fprintf-posix2.c b/tests/test-fprintf-posix2.c index 8c3ea8bbc..47f29116d 100644 --- a/tests/test-fprintf-posix2.c +++ b/tests/test-fprintf-posix2.c @@ -32,6 +32,8 @@ #include #include +#include "qemu.h" + int main (int argc, char *argv[]) { @@ -39,6 +41,9 @@ main (int argc, char *argv[]) int arg; int ret; + if (is_running_under_qemu_user ()) + return 77; + /* Some printf implementations allocate temporary space with malloc. */ /* On BSD systems, malloc() is limited by RLIMIT_DATA. */ #ifdef RLIMIT_DATA diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c index 41172b4ea..458f95784 100644 --- a/tests/test-fprintf-posix3.c +++ b/tests/test-fprintf-posix3.c @@ -48,6 +48,7 @@ main () # include #endif +#include "qemu.h" #include "resource-ext.h" /* Test against a memory leak in the fprintf replacement. */ @@ -70,6 +71,12 @@ main (int argc, char *argv[]) int arg; int result; + if (is_running_under_qemu_user ()) + { + fprintf (stderr, "Skipping test: cannot trust address space size when running under QEMU\n"); + return 79; + } + /* Limit the amount of malloc()ed memory to MAX_ALLOC_TOTAL or less. */ /* On AIX systems, malloc() is limited by RLIMIT_DATA. */ diff --git a/tests/test-fprintf-posix3.sh b/tests/test-fprintf-posix3.sh index 96609c7f2..a79273ee2 100755 --- a/tests/test-fprintf-posix3.sh +++ b/tests/test-fprintf-posix3.sh @@ -4,7 +4,7 @@ (${CHECKER} ./test-fprintf-posix3${EXEEXT} 0 result=$? - if test $result != 77 && test $result != 78 && test $result != 80; then result=1; fi + if test $result != 77 && test $result != 78 && test $result != 79 && test $result != 80; then result=1; fi exit $result ) 2>/dev/null malloc_result=$? @@ -16,6 +16,10 @@ if test $malloc_result = 78; then echo "Skipping test: cannot trust address space size on this platform" exit 77 fi +if test $malloc_result = 79; then + echo "Skipping test: cannot trust address space size when running under QEMU" + exit 77 +fi ${CHECKER} ./test-fprintf-posix3${EXEEXT} 1 > /dev/null result=$? diff --git a/tests/test-get-rusage-as.c b/tests/test-get-rusage-as.c index 41646db2b..7adb8cda3 100644 --- a/tests/test-get-rusage-as.c +++ b/tests/test-get-rusage-as.c @@ -21,6 +21,7 @@ #include #include +#include "qemu.h" #include "macros.h" void *memchunk1; @@ -46,6 +47,11 @@ main () fprintf (stderr, "Skipping test: no way to determine address space size\n"); return 77; } + else if (is_running_under_qemu_user ()) + { + fprintf (stderr, "Skipping test: running under QEMU\n"); + return 77; + } else { /* The address space size is positive. */ diff --git a/tests/test-get-rusage-data.c b/tests/test-get-rusage-data.c index c626540a3..a5acb4705 100644 --- a/tests/test-get-rusage-data.c +++ b/tests/test-get-rusage-data.c @@ -21,6 +21,7 @@ #include #include +#include "qemu.h" #include "macros.h" void *memchunk1; @@ -46,6 +47,11 @@ main () fprintf (stderr, "Skipping test: no way to determine data segment size\n"); return 77; } + else if (is_running_under_qemu_user ()) + { + fprintf (stderr, "Skipping test: running under QEMU\n"); + return 77; + } else { /* The data segment size is positive, except possibly at the beginning. */ diff --git a/tests/test-printf-posix2.c b/tests/test-printf-posix2.c index dc3c4e5f2..f8da61743 100644 --- a/tests/test-printf-posix2.c +++ b/tests/test-printf-posix2.c @@ -32,6 +32,8 @@ #include #include +#include "qemu.h" + int main (int argc, char *argv[]) { @@ -39,6 +41,9 @@ main (int argc, char *argv[]) int arg; int ret; + if (is_running_under_qemu_user ()) + return 77; + /* Some printf implementations allocate temporary space with malloc. */ /* On BSD systems, malloc() is limited by RLIMIT_DATA. */ #ifdef RLIMIT_DATA