From patchwork Fri Jan 24 09:48:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1228720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=FxNUlDCq; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483vV62Kv5z9sSH for ; Fri, 24 Jan 2020 20:48:45 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8EC673C23A5 for ; Fri, 24 Jan 2020 10:48:42 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 3D7EC3C2379 for ; Fri, 24 Jan 2020 10:48:40 +0100 (CET) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 8EFE31000540 for ; Fri, 24 Jan 2020 10:48:38 +0100 (CET) Received: by mail-pl1-x62d.google.com with SMTP id g6so559379plt.2 for ; Fri, 24 Jan 2020 01:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wa17AkViCZAC//FDkb7N/byTfZC83UHHxgAfLlEjpgI=; b=FxNUlDCqWNCxyb3gKjqgpvHyToR0mWOv4vkvvCDROpkjp9JMdSMfcScf5WrzX2RfXW /fCQ+b1S/AeVglm3hvn+FMIiFwNEk16nvaLpm8vZkCtqFHb5gUYsc1OFNy4GxD+IHvbz /eOKNu91jAS5Y8IzkkvSwvc7/n58KXYQv+O5aESE2d+EsnxdTW14mMv8VEa5DRJz5gGI QiYEFD8gY307sbhiVWCnVHtpiFd3+RZSokni+/tiLXMCbVhMJvuxnKt4F6eswCGVbK9H Ok5SoUuSIlyKTJBAUn+sXdnlybtU6eLVupIyhuopd8M0C2Y8vVXYlie9nonct7weIaeh kqVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wa17AkViCZAC//FDkb7N/byTfZC83UHHxgAfLlEjpgI=; b=T/ctQxpEvda4qaxRPLgdxtX8N6wi2yyIjpFExgbhkgUxNyYdwq5dMhJdDtb9f98VFj mMzAo66V890A49zcUUSootwBVvwz5HITH3zLk848FEFtGRsh2Fc20EcIl9/n5xQlQSPr ugz4ub0ba8/Yf4NAXhdtMS5goAQw69Ak6TAD+79As1mDriyAQRZ3Ubm/kjnm0KsX4iGD zkzp7vRr6asiuEz3v3Hb7NVsFcakJJtc7qW+lem6yBS/pyQrTlAh3ngmFTVyoNRouCcy HnUaT1G26+uz/Z0qKvfGLcwiXVIELiYM/nkmQhaKyOo1S6ltMJNxerWmmyUQXfCEF62k cfBQ== X-Gm-Message-State: APjAAAW0fA/5SgjuskOAzVTPVt2U7qji820KE5Xmxfsh3SKeT7yLZk/C l+iApfHkG1usjFcBcYq3NN+maA== X-Google-Smtp-Source: APXvYqwrC9tCKFr1XzIJZ2jFm3rxOQZkABcN2rb9mb24jCEE07NvCvDQynsF/f1dHiYF5DgTQEv2Ew== X-Received: by 2002:a17:902:968c:: with SMTP id n12mr2787749plp.144.1579859317529; Fri, 24 Jan 2020 01:48:37 -0800 (PST) Received: from localhost ([122.167.18.14]) by smtp.gmail.com with ESMTPSA id g11sm5954899pgd.26.2020.01.24.01.48.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jan 2020 01:48:36 -0800 (PST) From: Viresh Kumar To: Cyril Hrubis Date: Fri, 24 Jan 2020 15:18:26 +0530 Message-Id: <1dbcadb1781ba1f0584eb92c83aec5f66abb109c.1579858930.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH V3 1/2] Add Syscall numbers for pidfd_open X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Viresh Kumar --- V1->V3: - No changes include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+) diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index 0e00641bcf4d..19f3aa4475bd 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -270,4 +270,5 @@ pkey_mprotect 288 pkey_alloc 289 pkey_free 290 pidfd_send_signal 424 +pidfd_open 434 _sysctl 1078 diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in index a6a594c2e85d..979a0183d4f5 100644 --- a/include/lapi/syscalls/arm.in +++ b/include/lapi/syscalls/arm.in @@ -355,3 +355,4 @@ pkey_alloc (__NR_SYSCALL_BASE+395) pkey_free (__NR_SYSCALL_BASE+396) statx (__NR_SYSCALL_BASE+397) pidfd_send_signal (__NR_SYSCALL_BASE+424) +pidfd_open (__NR_SYSCALL_BASE+434) diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index d92f33f40a50..b0807ca6b69f 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -27,3 +27,4 @@ copy_file_range 346 preadv2 347 pwritev2 348 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in index bad6e409fbdc..f19e24bd63c9 100644 --- a/include/lapi/syscalls/i386.in +++ b/include/lapi/syscalls/i386.in @@ -354,3 +354,4 @@ pkey_alloc 381 pkey_free 382 statx 383 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index 0e6ba54a8f76..92cc881d933b 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -310,3 +310,4 @@ pkey_mprotect 1354 pkey_alloc 1355 pkey_free 1356 pidfd_send_signal 1448 +pidfd_open 1458 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index 91467f326ed2..f83f7d233e61 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -357,6 +357,7 @@ preadv2 380 pwritev2 381 statx 383 pidfd_send_signal 424 +pidfd_open 434 pkey_mprotect 386 pkey_alloc 384 pkey_free 385 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index 91467f326ed2..f83f7d233e61 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -357,6 +357,7 @@ preadv2 380 pwritev2 381 statx 383 pidfd_send_signal 424 +pidfd_open 434 pkey_mprotect 386 pkey_alloc 384 pkey_free 385 diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in index dcf0a71482ef..f99aceb71a81 100644 --- a/include/lapi/syscalls/s390.in +++ b/include/lapi/syscalls/s390.in @@ -344,3 +344,4 @@ pkey_mprotect 384 pkey_alloc 385 pkey_free 386 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index 2dce00f900a2..9666095b6bea 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -342,3 +342,4 @@ pkey_mprotect 384 pkey_alloc 385 pkey_free 386 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index 996ebc956a9a..73549b46e6dd 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -371,3 +371,4 @@ copy_file_range 391 preadv2 392 pwritev2 393 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index 65902e00aa23..6c610ba67308 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -349,3 +349,4 @@ pkey_mprotect 362 pkey_alloc 363 pkey_free 364 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index d303622b46df..d20e87926913 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -324,3 +324,4 @@ pkey_mprotect 362 pkey_alloc 363 pkey_free 364 pidfd_send_signal 424 +pidfd_open 434 diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in index 3e9e19ae6af0..cba0080dd27a 100644 --- a/include/lapi/syscalls/x86_64.in +++ b/include/lapi/syscalls/x86_64.in @@ -321,3 +321,4 @@ pkey_alloc 330 pkey_free 331 statx 332 pidfd_send_signal 424 +pidfd_open 434 From patchwork Fri Jan 24 09:48:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1228721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=q7Nvl1Vm; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483vVH0Zg4z9sP3 for ; Fri, 24 Jan 2020 20:48:55 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 617203C239F for ; Fri, 24 Jan 2020 10:48:52 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 313703C23CF for ; Fri, 24 Jan 2020 10:48:45 +0100 (CET) Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 0CFFD1000551 for ; Fri, 24 Jan 2020 10:48:41 +0100 (CET) Received: by mail-pf1-x444.google.com with SMTP id 4so826847pfz.9 for ; Fri, 24 Jan 2020 01:48:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cIFVBIDW7OjsV1+1vJ2OgSojfhnEDUCYtCe+78SfvGk=; b=q7Nvl1Vm+TPmPvc+KQIKaqdS7Gm8Oq5yePqqeHBvft1f+VeQDjwowd927TiBz3qGTh IcxfgCdY/aJybrTHKoiWlxwad2AxT+hq1pkVoUPgTCCMZZ/O8UGII56iqW8bSx9wB7le SX3UWvSq2tN6WhoIP5mVkX/9oxb+vBVrkXfGMQCLQQHLEC2Pz2Wfw/I/sO8hfn/WJQsD y/XrrguSIyiVVAUwk1L0pAvsM3bB0AkW+rpgCRwLXKeRw9MYGHbF+h5yvFwu1QmmC8+W 07yhRf5E4rIR1OsowigrIdOLv7T+neg9KooP6grSmQvVMyOKrWahXWt8XQl6jWRRlyzw TyAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cIFVBIDW7OjsV1+1vJ2OgSojfhnEDUCYtCe+78SfvGk=; b=LBbIOJa+lA5bpbLnobfl20Brw6dd/s59bl0rHfzY/U6MDZpDAweFFsYLGvewb9JR4c MqcFZ8RIBIaT2aBqKKMBCuowAUfj/NFrJk7YR681vJlvDQQANU3oo9Kp7Tlh4XkdEhBf 8jSYhCbrElEyhXgzssGEgJ9ZRnEYPw+GQCC/poh304Uea6he0hoYA5m9myJRoC/X0XA2 ilZoeOpq9M31Y80Z1g5RhqzBdmns79/qmco4MHOjA+A20rxEB3Hd7mFirR9RCSUUR+Mq yrq3a+5pxTR9ZPVs3GX9FGoR7MXHy3N6YLxpRVuhFl6oLWe9CWF7NS7WIG7hqa1woRsj 9Z8A== X-Gm-Message-State: APjAAAUdN+sqpZMQNgzHohgATD6BoIuwxAkna0RPoGAJvHDimIuHbTK1 6eCenkPBb4BrSmZrPQ5nY2aULA== X-Google-Smtp-Source: APXvYqwaAwIeNZJkqgJeL2MaL6/Tj/ZdIoedhKVhBw1uUzVdaGnBAJBPv5UsFIBlXCjN4sJtnWPCVg== X-Received: by 2002:a63:3d4:: with SMTP id 203mr3073593pgd.266.1579859320086; Fri, 24 Jan 2020 01:48:40 -0800 (PST) Received: from localhost ([122.167.18.14]) by smtp.gmail.com with ESMTPSA id l66sm6037884pga.30.2020.01.24.01.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jan 2020 01:48:39 -0800 (PST) From: Viresh Kumar To: Cyril Hrubis Date: Fri, 24 Jan 2020 15:18:27 +0530 Message-Id: <8dc3dff0390db58b2f472501c30595647a913e34.1579858930.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: <1dbcadb1781ba1f0584eb92c83aec5f66abb109c.1579858930.git.viresh.kumar@linaro.org> References: <1dbcadb1781ba1f0584eb92c83aec5f66abb109c.1579858930.git.viresh.kumar@linaro.org> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH V3 2/2] syscalls/pidfd_open X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Add tests to check working of pidfd_open() syscall. Signed-off-by: Viresh Kumar --- V2->V3: - Add pidfd_open03 to syscalls and .gitignore files. - Use TEST, tst_get_unused_pid, etc. - Do the failure testing with help of array and .tcnt. - Improved print messages. - Removed useless comments. - Few more minor changes. V1->V2: - New test to test failures - Use SAFE_FORK, checkpoints, etc - Print error numbers as well. - Improved print messages. configure.ac | 1 + include/lapi/pidfd_open.h | 21 +++++++ runtest/syscalls | 4 ++ .../kernel/syscalls/pidfd_open/.gitignore | 3 + testcases/kernel/syscalls/pidfd_open/Makefile | 6 ++ .../kernel/syscalls/pidfd_open/pidfd_open01.c | 34 ++++++++++ .../kernel/syscalls/pidfd_open/pidfd_open02.c | 63 +++++++++++++++++++ .../kernel/syscalls/pidfd_open/pidfd_open03.c | 63 +++++++++++++++++++ 8 files changed, 195 insertions(+) create mode 100644 include/lapi/pidfd_open.h create mode 100644 testcases/kernel/syscalls/pidfd_open/.gitignore create mode 100644 testcases/kernel/syscalls/pidfd_open/Makefile create mode 100644 testcases/kernel/syscalls/pidfd_open/pidfd_open01.c create mode 100644 testcases/kernel/syscalls/pidfd_open/pidfd_open02.c create mode 100644 testcases/kernel/syscalls/pidfd_open/pidfd_open03.c diff --git a/configure.ac b/configure.ac index 50d14967d3c6..1bf0911d88ad 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,7 @@ AC_CHECK_FUNCS([ \ mknodat \ name_to_handle_at \ openat \ + pidfd_open \ pidfd_send_signal \ pkey_mprotect \ preadv \ diff --git a/include/lapi/pidfd_open.h b/include/lapi/pidfd_open.h new file mode 100644 index 000000000000..ced163be83bf --- /dev/null +++ b/include/lapi/pidfd_open.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Linaro Limited. All rights reserved. + * Author: Viresh Kumar + */ + +#ifndef PIDFD_OPEN_H +#define PIDFD_OPEN_H + +#include "config.h" +#include +#include "lapi/syscalls.h" + +#ifndef HAVE_PIDFD_OPEN +int pidfd_open(pid_t pid, unsigned int flags) +{ + return tst_syscall(__NR_pidfd_open, pid, flags); +} +#endif + +#endif /* PIDFD_OPEN_H */ diff --git a/runtest/syscalls b/runtest/syscalls index f58fefe17c34..f083758bc637 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -848,6 +848,10 @@ pause03 pause03 personality01 personality01 personality02 personality02 +pidfd_open01 pidfd_open01 +pidfd_open02 pidfd_open02 +pidfd_open03 pidfd_open03 + pidfd_send_signal01 pidfd_send_signal01 pidfd_send_signal02 pidfd_send_signal02 pidfd_send_signal03 pidfd_send_signal03 diff --git a/testcases/kernel/syscalls/pidfd_open/.gitignore b/testcases/kernel/syscalls/pidfd_open/.gitignore new file mode 100644 index 000000000000..e0b8900c1c33 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/.gitignore @@ -0,0 +1,3 @@ +pidfd_open01 +pidfd_open02 +pidfd_open03 diff --git a/testcases/kernel/syscalls/pidfd_open/Makefile b/testcases/kernel/syscalls/pidfd_open/Makefile new file mode 100644 index 000000000000..5ea7d67db123 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c new file mode 100644 index 000000000000..e40ea4f2eff5 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Viresh Kumar + * + * Description: + * Basic pidfd_open() test, fetches the PID of the current process and tries to + * get its file descriptor. + */ +#include +#include + +#include "tst_test.h" +#include "lapi/pidfd_open.h" +#include "lapi/syscalls.h" + +static void run(void) +{ + int fd; + + TEST(pidfd_open(getpid(), 0)); + + fd = TST_RET; + if (fd == -1) + tst_brk(TFAIL | TTERRNO, "pidfd_open(getpid(), 0) failed"); + + SAFE_CLOSE(fd); + + tst_res(TPASS, "pidfd_open(getpid(), 0) passed"); +} + +static struct tst_test test = { + .min_kver = "5.3", + .test_all = run, +}; diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c new file mode 100644 index 000000000000..5e5431335731 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Viresh Kumar + * + * Description: + * Basic pidfd_open() test to test invalid arguments. + */ +#include +#include + +#include "tst_test.h" +#include "lapi/pidfd_open.h" +#include "lapi/syscalls.h" + +#define INVALID_PID -1 +#define MY_PID 0 +#define EXPIRED_PID 1 + +static struct tcase { + char *name; + int pid; + int flags; + int exp_errno; +} tcases[] = { + {"test-expired-pid", EXPIRED_PID, 0, ESRCH}, + {"test-invalid-pid", INVALID_PID, 0, EINVAL}, + {"test-invalid-flags", MY_PID, 1, EINVAL}, +}; + +static void run(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + pid_t pid; + + if (tc->pid == EXPIRED_PID) + pid = tst_get_unused_pid(); + else if (tc->pid == MY_PID) + pid = getpid(); + else + pid = tc->pid; + + TEST(pidfd_open(pid, tc->flags)); + + if (TST_RET != -1) { + SAFE_CLOSE(TST_RET); + tst_brk(TFAIL, "%s: pidfd_open succeeded unexpectedly (index: %d)", + tc->name, n); + } + + if (tc->exp_errno != TST_ERR) { + tst_brk(TFAIL | TTERRNO, "%s: pidfd_open() should fail with %s", + tc->name, tst_strerrno(tc->exp_errno)); + } + + tst_res(TPASS | TTERRNO, "%s: pidfd_open() failed as expected", + tc->name); +} + +static struct tst_test test = { + .min_kver = "5.3", + .tcnt = ARRAY_SIZE(tcases), + .test = run, +}; diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c new file mode 100644 index 000000000000..efa14dc52d7a --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 Viresh Kumar + * + * Description: + * This program opens the PID file descriptor of the child process created with + * fork(). It then uses poll to monitor the file descriptor for process exit, as + * indicated by an EPOLLIN event. + */ +#include +#include +#include +#include +#include + +#include "tst_test.h" +#include "lapi/pidfd_open.h" +#include "lapi/syscalls.h" + +static void run(void) +{ + struct pollfd pollfd; + int fd, ready; + pid_t pid; + + pid = SAFE_FORK(); + + if (!pid) { + TST_CHECKPOINT_WAIT(0); + exit(EXIT_SUCCESS); + } else { + TEST(pidfd_open(pid, 0)); + + fd = TST_RET; + if (fd == -1) + tst_brk(TFAIL | TTERRNO, "pidfd_open() failed"); + + TST_CHECKPOINT_WAKE(0); + + pollfd.fd = fd; + pollfd.events = POLLIN; + + ready = poll(&pollfd, 1, -1); + + SAFE_CLOSE(fd); + SAFE_WAITPID(pid, NULL, 0); + + if (ready == -1) + tst_brk(TBROK | TERRNO, "poll() failed"); + + if (ready != 1) + tst_brk(TBROK, "poll() should return 1"); + + tst_res(TPASS, "pidfd_open() passed"); + } +} + +static struct tst_test test = { + .min_kver = "5.3", + .test_all = run, + .forks_child = 1, + .needs_checkpoints = 1, +};