From patchwork Tue Mar 19 06:49:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 160527 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3526453jad; Mon, 18 Mar 2019 23:50:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDk7aVCdtHYFcgkBu28361bZvoFbT6I1r+KZae92xujvxSDeIuXrvCOxNou+S+j1x8HJ8u X-Received: by 2002:a1c:7ec2:: with SMTP id z185mr2196474wmc.69.1552978221221; Mon, 18 Mar 2019 23:50:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552978221; cv=none; d=google.com; s=arc-20160816; b=rFZpEMm6kpYv3drqjGEFxRVO5q1hzmKSdJnabK8FxxiaTEAQ3RasUGdQhhD3+sZraR qn0XPBK2HA5fxUGMXl8P0sK6kQzRFpn32Hvsn0btzqBf+dg0Apb1YBm100npc7tznsCq CWrfnq+PgD+XiAFZVDLRasSf2AEkbdDl3S37YcSkU6bTdGgYCwhY2EzJmK225cPcz38O /wQCO7acLL0raYxzfgxnNXDVKqOQ6K28bIX38cjLu7hF+/AJ/oUKU3ZKKP8Roh0V6NoX v8uVjSYSRP9S1melqJynPioanVeQ4+HoxTXksfelbyH6qC+FZuW6ZSY6ZfltBAS0FeMa VwkA== 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=mM0KU7s9R8k7pGWZJsOWy7x7vgdZSs+PWT2MkvgWBWc=; b=zeIeNug2EQdvOJlesYYvr3uaTNRFd/wn21SLUn3R2TfuwNbHtSjGeQHRc3yScetmbZ +AvAg355Sdfafv0HGOcdYArlXMnluusTYR/h8gbImE0N1tPN3NngwmLzqOMsvxXuGDZQ LiMvyYI2sATpEUSsTuPDscM1HCCM7c3B1cIiRT3iEVG95RZRixljbCFal3G8E/1gIvtD 5nPoAKaSieLHdk/WjooVPYEJ0D/jbevldDaxQ1QrEXHQbYZ7p4AwKbrSBLE0xtSnc/md yxUsyjm5e4cciJYJO2GDwmvqRlXS5wr0h7nDegAPHfWbjYvt4GbKMG0Eeb5eJTinSGhj 1NJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=c37C9MfS; 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 l11si7014657wrm.128.2019.03.18.23.50.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 23:50:21 -0700 (PDT) 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=c37C9MfS; 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 BF09F294AC5 for ; Tue, 19 Mar 2019 07:50:20 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id D18B63EAEC9 for ; Tue, 19 Mar 2019 07:50:12 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id BA1AC1A011EF for ; Tue, 19 Mar 2019 07:50:11 +0100 (CET) Received: by mail-pf1-x444.google.com with SMTP id i19so13056894pfd.0 for ; Mon, 18 Mar 2019 23:50:11 -0700 (PDT) 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=ADXPiECN0VcMyJNrjSmgk+tpFqj9cqIRecTA9SBHmzE=; b=c37C9MfSSN7F2e3wy/Otaew1L+DZj4WXfhQ3jDRKwYy5d/Ib3V7uTTIrA9ffcxIdNP Eu9xRgZKpH0CBLrpQUzpe2eEyt9ID0Ba1Gbqq139PK+IVfN7Kv5HPauqWaVh7SEAqqLl jtpyWfdtb8eUDLfcMyHGhEllsd+ApzAKzG993SDJPG1pxQEou4kZ+xy9+Mjeoz1G2Y8N guFhxrbB5TEQ0s5jHK5QbTvvxneGXH+rj55X481IiGxXnm/vPmNnfyN3WC9O4HCRrdy7 AfTihjalcb0WxnVxJxt2GvyobnT7ZiCFlOUfA3uuKfkybG/qw9xB8FEK15boJoOfbVFW 7NIw== 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=ADXPiECN0VcMyJNrjSmgk+tpFqj9cqIRecTA9SBHmzE=; b=E7uvjN/NsGgYR9Hd5SqKTLX+lhLTBpLmorF/y/0xbdFM2wW+VH2QuPYAjJnp9o8x1x lZsNGc6xbfFLe4JbpdmI0VzL2YT6tLTxM9hSOhVDnh3pOK/zJcs/lY4Gc+yiFgCU8cAS 8U7QX5KDZ6y3d07mWvrFJK6eyJVGbEYeFvPpzLfV9OXzybuDKFOoFwAGPpQ1u8d4aU5F 03fRDVSKf+OWwKwgwKzne9QrfNCdOg28N+zA0+RB/qgVDoKCbES9lA1ouBiMtJaEjOB3 /KFnmSX1bwvpg6U7BSj5aAEg8PALIpg3Q9iowu3zgc+rvYnvoSXVtjS6CTWApZBrkoZo VAHw== X-Gm-Message-State: APjAAAVc5lMIeATnXo75/Y15YzrdTb78jhlI4Q8K0guaD6GrXy5OIrwN TUP2CJ+Cvb7lvPDKJI560t4pspYobyKfUg== X-Received: by 2002:aa7:83ca:: with SMTP id j10mr23199911pfn.50.1552978210090; Mon, 18 Mar 2019 23:50:10 -0700 (PDT) Received: from localhost.localdomain ([117.196.233.204]) by smtp.gmail.com with ESMTPSA id 16sm12452852pfz.106.2019.03.18.23.50.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Mar 2019 23:50:09 -0700 (PDT) From: Sumit Garg To: ltp@lists.linux.it, chrubis@suse.cz Date: Tue, 19 Mar 2019 12:19:39 +0530 Message-Id: <1552978181-27748-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552978181-27748-1-git-send-email-sumit.garg@linaro.org> References: <1552978181-27748-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-3.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-3.smtp.seeweb.it Cc: daniel.thompson@linaro.org, Greg Hackmann Subject: [LTP] [PATCH v3 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 --- 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 | 134 ++++++++++++++++++++++++++++ 5 files changed, 169 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 03b613c..d6999f0 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1400,6 +1400,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..075bf48 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill01.c @@ -0,0 +1,134 @@ +// 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 + +#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 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); + + TST_CHECKPOINT_WAIT(1); + + 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; + + TST_CHECKPOINT_WAKE2(1, n_threads); + + for (i = 0; i < n_threads; i++) { + if (threads[i].tid == -1) + continue; + + SAFE_PTHREAD_JOIN(threads[i].thread, NULL); + threads[i].tid = -1; + } + + if (threads) + free(threads); +} + +static void run(void) +{ + int 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; + } + } + + tst_res(TPASS, "SIGUSR1 delivered to correct threads"); +} + +static void setup(void) +{ + int i; + + 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); + + for (i = 0; i < n_threads; i++) + threads[i].tid = -1; + + for (i = 0; i < n_threads; i++) + start_thread(&threads[i]); +} + +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 Tue Mar 19 06:49:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 160528 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3526506jad; Mon, 18 Mar 2019 23:50:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqztmDc8A33Qyiey+nD4wf8jA8hinp922K91VI7VcvoPkpkJ+LIaPPi/EaB9bcVYq71MP+5D X-Received: by 2002:adf:e50d:: with SMTP id j13mr5234731wrm.165.1552978226927; Mon, 18 Mar 2019 23:50:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552978226; cv=none; d=google.com; s=arc-20160816; b=dVpAoZSv5L7aRgW6OeAsMmhuNS/fPGscKLrlcMPTWQT2d1uA6J6c4cU7f/Yk9Prc0B /QchETG1PXIH6ovsSszzUQs4h8u7w7AjeFzkzE7w4AmTWmgPcYC7I8rT7qon+IbhNaRZ YnT/2gi/mTLGAD1Pm6aL7tBWfWbaaGxjVF1JxY9PWgd8ZbKGC9rWn39+i0K7xKHckitB 24DouPnjQrBRPL8+xqYRFZmuuyo5jpMtvtIXfyaIv3FaJfInlZ1FQZ0qS24r2JrjGbwM 87oogA1BIG6VRCAFuBTp9/s9PoS82vyBdsf623t62FUFj3GTF9LLtcKUvP3VirJlAxCu I0qQ== 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=+HtKaSYKl6EeaDSWsW06j81LUp7crUYv1F+wDI1rWPk=; b=eNMdKS4bIe50tjPcF1i2mrw/P1Ds5LWRh2sIYFJCG17xOHpXU8Q3tqTvztcL+vhPSL prq3tYHjHEaaB70Wq5QsnMzkIxMPaq1DzOAD9Lv7RV2YcnNd8nl4zx38JTA2Z3NiOvbE S/kTrSVoK6IhGa7CO4pZxltTetO5N8EBNkeIYGL4vSfKnlaE7hJtl+6tWn1XZfXaLmMV JixJBOvyI4ZlhXm7IMLu9nhFmoBZEy8hQGUjNq0f6qoQhgwy63HnwyWvDAwfaTftdW91 CzsQlASaP1/fY7p8Y9vgsTm/2Ld4i7D3SHomva9hXiOmirXX456RaKuIYzsCa6teE/Nk QfKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aXXoJA6F; 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 y14si7851869wro.331.2019.03.18.23.50.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 23:50:26 -0700 (PDT) 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=aXXoJA6F; 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 6E684294AD2 for ; Tue, 19 Mar 2019 07:50:26 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 1BB5A3EAEC7 for ; Tue, 19 Mar 2019 07:50:16 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 073C620E756 for ; Tue, 19 Mar 2019 07:50:16 +0100 (CET) Received: by mail-pf1-x444.google.com with SMTP id v21so13026039pfm.12 for ; Mon, 18 Mar 2019 23:50:15 -0700 (PDT) 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=OiBK8Wt1vg2VhPn24Nuj9SzmSRrI+ADUEWGHxxtIbXk=; b=aXXoJA6FijHLUA47GY3aKWiQflbNf8pyh5Q1gBTkqjWz6HPRBSuNbl2wmCc+zQ9vJs 6I9hau5Tq7bQ7YownaHtiIP8bhL2jq0sNrS8VocRK+0Qy4vzxRjTdZGqvS7mgQLTAj4+ KOQ1+NihBKGNAuaT5uqPtSdPvJgTa7oM5akOj/87zl0n0WRwNSADs/Ix8i5IrX7A1B0N 3n1B2QC/YBairwYX+d6cC+mBUs0gY6/8o0lt1NezynSEWFfLaZV5+4+JhynMM0BLS+Gu PJdN+XsGBCros5T31eMUJzrZyX4hFgTQpTFL/iLDnP4nR6M2AnW4BUuvAMgY6WjiZvGr DSjQ== 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=OiBK8Wt1vg2VhPn24Nuj9SzmSRrI+ADUEWGHxxtIbXk=; b=KgibTY+dCfwMBZV1YAB7coO53NFzNxWBiSskmTRJlyfKb6OiOaAoF5PL29q3w9jyXX 00wduEvyHTwVYc3lhi5DPAHPCgWRUsu4V/Dwug4g528mhSALy8E6iNi+RNSgGki7TtvM gRjYUhXo5hqQIk2/GzcIIJo+8inXrMWdSGr1tka66hVovh8ArjQ20pnPBsLEhVaoHK/P t6zhwRHvuSHMAtfjlqecjF4poTjjikE26KnLUwn7N/Di4HOA3PgPGq7zcTcKPmRVG92f CDNPRd9Aq+L8IVw8rNV482M7Be+BuvBH2Zv3RZWDyQMwsoWbreQ6IpJKrhZgtQvQSdIa 9z9w== X-Gm-Message-State: APjAAAUIP8qElRHRInEcno1dwIU373ohIC7cYInAn2UQRuUTusGIsqWd 4SbFe8KDlE9WOagsq5WhSZRAIUb7IjrAHg== X-Received: by 2002:aa7:8c8c:: with SMTP id p12mr628002pfd.0.1552978214375; Mon, 18 Mar 2019 23:50:14 -0700 (PDT) Received: from localhost.localdomain ([117.196.233.204]) by smtp.gmail.com with ESMTPSA id 16sm12452852pfz.106.2019.03.18.23.50.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Mar 2019 23:50:13 -0700 (PDT) From: Sumit Garg To: ltp@lists.linux.it, chrubis@suse.cz Date: Tue, 19 Mar 2019 12:19:40 +0530 Message-Id: <1552978181-27748-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552978181-27748-1-git-send-email-sumit.garg@linaro.org> References: <1552978181-27748-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 v3 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 Reviewed-by: Li Wang --- runtest/syscalls | 1 + testcases/kernel/syscalls/tgkill/.gitignore | 1 + testcases/kernel/syscalls/tgkill/tgkill02.c | 68 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/tgkill02.c diff --git a/runtest/syscalls b/runtest/syscalls index d6999f0..7af9136 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1401,6 +1401,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..88f3842 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill02.c @@ -0,0 +1,68 @@ +// 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 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_AND_WAIT(0); + + return arg; +} + +static void run(void) +{ + pthread_t thread; + pid_t tid = -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"); + + TST_CHECKPOINT_WAKE(0); + + SAFE_PTHREAD_JOIN(thread, NULL); +} + +static struct tst_test test = { + .needs_checkpoints = 1, + .test_all = run, +}; From patchwork Tue Mar 19 06:49:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 160529 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3526543jad; Mon, 18 Mar 2019 23:50:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYOhm3cXRXI6LVtgpo+PaMu2VXI+acPn6jDVyarJ91Ve3UPuQ6MGhmGnroS/fWf//3pgZf X-Received: by 2002:a1c:7706:: with SMTP id t6mr2071892wmi.141.1552978231815; Mon, 18 Mar 2019 23:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552978231; cv=none; d=google.com; s=arc-20160816; b=k0Zh8OOX114XXnE5Gt5pkrJNH/eC494BrJc1Xa8x42K2UsjOJwsR8eyT8kGPq8eyNE DHrsmzCHZpJMRoSRsszftALF2xhcwLLzS3pX/TZtt4RXaBTUVpFXJrDsjdBPjhFYmDwN DZLW1bFzb8n9xpPFKVeHaYZy/nxEnBoqKdHOGdEQvjyeFjpci0dwt9zHk1E38qNE4HT+ g7qAmRXbYVGeY/5eQ8O7cUNqIo9sDX160IungZ6Zv2gJ/oDTuYtCJgsxB9wtJdBxy5C5 13hoVgGuVGwfet9OYrmkGG1W+T19M3eTEVNgjFqldKOBfHnpunWYm63JRn9CWfNXfaXT 6WSw== 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=4rmNJdLKj5SvPUGtPyOvHXqikyzjk5VigNu9+5M/ZX8=; b=ZrPaTHgfK3UP/tORS87u9lHL00aarjikKpGdnu2jt6zlXmjhaw0NK4wycopRUsfIJH RKGyGy76uT2tZc+VRQlBnrDVlqAKYNbJcY57Zcj6VK46DxwzGDAuRPIj7padGDhjd7DU mBRhnXQV3BGGuVrhPt0DGNeFylHoGCAira0fA+qg00CBbRSFZohDsDij2NVcWVvbB2cu F2WXV9PVTQEVJOdOZam10804h9UPH1AZkM0GpqE9veW6yOX173xJqVDE6NNiHzBAQO47 YLaLg9aWj6sSsOyhGUIL/pAJxhTl4LE9T0u/huak4596w90TkzLaSJpLhA0vrNpPS8o0 8dZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=kSMgANG7; 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 l26si956234wmg.119.2019.03.18.23.50.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 23:50:31 -0700 (PDT) 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=kSMgANG7; 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 5E9F9294ABC for ; Tue, 19 Mar 2019 07:50:31 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 0FD2B294ABC for ; Tue, 19 Mar 2019 07:50:21 +0100 (CET) Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 4730C200219 for ; Tue, 19 Mar 2019 07:50:20 +0100 (CET) Received: by mail-pg1-x543.google.com with SMTP id h8so13202899pgp.6 for ; Mon, 18 Mar 2019 23:50:20 -0700 (PDT) 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=iKoyRWWX0pco8tQjuB1iQ/NXurqD9h8MHwIWbQydnzU=; b=kSMgANG7fbZhGvBJLD8dX2tg8hozR6Yh1mN/FJTj8IHeXzNgRe4AvpE2n14HwxhU6q vP51R+tDGzW8KPwi5jre4aLuWqdkhSgAvqesgEazPU0uOlK1kHyta4/hr5CePjgyJDVd /uznlvM/Gd3HhqO3P/dgR14xi7s6EQ9dNaXMah3Ad5JFayWsXuOPZD6nEMh1pXWT5Mfr Cs7+3ie7OtZTA/SPQaW/6xa+Wi3VSrJ8fBZxgKOXc5qyNAB3q9jASJ2YN1Y5S1Iqgke0 cEofBm8XTIsAvLcsq99xaq/MgpTpQuCYEN11OQIdmDlZz7eh4OAz1d5nJM3njB3rmPO5 fuUg== 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=iKoyRWWX0pco8tQjuB1iQ/NXurqD9h8MHwIWbQydnzU=; b=jYhddR7qkL4wIRbo+HCTYEXoGEU8acTvxRbO1Lv0wy/+JO5bJ8bKq3oO4GgO15/ep0 63MUXZT4T5wWxZQ1gDDMlh2NGFwwmmThA3n6lNAX3VeJyg64vswhuvaAlNXxMmPynC5U IVnvNFImjK3YVtyo1beS/5TBtk/TNs/Q8nsKuh2FV1qh/farzFAZe3Hxe49vj6cEFwGo u/EtxgZ2gK4DeE3197is9QiP3x5Nk+5r33glteQWyil3OragXORT25ES7imsLeJubW34 KpTd4GpbWXoyEx3JSO6UNnnNNewSiRHOMqNNTL0rb7OpL5C9pe6HFg6WYZuuC7jE6ZQa dTPg== X-Gm-Message-State: APjAAAUJGG/6TVTy6VgBTuTIfhbUwJovuEsU0JI3nLKbAq2VwVVLXn7u Vh5kjjQaLNvF7UdSBzcq/bKVhwdBbVAfsA== X-Received: by 2002:a63:5652:: with SMTP id g18mr2052336pgm.290.1552978218647; Mon, 18 Mar 2019 23:50:18 -0700 (PDT) Received: from localhost.localdomain ([117.196.233.204]) by smtp.gmail.com with ESMTPSA id 16sm12452852pfz.106.2019.03.18.23.50.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Mar 2019 23:50:18 -0700 (PDT) From: Sumit Garg To: ltp@lists.linux.it, chrubis@suse.cz Date: Tue, 19 Mar 2019 12:19:41 +0530 Message-Id: <1552978181-27748-4-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552978181-27748-1-git-send-email-sumit.garg@linaro.org> References: <1552978181-27748-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 v3 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 Reviewed-by: Li Wang --- runtest/syscalls | 1 + testcases/kernel/syscalls/tgkill/.gitignore | 1 + testcases/kernel/syscalls/tgkill/tgkill03.c | 110 ++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/tgkill03.c diff --git a/runtest/syscalls b/runtest/syscalls index 7af9136..b090408 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1402,6 +1402,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..b78e9d9 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill03.c @@ -0,0 +1,110 @@ +// 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 void *child_thread_func(void *arg) +{ + child_tid = sys_gettid(); + + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + 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(); + + 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) +{ + TST_CHECKPOINT_WAKE(0); + + 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, +};