From patchwork Sun Sep 29 16:34:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1990617 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c2PcQSJ1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XGqYl1tWqz1xt9 for ; Mon, 30 Sep 2024 02:35:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F68D385EC1B for ; Sun, 29 Sep 2024 16:35:05 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 640C6385EC1B for ; Sun, 29 Sep 2024 16:34:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 640C6385EC1B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 640C6385EC1B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727627687; cv=none; b=gZovd7NdK8iCglmQgE4wTMLQAWgDaFwjDGY+vDTS5iIjQvCsbd1moBOB9qha0RFkL1FvmEhrakPH/ux1OSDcDWrxYWm13ak7cL5rxuObScOnBbTEZAlliY/lu4CwWeoY60lAz0eYmQsjp8npSmCCHYlFtkBmLpnzQCbDyymSy28= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727627687; c=relaxed/simple; bh=P8zAWo2zh8eus5ssPaZPkIhSksL7gp57+xQtuw3Mojs=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=uN+vGSXG74UJOsMHUhrwsM8CwIkmiSoaxD/IN+3UN2UeHO1smJx8zZrQaAS7Wtc/M88Zm1X+c5BYUJziepz7lFm+K0plb31SiE5tFWVbTdHOvXUcRGGrWwXWNLhWjMfbnUWFzvYcGzAKcPUu7gEYBJImh4JwGpGCs/hda5QoVjQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727627685; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=EIuCI2yklA2h588wyzZKFeufHCn0sxhgne9Mv4VjsCI=; b=c2PcQSJ1D6BfnIXGtz+GrFoljxmwMwXB4ttS/FAZ8+qkv53WVkseFnMsfZQMHwzMyd/YPa u8JU0QQB+UcOQs+PqMLMi3tt8u6i/kUUp/sXfuze63z9bC54bq8Rb+IcvR9LORg4rfftW4 qPQIPPg3/3zJ/RQbj/021YasLrem15E= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-eLJwSITVMHSthnCn6WJ4lw-1; Sun, 29 Sep 2024 12:34:43 -0400 X-MC-Unique: eLJwSITVMHSthnCn6WJ4lw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C439F19792DA for ; Sun, 29 Sep 2024 16:34:42 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.45.224.151]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C6EED19541A0 for ; Sun, 29 Sep 2024 16:34:41 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v3 21/29] misc: Add tst-getpagesize In-Reply-To: Message-ID: References: X-From-Line: a4d305f48d27c5fc07cf8c9ddbf85d43d6e22386 Mon Sep 17 00:00:00 2001 Date: Sun, 29 Sep 2024 18:34:38 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org This test checks the system page size against the hard-coded range in . --- misc/Makefile | 1 + misc/tst-getpagesize.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 misc/tst-getpagesize.c diff --git a/misc/Makefile b/misc/Makefile index a932b1aab4..4250b789d1 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -243,6 +243,7 @@ tests := \ tst-empty \ tst-error1 \ tst-fdset \ + tst-getpagesize \ tst-hsearch \ tst-insremque \ tst-ioctl \ diff --git a/misc/tst-getpagesize.c b/misc/tst-getpagesize.c new file mode 100644 index 0000000000..d8bcdc6dc5 --- /dev/null +++ b/misc/tst-getpagesize.c @@ -0,0 +1,65 @@ +/* Run-time tests for page size. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __linux__ +# define HAVE_AUXV 1 +# include +#else +# define HAVE_AUXV 0 +#endif + +static int +do_test (void) +{ + printf ("info: getpagesize (): %d\n", getpagesize ()); + TEST_COMPARE (getpagesize (), sysconf (_SC_PAGE_SIZE)); + TEST_COMPARE (_SC_PAGE_SIZE, _SC_PAGESIZE); + + /* The page size in the auxiliary vector is not optimized. */ +#ifdef HAVE_AUX + TEST_COMPARE (getpagesize (), getauxval (AT_PAGESZ)); +#endif + + /* Test against the page size ranges from . */ + TEST_VERIFY (getpagesize () >= PAGE_SIZE_MIN); + TEST_VERIFY (getpagesize () <= PAGE_SIZE_MAX); + _Static_assert (PAGE_SHIFT_MIN == __GLIBC_PAGE_SHIFT_MIN, "PAGE_SHIFT_MIN"); + _Static_assert (PAGE_SHIFT_MAX == __GLIBC_PAGE_SHIFT_MAX, "PAGE_SHIFT_MAX"); + _Static_assert (PAGE_SIZE_MIN == (1UL << PAGE_SHIFT_MIN), "PAGE_SIZE_MIN"); + _Static_assert (PAGE_SIZE_MAX == (1UL << PAGE_SHIFT_MAX), "PAGE_SIZE_MAX"); + _Static_assert (PAGE_SIZE_MIN <= PAGE_SIZE_MAX, "page size ordering"); + + /* Create a few mappings to verify that the address is a multiple of + the page size. */ + for (int i = 0; i < 1000; i++) + TEST_COMPARE ((uintptr_t) xmmap (NULL, 1, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1) + % 4096, 0); + + return 0; +} + +#include