From patchwork Tue Mar 5 14:22:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 159663 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp5025819jad; Tue, 5 Mar 2019 06:22:56 -0800 (PST) X-Google-Smtp-Source: APXvYqwGwm0aj6MEAmTUi9eYD6cmC/lu1S1EUEz5zlqS1SBR+YCsrimIYCU+7HUKxKDuSBXMb5/M X-Received: by 2002:a50:aea7:: with SMTP id e36mr19596308edd.276.1551795776354; Tue, 05 Mar 2019 06:22:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551795776; cv=none; d=google.com; s=arc-20160816; b=q3R0bEnYkB9Qnve0ETizPH/6xb4P/uRFb/nbotEdcql3K0TCpN8ZagvCOX7pNKnBG7 kBG3Bc/Xx2WwD2jxwbRGK1rlhYUcSqINT+5mXwIjuGGXAiD0jleDrwF0Jo5NcK6utj+w KTjFyLjYpLBCu6mo32VfR8ShTwDYf9Cegda4N6WZXnoWZQXtZjfRFjZlFDWl5JhS/ZDN KLcIuW738lI0am2D2BP1mOGX+baoteb+GFb7aiYFlXrvowFqI5rmOmwJXk1BxEWYaP2g bKS6x7hj3AeLRMxa+JefAfZwKjueKrlBcTXo5nhWgNMXYwn43LiTbc7ViDUemzKVsHb+ uOTg== 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=MEQPeWzimiWks1FNSUEwDQZItHB7akCfb/VPpV2kvAk=; b=EIR0knnI7I+8phU2Yqrhn3d2v6CFATxfRVyJPu4KP5H6AsRsWEUoMBLuniQWD07gnB kHLLVFfVAGqmCn9J7OxM7OdE4ufhoPcRQCJnWr9qbw2chyVoKbQL6RcUu7k5OwwJ4j6i Y8hqrIqjZd8zeY4K3nEDx7Yz0DP/2W36L2wMjGv4+GgjLHDVtWqn4X8f/S7LHKuIlRl5 CFrcE/3FqDMi/3iqjsuP2yp1WM/ATziSjbRuwEm5fwndDEtpT1PYzbsPaXHkIOww7Ujp 697QicI5M4FXonoKQfaVXx7gBjFL6cAyQorI8SKx/Nyfc37ZmMaNP+P512ZRVPRS1D92 +J8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=buwybP9j; 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 bq16si1061363ejb.242.2019.03.05.06.22.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 06:22:56 -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=buwybP9j; 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 DC1913EA351 for ; Tue, 5 Mar 2019 15:22:55 +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 1E34F3EA2FF for ; Tue, 5 Mar 2019 15:22:52 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 267D020076E for ; Tue, 5 Mar 2019 15:22:51 +0100 (CET) Received: by mail-pg1-x542.google.com with SMTP id 125so5502181pgc.12 for ; Tue, 05 Mar 2019 06:22:51 -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=nT39OeZlCzgt4fqlKn1FZ5WqXrAvEoqRO509TPmg270=; b=buwybP9jfrzlHJmFsD611GC9gUBITeanTyi8YtPCUV/HtCZ08S3AndeET6Mi+491HS 9v2W6Ojs5TMAZrgcyaDpq3zbU4PIC3ODT7SwGLYuw62tRemJhS5Grg7LGunXPWm1twnW W32ITx9bEiRGclsRXS/LUvYdh3S1TCYcMGhkyehZE0UC0HocYR0nzDl8qXJA6ASNGdD0 VsRFbqYzvwvfptNtjMZGdivrIwOU+x4ApS1wKYxc0tkconcJ8nXzw223xgVu5JBW77Uu ht+CcZZMMtvH0XsVbeUtmYECxN4cqUyGAsv99mZ3xHGbtTlJ1bDzB+TYo9zVlfiu5Cyf XQAg== 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=nT39OeZlCzgt4fqlKn1FZ5WqXrAvEoqRO509TPmg270=; b=gz6hsinyYjurrh97nPfTBJpAabo3lpkm6WWrDEpKfW8rl2dB6sbrB7DO9d/pFDuZeT SR9f93yZ0lCzQ9/RUfQexJ/vzEfUUMCih3P+tYSjdV3ClUupTRE2Chk+OeQ1yf3Hn63p gNo5EsVf/GidbBa2qh1xQKZUdk7rU68Km8eNiY8hXx8baILOThHHqxHCRQd8De0XCvH+ OgMJG8i3cLp36zvVDdVfURehVgUI6dXb2RS+JAINw6npuM0CQJf4VhFDnLR425kvLo7Y 4gcLIqi5qOMm1IuQatDZTWinlpDu/X8VrUqas3hYJkM+GvhF1IUZ7DesEJLj0wVowkSv HAog== X-Gm-Message-State: APjAAAXq2Iwd3fpuTQTbN03P4VNS6u2I116ObF3GZE+J2VD7arENRsN+ FUBzaVRbKluiY3tBLrfJrFzVtz9s2XE= X-Received: by 2002:a17:902:6b4b:: with SMTP id g11mr1445706plt.92.1551795769173; Tue, 05 Mar 2019 06:22:49 -0800 (PST) Received: from localhost.localdomain ([117.252.64.200]) by smtp.gmail.com with ESMTPSA id h87sm17920921pfj.20.2019.03.05.06.22.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Mar 2019 06:22:48 -0800 (PST) From: Sumit Garg To: ltp@lists.linux.it Date: Tue, 5 Mar 2019 19:52:23 +0530 Message-Id: <1551795743-30614-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-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 Subject: [LTP] [PATCH v2] 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 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 | 200 +++++++++++++++++++++ 4 files changed, 212 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..132b31c --- /dev/null +++ b/testcases/kernel/syscalls/rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c @@ -0,0 +1,200 @@ +// 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 +#include "tst_safe_pthread.h" +#include "tst_test.h" +#include "lapi/syscalls.h" + +static char sigval_send[] = "rt_tgsigqueueinfo data"; +static int signum_rcv; +static char sigval_rcv[128]; + +static pthread_cond_t sigusr1_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t sigusr1_mutex = PTHREAD_MUTEX_INITIALIZER; + +static pthread_cond_t tid_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t tid_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void sigusr1_handler(int signum, siginfo_t *uinfo, + void *p LTP_ATTRIBUTE_UNUSED) +{ + char *rcv = uinfo->_sifields._rt.si_sigval.sival_ptr; + + if (rcv) + strcpy(sigval_rcv, rcv); + signum_rcv = signum; + + pthread_cond_broadcast(&sigusr1_cond); +} + +void *tfunc_self(void *arg LTP_ATTRIBUTE_UNUSED) +{ + siginfo_t uinfo; + + signum_rcv = 0; + memset(sigval_rcv, 0, sizeof(sigval_rcv)); + + 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"); + + pthread_mutex_lock(&sigusr1_mutex); + while (!signum_rcv) + pthread_cond_wait(&sigusr1_cond, &sigusr1_mutex); + pthread_mutex_unlock(&sigusr1_mutex); + + if ((signum_rcv == SIGUSR1) && !strcmp(sigval_send, sigval_rcv)) + tst_res(TPASS, "Test signal to self succeeded"); + else + tst_res(TFAIL, "Test failed"); + + return NULL; +} + +static void verify_signal_self(void) +{ + pthread_t pt; + + SAFE_PTHREAD_CREATE(&pt, NULL, tfunc_self, NULL); + + SAFE_PTHREAD_JOIN(pt, NULL); +} + +void *t1func(void *arg) +{ + pid_t *tid = arg; + + *tid = syscall(__NR_gettid); + + pthread_cond_broadcast(&tid_cond); + + signum_rcv = 0; + memset(sigval_rcv, 0, sizeof(sigval_rcv)); + + pthread_mutex_lock(&sigusr1_mutex); + while (!signum_rcv) + pthread_cond_wait(&sigusr1_cond, &sigusr1_mutex); + pthread_mutex_unlock(&sigusr1_mutex); + + if ((signum_rcv == SIGUSR1) && !strcmp(sigval_send, sigval_rcv)) + tst_res(TPASS, "Test signal to different thread succeeded"); + else + tst_res(TFAIL, "Test failed"); + + return NULL; +} + +static void verify_signal_parent_thread(void) +{ + pid_t tid = -1; + pthread_t pt; + siginfo_t uinfo; + + SAFE_PTHREAD_CREATE(&pt, NULL, t1func, &tid); + + pthread_mutex_lock(&tid_mutex); + while (tid == -1) + pthread_cond_wait(&tid_cond, &tid_mutex); + pthread_mutex_unlock(&tid_mutex); + + 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 *t2func(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, t1func, &tid); + + pthread_mutex_lock(&tid_mutex); + while (tid == -1) + pthread_cond_wait(&tid_cond, &tid_mutex); + pthread_mutex_unlock(&tid_mutex); + + SAFE_PTHREAD_CREATE(&pt2, NULL, t2func, &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), + .setup = setup, + .test = run, +};