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