Received: by 10.223.164.202 with SMTP id h10csp290120wrb; Mon, 6 Nov 2017 06:42:59 -0800 (PST) X-Google-Smtp-Source: ABhQp+RKg+IeKs0YDZWZBGxx5g4BToQPJUGZzPwUTKp5Vky0/Qhscb/L0LOCij2yROnwupiqo7fx X-Received: by 10.84.231.129 with SMTP id g1mr14549761plk.188.1509979379073; Mon, 06 Nov 2017 06:42:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509979379; cv=none; d=google.com; s=arc-20160816; b=XQMDWqI0iWps8433comGygi3VtFVLKw+bJTDrHN1/KMcgDPjh+htjBUhkvVzyw6WMv AU6Nl0bYYoZMBZCRfz+6IWvoKYqVnELadYA7XeEuwovOiyucfmA4CyVnqB7QcPPzc165 ezvNnLaRVeoIIz9kTElPEtMUGXPY8HOSH8/WxhzBAe+YIREj6E6/4ir0GLZZD+qJ096t 7j1fvlulzw3Czb+W7oEw8q8l5s408j3fGk9BrMO1j1oJzDstbXUKYSziu/zefE+Xw7ER gy+Od5Zv3hos0woPU974c1KmfUWInnblrW5eNjK0tOX/piWsdXp29+trxm7wlHoRhZQE V8wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dmarc-filter:arc-authentication-results; bh=BztSYUGrNONpyiyjYd4JyjGdoq4UzAs2mBbEioh1O3o=; b=Dh8fJ2MQI9R85SCbmwPQm96oAHnukWvinpnY9lsgbbIqK9BHd3S5vuE0NQgRAcmPCG N7eyO9C9C3DdjvyxQTJjpOYUY4ncmm8apXr29IS3B6YwGra3nWGOyuUdiYdxtLS++Csd ryhOyQ2/6X6FgcgciIVwMn6VTT/XILZcJCNrGwlN2c76rxhx7KNTZwayHe7T4luYIyX6 PslKvKOwFrb92uBuyc85MYeXgckNvmelynKJEKXh1iODDpPiTpwNM3CzGWuiuR7G4rJF /pPSLWK8Llpbm6ZnlbrhDl/5FORgZ4/Ba4qG34Ne8o8hJJ5OjnaLGd5KLwE5pTAAGTI+ r1kQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24si11507022pge.245.2017.11.06.06.42.45; Mon, 06 Nov 2017 06:42:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932519AbdKFOke (ORCPT + 97 others); Mon, 6 Nov 2017 09:40:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60186 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932196AbdKFOka (ORCPT ); Mon, 6 Nov 2017 09:40:30 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB6ADC04AC5D; Mon, 6 Nov 2017 14:40:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CB6ADC04AC5D Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 302385EDF5; Mon, 6 Nov 2017 14:40:26 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: aarcange@redhat.com, hughd@google.com, nyc@holomorphy.com, mike.kravetz@oracle.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 8/9] memfd-test: move common code to a shared unit Date: Mon, 6 Nov 2017 15:39:43 +0100 Message-Id: <20171106143944.13821-9-marcandre.lureau@redhat.com> In-Reply-To: <20171106143944.13821-1-marcandre.lureau@redhat.com> References: <20171106143944.13821-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Nov 2017 14:40:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memfd & fuse tests will share more common code in the following commits to test hugetlb support. Signed-off-by: Marc-André Lureau --- tools/testing/selftests/memfd/Makefile | 5 ++++ tools/testing/selftests/memfd/common.c | 45 ++++++++++++++++++++++++++++++ tools/testing/selftests/memfd/common.h | 9 ++++++ tools/testing/selftests/memfd/fuse_test.c | 8 ++---- tools/testing/selftests/memfd/memfd_test.c | 36 ++---------------------- 5 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 tools/testing/selftests/memfd/common.c create mode 100644 tools/testing/selftests/memfd/common.h diff --git a/tools/testing/selftests/memfd/Makefile b/tools/testing/selftests/memfd/Makefile index 3926a0409dda..a5276a91dfbf 100644 --- a/tools/testing/selftests/memfd/Makefile +++ b/tools/testing/selftests/memfd/Makefile @@ -12,3 +12,8 @@ fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags) include ../lib.mk $(OUTPUT)/fuse_mnt: LDLIBS += $(shell pkg-config fuse --libs) + +$(OUTPUT)/memfd_test: memfd_test.c common.o +$(OUTPUT)/fuse_test: fuse_test.c common.o + +EXTRA_CLEAN = common.o diff --git a/tools/testing/selftests/memfd/common.c b/tools/testing/selftests/memfd/common.c new file mode 100644 index 000000000000..7ed269cd3abb --- /dev/null +++ b/tools/testing/selftests/memfd/common.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#define __EXPORTED_HEADERS__ + +#include +#include +#include +#include +#include + +#include "common.h" + +int hugetlbfs_test = 0; + +/* + * Copied from mlock2-tests.c + */ +unsigned long default_huge_page_size(void) +{ + unsigned long hps = 0; + char *line = NULL; + size_t linelen = 0; + FILE *f = fopen("/proc/meminfo", "r"); + + if (!f) + return 0; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { + hps <<= 10; + break; + } + } + + free(line); + fclose(f); + return hps; +} + +int sys_memfd_create(const char *name, unsigned int flags) +{ + if (hugetlbfs_test) + flags |= MFD_HUGETLB; + + return syscall(__NR_memfd_create, name, flags); +} diff --git a/tools/testing/selftests/memfd/common.h b/tools/testing/selftests/memfd/common.h new file mode 100644 index 000000000000..522d2c630bd8 --- /dev/null +++ b/tools/testing/selftests/memfd/common.h @@ -0,0 +1,9 @@ +#ifndef COMMON_H_ +#define COMMON_H_ + +extern int hugetlbfs_test; + +unsigned long default_huge_page_size(void); +int sys_memfd_create(const char *name, unsigned int flags); + +#endif diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/selftests/memfd/fuse_test.c index 1ccb7a3eb14b..795a25ba8521 100644 --- a/tools/testing/selftests/memfd/fuse_test.c +++ b/tools/testing/selftests/memfd/fuse_test.c @@ -33,15 +33,11 @@ #include #include +#include "common.h" + #define MFD_DEF_SIZE 8192 #define STACK_SIZE 65536 -static int sys_memfd_create(const char *name, - unsigned int flags) -{ - return syscall(__NR_memfd_create, name, flags); -} - static int mfd_assert_new(const char *name, loff_t sz, unsigned int flags) { int r, fd; diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c index 955d09ee16ca..4c049b6b6985 100644 --- a/tools/testing/selftests/memfd/memfd_test.c +++ b/tools/testing/selftests/memfd/memfd_test.c @@ -19,6 +19,8 @@ #include #include +#include "common.h" + #define MEMFD_STR "memfd:" #define MEMFD_HUGE_STR "memfd-hugetlb:" #define SHARED_FT_STR "(shared file-table)" @@ -29,43 +31,9 @@ /* * Default is not to test hugetlbfs */ -static int hugetlbfs_test; static size_t mfd_def_size = MFD_DEF_SIZE; static const char *memfd_str = MEMFD_STR; -/* - * Copied from mlock2-tests.c - */ -static unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - - free(line); - fclose(f); - return hps; -} - -static int sys_memfd_create(const char *name, - unsigned int flags) -{ - if (hugetlbfs_test) - flags |= MFD_HUGETLB; - - return syscall(__NR_memfd_create, name, flags); -} - static int mfd_assert_new(const char *name, loff_t sz, unsigned int flags) { int r, fd; -- 2.15.0.rc0.40.gaefcc5f6f From 1583367763699105096@xxx Tue Nov 07 01:12:49 +0000 2017 X-GM-THRID: 1583367763699105096 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread