From patchwork Wed Mar 6 10:45:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 159739 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp6012106jad; Wed, 6 Mar 2019 02:46:16 -0800 (PST) X-Google-Smtp-Source: APXvYqxTHKeawY8COCa/Zl1Bv1KC6lXXynmraFZebi3q5Y7v3xxKY0JJEZp2Sz1jePbVRka+C95p X-Received: by 2002:adf:dd4f:: with SMTP id u15mr2410101wrm.61.1551869176162; Wed, 06 Mar 2019 02:46:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551869176; cv=none; d=google.com; s=arc-20160816; b=iYoLR1pkpoD7Z0yGFHcjxpJnWniaTqLETp2cJ75kIBu/pARV3T8XuYljRmaQ0f7joa eCSum3yc0b+nUSU8C18YbLVrwfk4GiYZbj2RqT6gDyR7AbvckPtLoOFGtVCnmDFcSyGU skFaQL/Da/0rUe2qdFNc1d/TTrF5aswv1df6lfahvcV3cs9auDDgtAZjCOKQ7BUeAwUZ gRY4uikgKg2VcX8xAkGZ8Niktyigg71g0uOx+aLd6PG25YE146qYlEMKkIuQ5EPNKnFG GTnDbZKaL3kCt9VRx/2gtX1TrADQozUUf96BjTaU2ho0g4ruavzOnIpUEi958EmClFpg 1yvQ== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=h3VYQ0sn+b05Rt+WA648ahd0ydg87Mqg7UgdAUwpfaw=; b=A1Ah8asmYC0QgEEzdOFoFYtUgoKRE1JfqTuVR7K7IECYLCWb8H+S2QeYmiSC3ldwxQ XCGPUxkPihBvVWHlzBzvQarSOdPc5uljrv9mXK0H4+Oax+thiwaWTTvuajuizNUZeRmg fI1ZDFjCe4MxTqHT9njgAFUeDVIWeZmp1rGviCBPKT0YcM96ZQOZkl26OC4cwCATO5ZN rhMGQdmvU8YZktOoD9ge3b0cmAPLdygoUdS57+RiI35s3CZNnFNE4ULALz/J9apKtg0i 5GOaVjqNsb7IVE74BeJvJjBlAGby/i+h2J+NsFsYtsg+lmi/2bWWDuLfQDxPS5Twf2Oo lv+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JEdEtmbo; 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 l13si802831wrp.193.2019.03.06.02.46.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 02:46:16 -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=JEdEtmbo; 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 A1C133EADB8 for ; Wed, 6 Mar 2019 11:46:15 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 571723EA925 for ; Wed, 6 Mar 2019 11:46:12 +0100 (CET) Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 34BEF60125A for ; Wed, 6 Mar 2019 11:46:12 +0100 (CET) Received: by mail-pg1-x542.google.com with SMTP id u9so8093438pgo.7 for ; Wed, 06 Mar 2019 02:46:10 -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; bh=mFG8sQS+ZMuLTuhdWXM6006eexSeE8v8KjztURgB5MA=; b=JEdEtmboRlziV5uzGCOXw5b3g2RyZAfgLUQOP0wZlHO6h5aftzxVwyCvECXymjAUf7 gIBmEi0MDlJseqTSGAjFxI4izmhJO0O0LmfDnY2Wz9x2RNxnenz5SYuZv4BY1Z+K+R3d q/vFYmpcpT9+9XLTG1UiZu9en6pbtCER5+yxYCPwtxhiZ5ar8onKcpMu3yAe9PD0g/zb KkrZC/fv9WwT5Ev2tszNGvCb0kp6pNXMJDJMjmd7J8PG+/iPqntHAyHbStLsqSPBoP7w 0/9M7uuf60wvLXrcZuFtTpJ6asbDzBB/THwAtuC5xxMAPavlIvy8lGNbgW3NV3BYW7CX MOFA== 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; bh=mFG8sQS+ZMuLTuhdWXM6006eexSeE8v8KjztURgB5MA=; b=PGS3i2NxdOo0A+GOKFV8cSx3ZBUnwfazYhUl/g3HTTCgmClgxJ8+lwGA4V6kk10yU7 /LKvWzxmS/9SePS/HWq65x9zMFbILukSGkM+/ZziAHxRnYFc3hkEsSGbtW2WAZ6RMFeY 3FglDiWXbfwolMpbo+ruRgC5I1cZIZH9S+60OVUzI2Q6eMCZCZmH07VEIWQ8uAL8+5lo LY8sdDfmOiwxq67+x8a61UdRHaOsxJ91ykRizGXjOfP1lHTERVVnZHbm1QY/2Euq+DIu xDF3WjytqWWjuSKvMqfdybcz+RgEwXTgaAjZCvI1fyqrqUk+J1KEvgaS/QTajxYZn6Lj yw3A== X-Gm-Message-State: APjAAAWryrG5TB7yZPWGuh3tsoJXWNdjb4tmvaF9jctzX57bdKs4i4Ku 6U8aK4p2jWU+TnJPW4djsAM6SOc2+9s= X-Received: by 2002:a63:81c7:: with SMTP id t190mr5820496pgd.166.1551869168906; Wed, 06 Mar 2019 02:46:08 -0800 (PST) Received: from localhost.localdomain ([117.252.64.200]) by smtp.gmail.com with ESMTPSA id y133sm3235765pfb.107.2019.03.06.02.46.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Mar 2019 02:46:08 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Wed, 6 Mar 2019 16:15:49 +0530 Message-Id: <1551869149-7306-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.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-5.smtp.seeweb.it Cc: daniel.thompson@linaro.org Subject: [LTP] [PATCH v3] syscalls: add rt_tgsigqueueinfo() test-case 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" This tests the rt_tgsigqueueinfo() syscall used to queue a signal and data to the single thread specified by the combination of tgid, a thread group ID, and tid, a thread in that thread group. Also this test implement 3 cases differing on the basis of signal sender: - Sender and receiver is the same thread. - Sender is parent of the thread. - Sender is different thread. Signed-off-by: Sumit Garg --- Changes in v3: 1. Remove usage of non asyn-safe function in signal handler. 2. Use checkpoint library for synchronization. 3. Fix possible race condition. 4. Miscellaneous fixes. Changes in v2: 1. Add following cases where the sender differs: - parent -> thread - thread1 -> thread2 2. Add verification of signal and data delivered by rt_tgsigqueueinfo(). runtest/syscalls | 1 + .../kernel/syscalls/rt_tgsigqueueinfo/.gitignore | 1 + .../kernel/syscalls/rt_tgsigqueueinfo/Makefile | 10 ++ .../rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c | 180 +++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 testcases/kernel/syscalls/rt_tgsigqueueinfo/.gitignore create mode 100644 testcases/kernel/syscalls/rt_tgsigqueueinfo/Makefile create mode 100644 testcases/kernel/syscalls/rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c diff --git a/runtest/syscalls b/runtest/syscalls index 78a1f78..f6c2f1b 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -999,6 +999,7 @@ rt_sigprocmask01 rt_sigprocmask01 rt_sigprocmask02 rt_sigprocmask02 rt_sigqueueinfo01 rt_sigqueueinfo01 rt_sigsuspend01 rt_sigsuspend01 +rt_tgsigqueueinfo01 rt_tgsigqueueinfo01 sbrk01 sbrk01 sbrk02 sbrk02 diff --git a/testcases/kernel/syscalls/rt_tgsigqueueinfo/.gitignore b/testcases/kernel/syscalls/rt_tgsigqueueinfo/.gitignore new file mode 100644 index 0000000..f9ffa58 --- /dev/null +++ b/testcases/kernel/syscalls/rt_tgsigqueueinfo/.gitignore @@ -0,0 +1 @@ +rt_tgsigqueueinfo01 diff --git a/testcases/kernel/syscalls/rt_tgsigqueueinfo/Makefile b/testcases/kernel/syscalls/rt_tgsigqueueinfo/Makefile new file mode 100644 index 0000000..035ca64 --- /dev/null +++ b/testcases/kernel/syscalls/rt_tgsigqueueinfo/Makefile @@ -0,0 +1,10 @@ +# Copyright (c) 2019 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +rt_tgsigqueueinfo01: CFLAGS+=-pthread + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c b/testcases/kernel/syscalls/rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c new file mode 100644 index 0000000..4ae17c2 --- /dev/null +++ b/testcases/kernel/syscalls/rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 Linaro Limited. All rights reserved. + * Author: Sumit Garg + */ + +/* + * Test rt_tgsigqueueinfo + * + * This tests the rt_tgsigqueueinfo() syscall. It sends the signal and data + * to the single thread specified by the combination of tgid, a thread group + * ID, and tid, a thread in that thread group. + * + * Also this implement 3 tests differing on the basis of signal sender: + * - Sender and receiver is the same thread. + * - Sender is parent of the thread. + * - Sender is different thread. + */ + +#define _GNU_SOURCE +#include +#include +#include "tst_safe_pthread.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +static char sigval_send[] = "rt_tgsigqueueinfo data"; +static volatile int signum_rcv; +static char *sigval_rcv; + +static void sigusr1_handler(int signum, siginfo_t *uinfo, + void *p LTP_ATTRIBUTE_UNUSED) +{ + signum_rcv = signum; + sigval_rcv = uinfo->_sifields._rt.si_sigval.sival_ptr; +} + +void *send_rcv_func(void *arg) +{ + siginfo_t uinfo; + + signum_rcv = 0; + sigval_rcv = NULL; + + uinfo.si_errno = 0; + uinfo.si_code = SI_QUEUE; + uinfo._sifields._rt.si_sigval.sival_ptr = sigval_send; + + TEST(tst_syscall(__NR_rt_tgsigqueueinfo, getpid(), + syscall(__NR_gettid), SIGUSR1, &uinfo)); + if (TST_RET) + tst_brk(TFAIL | TTERRNO, "rt_tgsigqueueinfo failed"); + + while (!signum_rcv) + usleep(1000); + + if ((signum_rcv == SIGUSR1) && (sigval_rcv == sigval_send)) + tst_res(TPASS, "Test signal to self succeeded"); + else + tst_res(TFAIL, "Failed to deliver signal/data to self thread"); + + return arg; +} + +static void verify_signal_self(void) +{ + pthread_t pt; + + SAFE_PTHREAD_CREATE(&pt, NULL, send_rcv_func, NULL); + + SAFE_PTHREAD_JOIN(pt, NULL); +} + +void *receiver_func(void *arg) +{ + pid_t *tid = arg; + + *tid = syscall(__NR_gettid); + + signum_rcv = 0; + sigval_rcv = NULL; + + TST_CHECKPOINT_WAKE(0); + + while (!signum_rcv) + usleep(1000); + + if ((signum_rcv == SIGUSR1) && (sigval_rcv == sigval_send)) + tst_res(TPASS, "Test signal to different thread succeeded"); + else + tst_res(TFAIL, + "Failed to deliver signal/data to different thread"); + + return NULL; +} + +static void verify_signal_parent_thread(void) +{ + pid_t tid = -1; + pthread_t pt; + siginfo_t uinfo; + + SAFE_PTHREAD_CREATE(&pt, NULL, receiver_func, &tid); + + TST_CHECKPOINT_WAIT(0); + + uinfo.si_errno = 0; + uinfo.si_code = SI_QUEUE; + uinfo._sifields._rt.si_sigval.sival_ptr = sigval_send; + + TEST(tst_syscall(__NR_rt_tgsigqueueinfo, getpid(), + tid, SIGUSR1, &uinfo)); + if (TST_RET) + tst_brk(TFAIL | TTERRNO, "rt_tgsigqueueinfo failed"); + + SAFE_PTHREAD_JOIN(pt, NULL); +} + +void *sender_func(void *arg) +{ + pid_t *tid = arg; + siginfo_t uinfo; + + uinfo.si_errno = 0; + uinfo.si_code = SI_QUEUE; + uinfo._sifields._rt.si_sigval.sival_ptr = sigval_send; + + TEST(tst_syscall(__NR_rt_tgsigqueueinfo, getpid(), + *tid, SIGUSR1, &uinfo)); + if (TST_RET) + tst_brk(TFAIL | TTERRNO, "rt_tgsigqueueinfo failed"); + + return NULL; +} + +static void verify_signal_inter_thread(void) +{ + pid_t tid = -1; + pthread_t pt1, pt2; + + SAFE_PTHREAD_CREATE(&pt1, NULL, receiver_func, &tid); + + TST_CHECKPOINT_WAIT(0); + + SAFE_PTHREAD_CREATE(&pt2, NULL, sender_func, &tid); + + SAFE_PTHREAD_JOIN(pt2, NULL); + + SAFE_PTHREAD_JOIN(pt1, NULL); +} + +static struct tcase { + void (*tfunc)(void); +} tcases[] = { + {&verify_signal_self}, + {&verify_signal_parent_thread}, + {&verify_signal_inter_thread}, +}; + +static void run(unsigned int i) +{ + tcases[i].tfunc(); +} + +static void setup(void) +{ + struct sigaction sigusr1 = { + .sa_flags = SA_SIGINFO, + .sa_sigaction = sigusr1_handler, + }; + + SAFE_SIGACTION(SIGUSR1, &sigusr1, NULL); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .needs_checkpoints = 1, + .setup = setup, + .test = run, +};