From patchwork Tue Jun 12 15:46:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 928403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 414vQj1Kq2z9ryk for ; Wed, 13 Jun 2018 01:47:24 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8950D3E631D for ; Tue, 12 Jun 2018 17:47:16 +0200 (CEST) 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 7EA311B9974 for ; Tue, 12 Jun 2018 17:46:53 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id CF39E1000434 for ; Tue, 12 Jun 2018 17:46:52 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6D7A6AD2B for ; Tue, 12 Jun 2018 15:46:52 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Tue, 12 Jun 2018 17:46:29 +0200 Message-Id: <20180612154631.435-8-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180612154631.435-1-chrubis@suse.cz> References: <20180612154631.435-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 Subject: [LTP] [RFC PATCH 7/9] syscalls/ipc: Rewrite msgctl12 to new library 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+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis Reviewed-by: Petr Vorel --- testcases/kernel/syscalls/ipc/msgctl/msgctl12.c | 84 +++++++++---------------- 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c index 2621f8040..46e9fdb44 100644 --- a/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c +++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl12.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2014 Fujitsu Ltd. * Author: Zeng Linggang + * Copyright (c) 2018 Cyril Hrubis * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -14,87 +15,60 @@ * with this program. */ /* - * DESCRIPTION - * msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT. + * msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT. */ #define _GNU_SOURCE -#include -#include -#include #include -#include "test.h" -#include "ipcmsg.h" +#include "tst_test.h" +#include "tst_safe_sysv_ipc.h" +#include "libnewipc.h" static int msg_q; static int index_q; static struct msginfo msginfo_buf; static struct msqid_ds msgqid_buf; -static struct test_case_t { - int *queue_id; - int ipc_cmd; +static struct tcase { + int *msg_id; + int cmd; char *name; void *buf; -} test_cases[] = { +} tc[] = { {&msg_q, IPC_INFO, "IPC_INFO", &msginfo_buf}, {&msg_q, MSG_INFO, "MSG_INFO", &msginfo_buf}, {&index_q, MSG_STAT, "MSG_STAT", &msgqid_buf}, }; -char *TCID = "msgctl12"; -int TST_TOTAL = ARRAY_SIZE(test_cases); - -int main(int argc, char *argv[]) +static void verify_msgctl(unsigned int i) { - int lc; - int i; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { + TEST(msgctl(*tc[i].msg_id, tc[i].cmd, tc[i].buf)); - TEST(msgctl(*test_cases[i].queue_id, - test_cases[i].ipc_cmd, test_cases[i].buf)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, - "msgctl() test %s failed with errno: " - "%d", test_cases[i].name, TEST_ERRNO); - } else { - tst_resm(TPASS, "msgctl() test %s succeeded", - test_cases[i].name); - } - } + if (TEST_RETURN == -1) { + tst_res(TFAIL, + "msgctl() test %s failed with errno: " + "%d", tc[i].name, TEST_ERRNO); } - cleanup(); - tst_exit(); + tst_res(TPASS, "msgctl() test %s succeeded", tc[i].name); } -void setup(void) +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - msg_q = msgget(IPC_PRIVATE, MSG_RW); - if (msg_q < 0) - tst_brkm(TBROK, cleanup, "Can't create message queue"); - - index_q = msgctl(msg_q, IPC_INFO, (struct msqid_ds *)&msginfo_buf); - if (index_q < 0) - tst_brkm(TBROK, cleanup, "Can't create message queue"); + msg_q = SAFE_MSGGET(IPC_PRIVATE, MSG_RW); + index_q = SAFE_MSGCTL(msg_q, IPC_INFO, (struct msqid_ds*)&msginfo_buf); } -void cleanup(void) +static void cleanup(void) { - rm_queue(msg_q); + if (msg_q > 0) + SAFE_MSGCTL(msg_q, IPC_RMID, NULL); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = verify_msgctl, + .tcnt = ARRAY_SIZE(tc), +};