From patchwork Wed Mar 13 06:12:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 160195 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13941646jad; Tue, 12 Mar 2019 23:13:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxywPADh68WD11ln1AgqPlVR1pRquFORBIGf95zpRnrWOwcTzilhOUsf6IugR76B155Wvkl X-Received: by 2002:adf:fd01:: with SMTP id e1mr20914285wrr.204.1552457617194; Tue, 12 Mar 2019 23:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552457617; cv=none; d=google.com; s=arc-20160816; b=fJXEVY5KqevKFWbeIJRIzb8n1ogeBNQGRrXeVThMJeA/yEKfJtKCc7vD51Kk5fn8y0 DcoDJi11F43b7IgrfpoaP+vPNc5533hLc0b/0wg9g/Pc3784cu/C68rkt7sioM9uZuvj KP/pWh6NZqhkiUcO9NZTX8M4Xbkv3WfUtgFk/5fQTgVNHy1Rvb/V8STlsOsnPuvtoyfq U7ngsQ00vLK59FItLk8o2zDR58O2eLmelO4z+CNMuefmJTJnJQx4xSLVQo1Uv6LVTNl3 1paZZUhkvQtD9tnFEyuYtj2hl5GC2EZD4tN3SfqwGrKnK+Uwhv6DWwa+mI5bRUTWqtDB vdqg== 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=Lgii/FQ7xTe7o1gXQ24druB/Wb0zKO3eFrAXKAqDbHs=; b=k4noLhOBhejojea83u5SHAcXFW97gPVgPkYVFsyJuBnUjLaOjKKJ/Kt02iuTI2gGJg EB4auIJwAvLJ6BJ0aKeMfQlQCVvksE8dWHpLIziD6gCEW/2z5fn1fJljrDmCgeO8IFJ8 oR57QFV84/d4sv0p3aszFozGtr60qFeBipRsAfCjStt1KNCS9teOEFK5/GmvwGsu0tYm D1IjyRtXGNRoKJH+fpfcgU4K0/EZXI+MKG8stoV7nPK/xBA14jzvjfslIVPNU1ocHckT LZ0SV/IX3Z8aNvd09bha4xzZcvk2wBJy86xYlVat4Q+lgJQPt4ct2Uk8OY0dqrTpzJIm nKJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Sia/XLuu"; 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 n3si522661wma.47.2019.03.12.23.13.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:13:37 -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="Sia/XLuu"; 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 AA8AE3EA37A for ; Wed, 13 Mar 2019 07:13:36 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id D6BBB3EA2E6 for ; Wed, 13 Mar 2019 07:13:30 +0100 (CET) Received: from mail-yw1-xc43.google.com (mail-yw1-xc43.google.com [IPv6:2607:f8b0:4864:20::c43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id BFF8D60198D for ; Wed, 13 Mar 2019 07:13:29 +0100 (CET) Received: by mail-yw1-xc43.google.com with SMTP id z191so511454ywa.6 for ; Tue, 12 Mar 2019 23:13:29 -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=L+KttGWwXvacbXBzobreH+y35jT7oHgukKowAan/NOk=; b=Sia/XLuuWlNF1g5l7uHwEQQlrXRUT1Ra2EbtMQQBb48w0Ro7N8mA5YsZ/5nc6ndkiq P9RMbHela2zYddiLEVBrr9OeoIMzipB0/FE2XQBhVxmD0zRJLrndliN70PZWPLdGzM9o rGDxCsoilaSg1icd2eToXYef0FJHpmNqCAAvA6OR18Rikj9BDC2FSNy1FX/kj4D0y7Cy 0ci1YfcO3784q6r9HwpN+PQT/5DlYwZ2ewEEgFZOPURXgVA1Nj/+D0KUe85ucbu8GaWT UcGFCg1FZNgNXP5m4pHCZMSq7HlvBaL3xeRhT/Xq+qITVw2HrKEMV2tAkUdFcB4Dcu3n /baA== 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+KttGWwXvacbXBzobreH+y35jT7oHgukKowAan/NOk=; b=sJCodemisfh2fEqI8lE1hxE4rF4v/CjJWsjZAe9yqrTVasEXkE05kuK7ejUFY8Lo3i pymtBsBddg+FuJ5iUZkHcXUkBY7MvUA3otD8DVP1axH/PdlW6eIxkrouRHCEIRXbGu8V X7sUstyRVLSmdoe1uzDziF+3TaFn3QZQ0cofUBx6bJx282MNoAJ5j/SuGf+OV+b/WDl5 6nXc2Dz8kMrmU1S4QKDc26OdDgbOgGwjeaJVAgV/ejAPPz1jUxl0A6QAzouKklzQpFhn wrxRtzK6HL/RarKgbY5/81ux2Kj/o0W1y31RNMyZgNjxq4V05I68vKdLFWVPg7b+ylBy 534g== X-Gm-Message-State: APjAAAUVla/XspkVBZhLZeA4ZlOqsqfk4W07I2d2rRgIGTFFQJrsoP6M qejeBLGLNZcFxaphOzoUl0FB+EFRhTU= X-Received: by 2002:a25:3507:: with SMTP id c7mr35247986yba.390.1552457608424; Tue, 12 Mar 2019 23:13:28 -0700 (PDT) Received: from localhost.localdomain ([117.196.233.204]) by smtp.gmail.com with ESMTPSA id b132sm4319949ywh.79.2019.03.12.23.13.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:13:27 -0700 (PDT) From: Sumit Garg To: ltp@lists.linux.it Date: Wed, 13 Mar 2019 11:42:51 +0530 Message-Id: <1552457573-1354-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552457573-1354-1-git-send-email-sumit.garg@linaro.org> References: <1552457573-1354-1-git-send-email-sumit.garg@linaro.org> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.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-2.smtp.seeweb.it Cc: daniel.thompson@linaro.org, Greg Hackmann Subject: [LTP] [PATCH v2 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 | 141 ++++++++++++++++++++++++++++ 5 files changed, 176 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 d752dba..8cd99e0 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1399,6 +1399,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..acc9977 --- /dev/null +++ b/testcases/kernel/syscalls/tgkill/tgkill01.c @@ -0,0 +1,141 @@ +// 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 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; + } + + if (threads) + free(threads); +} + +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; + } + } + + 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 Wed Mar 13 06:12:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 160196 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13941708jad; Tue, 12 Mar 2019 23:13:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqydIYaieN8e3kLS9pGXrDJv0iXb5vy7TbCuHVNbdiY8Nqyi1VZd/Ua7NNUBZeoxgE0MlnA+ X-Received: by 2002:a05:6000:1152:: with SMTP id d18mr27581784wrx.128.1552457622199; Tue, 12 Mar 2019 23:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552457622; cv=none; d=google.com; s=arc-20160816; b=QSt2xqrQf7NYkALfxM80LSDvI6vhZa69C/+d0pSBUBKNfr/4bNIP15qIkUlWUrAjk2 qg5cOil7yfjVl1zym/AJMtnUxQVZu19lhVLyaJPKipHFzidvqnUyPJxU4ruKwjGfAAqO i9/ZXPDGdK9WYCT3PDtgVlw89k4lQBTr/3q/XsEmJLzNa+xQyvVhgoOYaJwMrUEzK9s7 kQtszPLaq0jhDHIDmR2SQ0xrZjm9V8Dp+DaBV1YPogIuJXJBxqNkqok74bnkORwg73hL 1Gm5Di5D852w3/TxMeHEmk8LoSbB5gvGP2OWwV+f2pBVCr3BIABVoD4WxAT4IExE8qUB nmxQ== 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=WcvpMldUlnDYnc3tCMYqwj1qv3PE4fiwKT7ZlCG1x48=; b=q/fEfQ48wgBgS4NTLfQuK4RjueIWs7aYtPU7TG/tsbsf8CEArwSUxHpRE0mZe4La7K em8HJbVsrmMr7HqWgAQLEEFbSxZmw8DpeT7/IWGLd7b/jxZoecTrI8cm6wwdtRXWwHon O9aeabwJ5E1qLM7BHR2WSQ4HYEKObRkCHcKm0CvkWwxsUDsEMaLqR2i896tdaPVHw+r3 ImxJcOe2UigZT4MxygfxXzU1Ka1/PY+GmkOn/HKg0SQg2YKTfTiuQ/PNBalt6AkRKMTu GOj0/1ByNRAysab5SoQXAs7nJ0kyv5+8GuY4CYecNwkWBkmVK5UQE+Fci1JxQdwa9fMs nnhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Vfhd2I6H; 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 c14si4709674wrb.419.2019.03.12.23.13.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:13:42 -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=Vfhd2I6H; 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 BF4B73EA1DB for ; Wed, 13 Mar 2019 07:13:41 +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 971D53EA36B for ; Wed, 13 Mar 2019 07:13:35 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id 6D9F110009EB for ; Wed, 13 Mar 2019 07:13:33 +0100 (CET) Received: by mail-yw1-xc44.google.com with SMTP id a199so533824ywa.0 for ; Tue, 12 Mar 2019 23:13:34 -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=ddyIY6o8SBT9qJTB5ZNozQYxllA3k1P1II6hY1NI2QM=; b=Vfhd2I6HRSMun3o1T+fF7wQp9gPlnwbFrPLx8aEOKosYddJFQYjmE7JZH9goWxIOV/ 2lWW1YH4UTfadhPBqLQ/Au9fzVIFmQEz404mimpyp5H8x0kJB982LVfpKJ4O0QZlQ+TU YJwaM+1y2xtboVPe9q32Xdh2twpEVnzuAY9fa5fkS9qHtWAktF+6/PK/6FbZ9R3QLc5J BnicF+HW/PftwdnAMLX+P2yRj3aq596RgkqkodX406zzbs+TI3hlNjzxOo12NkkJ/Ogd uhTGXZF2k8RgL+RXSZ43ElYbq9eq83PObZXazyeTeFL29TIYNP+mNPbim8Bh6Yyh1GrG PH5A== 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=ddyIY6o8SBT9qJTB5ZNozQYxllA3k1P1II6hY1NI2QM=; b=q9negLs+0cOWdwtZpmGNdXWStsc0fuZlwT504K9Lbh5gkf7tAuubKrAxL3ziRtebrF jmWpw4wAtTrJas7/NYLWwul8DCBTojA70fecRDuzkrDJUkL0hKPZaHy2jRW0LLO2y5R+ pS4Iapn9JhunziUHFF1Dts94OblQ0qlw6FKC7tvsnXGF2BibFtF+t6Ukmjpsii5lsSg5 LdimzoBGl2/73fWxXQPdBalULR4td79qucO5QhmGlbo2URBvyrn7aSpxnKFf+W7Snerl K6poUm1kZTxLAVZQNAW2MIKChyEdPZdDnK5JnsYtBJY0v5caGRmpv0l8hXXT4HnUKIRN H5yw== X-Gm-Message-State: APjAAAVer1BXwJRof8VIx+8EkA75pt+Gi4K6fVWvlCCx9NtoTxH6nkZy JqoZbuND6lP1LZ8LV/bU9gj7NKx4neI= X-Received: by 2002:a81:288f:: with SMTP id o137mr12282258ywo.464.1552457613651; Tue, 12 Mar 2019 23:13:33 -0700 (PDT) Received: from localhost.localdomain ([117.196.233.204]) by smtp.gmail.com with ESMTPSA id b132sm4319949ywh.79.2019.03.12.23.13.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:13:33 -0700 (PDT) From: Sumit Garg To: ltp@lists.linux.it Date: Wed, 13 Mar 2019 11:42:52 +0530 Message-Id: <1552457573-1354-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552457573-1354-1-git-send-email-sumit.garg@linaro.org> References: <1552457573-1354-1-git-send-email-sumit.garg@linaro.org> 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_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: daniel.thompson@linaro.org, Greg Hackmann Subject: [LTP] [PATCH v2 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 | 80 +++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/tgkill02.c diff --git a/runtest/syscalls b/runtest/syscalls index 8cd99e0..1f4a2da 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1400,6 +1400,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 Wed Mar 13 06:12:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 160197 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13941786jad; Tue, 12 Mar 2019 23:13:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYLCqwtRquAXd8PRcml4uNA3G+2yoFlMhtjmA3F4BgfZwRUZLLvA0nYBByY/7L3OFzFI8u X-Received: by 2002:adf:f149:: with SMTP id y9mr25231227wro.282.1552457627990; Tue, 12 Mar 2019 23:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552457627; cv=none; d=google.com; s=arc-20160816; b=GsPs0IsoSzCuaByldmGFyMoqvjww7KXAsyuGUVI5p7Z3BlXMhYMYTB5a0bIpugJrDx wHwXA3HNYWEftpdCbysumFaDd2WQ8purAMFfa/1MmWHIdKAObbve9VV6Q/vhXY41g3Je btEYszugaXQhEcPo6e/70KhzbQNcTC6AnJhDrQHYjtYZ9Gdg38M8X0LXWRcX7I+94AXM GCLsW0pR1VJUW8w4cUXQQshsCiP26X6Ik7VAfX2Kc132PiHaq2X17BI0nQtT5E4BoK7O J3YZSoRyVI6ePMrWo68fp3r8f/4TjOwFTEiTxX47BiaOOLkNix7/FaM6Pu9tPeOf4vk+ I3CQ== 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=pNQXHzId4OMHRv+Xps24KSk0/4jsGo2OwK/vXrsfnSg=; b=g6p1l8PBGUjz9nM3+KqQzDpeS5podOSMnXwt3+Xc0MJw5fPVLvES6eE66xy3zOw1jF r7GMl4f1V3Ge5e05GKT2v4PH2uNySOrfir+wL9MZ4K3A8bbvKmfGmUmTLaKiUaUObGm4 sJr49DYJ9gRVKDLfN6w7LACZM6gFmbrdzylEB8wOzx447GD4G2UwhSMwWbQ688xLp4io aHLonraABsacKE4ciAjcOZrIx3/kN7BRuWsg/jqBDqVndL5obk+/fJ6+BwOALT46s518 oA/3RO9fztvlHB2T/3s1n0ZhEu68IJqLjTDguzzChccoAzG6YQ31AxMPq+S/V2Oa4LJx ZBHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=j0qYNG5p; 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 n11si6584969wrp.151.2019.03.12.23.13.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:13:47 -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=j0qYNG5p; 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 828B23EA452 for ; Wed, 13 Mar 2019 07:13:47 +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 D12DC3EA37D for ; Wed, 13 Mar 2019 07:13:40 +0100 (CET) Received: from mail-yw1-xc42.google.com (mail-yw1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) (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 16FEA1400E05 for ; Wed, 13 Mar 2019 07:13:40 +0100 (CET) Received: by mail-yw1-xc42.google.com with SMTP id 189so524038ywi.3 for ; Tue, 12 Mar 2019 23:13:40 -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=kQWap+WkUDTEK03wgdD1UaUPh7EgDyiYegPY+sAW2Ss=; b=j0qYNG5p5ZNPr3S6xpWpDiaExGtRQPTmp8Cgq1HmKFPgFYM9s3eCA815pW0KtLEJgj fkO0FA1/UT4CoLSxDEFC5vgXkdC4fQ4ed0TvHisIi1ndtssdpIWTSqtlf/QAtKsZHjLW KxavGduAU3bNi8RsqjNmk/Qe1u4Zu+9fgst1cCu6JBlUunxhkSffgv0Capfc/6/4UZKW 8Yc97ApEmPY2cnzqcUiQSkDlSsR+LfZV1R0GGAOjjnIiCwA/oX7h1lgDiqy0V1+6Eas4 0voASkxIHl/qWz5TnSfMGGrtVxjuQ1uJJ08BAnHRD6r6bnIxv5oKPtPpn3PDHtS7etel qM3A== 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=kQWap+WkUDTEK03wgdD1UaUPh7EgDyiYegPY+sAW2Ss=; b=c13nDSkNOjm+mDo0eslRyaZwwcNBYMOqUAADafSdeA6O24kf6GDTXGoByWnRlNbMfu EIrqZLtSswvvHApRBc45uXPzdE9WILtuoiKy63wxqLozEUad1MUt21K4Xem7xzcClJPN am3gJw11zVOqODGoXLBDQ/d3YE2bRX5mKAbZFQmMNQYUcrUS0DmW3X24Ro6RVeePKCGl XG5ej6Pg5V2nQlEmmHLGWWy2sm1dv/pOMY4eXxTtx6J1fNWCV8MIyoRno9/drrlZ+D7Q alajuxj0P+k8WmsVXAAY/USj3ChY9xbHSe4KFE9FEZ9g/dxHHdxK0eHcbl5TIEw9sexa xP3Q== X-Gm-Message-State: APjAAAWa91PtrxgAG/ngY1AXh9TVElVJs5jmx468viN5n+FW0HOAs9XB g2o/s4ansQnUPSyWqyGeywlDmiVAvl0= X-Received: by 2002:a25:d656:: with SMTP id n83mr33464949ybg.423.1552457618832; Tue, 12 Mar 2019 23:13:38 -0700 (PDT) Received: from localhost.localdomain ([117.196.233.204]) by smtp.gmail.com with ESMTPSA id b132sm4319949ywh.79.2019.03.12.23.13.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:13:38 -0700 (PDT) From: Sumit Garg To: ltp@lists.linux.it Date: Wed, 13 Mar 2019 11:42:53 +0530 Message-Id: <1552457573-1354-4-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1552457573-1354-1-git-send-email-sumit.garg@linaro.org> References: <1552457573-1354-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 v2 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 | 122 ++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 testcases/kernel/syscalls/tgkill/tgkill03.c diff --git a/runtest/syscalls b/runtest/syscalls index 1f4a2da..b92244d 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1401,6 +1401,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, +};