Received: by 10.223.164.202 with SMTP id h10csp233200wrb; Tue, 7 Nov 2017 05:41:08 -0800 (PST) X-Google-Smtp-Source: ABhQp+QStrNng7zU0pQ+KrvRALkA1qSYZ0NS91dNqmHAplI5DDx8fL1AB1dpvqy8Iy6xwZ3adeQx X-Received: by 10.98.65.218 with SMTP id g87mr20605109pfd.105.1510062068543; Tue, 07 Nov 2017 05:41:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510062068; cv=none; d=google.com; s=arc-20160816; b=ubPyLNJfRSLJN2QIYQKPeV1xpgzaPCZcc+YbuscsJDnb0CPBp+/i1iOnUU0D+32RCz ds5ODM5iWhX3Fr4vovww24qXCq/s32L6ZQKW11nPFWOWrKQf0KLVv2Q8VW49KaumiboV qmevbnx5tGTt7wpG5ZxIimGyhArFKijJyLXj4ZTT/Jwd56lo4WMMWF3qxZCXe/Ea0eHE 4LmVeIxETk5mLhZha9EFG8ed3f8A86w0aT7zH0/RLGSBoXvv76XxA+t+NDGlLU0dTSub E/uf3TbLl36o5+T5C+25/n6DIeyI2txPtn1J6QIRba2StHrg2xVFIJsYQNOEIgYbsvcB F0ug== 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=8vrVUoNbPhIIfq7l9J7wbsBOCit6nUd/7u7sztIBZEM=; b=pyloZTZprBBlHd41v0r7LDRZ1CbSOlvGtjb4lVJiV4QR0YMNiQEJvWUjGCqGZQVyn9 NYAw7PqiNksPl/+Z6wxvJE+IYFNJuPGaohnUC6sot0EpGDIXTM6tCPIGWv0Rr/FEizAq A+gpMgYzf+ie7dD+7iTQK3j2FCaZGTbJ67WbdEvnQ6HNZmCYo4kv8oj774ehqWtTmGmc fvMTA6Ns+U37nQv7ms7FrgpU+duDZUhiYhDtv9zRbcOuPPjz7C9LYUW23MTBGCwkG3Ul Y7AEUzQT2Rv0syB/X7JyRmJY5mPc6q8ZkjbfLeSJAneLp5tRDxvtOqxmkJtDb7/LSqto zzdw== 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 i10si1200639pgs.259.2017.11.07.05.40.55; Tue, 07 Nov 2017 05:41:08 -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 S934000AbdKGMbb (ORCPT + 91 others); Tue, 7 Nov 2017 07:31:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46698 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757681AbdKGM2d (ORCPT ); Tue, 7 Nov 2017 07:28:33 -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 784603D94F; Tue, 7 Nov 2017 12:28:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 784603D94F Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E20A5D6A9; Tue, 7 Nov 2017 12:28:30 +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 v3 8/9] memfd-test: move common code to a shared unit Date: Tue, 7 Nov 2017 13:27:59 +0100 Message-Id: <20171107122800.25517-9-marcandre.lureau@redhat.com> In-Reply-To: <20171107122800.25517-1-marcandre.lureau@redhat.com> References: <20171107122800.25517-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.30]); Tue, 07 Nov 2017 12:28:33 +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 Reviewed-by: Mike Kravetz --- tools/testing/selftests/memfd/Makefile | 5 ++++ tools/testing/selftests/memfd/common.c | 46 ++++++++++++++++++++++++++++++ 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, 64 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..8eb3d75f6e60 --- /dev/null +++ b/tools/testing/selftests/memfd/common.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#define __EXPORTED_HEADERS__ + +#include +#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.125.g8f49766d64 From 1583365474175411955@xxx Tue Nov 07 00:36:26 +0000 2017 X-GM-THRID: 1583362889301573110 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread