From patchwork Thu Mar 7 07:28:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 159798 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7119621jad; Wed, 6 Mar 2019 23:29:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwuD8QsnOJ/FGpaA6bYC+MDok4pFE244sKr4ZMbdVL6hDHggQgofawdXnKcCkp8ZbGdC1Vq X-Received: by 2002:a50:9863:: with SMTP id h32mr27663189edb.291.1551943760191; Wed, 06 Mar 2019 23:29:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551943760; cv=none; d=google.com; s=arc-20160816; b=TO4E/SR3p61AiLzUJEng6uSTL2yvb5IYKH39oV61PPxDP0KK+99RNKwIxbRIa6ldaR Op5b0Ow5u0EPV5EZTZrv1PtQAY+lQ0iSZgEGOsa1X08//z4WIav9E/WYeHzUIjexCiG+ 6vEYVmqof7npDyUuj5deQ7xhYj1ME2KBPAuXGgNamR+1PHaeBNYoURiqqSfaDADppqRv 1FoB2NAhjtwXxU6zYmMDqIl36TNy/XwNSw801Ved9qp3NLl1uOIxBAZf47lbl9hFtHdb Vu3J4hrucMmHktokkspz9X6TvW/z7YWy9o9QC0NbjR3ScSQboBEmkmUakVToPKTEA8wa 2vUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=Xd8IwMKsm29RcSHuvLHKbbeFRKp8Ck6UdgTnRUkrNpw=; b=W9TrbORG5t5OY7Wn2bStADvXN1mNOOcappfEQOsKlXZjQsBDwSu2RJ+DGLbOmTvgOP OKMNjaCJ5LDVBjrdYywXXF83CpXIC36yw8Yr8XJgxKwXhVC/MeyJfLNwJLrTV8TE5+p7 yeGZ9s23fMMa39dbR2hD1LMqf9fupoHCuyYO2HU2zk1z/WVl6eW+opsQJa2cSwgAgt/q 30hZgM16vFfTe2L/shgOQvrL5OpHHqm+FPBwmCP7/Vfcd4eKl/DvJS29Ju/Sgn/EgXXV 4YaEm5yTIWjVwvrLk0nLCC2pJ/Y+z0TOk0ite10/2qd1EnR9wccBA5Tu1qgX9jkv0esP KwKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=YXACJvbd; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id e16si1431565edd.365.2019.03.06.23.29.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 23:29:20 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=YXACJvbd; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B48383EA3E8 for ; Thu, 7 Mar 2019 08:29:19 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 225F63EA19D for ; Thu, 7 Mar 2019 08:29:16 +0100 (CET) Received: from mail-yw1-xc44.google.com (mail-yw1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 500591401A6E for ; Thu, 7 Mar 2019 08:29:15 +0100 (CET) Received: by mail-yw1-xc44.google.com with SMTP id u205so12549186ywe.1 for ; Wed, 06 Mar 2019 23:29:15 -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; bh=L+7xv0EywF8y9lxiY/HIaEsxwjNp6S5h9MOlxUnAMRk=; b=YXACJvbdZ9LsC3UVVxDn0ul2kHzEHrfXSfh8SdY4SQks3Gd5HjDQc7gEVUGPAq4FVj 6ptnNVImgaBNjUVLMOQvNyijWeslI9LZzXz2TfMGgjsWzXdyj/+pE/i7J1OcIMwTaWrR fkAX/bGjFCM5WG/db+1RUaR7QeH/jhzYyAfDG3+HWXKTaDgApPOS5+M65pKUBQuO5kEq OwO097C3n3cHQgw0SK0GXQ0HOAlXUzEFIJw/PGkdVVaBSWtZ5f8tZQjJv4P9Os/Wsl/E snYoiQZdk0Vuz32C5RTkLDFQDuryU8WYrE20akBQQyMEpo4QTwERfkVVHUXhuRN1fqjt Qz4A== 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; bh=L+7xv0EywF8y9lxiY/HIaEsxwjNp6S5h9MOlxUnAMRk=; b=tFxWWt1qlQ+wujJtAsjICGtQ5DYdsi7AF/AIjNe0Dy7ccnMbP5MfXVPyMYaNXoqDnD 2Zggrd9X13lIT+tiUNMjQJUYdV51mYlLptPHSYAerL+ZLFY7iWLtzXTEHiZ9SiEaPaLJ VtSNNwQDMQ4DjGfERMDieAwg0dgos2F4pWzigKPEU2dO8m1NFzhT6Xr5L8iXLS4hqJQz XctDMz5QDBMVwUhrZRPM5RJRT5IEWqevfDg47rrAP/3DnoKjMuLIVBnh/0yDaB3LA4G4 Mwk0CPUr/4ZadUp3vDecQ1mdcTBLfSsRUMA0XYtrJLFEBFdSMGd3EVO8fD1NKhQMLyK9 TIdQ== X-Gm-Message-State: APjAAAWBg1e+4PIrZoLnCnLdLa4CtLKEN7C5JQ7u2M2y8IopFqOJn1+w 6UnwggkZ3zRd8rQFSSbswaf3Vjz8ZXc= X-Received: by 2002:a25:2b09:: with SMTP id r9mr6327297ybr.353.1551943753978; Wed, 06 Mar 2019 23:29:13 -0800 (PST) Received: from localhost.localdomain ([117.252.64.200]) by smtp.gmail.com with ESMTPSA id v6sm1464108ywc.107.2019.03.06.23.29.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Mar 2019 23:29:13 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Thu, 7 Mar 2019 12:58:46 +0530 Message-Id: <1551943728-16222-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551943728-16222-1-git-send-email-sumit.garg@linaro.org> References: <1551943728-16222-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.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_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: daniel.thompson@linaro.org, Greg Hackmann Subject: [LTP] [PATCH 1/3] syscalls/tgkill01: add new test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" From: Greg Hackmann tgkill() delivers a signal to a specific thread. Test this by installing a SIGUSR1 handler which records the current pthread ID. Start a number of threads in parallel, then one-by-one call tgkill(..., tid, SIGUSR1) and check that the expected pthread ID was recorded. Signed-off-by: Greg Hackmann Signed-off-by: Sumit Garg Reviewed-by: Li Wang Signed-off-by: Greg Hackmann <ghackmann@google.com>
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Reviewed-by: Li Wang <liwang@redhat.com>

This patch set looks pretty good to me. Just have a tiny comments for PATCH 1/3 in below.
 
--- runtest/syscalls | 2 + testcases/kernel/syscalls/tgkill/.gitignore | 1 + testcases/kernel/syscalls/tgkill/Makefile | 10 ++ testcases/kernel/syscalls/tgkill/tgkill.h | 22 +++++ testcases/kernel/syscalls/tgkill/tgkill01.c | 138 ++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/.gitignore create mode 100644 testcases/kernel/syscalls/tgkill/Makefile create mode 100644 testcases/kernel/syscalls/tgkill/tgkill.h create mode 100644 testcases/kernel/syscalls/tgkill/tgkill01.c diff --git a/runtest/syscalls b/runtest/syscalls index b43de7a..9ed1214 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1395,6 +1395,8 @@ syslog10 syslog10 syslog11 syslog11 syslog12 syslog12 +tgkill01 tgkill01 + time01 time01 time02 time02 diff --git a/testcases/kernel/syscalls/tgkill/.gitignore b/testcases/kernel/syscalls/tgkill/.gitignore new file mode 100644 index 0000000..f4566fd --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/.gitignore @@ -0,0 +1 @@ +tgkill01 diff --git a/testcases/kernel/syscalls/tgkill/Makefile b/testcases/kernel/syscalls/tgkill/Makefile new file mode 100644 index 0000000..a51080c --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2018 Google, Inc. + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +LDLIBS += -pthread diff --git a/testcases/kernel/syscalls/tgkill/tgkill.h b/testcases/kernel/syscalls/tgkill/tgkill.h new file mode 100644 index 0000000..a7d96f4 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Google, Inc. + */ + +#ifndef TGKILL_H +#define TGKILL_H + +#include "config.h" +#include "lapi/syscalls.h" + +static inline int sys_tgkill(int tgid, int tid, int sig) +{ + return tst_syscall(__NR_tgkill, tgid, tid, sig); +} + +static inline pid_t sys_gettid(void) +{ + return tst_syscall(__NR_gettid); +} + +#endif /* TGKILL_H */ diff --git a/testcases/kernel/syscalls/tgkill/tgkill01.c b/testcases/kernel/syscalls/tgkill/tgkill01.c new file mode 100644 index 0000000..1fb1171 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill01.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Google, Inc. + * + * tgkill() delivers a signal to a specific thread. Test this by installing + * a SIGUSR1 handler which records the current pthread ID. Start a number + * of threads in parallel, then one-by-one call tgkill(..., tid, SIGUSR1) + * and check that the expected pthread ID was recorded. + */ + +#include + +#include "tst_safe_pthread.h" +#include "tst_test.h" +#include "tgkill.h" + +struct thread_state { + pthread_t thread; + pid_t tid; +}; + +static char *str_threads; +static int n_threads = 10; +static struct thread_state *threads; + +static pthread_t sigusr1_thread; + +static int test_running; +static pthread_cond_t test_running_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t test_running_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void sigusr1_handler(int signum __attribute__((unused))) +{ + sigusr1_thread = pthread_self(); +} + +static void *thread_func(void *arg) +{ + struct thread_state *thread = arg; + + /** + * There is no standard way to map pthread -> tid, so we will have the + * child stash its own tid then notify the parent that the stashed tid + * is available. + */ + thread->tid = sys_gettid(); + + TST_CHECKPOINT_WAKE(0); + + pthread_mutex_lock(&test_running_mutex); + while (test_running) + pthread_cond_wait(&test_running_cond, &test_running_mutex); + pthread_mutex_unlock(&test_running_mutex); + + return arg; +} + +static void start_thread(struct thread_state *thread) +{ + SAFE_PTHREAD_CREATE(&thread->thread, NULL, thread_func, thread); + + TST_CHECKPOINT_WAIT(0); +} + +static void stop_threads(void) +{ + int i; + + test_running = 0; + pthread_cond_broadcast(&test_running_cond); + + for (i = 0; i < n_threads; i++) { + if (threads[i].tid == -1) + continue; + + SAFE_PTHREAD_JOIN(threads[i].thread, NULL); + threads[i].tid = -1; + } +} + +static void run(void) +{ + int i; + + for (i = 0; i < n_threads; i++) + threads[i].tid = -1; + + test_running = 1; + for (i = 0; i < n_threads; i++) + start_thread(&threads[i]); + + for (i = 0; i < n_threads; i++) { + sigusr1_thread = pthread_self(); + + TEST(sys_tgkill(getpid(), threads[i].tid, SIGUSR1)); + if (TST_RET) { + tst_res(TFAIL | TTERRNO, "tgkill() failed"); + return; + } + + while (pthread_equal(sigusr1_thread, pthread_self())) + usleep(1000); + + if (!pthread_equal(sigusr1_thread, threads[i].thread)) { + tst_res(TFAIL, "SIGUSR1 delivered to wrong thread"); + return; + } + } + + stop_threads(); + tst_res(TPASS, "SIGUSR1 delivered to correct threads"); +} + +static void setup(void) +{ + if (tst_parse_int(str_threads, &n_threads, 1, INT_MAX)) + tst_brk(TBROK, "Invalid number of threads '%s'", str_threads); + + threads = SAFE_MALLOC(sizeof(*threads) * n_threads); + + struct sigaction sigusr1 = { + .sa_handler = sigusr1_handler, + }; + SAFE_SIGACTION(SIGUSR1, &sigusr1, NULL); +} + +static struct tst_option options[] = { + {"t:", &str_threads, "-t Number of threads (default 10)"}, + {NULL, NULL, NULL}, +}; + +static struct tst_test test = { + .options = options, + .needs_checkpoints = 1, + .setup = setup, + .test_all = run, + .cleanup = stop_threads, +}; From patchwork Thu Mar 7 07:28:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 159799 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7119683jad; Wed, 6 Mar 2019 23:29:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzk9FZU1uGDA2Gy1UEDEOfchYtcND3xEZTho1NgaIxgBPsL07fbaRIFgBmH6SZOKoUljCu+ X-Received: by 2002:a1c:d044:: with SMTP id h65mr4821987wmg.120.1551943764976; Wed, 06 Mar 2019 23:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551943764; cv=none; d=google.com; s=arc-20160816; b=wsX/qCHvcQGQrAKZx5BJWoHTcZlDnBXmjIs/oqtqiqfS6x1hbcFnMSksBApGS/KHz1 6FbXLeU0EN9VqpBe3xPbfaTtddYgmhFzsVZEQ6xKza5R6HarOBROwQMIM3KAXDrePaJ2 e0S62HXieSbmIuN38QG3UDNZjsIB9PRwbtijfpAm7eLUsmxXyHtD0zk/fuQcqvglEkcM 0gxaIYXtpc5NGUn+4yuDCXseLE8YTanFyDt37/sJSDIVGaQIyRw6WYd2aSIIBdaIANoF Rz8V50eR/D93qYggL52rzDM1V9n0ExP95asQvHRMKNmAygtEYdc9i0sF2l6S2QYCGHN4 7Ehg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=Sw2OSJVmiJXC3PZxT5a8M76rWXt6bgqqxdQLCytaUuk=; b=kbRnTCAOf3yaspYlko3jNqcXM/8c8HoOz0h25lLw92q5eT0UB7mMfzS+cJvEnGKzEj FTsfwd5070NFPTZjry4U2m2dVPHTRgVOeaKtnTgmyh41sQrN1zHYzWB9Ml9/jbb6qgnT W03zy7oBBfms3AF1OCjzUJBjdOEnzxfGMQHCROuCuTTE3Takz5sRPQ/0S807TVHC4zuW R904OGFp5BlztsiiCSQTOkCBgGEtDeqUHo0K4k+/CKkaL5/r9+wJloJZyvGHwdyRUQ3q ztib6VO3LU15Yby5b6iOM69FYeA27Cbxkz+QMzUqJap3KtMw9e92id7WUGHHaPmMlgLe vnPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Vu/o2oGU"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id s13si2336541wme.101.2019.03.06.23.29.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 23:29:24 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) client-ip=2001:1418:10:5::2; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Vu/o2oGU"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 854DF294AC6 for ; Thu, 7 Mar 2019 08:29:24 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 45C363EA2BA for ; Thu, 7 Mar 2019 08:29:20 +0100 (CET) Received: from mail-yw1-xc44.google.com (mail-yw1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 988002003BA for ; Thu, 7 Mar 2019 08:29:19 +0100 (CET) Received: by mail-yw1-xc44.google.com with SMTP id u200so12507003ywu.10 for ; Wed, 06 Mar 2019 23:29:19 -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; bh=zLfJ9CBWMRNXOyE54GG54r6drWa8CqkGDZwYHZGeEuw=; b=Vu/o2oGU2l6a4GbMHlaCs5+zSsjkAEBdGPyTcLCrcofh4oE0gzvpxnMpMnNgi1M+mB arDMZB4+ZpW9XSpHhnRpSeqgg/0yFsHTkI+SjSYBPHRrj0v1XILQF6x9/LvJZUdFq1Ah c25t8Dl2vGWi+zkLZ4nvm91M739zYf7HG56dOxe2gGIELn0k0slktgqyp5Ycn+uUAQBk 77oqCTeSRikbfsGZMe1SLFNjp3i/P4v80RJc4hhZAUzHqT+nT/QDrtzgLLoD4hMBaP0D cu1W4sCxuB33DTFZf/umSqmYT48HDrpGgwRh0jS9IbzqlVB7s0TLXTOw9McpcDmWzhfi eXrQ== 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; bh=zLfJ9CBWMRNXOyE54GG54r6drWa8CqkGDZwYHZGeEuw=; b=Izd55LDjfIjNe3HRtvop5UG1aOpWIFhg8/FRirSeuf35mLQMJKucvqnmooJtUxKLUT YdG2dNtW1jmF8UlkIgzzFhE0HfyAEC0458qaboCIOgBV1X4UW+3jir8zM5aw0alPxx5i irV9jYwKK9/jq42MKgF3jIQoulloDLoohQQAJeMP1vK6xBeMSmpxguwCYy3qewHSeM8N AXC5qbOpbLMbpyPG+KAe1jpHRokbO7B6vX6AdRzL/+1TeboUjKMPXRLGrv61C2PidZI+ FBaImgM1hgaDIf4M5wkkWnQRGRVHFatUrjGnJo6Uux9a8UqDpIXQd0kE6VeMjPiXhItl 95cQ== X-Gm-Message-State: APjAAAWAeo/Ad7INnFgqJBCxEIyO+vW5kIQweaB9OVHPfDnuXj65ft4X JoTe4ox5rs4m758eBt0Kn+wPJQZwxQo= X-Received: by 2002:a25:d3c3:: with SMTP id e186mr4845342ybf.493.1551943758334; Wed, 06 Mar 2019 23:29:18 -0800 (PST) Received: from localhost.localdomain ([117.252.64.200]) by smtp.gmail.com with ESMTPSA id v6sm1464108ywc.107.2019.03.06.23.29.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Mar 2019 23:29:18 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Thu, 7 Mar 2019 12:58:47 +0530 Message-Id: <1551943728-16222-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551943728-16222-1-git-send-email-sumit.garg@linaro.org> References: <1551943728-16222-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: daniel.thompson@linaro.org, Greg Hackmann Subject: [LTP] [PATCH 2/3] syscalls/tgkill02: add new test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" From: Greg Hackmann tgkill() should fail with EAGAIN when RLIMIT_SIGPENDING is reached with a real-time signal. Test this by starting a child thread with SIGRTMIN blocked and a limit of 0 pending signals, then attempting to deliver SIGRTMIN from the parent thread. Signed-off-by: Greg Hackmann Signed-off-by: Sumit Garg --- runtest/syscalls | 1 + testcases/kernel/syscalls/tgkill/.gitignore | 1 + testcases/kernel/syscalls/tgkill/tgkill02.c | 80 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/tgkill02.c diff --git a/runtest/syscalls b/runtest/syscalls index 9ed1214..fef45fd 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1396,6 +1396,7 @@ syslog11 syslog11 syslog12 syslog12 tgkill01 tgkill01 +tgkill02 tgkill02 time01 time01 time02 time02 diff --git a/testcases/kernel/syscalls/tgkill/.gitignore b/testcases/kernel/syscalls/tgkill/.gitignore index f4566fd..42be2bb 100644 --- a/testcases/kernel/syscalls/tgkill/.gitignore +++ b/testcases/kernel/syscalls/tgkill/.gitignore @@ -1 +1,2 @@ tgkill01 +tgkill02 diff --git a/testcases/kernel/syscalls/tgkill/tgkill02.c b/testcases/kernel/syscalls/tgkill/tgkill02.c new file mode 100644 index 0000000..a121992 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill02.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Google, Inc. + * + * tgkill() should fail with EAGAIN when RLIMIT_SIGPENDING is reached with a + * real-time signal. Test this by starting a child thread with SIGRTMIN + * blocked and a limit of 0 pending signals, then attempting to deliver + * SIGRTMIN from the parent thread. + */ + +#include +#include + +#include "tst_safe_pthread.h" +#include "tst_test.h" +#include "tgkill.h" + +static int test_running; +static pthread_cond_t test_running_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t test_running_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void *thread_func(void *arg) +{ + const struct rlimit sigpending = { + .rlim_cur = 0, + .rlim_max = 0, + }; + sigset_t sigrtmin; + int err; + pid_t *tid = arg; + + sigemptyset(&sigrtmin); + sigaddset(&sigrtmin, SIGRTMIN); + + err = pthread_sigmask(SIG_BLOCK, &sigrtmin, NULL); + if (err) + tst_brk(TBROK, "pthread_sigmask() failed: %s", + tst_strerrno(err)); + + SAFE_SETRLIMIT(RLIMIT_SIGPENDING, &sigpending); + *tid = sys_gettid(); + + TST_CHECKPOINT_WAKE(0); + + pthread_mutex_lock(&test_running_mutex); + while (test_running) + pthread_cond_wait(&test_running_cond, &test_running_mutex); + pthread_mutex_unlock(&test_running_mutex); + + return arg; +} + +static void run(void) +{ + pthread_t thread; + pid_t tid = -1; + + test_running = 1; + + SAFE_PTHREAD_CREATE(&thread, NULL, thread_func, &tid); + + TST_CHECKPOINT_WAIT(0); + + TEST(sys_tgkill(getpid(), tid, SIGRTMIN)); + if (TST_RET && TST_ERR == EAGAIN) + tst_res(TPASS, "tgkill() failed with EAGAIN as expected"); + else + tst_res(TFAIL | TTERRNO, + "tgkill() should have failed with EAGAIN"); + + test_running = 0; + pthread_cond_broadcast(&test_running_cond); + + SAFE_PTHREAD_JOIN(thread, NULL); +} + +static struct tst_test test = { + .needs_checkpoints = 1, + .test_all = run, +}; From patchwork Thu Mar 7 07:28:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 159800 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7119753jad; Wed, 6 Mar 2019 23:29:30 -0800 (PST) X-Google-Smtp-Source: APXvYqwt5roY6sg2DQLXk7Iow0a6lxvOMAR4Z+opfq7IFAIReT/22m+mSLYPuajN/I1Nx1Fub6Jt X-Received: by 2002:a17:906:c45a:: with SMTP id ck26mr6761287ejb.216.1551943770304; Wed, 06 Mar 2019 23:29:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551943770; cv=none; d=google.com; s=arc-20160816; b=c0Fzs4/6BksC/dW+CY2BG41GYZsPvztFWpP/ryggd09RzWMj8sEvdhO3FisXHD6fg9 v0hiuCGJ3jkydz2VbxD4oBj2esECCLIivZsRIklBnmDwvSpzOWrDxIoS+460xDQwJiM3 OtfBGbWJSf72Wb6U66gn/mKbFf/Y/eAEU7tafswD7kcqzaY+qfHotSNHeNkvGyA48gYM 7jSTz2R/3YAIHlf8es+qQsWXUh1plZCF2tYg8WxaTLMYvDL5FmDeFUjrmLXKHG3/4bgq LhHKe0RwnLNirEUEzB6UhGyVxvgP19fQkkfXjYiPEyLQD/iWNf10kDQDXSMUqHTFVKCq Avpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=nrNMnFSoWNtgpZZMO1wGdwHjJJVfR+MtwTale64U+kQ=; b=RdqWPri2hSdZUkDnw1zc/AqP3t7cCqnJ+3SdbE/sVOBdOISJQDVE1L8hZjo7YKZGaV lvcEKhhojxWjCk6GgGg9pd+XNU2DfsQJ2FRKgWuJn+74mz7TdfmqlsFkFf8T6lb6z82Z 36/solKXA8P4C4yg0IyM9IK2PjqhLNHDBbSa/Or86d+atlwiiwycJU4hxrz8TCDOY2+v Lb/+FfBVxXTRJjPL79dcDUhHsTzOR3U/P7KFgKXShl6j5B7x2lMTqL7VS2uE6qLeWzxH wr0ja5HNLuNBbtyp1uyq99n7BreTgO2TsytQ0imVq2PiboEeYWYDfaD2d1CfANErTzJV 1khw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FnUX8Atq; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id q2si599306edg.42.2019.03.06.23.29.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 23:29:30 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FnUX8Atq; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DF9413EA221 for ; Thu, 7 Mar 2019 08:29:29 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 6CF9D3EA25F for ; Thu, 7 Mar 2019 08:29:25 +0100 (CET) Received: from mail-yw1-xc41.google.com (mail-yw1-xc41.google.com [IPv6:2607:f8b0:4864:20::c41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id B5072200B73 for ; Thu, 7 Mar 2019 08:29:24 +0100 (CET) Received: by mail-yw1-xc41.google.com with SMTP id c67so12506512ywa.7 for ; Wed, 06 Mar 2019 23:29:24 -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; bh=SF4QrKKRJ80Xhop5dbPmFKAILWhw/6pnEBx40evMmF4=; b=FnUX8AtqE8A2xJfcgtQoYwPrcGHKnHoVqv7b9lxiQA8vzeTohIVhOzrzFRvk7ZppM1 HznG6iD6FhPUQf4+AOAzOefysTIyCfFVonB755dRFbmrurm2yA1H4cTSGHzozsk1ViZX o50PPygmx+s/zn5cL7Aqwj/tDodRhyfIlg6BTGzmsh+gU7MJwVwkhGMwf3ng3Ip5wxeH VlkXcOnGFwS3ijFNkja4P8F5EoQNKfCcTtNI5BjYxVDiQOcKww3cFYaGM5F6DIKfQsSk ltrDPHnIJs4oZ8xmANT2FMnQoGkCvHE/nGltTn4eOPyxxcj+q1EamGTEOec1uVUJB7iF vOiw== 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; bh=SF4QrKKRJ80Xhop5dbPmFKAILWhw/6pnEBx40evMmF4=; b=m76d6P7XahVQDzP66LEJoUz0K4v7ww1JpfMjQfZkCzLXJlv2XO9+nfnhAqFBibkLaa jNBovjDFpmeYICGReDeuZT7Kegdiz1D4PdkRAdWMLjaABNvyb5t+Xhv2mZmsAw/QVDoV m9+wk+UUxhwxfLYLghJX4aol93z0RBWPwZgNRWpoWWCpoOX8FNYTBCF19eSv+79wt8aA uIQSa6yPM25Soev0yCx1j6U5OKUEkdMOL+auI7AW4syZrS4lRAs1PdWE1JhccZxRtpfO oG6GnzuwDhZVWI8HiXBpdNz+7nhTelDEjB4Cy4bxd3FuPs5qtHLNEI9OpN8x9k/w6c7o gGQA== X-Gm-Message-State: APjAAAVQjGvy0fdpACM965QcNVK0yLEf1kOWECkqJgzJwsGLDbpMHgrm 6j4ztVOPNzN6RV67w6VWDL6dJObuQdk= X-Received: by 2002:a25:2396:: with SMTP id j144mr8270016ybj.58.1551943763503; Wed, 06 Mar 2019 23:29:23 -0800 (PST) Received: from localhost.localdomain ([117.252.64.200]) by smtp.gmail.com with ESMTPSA id v6sm1464108ywc.107.2019.03.06.23.29.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Mar 2019 23:29:23 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Thu, 7 Mar 2019 12:58:48 +0530 Message-Id: <1551943728-16222-4-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551943728-16222-1-git-send-email-sumit.garg@linaro.org> References: <1551943728-16222-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.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_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: daniel.thompson@linaro.org, Greg Hackmann Subject: [LTP] [PATCH 3/3] syscalls/tgkill03: add new test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" From: Greg Hackmann Test simple tgkill() error cases. Signed-off-by: Greg Hackmann Signed-off-by: Sumit Garg --- runtest/syscalls | 1 + testcases/kernel/syscalls/tgkill/.gitignore | 1 + testcases/kernel/syscalls/tgkill/tgkill03.c | 122 ++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/tgkill03.c diff --git a/runtest/syscalls b/runtest/syscalls index fef45fd..13096f3 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1397,6 +1397,7 @@ syslog12 syslog12 tgkill01 tgkill01 tgkill02 tgkill02 +tgkill03 tgkill03 time01 time01 time02 time02 diff --git a/testcases/kernel/syscalls/tgkill/.gitignore b/testcases/kernel/syscalls/tgkill/.gitignore index 42be2bb..a6d2299 100644 --- a/testcases/kernel/syscalls/tgkill/.gitignore +++ b/testcases/kernel/syscalls/tgkill/.gitignore @@ -1,2 +1,3 @@ tgkill01 tgkill02 +tgkill03 diff --git a/testcases/kernel/syscalls/tgkill/tgkill03.c b/testcases/kernel/syscalls/tgkill/tgkill03.c new file mode 100644 index 0000000..3597d1b --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill03.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Google, Inc. + * + * Test simple tgkill() error cases. + */ + +#include +#include +#include + +#include "tst_safe_pthread.h" +#include "tst_test.h" +#include "tgkill.h" + +static pthread_t child_thread; + +static pid_t parent_tgid; +static pid_t parent_tid; +static pid_t child_tid; +static pid_t defunct_tid; + +static const int invalid_pid = -1; + +static int test_running; +static pthread_cond_t test_running_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t test_running_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void *child_thread_func(void *arg) +{ + child_tid = sys_gettid(); + + TST_CHECKPOINT_WAKE(0); + + pthread_mutex_lock(&test_running_mutex); + while (test_running) + pthread_cond_wait(&test_running_cond, &test_running_mutex); + pthread_mutex_unlock(&test_running_mutex); + + return arg; +} + +static void *defunct_thread_func(void *arg) +{ + defunct_tid = sys_gettid(); + + return arg; +} + +static void setup(void) +{ + sigset_t sigusr1; + pthread_t defunct_thread; + + sigemptyset(&sigusr1); + sigaddset(&sigusr1, SIGUSR1); + pthread_sigmask(SIG_BLOCK, &sigusr1, NULL); + + parent_tgid = getpid(); + parent_tid = sys_gettid(); + + test_running = 1; + + SAFE_PTHREAD_CREATE(&child_thread, NULL, child_thread_func, NULL); + + TST_CHECKPOINT_WAIT(0); + + SAFE_PTHREAD_CREATE(&defunct_thread, NULL, defunct_thread_func, NULL); + + SAFE_PTHREAD_JOIN(defunct_thread, NULL); +} + +static void cleanup(void) +{ + test_running = 0; + pthread_cond_broadcast(&test_running_cond); + + SAFE_PTHREAD_JOIN(child_thread, NULL); +} + +static const struct testcase { + const char *desc; + const int *tgid; + const int *tid; + const int sig; + const int err; +} testcases[] = { + { "Invalid tgid", &invalid_pid, &parent_tid, SIGUSR1, EINVAL }, + { "Invalid tid", &parent_tgid, &invalid_pid, SIGUSR1, EINVAL }, + { "Invalid signal", &parent_tgid, &parent_tid, -1, EINVAL }, + { "Defunct thread ID", &parent_tgid, &defunct_tid, SIGUSR1, ESRCH }, + { "Valid tgkill call", &parent_tgid, &child_tid, SIGUSR1, 0 }, +}; + +static void run(unsigned int i) +{ + const struct testcase *tc = &testcases[i]; + + TEST(sys_tgkill(*tc->tgid, *tc->tid, tc->sig)); + if (tc->err) { + if (TST_RET < 0 && TST_ERR == tc->err) + tst_res(TPASS | TTERRNO, "%s failed as expected", + tc->desc); + else + tst_res(TFAIL | TTERRNO, + "%s should have failed with %s", tc->desc, + tst_strerrno(tc->err)); + } else { + if (TST_RET == 0) + tst_res(TPASS, "%s succeeded", tc->desc); + else + tst_res(TFAIL | TTERRNO, "%s failed", tc->desc); + } +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(testcases), + .needs_checkpoints = 1, + .setup = setup, + .cleanup = cleanup, + .test = run, +};