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, +};