From patchwork Wed Jul 29 07:55:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1338177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=cshwcxub; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGm7v4jPwz9sRN for ; Wed, 29 Jul 2020 17:56:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D8FB83C176D for ; Wed, 29 Jul 2020 09:56:08 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 9B07B3C176D for ; Wed, 29 Jul 2020 09:56:06 +0200 (CEST) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id B87171400332 for ; Wed, 29 Jul 2020 09:56:04 +0200 (CEST) Received: by mail-pf1-x42c.google.com with SMTP id k18so5295163pfp.7 for ; Wed, 29 Jul 2020 00:56:04 -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; bh=ef24rJl8fHhDE7IBYOndWSnwZl6x3XAYbB9LIVo+Mu4=; b=cshwcxubnpjdn76tx32Qqssy4xjQKQ9a1Um6or9uy8e/iCVy1SREm0N4mPZQHENUkI LN9ThsO3QuDfOk/KDbtZX0yKfL+mR2JfjTWDRFuJFp3509fKEFVZF9kP8yKdrYDD/W5F DRaSSTWnp85L4GAPps8jG07XOWOqueSAxH20avFMNqf15ueMv61U55zAXRo2gMgj0m4N vmJu9KhoOldkEQy75aLgxvyAMlbcYzkz5aNxBGmcWsg6qP+ogSfh7weE2vH4PpsLuWjn WK1SH//RyOIEcpIWtWD8g7zLrAlflyTrvmn6UbmNzhSIRk3R0IxtOno/lBtEEYnvN80Y 08kg== 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=ef24rJl8fHhDE7IBYOndWSnwZl6x3XAYbB9LIVo+Mu4=; b=Z1IudeH3oh73wUjaHsVr5Ey+7mtOG/Lv6bfi8lPsiCYEKZk7c87C8fOGwWsbeK2fS4 Lc1XjH0sM5A8K7v3oZ+zaaXyPTVx521SJ01aqZyFYwgeEluo5mdUWBSMnQ68JiJTjh6+ upAs8LU63KyMPQUUCLaOWT8IDYtEwAzRFHg5mB6+EM1BJK742Apkm8CzdEdJR6Y0SViU s4/+PM1kDC/6OZ/ndAzqEpfWuvEc8RK4pY+MuFWHRS+VWkAtwJivMoVZKzieEpf0ypyM Zx/3gsR5DCUdTtRVbVTwNa4G4zR5ITJcuAu9lD5ZXr1EdZq1rSTWe8CG0uHZ/ApD4jT1 +qvw== X-Gm-Message-State: AOAM53251EdxyIrqbenvWjbncLRgMXM6qyfYaCk11n1S39a+hR+7MtXb 950Sx4kcS0ZPEKZSxewOVxbdw9eRNuo= X-Google-Smtp-Source: ABdhPJzPYAUWWqxX1ugxGpJtYl5GFEYWubmnJ3t9amqyDz2JJ1XKt4Kv5s+hTmK/MdqCt2VihnBf1g== X-Received: by 2002:a63:5915:: with SMTP id n21mr28503951pgb.323.1596009361624; Wed, 29 Jul 2020 00:56:01 -0700 (PDT) Received: from localhost ([106.215.77.228]) by smtp.gmail.com with ESMTPSA id z190sm1345964pfz.67.2020.07.29.00.55.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jul 2020 00:56:00 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Wed, 29 Jul 2020 13:25:49 +0530 Message-Id: X-Mailer: git-send-email 2.14.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.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_HELO_NONE,SPF_PASS,T_FILL_THIS_FORM_SHORT autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH V8 1/5] syscalls/semop: Migrate to new test framework X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This migrates the semop tests to the new test framework. Signed-off-by: Viresh Kumar --- V8: - 1/5 remains unchanged and I have added four new patches as suggested by Cyril. - I have kept 2/5 separate to make it more reviewable, but you can merge it while applying if you want to. - I was required to keep 3/5 and 4/5 separate as well to make review easier. testcases/kernel/syscalls/ipc/semop/Makefile | 4 +- testcases/kernel/syscalls/ipc/semop/semop01.c | 140 +++++------- testcases/kernel/syscalls/ipc/semop/semop02.c | 145 +++++------- testcases/kernel/syscalls/ipc/semop/semop03.c | 150 +++++-------- testcases/kernel/syscalls/ipc/semop/semop04.c | 165 +++++--------- testcases/kernel/syscalls/ipc/semop/semop05.c | 303 +++++++++++--------------- 6 files changed, 348 insertions(+), 559 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/semop/Makefile b/testcases/kernel/syscalls/ipc/semop/Makefile index f62cd1f481d9..a11cbcf2e699 100644 --- a/testcases/kernel/syscalls/ipc/semop/Makefile +++ b/testcases/kernel/syscalls/ipc/semop/Makefile @@ -3,10 +3,10 @@ top_srcdir ?= ../../../../.. -LTPLIBS = ltpipc +LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -LDLIBS += -lltpipc +LDLIBS += -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/semop/semop01.c b/testcases/kernel/syscalls/ipc/semop/semop01.c index ea05c53eb919..bcb45fa69320 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop01.c +++ b/testcases/kernel/syscalls/ipc/semop/semop01.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -52,92 +36,73 @@ * none */ -#include "ipcsem.h" +#include +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" #define NSEMS 4 /* the number of primitive semaphores to test */ -char *TCID = "semop01"; -int TST_TOTAL = 1; - -int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ +static int sem_id = -1; /* a semaphore set with read & alter permissions */ +static key_t semkey; -union semun get_arr; -struct sembuf sops[PSEMS]; +static union semun get_arr; +static struct sembuf sops[PSEMS]; -int main(int ac, char **av) +static void run(void) { - int lc; - int i; + union semun arr = { .val = 0 }; int fail = 0; + int i; - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - TEST(semop(sem_id_1, sops, NSEMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "%s call failed - errno = %d : %s", - TCID, TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - /* get the values and make sure they */ - /* are the same as what was set */ - if (semctl(sem_id_1, 0, GETALL, get_arr) == -1) { - tst_brkm(TBROK, cleanup, - "semctl() failed in functional test"); - } - - for (i = 0; i < NSEMS; i++) { - if (get_arr.array[i] != i * i) { - fail = 1; - } - } - if (fail) - tst_resm(TFAIL, - "semaphore values are wrong"); - else - tst_resm(TPASS, - "semaphore values are correct"); - } + TEST(semop(sem_id, sops, NSEMS)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "semop() failed"); + } else { /* - * clean up things in case we are looping + * Get the values and make sure they are the same as what was + * set */ - union semun set_arr; - set_arr.val = 0; + if (semctl(sem_id, 0, GETALL, get_arr) == -1) { + tst_brk(TBROK | TERRNO, "semctl() failed in functional test"); + } + for (i = 0; i < NSEMS; i++) { - if (semctl(sem_id_1, i, SETVAL, set_arr) == -1) { - tst_brkm(TBROK, cleanup, "semctl failed"); + if (get_arr.array[i] != i * i) { + fail = 1; } } + if (fail) + tst_res(TFAIL | TERRNO, "semaphore values are wrong"); + else + tst_res(TPASS, "semaphore values are correct"); } - cleanup(); - tst_exit(); + /* + * clean up things in case we are looping + */ + for (i = 0; i < NSEMS; i++) { + if (semctl(sem_id, i, SETVAL, arr) == -1) { + tst_brk(TBROK | TERRNO, "semctl failed"); + } + } } -void setup(void) +static void setup(void) { int i; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - get_arr.array = malloc(sizeof(unsigned short int) * PSEMS); if (get_arr.array == NULL) - tst_brkm(TBROK, cleanup, "malloc failed"); + tst_brk(TBROK, "malloc failed"); - semkey = getipckey(); + semkey = GETIPCKEY(); - sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); - if (sem_id_1 == -1) - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); + sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); + if (sem_id == -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); for (i = 0; i < NSEMS; i++) { sops[i].sem_num = i; @@ -146,11 +111,20 @@ void setup(void) } } -void cleanup(void) +static void cleanup(void) { - rm_sema(sem_id_1); + union semun arr; + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } free(get_arr.array); - - tst_rmdir(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c index f067229b1cf5..f24d284776a4 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop02.c +++ b/testcases/kernel/syscalls/ipc/semop/semop02.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * DESCRIPTION @@ -31,30 +15,27 @@ #define _GNU_SOURCE #include -#include "test.h" -#include "safe_macros.h" -#include "ipcsem.h" - -char *TCID = "semop02"; - -static void semop_verify(int i); -int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ -int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ -int bad_id = -1; - -struct sembuf s_buf[PSEMS]; - -int badbuf = -1; +#include +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" + +static int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ +static int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ +static int bad_id = -1; +static key_t semkey; +static struct sembuf s_buf[PSEMS]; #define NSOPS 5 /* a resonable number of operations */ #define BIGOPS 1024 /* a value that is too large for the number */ /* of semop operations that are permitted */ -struct test_case_t { +static struct test_case_t { int *semid; struct sembuf *t_sbuf; unsigned t_ops; int error; -} TC[] = { +} tc[] = { {&sem_id_1, (struct sembuf *)&s_buf, BIGOPS, E2BIG}, {&sem_id_2, (struct sembuf *)&s_buf, NSOPS, EACCES}, {&sem_id_1, (struct sembuf *)-1, NSOPS, EFAULT}, @@ -63,29 +44,7 @@ struct test_case_t { {&sem_id_1, (struct sembuf *)&s_buf, 1, ERANGE} }; -int TST_TOTAL = ARRAY_SIZE(TC); - -int main(int ac, char **av) -{ - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - semop_verify(i); - } - - cleanup(); - tst_exit(); -} - -void setup(void) +static void setup(void) { char nobody_uid[] = "nobody"; struct passwd *ltpuser; @@ -93,71 +52,73 @@ void setup(void) struct seminfo ipc_buf; union semun arr; - tst_require_root(); - - ltpuser = SAFE_GETPWNAM(NULL, nobody_uid); - SAFE_SETUID(NULL, ltpuser->pw_uid); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); + ltpuser = SAFE_GETPWNAM(nobody_uid); + SAFE_SETUID(ltpuser->pw_uid); /* get an IPC resource key */ - semkey = getipckey(); + semkey = GETIPCKEY(); /* create a semaphore set with read and alter permissions */ sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); - if (sem_id_1 == -1) { - tst_brkm(TBROK | TERRNO, cleanup, - "couldn't create semaphore in setup"); - } + if (sem_id_1 == -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); /* Get an new IPC resource key. */ - semkey2 = getipckey(); + semkey2 = GETIPCKEY(); /* create a semaphore set without read and alter permissions */ sem_id_2 = semget(semkey2, PSEMS, IPC_CREAT | IPC_EXCL); - if (sem_id_2 == -1) { - tst_brkm(TBROK | TERRNO, cleanup, - "couldn't create semaphore in setup"); - } + if (sem_id_2 == -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); arr.__buf = &ipc_buf; if (semctl(sem_id_1, 0, IPC_INFO, arr) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "semctl() IPC_INFO failed"); + tst_brk(TBROK | TERRNO, "semctl() IPC_INFO failed"); /* for ERANGE errno test */ arr.val = 1; s_buf[0].sem_op = ipc_buf.semvmx; if (semctl(sem_id_1, 0, SETVAL, arr) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "semctl() SETVAL failed"); + tst_brk(TBROK | TERRNO, "semctl() SETVAL failed"); } -static void semop_verify(int i) +static void run(unsigned int i) { - TEST(semop(*(TC[i].semid), TC[i].t_sbuf, TC[i].t_ops)); + TEST(semop(*(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops)); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + if (TST_RET != -1) { + tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); return; } - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS | TTERRNO, "semop failed as expected"); + if (TST_ERR == tc[i].error) { + tst_res(TPASS | TTERRNO, "semop failed as expected"); } else { - tst_resm(TFAIL | TTERRNO, + tst_res(TFAIL | TTERRNO, "semop failed unexpectedly; expected: " - "%d - %s", TC[i].error, strerror(TC[i].error)); + "%d - %s", tc[i].error, strerror(tc[i].error)); } } -void cleanup(void) +static void cleanup(void) { - /* if they exist, remove the semaphore resources */ - rm_sema(sem_id_1); - rm_sema(sem_id_2); + union semun arr; - tst_rmdir(); + if (sem_id_1 != -1) { + if (semctl(sem_id_1, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } + if (sem_id_2 != -1) { + if (semctl(sem_id_2, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop03.c b/testcases/kernel/syscalls/ipc/semop/semop03.c index 9c1c58202ad3..4f5f78eb6d8d 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop03.c +++ b/testcases/kernel/syscalls/ipc/semop/semop03.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -50,109 +34,75 @@ * none */ -#include "ipcsem.h" - -char *TCID = "semop03"; -int TST_TOTAL = 2; +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" -int sem_id_1 = -1; +static key_t semkey; +static int sem_id = -1; +static struct sembuf s_buf; -struct sembuf s_buf; +static int tc[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas */ -int TC[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas */ - -int main(int ac, char **av) +static void run(unsigned int i) { - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup */ - /* initialize two fields in the sembuf structure here */ s_buf.sem_op = 1; /* add this value to struct sem.semval */ s_buf.sem_flg = SEM_UNDO; /* undo when process exits */ - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - - /* initialize the last field in the sembuf */ - /* structure to the test dependent value */ - s_buf.sem_num = TC[i]; - - /* - * use the TEST macro to make the call - */ + /* + * initialize the last field in the sembuf structure to the test + * dependent value. + */ + s_buf.sem_num = tc[i]; - TEST(semop(sem_id_1, &s_buf, 1)); + /* + * use the TEST macro to make the call + */ - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } + TEST(semop(sem_id, &s_buf, 1)); - switch (TEST_ERRNO) { - case EFBIG: - tst_resm(TPASS, "expected failure - errno = " - "%d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - break; - default: - tst_resm(TFAIL, "unexpected error - " - "%d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - break; - } - } + if (TST_RET != -1) { + tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); + return; } - cleanup(); - - tst_exit(); + switch (TST_ERR) { + case EFBIG: + tst_res(TPASS | TTERRNO, "expected failure"); + break; + default: + tst_res(TFAIL | TTERRNO, "unexpected failure"); + break; + } } -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void setup(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. - */ - tst_tmpdir(); - /* get an IPC resource key */ - semkey = getipckey(); + semkey = GETIPCKEY(); /* create a semaphore with read and alter permissions */ - if ((sem_id_1 = - semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); - } + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); + union semun arr; + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop04.c b/testcases/kernel/syscalls/ipc/semop/semop04.c index c1fa2eba7584..0faf00a3585f 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop04.c +++ b/testcases/kernel/syscalls/ipc/semop/semop04.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -50,22 +34,24 @@ * none */ -#include "ipcsem.h" - -char *TCID = "semop04"; -int TST_TOTAL = 2; +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" -int sem_id_1 = -1; +static int sem_id = -1; +static int val; /* value for SETVAL */ -struct sembuf s_buf; +static key_t semkey; +static struct sembuf s_buf; -struct test_case_t { +static struct test_case_t { union semun get_arr; short op; short flg; short num; int error; -} TC[] = { +} tc[] = { /* EAGAIN sem_op = 0 */ { { 1}, 0, IPC_NOWAIT, 2, EAGAIN}, @@ -74,104 +60,61 @@ struct test_case_t { 0}, -1, IPC_NOWAIT, 2, EAGAIN} }; -int main(int ac, char **av) +static void run(unsigned int i) { - int lc; - int val; /* value for SETVAL */ - - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup */ - - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - val = 1; - for (i = 0; i < TST_TOTAL; i++) { - - /* initialize the s_buf buffer */ - s_buf.sem_op = TC[i].op; - s_buf.sem_flg = TC[i].flg; - s_buf.sem_num = TC[i].num; - - /* initialize all the primitive semaphores */ - TC[i].get_arr.val = val--; - if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].get_arr) - == -1) { - tst_brkm(TBROK, cleanup, "semctl() failed"); - } - - /* - * make the call with the TEST macro - */ - - TEST(semop(sem_id_1, &s_buf, 1)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, - "expected failure - errno = %d" - " : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - " - "%d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } - } + /* initialize the s_buf buffer */ + s_buf.sem_op = tc[i].op; + s_buf.sem_flg = tc[i].flg; + s_buf.sem_num = tc[i].num; + + /* initialize all the primitive semaphores */ + tc[i].get_arr.val = val--; + if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1) + tst_brk(TBROK | TERRNO, "semctl() failed"); + + TEST(semop(sem_id, &s_buf, 1)); + if (TST_RET != -1) { + tst_res(TFAIL, "call succeeded unexpectedly"); + return; } - cleanup(); - - tst_exit(); + if (TST_ERR == tc[i].error) + tst_res(TPASS | TTERRNO, "expected failure"); + else + tst_res(TFAIL | TTERRNO, "unexpected failure"); } -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void setup(void) { + val = 1; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + /* get an IPC resource key */ + semkey = GETIPCKEY(); /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. + * create a semaphore set with read and alter permissions and PSEMS + * "primitive" semaphores. */ - tst_tmpdir(); - - /* get an IPC resource key */ - semkey = getipckey(); - - /* create a semaphore set with read and alter permissions */ - /* and PSEMS "primitive" semaphores */ - if ((sem_id_1 = - semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) { + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); } } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); + union semun arr; + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop05.c b/testcases/kernel/syscalls/ipc/semop/semop05.c index e97ad42fe01d..9e8e040b0b19 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop05.c +++ b/testcases/kernel/syscalls/ipc/semop/semop05.c @@ -1,21 +1,5 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) International Business Machines Corp., 2001 */ /* * NAME @@ -60,18 +44,18 @@ * none */ -#include "ipcsem.h" - +#include +#include #include #include -#include "safe_macros.h" - -char *TCID = "semop05"; -int TST_TOTAL = 4; - -int sem_id_1 = -1; +#include +#include "tst_test.h" +#include "libnewipc.h" +#include "lapi/semun.h" -struct sembuf s_buf; +static key_t semkey; +static int sem_id = -1; +static struct sembuf s_buf; struct test_case_t { union semun semunptr; @@ -79,7 +63,7 @@ struct test_case_t { short flg; short num; int error; -} TC[] = { +} tc[] = { /* EIRDM sem_op = 0 */ { { 1}, 0, 0, 2, EIDRM}, @@ -96,189 +80,166 @@ struct test_case_t { #ifdef UCLINUX #define PIPE_NAME "semop05" -void do_child_uclinux(); +static void do_child_uclinux(); static int i_uclinux; #endif -int main(int ac, char **av) +static inline int process_state_wait2(pid_t pid, const char state) { - int lc; - int i; - pid_t pid; - void do_child(); + char proc_path[128], cur_state; - tst_parse_opts(ac, av, NULL, NULL); + snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid); -#ifdef UCLINUX - maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1); -#endif - - setup(); /* global setup */ - - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - - /* initialize the s_buf buffer */ - s_buf.sem_op = TC[i].op; - s_buf.sem_flg = TC[i].flg; - s_buf.sem_num = TC[i].num; - - /* initialize all of the primitive semaphores */ - if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr) - == -1) { - tst_brkm(TBROK, cleanup, "semctl() failed"); - } - - if ((pid = FORK_OR_VFORK()) == -1) { - tst_brkm(TBROK, cleanup, "could not fork"); - } - - if (pid == 0) { /* child */ + for (;;) { + FILE *f = fopen(proc_path, "r"); + if (!f) { + tst_res(TFAIL, "Failed to open '%s': %s\n", proc_path, + strerror(errno)); + return 1; + } -#ifdef UCLINUX - if (self_exec(av[0], "dd", i, sem_id_1) < 0) { - tst_brkm(TBROK, cleanup, - "could not self_exec"); - } -#else - do_child(i); -#endif - } else { - TST_PROCESS_STATE_WAIT(cleanup, pid, 'S'); - - /* - * If we are testing for EIDRM then remove - * the semaphore, else send a signal that - * must be caught as we are testing for - * EINTR. - */ - if (TC[i].error == EIDRM) { - /* remove the semaphore resource */ - rm_sema(sem_id_1); - } else { - SAFE_KILL(cleanup, pid, SIGHUP); - } - - /* let the child carry on */ - waitpid(pid, NULL, 0); - } - - /* - * recreate the semaphore resource if needed - */ - if (TC[i].error == EINTR) { - continue; - } - - if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | - IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't recreate " - "semaphore"); - } + if (fscanf(f, "%*i %*s %c", &cur_state) != 1) { + fclose(f); + tst_res(TFAIL, "Failed to read '%s': %s\n", proc_path, + strerror(errno)); + return 1; } - } + fclose(f); - cleanup(); + if (state == cur_state) + return 0; - tst_exit(); + usleep(10000); + } } -/* - * do_child() - */ -void do_child(int i) +static void do_child(int i) { - /* - * make the call with the TEST macro - */ - - TEST(semop(sem_id_1, &s_buf, 1)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded when error expected"); + TEST(semop(sem_id, &s_buf, 1)); + if (TST_RET != -1) { + tst_res(TFAIL, "call succeeded when error expected"); exit(-1); } - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, "expected failure - errno = %d" - " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - " - "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - } + if (TST_ERR == tc[i].error) + tst_res(TPASS | TTERRNO, "expected failure"); + else + tst_res(TFAIL | TTERRNO, "unexpected failure"); exit(0); } -void sighandler(int sig) +static void sighandler(int sig) { - if (sig == SIGHUP) - return; - else - tst_brkm(TBROK, NULL, "unexpected signal %d received", sig); + if (sig != SIGHUP) + tst_brk(TBROK, "unexpected signal %d received", sig); } -#ifdef UCLINUX -/* - * do_child_uclinux() - capture signals, re-initialize s_buf then call do_child - * with the appropriate argument - */ -void do_child_uclinux(void) +static void setup(void) { - int i = i_uclinux; + SAFE_SIGNAL(SIGHUP, sighandler); - tst_sig(FORK, sighandler, cleanup); + /* get an IPC resource key */ + semkey = GETIPCKEY(); - /* initialize the s_buf buffer */ - s_buf.sem_op = TC[i].op; - s_buf.sem_flg = TC[i].flg; - s_buf.sem_num = TC[i].num; + /* + * create a semaphore set with read and alter permissions and PSEMS + * "primitive" semaphores. + */ + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) + tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); +} - do_child(i); +static void cleanup(void) +{ + union semun arr; + + if (sem_id != -1) { + if (semctl(sem_id, 0, IPC_RMID, arr) == -1) + tst_res(TINFO, "WARNING: semaphore deletion failed."); + } } -#endif -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void run(unsigned int i) { + pid_t pid; - tst_sig(FORK, sighandler, cleanup); +#ifdef UCLINUX + maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id); +#endif + /* initialize the s_buf buffer */ + s_buf.sem_op = tc[i].op; + s_buf.sem_flg = tc[i].flg; + s_buf.sem_num = tc[i].num; - TEST_PAUSE; + /* initialize all of the primitive semaphores */ + if (semctl(sem_id, tc[i].num, SETVAL, tc[i].semunptr) == -1) + tst_brk(TBROK | TERRNO, "semctl() failed"); - /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. - */ - tst_tmpdir(); + pid = SAFE_FORK(); - /* get an IPC resource key */ - semkey = getipckey(); + if (pid == 0) { /* child */ +#ifdef UCLINUX + if (self_exec(av[0], "dd", i, sem_id) < 0) + tst_brk(TBROK, "could not self_exec"); +#else + do_child(i); +#endif + } else { + process_state_wait2(pid, 'S'); + + /* + * If we are testing for EIDRM then remove + * the semaphore, else send a signal that + * must be caught as we are testing for + * EINTR. + */ + if (tc[i].error == EIDRM) { + /* remove the semaphore resource */ + cleanup(); + } else { + SAFE_KILL(pid, SIGHUP); + } - /* create a semaphore set with read and alter permissions */ - /* and PSEMS "primitive" semaphores */ - if ((sem_id_1 = - semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); + /* let the child carry on */ + waitpid(pid, NULL, 0); } + + /* + * recreate the semaphore resource if needed + */ + if (tc[i].error == EINTR) + return; + + if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == + -1) + tst_brk(TBROK | TERRNO, "couldn't recreate semaphore"); } +#ifdef UCLINUX /* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. + * do_child_uclinux() - capture signals, re-initialize s_buf then call do_child + * with the appropriate argument */ -void cleanup(void) +static void do_child_uclinux(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); + int i = i_uclinux; + + /* initialize the s_buf buffer */ + s_buf.sem_op = tc[i].op; + s_buf.sem_flg = tc[i].flg; + s_buf.sem_num = tc[i].num; - tst_rmdir(); + do_child(i); } +#endif + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tc), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .forks_child = 1, +}; From patchwork Wed Jul 29 07:55:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1338178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yascx5fQ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGm8B56rRz9sSd for ; Wed, 29 Jul 2020 17:56:26 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 027D53C266C for ; Wed, 29 Jul 2020 09:56:21 +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 6C4AB3C4C12 for ; Wed, 29 Jul 2020 09:56:12 +0200 (CEST) Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 359AA1001F3E for ; Wed, 29 Jul 2020 09:56:11 +0200 (CEST) Received: by mail-pg1-x541.google.com with SMTP id e8so13818850pgc.5 for ; Wed, 29 Jul 2020 00:56:11 -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 :mime-version:in-reply-to:references:content-transfer-encoding; bh=vmmvlsHnxjzxMFecyyy+6o/EmopCi3zhq0XjNZUKpr8=; b=yascx5fQCuOj6Hh96SWuBoaq9yPUzIasAu0LB40hnkMW6j79x1vN90WonKllDyfhJn 4CALDeBaJV+TCRu94/YeS1+O3/hXTRjFnmr1cwE3ATluMwDnGhl8Jahedi0fRzaOUCF5 Z5AJ8/WZgnBvNt/qCCN+9iNYAZQeqmtmFA7QaWQ6Z+M+IsPmn5bqWgherQuRm5hKgNlv O6DOSPB64BBGJbOOaNllGESIQiuhfVg9y7Ufx7K0WIeqYrCg12Y9Ocp5b9kL4uNy56VC 4KSCR3yywUwfZIK25NIF2DXIBKF5AR9MdZQVK/zWrgdFseVfNPlxyA/3u4QhG1iQdHzY BqKw== 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:mime-version:in-reply-to:references :content-transfer-encoding; bh=vmmvlsHnxjzxMFecyyy+6o/EmopCi3zhq0XjNZUKpr8=; b=FkUGy/w3wk3npRE0RImQlYvvrERH3ZXb0KERnBNt6DgADT3gh4eWq9eytIWtkmYsMr uqLDwyYxbR7a73Tzg/X4g+k+gHV4a+ao+lZVJ3LMvgxhPoF9l+FnR6JLuNb5aygYX8yw vtqjNMT4ehulam52jomphfSzi6qIgWOA0QJjLUkOOVcsS4Km8y144/gbNqKZ5J7t3TB7 qAFzB3m2JCvg8JnqMLV4ykZ8xL2ZvTRrJbiXJdACtTyUeIqwKBMEQ2cdM3ogLF0Bw/tm MzVSquo1FAZWT3X7xrKOsqCzWcXvtKP3fxT/4LPdC90mR3SqX2GpZSAYxCFrQ4guiSNL wvQA== X-Gm-Message-State: AOAM531W75UocVc8bFu3TqF1NybMJkEmgnjngQojThNEvPUAw0Sgw6lv rdpYMuICwy8iTWoy8rJt/DwcBTafzWU= X-Google-Smtp-Source: ABdhPJxsnLG6E7kVzYMSljMWH1Cn1sqBq33Hw3TMa1Z8Yn1JpuoyshQ4EdloeSkVhLb8JPaXaXSA8A== X-Received: by 2002:a63:b74f:: with SMTP id w15mr29035208pgt.314.1596009369084; Wed, 29 Jul 2020 00:56:09 -0700 (PDT) Received: from localhost ([106.215.77.228]) by smtp.gmail.com with ESMTPSA id n24sm1278675pfa.125.2020.07.29.00.56.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jul 2020 00:56:08 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Wed, 29 Jul 2020 13:25:50 +0530 Message-Id: <0b21c4b180da1679a4cbe6233634028a01514c43.1596008484.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.99.2 at in-4.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_HELO_NONE,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] [PATCH V8 2/5] syscalls: semop: Do code cleanup X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This gets rid of not so useful stuff like unnecessary comments and uClinux support which isn't used anymore. Signed-off-by: Viresh Kumar --- testcases/kernel/syscalls/ipc/semop/semop01.c | 46 +---------- testcases/kernel/syscalls/ipc/semop/semop02.c | 31 +++----- testcases/kernel/syscalls/ipc/semop/semop03.c | 49 +----------- testcases/kernel/syscalls/ipc/semop/semop04.c | 50 ++---------- testcases/kernel/syscalls/ipc/semop/semop05.c | 105 ++------------------------ 5 files changed, 31 insertions(+), 250 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/semop/semop01.c b/testcases/kernel/syscalls/ipc/semop/semop01.c index bcb45fa69320..19607ee6d653 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop01.c +++ b/testcases/kernel/syscalls/ipc/semop/semop01.c @@ -1,39 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* Copyright (c) International Business Machines Corp., 2001 */ - /* - * NAME - * semop01.c - * - * DESCRIPTION - * semop01 - test that semop() basic functionality is correct - * - * ALGORITHM - * create a semaphore set and initialize some values - * loop if that option was specified - * call semop() to set values for the primitive semaphores - * check the return code - * if failure, issue a FAIL message. - * otherwise, - * if doing functionality testing - * get the semaphore values and compare with expected values - * if correct, - * issue a PASS message - * otherwise - * issue a FAIL message - * else issue a PASS message - * call cleanup + * Test that semop() basic functionality is correct * - * HISTORY - * 03/2001 - Written by Wayne Boyer + * Copyright (c) International Business Machines Corp., 2001 + * 03/2001 - Written by Wayne Boyer * 17/01/02 - Modified. Manoj Iyer, IBM Austin. TX. manjo@austin.ibm.com - * 4th argument to semctl() system call was modified according - * to man pages. - * In my opinion The test should not even have compiled but - * it was working due to some mysterious reason. - * - * RESTRICTIONS - * none */ #include @@ -57,14 +28,9 @@ static void run(void) int i; TEST(semop(sem_id, sops, NSEMS)); - if (TST_RET == -1) { tst_res(TFAIL | TTERRNO, "semop() failed"); } else { - /* - * Get the values and make sure they are the same as what was - * set - */ if (semctl(sem_id, 0, GETALL, get_arr) == -1) { tst_brk(TBROK | TERRNO, "semctl() failed in functional test"); } @@ -80,13 +46,9 @@ static void run(void) tst_res(TPASS, "semaphore values are correct"); } - /* - * clean up things in case we are looping - */ for (i = 0; i < NSEMS; i++) { - if (semctl(sem_id, i, SETVAL, arr) == -1) { + if (semctl(sem_id, i, SETVAL, arr) == -1) tst_brk(TBROK | TERRNO, "semctl failed"); - } } } diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c index f24d284776a4..66b0bef56257 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop02.c +++ b/testcases/kernel/syscalls/ipc/semop/semop02.c @@ -1,16 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* Copyright (c) International Business Machines Corp., 2001 */ - /* - * DESCRIPTION - * semop02 - test for E2BIG, EACCES, EFAULT, EINVAL and ERANGE errors + * semop02 - test for E2BIG, EACCES, EFAULT, EINVAL and ERANGE errors * - * HISTORY + * Copyright (c) International Business Machines Corp., 2001 * 03/2001 - Written by Wayne Boyer - * - * 10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com) - * - Fix concurrency issue. The second key used for this test could - * conflict with the key from another task. + * 10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com) */ #define _GNU_SOURCE @@ -27,21 +21,21 @@ static int bad_id = -1; static key_t semkey; static struct sembuf s_buf[PSEMS]; -#define NSOPS 5 /* a resonable number of operations */ +#define NSOPS 5 /* a reasonable number of operations */ #define BIGOPS 1024 /* a value that is too large for the number */ - /* of semop operations that are permitted */ + /* of semop operations that are permitted */ static struct test_case_t { int *semid; struct sembuf *t_sbuf; unsigned t_ops; int error; } tc[] = { - {&sem_id_1, (struct sembuf *)&s_buf, BIGOPS, E2BIG}, - {&sem_id_2, (struct sembuf *)&s_buf, NSOPS, EACCES}, + {&sem_id_1, s_buf, BIGOPS, E2BIG}, + {&sem_id_2, s_buf, NSOPS, EACCES}, {&sem_id_1, (struct sembuf *)-1, NSOPS, EFAULT}, - {&sem_id_1, (struct sembuf *)&s_buf, 0, EINVAL}, - {&bad_id, (struct sembuf *)&s_buf, NSOPS, EINVAL}, - {&sem_id_1, (struct sembuf *)&s_buf, 1, ERANGE} + {&sem_id_1, s_buf, 0, EINVAL}, + {&bad_id, s_buf, NSOPS, EINVAL}, + {&sem_id_1, s_buf, 1, ERANGE} }; static void setup(void) @@ -55,18 +49,14 @@ static void setup(void) ltpuser = SAFE_GETPWNAM(nobody_uid); SAFE_SETUID(ltpuser->pw_uid); - /* get an IPC resource key */ semkey = GETIPCKEY(); - /* create a semaphore set with read and alter permissions */ sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); if (sem_id_1 == -1) tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); - /* Get an new IPC resource key. */ semkey2 = GETIPCKEY(); - /* create a semaphore set without read and alter permissions */ sem_id_2 = semget(semkey2, PSEMS, IPC_CREAT | IPC_EXCL); if (sem_id_2 == -1) tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); @@ -75,7 +65,6 @@ static void setup(void) if (semctl(sem_id_1, 0, IPC_INFO, arr) == -1) tst_brk(TBROK | TERRNO, "semctl() IPC_INFO failed"); - /* for ERANGE errno test */ arr.val = 1; s_buf[0].sem_op = ipc_buf.semvmx; if (semctl(sem_id_1, 0, SETVAL, arr) == -1) diff --git a/testcases/kernel/syscalls/ipc/semop/semop03.c b/testcases/kernel/syscalls/ipc/semop/semop03.c index 4f5f78eb6d8d..c569033eebc2 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop03.c +++ b/testcases/kernel/syscalls/ipc/semop/semop03.c @@ -1,37 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* Copyright (c) International Business Machines Corp., 2001 */ - /* - * NAME - * semop03.c - * - * DESCRIPTION - * semop03 - test for EFBIG error - * - * ALGORITHM - * create a semaphore set with read and alter permissions - * loop if that option was specified - * call semop() using two different invalid cases - * check the errno value - * issue a PASS message if we get EFBIG - * otherwise, the tests fails - * issue a FAIL message - * call cleanup - * - * USAGE: - * semop03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * semop03 - test for EFBIG error * - * HISTORY + * Copyright (c) International Business Machines Corp., 2001 * 03/2001 - Written by Wayne Boyer - * - * RESTRICTIONS - * none */ #include @@ -47,22 +19,11 @@ static int tc[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas static void run(unsigned int i) { - /* initialize two fields in the sembuf structure here */ - s_buf.sem_op = 1; /* add this value to struct sem.semval */ - s_buf.sem_flg = SEM_UNDO; /* undo when process exits */ - - /* - * initialize the last field in the sembuf structure to the test - * dependent value. - */ + s_buf.sem_op = 1; + s_buf.sem_flg = SEM_UNDO; s_buf.sem_num = tc[i]; - /* - * use the TEST macro to make the call - */ - TEST(semop(sem_id, &s_buf, 1)); - if (TST_RET != -1) { tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); return; @@ -80,10 +41,8 @@ static void run(unsigned int i) static void setup(void) { - /* get an IPC resource key */ semkey = GETIPCKEY(); - /* create a semaphore with read and alter permissions */ if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); diff --git a/testcases/kernel/syscalls/ipc/semop/semop04.c b/testcases/kernel/syscalls/ipc/semop/semop04.c index 0faf00a3585f..1904b177f71b 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop04.c +++ b/testcases/kernel/syscalls/ipc/semop/semop04.c @@ -1,37 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* Copyright (c) International Business Machines Corp., 2001 */ - /* - * NAME - * semop04.c - * - * DESCRIPTION - * semop04 - test for EAGAIN error - * - * ALGORITHM - * create a semaphore set with read and alter permissions - * loop if that option was specified - * call semop() with two different invalid cases - * check the errno value - * issue a PASS message if we get EAGAIN - * otherwise, the tests fails - * issue a FAIL message - * call cleanup + * semop04 - test for EAGAIN error * - * USAGE: - * semop04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY + * Copyright (c) International Business Machines Corp., 2001 * 03/2001 - Written by Wayne Boyer - * - * RESTRICTIONS - * none */ #include @@ -40,7 +12,7 @@ #include "lapi/semun.h" static int sem_id = -1; -static int val; /* value for SETVAL */ +static int val; static key_t semkey; static struct sembuf s_buf; @@ -52,22 +24,16 @@ static struct test_case_t { short num; int error; } tc[] = { - /* EAGAIN sem_op = 0 */ - { { - 1}, 0, IPC_NOWAIT, 2, EAGAIN}, - /* EAGAIN sem_op = -1 */ - { { - 0}, -1, IPC_NOWAIT, 2, EAGAIN} + {{1}, 0, IPC_NOWAIT, 2, EAGAIN}, + {{0}, -1, IPC_NOWAIT, 2, EAGAIN} }; static void run(unsigned int i) { - /* initialize the s_buf buffer */ s_buf.sem_op = tc[i].op; s_buf.sem_flg = tc[i].flg; s_buf.sem_num = tc[i].num; - /* initialize all the primitive semaphores */ tc[i].get_arr.val = val--; if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1) tst_brk(TBROK | TERRNO, "semctl() failed"); @@ -87,14 +53,8 @@ static void run(unsigned int i) static void setup(void) { val = 1; - - /* get an IPC resource key */ semkey = GETIPCKEY(); - /* - * create a semaphore set with read and alter permissions and PSEMS - * "primitive" semaphores. - */ if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) { tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); diff --git a/testcases/kernel/syscalls/ipc/semop/semop05.c b/testcases/kernel/syscalls/ipc/semop/semop05.c index 9e8e040b0b19..df8ce7d16ee5 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop05.c +++ b/testcases/kernel/syscalls/ipc/semop/semop05.c @@ -1,47 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* Copyright (c) International Business Machines Corp., 2001 */ - /* - * NAME - * semop05.c - * - * DESCRIPTION - * semop05 - test for EINTR and EIDRM errors - * - * ALGORITHM - * create a semaphore set with read and alter permissions - * loop if that option was specified - * set up the s_buf buffer - * initialize the primitive semaphores - * fork a child process - * child calls semop() and sleeps - * parent either removes the semaphore set or sends a signal to the child - * parent then exits - * child gets a return from the semop() call - * check the errno value - * issue a PASS message if we get EINTR or EIDRM - * otherwise, the tests fails - * issue a FAIL message - * call cleanup + * semop05 - test for EINTR and EIDRM errors * - * USAGE: - * semop05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY + * Copyright (c) International Business Machines Corp., 2001 * 03/2001 - Written by Wayne Boyer - * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr) - * - Fix concurrency issue. Due to the use of usleep function to - * synchronize processes, synchronization issues can occur on a loaded - * system. Fix this by using pipes to synchronize processes. - * - * RESTRICTIONS - * none + * 14/03/2008 Matthieu Fertré (Matthieu.Fertre@irisa.fr) */ #include @@ -64,26 +27,12 @@ struct test_case_t { short num; int error; } tc[] = { - /* EIRDM sem_op = 0 */ - { { - 1}, 0, 0, 2, EIDRM}, - /* EIRDM sem_op = -1 */ - { { - 0}, -1, 0, 3, EIDRM}, - /* EINTR sem_op = 0 */ - { { - 1}, 0, 0, 4, EINTR}, - /* EINTR sem_op = -1 */ - { { - 0}, -1, 0, 5, EINTR} + {{1}, 0, 0, 2, EIDRM}, + {{0}, -1, 0, 3, EIDRM}, + {{1}, 0, 0, 4, EINTR}, + {{0}, -1, 0, 5, EINTR} }; -#ifdef UCLINUX -#define PIPE_NAME "semop05" -static void do_child_uclinux(); -static int i_uclinux; -#endif - static inline int process_state_wait2(pid_t pid, const char state) { char proc_path[128], cur_state; @@ -138,14 +87,8 @@ static void sighandler(int sig) static void setup(void) { SAFE_SIGNAL(SIGHUP, sighandler); - - /* get an IPC resource key */ semkey = GETIPCKEY(); - /* - * create a semaphore set with read and alter permissions and PSEMS - * "primitive" semaphores. - */ if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); @@ -165,27 +108,17 @@ static void run(unsigned int i) { pid_t pid; -#ifdef UCLINUX - maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id); -#endif - /* initialize the s_buf buffer */ s_buf.sem_op = tc[i].op; s_buf.sem_flg = tc[i].flg; s_buf.sem_num = tc[i].num; - /* initialize all of the primitive semaphores */ if (semctl(sem_id, tc[i].num, SETVAL, tc[i].semunptr) == -1) tst_brk(TBROK | TERRNO, "semctl() failed"); pid = SAFE_FORK(); - if (pid == 0) { /* child */ -#ifdef UCLINUX - if (self_exec(av[0], "dd", i, sem_id) < 0) - tst_brk(TBROK, "could not self_exec"); -#else + if (pid == 0) { do_child(i); -#endif } else { process_state_wait2(pid, 'S'); @@ -202,13 +135,9 @@ static void run(unsigned int i) SAFE_KILL(pid, SIGHUP); } - /* let the child carry on */ waitpid(pid, NULL, 0); } - /* - * recreate the semaphore resource if needed - */ if (tc[i].error == EINTR) return; @@ -217,24 +146,6 @@ static void run(unsigned int i) tst_brk(TBROK | TERRNO, "couldn't recreate semaphore"); } -#ifdef UCLINUX -/* - * do_child_uclinux() - capture signals, re-initialize s_buf then call do_child - * with the appropriate argument - */ -static void do_child_uclinux(void) -{ - int i = i_uclinux; - - /* initialize the s_buf buffer */ - s_buf.sem_op = tc[i].op; - s_buf.sem_flg = tc[i].flg; - s_buf.sem_num = tc[i].num; - - do_child(i); -} -#endif - static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), From patchwork Wed Jul 29 07:55:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1338179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=JutG4ORo; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGm8L4hBFz9sRN for ; Wed, 29 Jul 2020 17:56:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 18DAF3C2682 for ; Wed, 29 Jul 2020 09:56:32 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 778D93C5D1C for ; Wed, 29 Jul 2020 09:56:20 +0200 (CEST) Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 961891A01CA9 for ; Wed, 29 Jul 2020 09:56:19 +0200 (CEST) Received: by mail-pl1-x62b.google.com with SMTP id p1so11450505pls.4 for ; Wed, 29 Jul 2020 00:56:19 -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 :in-reply-to:references; bh=ivKz2CzLlRgAxixB7Doq8b+aBZ0XFvi2rrcRCU1MzW0=; b=JutG4ORo/bRW6EJKuSlVq52/P52K2d0m14eG8klj0HOSWEDvLGQ8DIK8oS9+dEn50P aea0pgLBd4hIUeanoPitmiJmsUQlf+gaDkDXna3N2JjnD3odIC8/u0yYPQsRALUGfAdq Ib7C3hmpLDiSJGtcL326gP55iTPzcxGLXbNgtpNnQmU18Krw8gqHEMqlDWh4IS1+BSH7 EC0b4HHKKeKRJ7KZf2Fnl+6SK3IUqFj1PZchhuPeOfIubiMiXYcI08BuNXT8Pb6t9p7J myPLdrux70IaCNJ7Vm2KXrohKgRw3zLnCgXEkYIRg56gqw4VMkP0VxPRF4JuF5tpOthS qyAg== 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:in-reply-to:references; bh=ivKz2CzLlRgAxixB7Doq8b+aBZ0XFvi2rrcRCU1MzW0=; b=Zh8Mxmm9PwmdHVSwAk2cWXjR/1CJuBPybJNS9GPWtt2zTi89SdB5usmYz1+RR1y+id mq+e3PBqvRDQrqbO2CKyoQfXsKUnNsbhTt6drRi/aGrK2Ik5O8wvvMXPKzIiK949vLPf eXU92cpZpJleqqw9JkLl1JaqIn0dVITFqSTnWNr4F3NKLCcM5vTY8HrinY+Xoj1Wm0a0 BeT14lGqPXXR8DM80KdQZy0uHIQEvENw9T5RqN8wbo1qndztjwaWa56VZL5Lzt+BTQUl ggGpWRwlE4OWvx1LJ9gI2SsWu+/mzIHlHBx8nZnF1uXDC9L9Rk0i/A9KXJJH6oDR8lMm xEEw== X-Gm-Message-State: AOAM530EQsYrhlwh5A6vOXMPr6DgXaa6DWW61+Njj7rTw05Ss9mdQabG oxBVPv//udOXtO4XzUeh+Sbvlbvs9gM= X-Google-Smtp-Source: ABdhPJwyec7rW1sQgLmPua30P7S3XkHSwg9aZjsJGLzjv5Cz2WD4tfGsq9WCggd0u1ZJxBFCga9bSg== X-Received: by 2002:a17:90a:1589:: with SMTP id m9mr8896662pja.122.1596009376629; Wed, 29 Jul 2020 00:56:16 -0700 (PDT) Received: from localhost ([106.215.77.228]) by smtp.gmail.com with ESMTPSA id t73sm1335517pfc.78.2020.07.29.00.56.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jul 2020 00:56:16 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Wed, 29 Jul 2020 13:25:51 +0530 Message-Id: <56d89f2356cf51135c3b6d9219745cbe3868dec8.1596008484.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.99.2 at in-3.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_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH V8 3/5] syscalls: semop: Merge semop0[234].c files X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" All these can be handled together in semop02.c easily. Signed-off-by: Viresh Kumar --- runtest/syscalls | 2 - runtest/syscalls-ipc | 2 - testcases/kernel/syscalls/ipc/semop/.gitignore | 2 - testcases/kernel/syscalls/ipc/semop/semop02.c | 47 ++++++++++----- testcases/kernel/syscalls/ipc/semop/semop03.c | 67 --------------------- testcases/kernel/syscalls/ipc/semop/semop04.c | 80 -------------------------- 6 files changed, 34 insertions(+), 166 deletions(-) delete mode 100644 testcases/kernel/syscalls/ipc/semop/semop03.c delete mode 100644 testcases/kernel/syscalls/ipc/semop/semop04.c diff --git a/runtest/syscalls b/runtest/syscalls index 70b3277d38ea..99831f6aa36e 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1169,8 +1169,6 @@ semget06 semget06 semop01 semop01 semop02 semop02 -semop03 semop03 -semop04 semop04 semop05 semop05 send01 send01 diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc index c3a35896c5a8..1a63071b22cf 100644 --- a/runtest/syscalls-ipc +++ b/runtest/syscalls-ipc @@ -44,8 +44,6 @@ semget06 semget06 semop01 semop01 semop02 semop02 -semop03 semop03 -semop04 semop04 semop05 semop05 shmat01 shmat01 diff --git a/testcases/kernel/syscalls/ipc/semop/.gitignore b/testcases/kernel/syscalls/ipc/semop/.gitignore index cc67b1862f41..35b7af66c465 100644 --- a/testcases/kernel/syscalls/ipc/semop/.gitignore +++ b/testcases/kernel/syscalls/ipc/semop/.gitignore @@ -1,5 +1,3 @@ /semop01 /semop02 -/semop03 -/semop04 /semop05 diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c index 66b0bef56257..7a49b2648b2b 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop02.c +++ b/testcases/kernel/syscalls/ipc/semop/semop02.c @@ -18,24 +18,37 @@ static int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ static int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ static int bad_id = -1; +static short sem_op_dyn, sem_op_1 = 1, sem_op_negative = -1, sem_op_zero = 0; static key_t semkey; static struct sembuf s_buf[PSEMS]; +static struct sembuf *faulty_buf; +static struct sembuf *valid_buf = s_buf; +static union semun arr; #define NSOPS 5 /* a reasonable number of operations */ #define BIGOPS 1024 /* a value that is too large for the number */ /* of semop operations that are permitted */ static struct test_case_t { int *semid; - struct sembuf *t_sbuf; + struct sembuf **buf; + short *sem_op; /* semaphore operation */ + unsigned short ctl_sem_num; + unsigned short sem_num; /* semaphore index in array */ + short sem_flg; /* operation flags */ unsigned t_ops; + int arr_val; int error; } tc[] = { - {&sem_id_1, s_buf, BIGOPS, E2BIG}, - {&sem_id_2, s_buf, NSOPS, EACCES}, - {&sem_id_1, (struct sembuf *)-1, NSOPS, EFAULT}, - {&sem_id_1, s_buf, 0, EINVAL}, - {&bad_id, s_buf, NSOPS, EINVAL}, - {&sem_id_1, s_buf, 1, ERANGE} + {&sem_id_1, &valid_buf, &sem_op_dyn, 0, 0, 0, BIGOPS, 1, E2BIG}, + {&sem_id_2, &valid_buf, &sem_op_dyn, 0, 0, 0, NSOPS, 1, EACCES}, + {&sem_id_1, &faulty_buf, &sem_op_dyn, 0, 0, 0, NSOPS, 1, EFAULT}, + {&sem_id_1, &valid_buf, &sem_op_dyn, 0, 0, 0, 0, 1, EINVAL}, + {&bad_id, &valid_buf, &sem_op_dyn, 0, 0, 0, NSOPS, 1, EINVAL}, + {&sem_id_1, &valid_buf, &sem_op_dyn, 0, 0, 0, 1, 1, ERANGE}, + {&sem_id_1, &valid_buf, &sem_op_1, 0, -1, SEM_UNDO, 1, 1, EFBIG}, + {&sem_id_1, &valid_buf, &sem_op_1, 0, PSEMS + 1, SEM_UNDO, 1, 1, EFBIG}, + {&sem_id_1, &valid_buf, &sem_op_zero, 2, 2, IPC_NOWAIT, 1, 1, EAGAIN}, + {&sem_id_1, &valid_buf, &sem_op_negative, 2, 2, IPC_NOWAIT, 1, 0, EAGAIN} }; static void setup(void) @@ -44,7 +57,6 @@ static void setup(void) struct passwd *ltpuser; key_t semkey2; struct seminfo ipc_buf; - union semun arr; ltpuser = SAFE_GETPWNAM(nobody_uid); SAFE_SETUID(ltpuser->pw_uid); @@ -65,15 +77,24 @@ static void setup(void) if (semctl(sem_id_1, 0, IPC_INFO, arr) == -1) tst_brk(TBROK | TERRNO, "semctl() IPC_INFO failed"); - arr.val = 1; - s_buf[0].sem_op = ipc_buf.semvmx; - if (semctl(sem_id_1, 0, SETVAL, arr) == -1) - tst_brk(TBROK | TERRNO, "semctl() SETVAL failed"); + sem_op_dyn = ipc_buf.semvmx; + faulty_buf = tst_get_bad_addr(NULL); } static void run(unsigned int i) { - TEST(semop(*(tc[i].semid), tc[i].t_sbuf, tc[i].t_ops)); + if (*tc[i].buf != faulty_buf) { + arr.val = tc[i].arr_val; + + if (semctl(sem_id_1, tc[i].ctl_sem_num, SETVAL, arr) == -1) + tst_brk(TBROK | TERRNO, "semctl() SETVAL failed"); + + s_buf[0].sem_op = *tc[i].sem_op; + s_buf[0].sem_flg = tc[i].sem_flg; + s_buf[0].sem_num = tc[i].sem_num; + } + + TEST(semop(*(tc[i].semid), *tc[i].buf, tc[i].t_ops)); if (TST_RET != -1) { tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); diff --git a/testcases/kernel/syscalls/ipc/semop/semop03.c b/testcases/kernel/syscalls/ipc/semop/semop03.c deleted file mode 100644 index c569033eebc2..000000000000 --- a/testcases/kernel/syscalls/ipc/semop/semop03.c +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * semop03 - test for EFBIG error - * - * Copyright (c) International Business Machines Corp., 2001 - * 03/2001 - Written by Wayne Boyer - */ - -#include -#include "tst_test.h" -#include "libnewipc.h" -#include "lapi/semun.h" - -static key_t semkey; -static int sem_id = -1; -static struct sembuf s_buf; - -static int tc[] = { -1, PSEMS + 1 }; /* negative and too many "primitive" semas */ - -static void run(unsigned int i) -{ - s_buf.sem_op = 1; - s_buf.sem_flg = SEM_UNDO; - s_buf.sem_num = tc[i]; - - TEST(semop(sem_id, &s_buf, 1)); - if (TST_RET != -1) { - tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); - return; - } - - switch (TST_ERR) { - case EFBIG: - tst_res(TPASS | TTERRNO, "expected failure"); - break; - default: - tst_res(TFAIL | TTERRNO, "unexpected failure"); - break; - } -} - -static void setup(void) -{ - semkey = GETIPCKEY(); - - if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == - -1) - tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); -} - -static void cleanup(void) -{ - union semun arr; - - if (sem_id != -1) { - if (semctl(sem_id, 0, IPC_RMID, arr) == -1) - tst_res(TINFO, "WARNING: semaphore deletion failed."); - } -} - -static struct tst_test test = { - .test = run, - .tcnt = ARRAY_SIZE(tc), - .setup = setup, - .cleanup = cleanup, - .needs_tmpdir = 1, -}; diff --git a/testcases/kernel/syscalls/ipc/semop/semop04.c b/testcases/kernel/syscalls/ipc/semop/semop04.c deleted file mode 100644 index 1904b177f71b..000000000000 --- a/testcases/kernel/syscalls/ipc/semop/semop04.c +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * semop04 - test for EAGAIN error - * - * Copyright (c) International Business Machines Corp., 2001 - * 03/2001 - Written by Wayne Boyer - */ - -#include -#include "tst_test.h" -#include "libnewipc.h" -#include "lapi/semun.h" - -static int sem_id = -1; -static int val; - -static key_t semkey; -static struct sembuf s_buf; - -static struct test_case_t { - union semun get_arr; - short op; - short flg; - short num; - int error; -} tc[] = { - {{1}, 0, IPC_NOWAIT, 2, EAGAIN}, - {{0}, -1, IPC_NOWAIT, 2, EAGAIN} -}; - -static void run(unsigned int i) -{ - s_buf.sem_op = tc[i].op; - s_buf.sem_flg = tc[i].flg; - s_buf.sem_num = tc[i].num; - - tc[i].get_arr.val = val--; - if (semctl(sem_id, tc[i].num, SETVAL, tc[i].get_arr) == -1) - tst_brk(TBROK | TERRNO, "semctl() failed"); - - TEST(semop(sem_id, &s_buf, 1)); - if (TST_RET != -1) { - tst_res(TFAIL, "call succeeded unexpectedly"); - return; - } - - if (TST_ERR == tc[i].error) - tst_res(TPASS | TTERRNO, "expected failure"); - else - tst_res(TFAIL | TTERRNO, "unexpected failure"); -} - -static void setup(void) -{ - val = 1; - semkey = GETIPCKEY(); - - if ((sem_id = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == - -1) { - tst_brk(TBROK | TERRNO, "couldn't create semaphore in setup"); - } -} - -static void cleanup(void) -{ - union semun arr; - - if (sem_id != -1) { - if (semctl(sem_id, 0, IPC_RMID, arr) == -1) - tst_res(TINFO, "WARNING: semaphore deletion failed."); - } -} - -static struct tst_test test = { - .test = run, - .tcnt = ARRAY_SIZE(tc), - .setup = setup, - .cleanup = cleanup, - .needs_tmpdir = 1, -}; From patchwork Wed Jul 29 07:55:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1338181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=a5Wq4z2q; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGm8Z1kJGz9sRN for ; Wed, 29 Jul 2020 17:56:46 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 648453C268F for ; Wed, 29 Jul 2020 09:56:43 +0200 (CEST) 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 2651B3C262F for ; Wed, 29 Jul 2020 09:56:24 +0200 (CEST) Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (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 757A4601256 for ; Wed, 29 Jul 2020 09:55:00 +0200 (CEST) Received: by mail-pf1-x442.google.com with SMTP id l2so6197721pff.0 for ; Wed, 29 Jul 2020 00:56:23 -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 :in-reply-to:references; bh=RitYU0ehHkqriGtt4zAr4TgW2fwdbw7+LsITx25shOw=; b=a5Wq4z2qzAh1jC/hH1y+8ug6dmv7Hha94uyVeecsmfJZUzekIP2LptIlDANhvYpCNP VvIWuDs0C0o4nzg+KRSFYZT38LXcLHAq0P/S+K4hv4Na55kd+0i9tgvQzg/DM0MEAnWc bW3mOMnIuHSBeYn/oeBLc2ukaoagOKzyXVl86UIPbdDPKiCsXYbe0iPzvQx7uLJ8nXzC mvlJqRHrrPALjmK5YhLMxxsLEXr/38tU3cNw8MtCmN9WSrtQkfx75zTID9EwZj16sQBp 9kSR8Vn60X2OQIHEb0AzQshUs6SxCogTR95ipHtkMN5Po65aRC/i38kIYApMZuRD8vJF Ch5Q== 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:in-reply-to:references; bh=RitYU0ehHkqriGtt4zAr4TgW2fwdbw7+LsITx25shOw=; b=Ks78Prf2OeC+j3ZSjcQk9orFmkngevuxsjMe9k6m7Ymxu+NP31c8sQhPtGTN3Fwo/u 5/i7jAeLR7zZMpUKZZc7D9TpsdpZebR3eF5He6KNgwNmldJVygE6Dsa6MyICGccqyTHZ 7+kniOKW2GYf1aqqBrL+QU6almja3KlTS2QqwySIIVLxks6ioK3c+899BV3BkUIFOhlj NLZmsfLUR849iWEXjdl6T21PiAXt1U3yF0wvW+KlSLX+GV7B9LdX3sG+oWyNTqcvdt4k WamDmcRt0z/QZDCtQe59XExehOJx8f4JHAcfPC1vp+FRa6GieCou4i3ItkvA1gFlz6wf 2FYQ== X-Gm-Message-State: AOAM530CIPvt+ItMLdwlTVahetV3DIqpU3nGA8UF2QaTT7b2uv3oe9BD vg+vSxxZXKZKdq4XRgdBdpEmUZjU3vI= X-Google-Smtp-Source: ABdhPJz5/BsymkmRcKpKMejMkoOGdG6PsSKPcNvrR4XzOZjaRUPtsoef383NEGWECeYWxhZMLIQ2yg== X-Received: by 2002:aa7:9d0e:: with SMTP id k14mr4384806pfp.162.1596009380500; Wed, 29 Jul 2020 00:56:20 -0700 (PDT) Received: from localhost ([106.215.77.228]) by smtp.gmail.com with ESMTPSA id y6sm1359453pfr.61.2020.07.29.00.56.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jul 2020 00:56:20 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Wed, 29 Jul 2020 13:25:52 +0530 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: 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_HELO_NONE,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 Subject: [LTP] [PATCH V8 4/5] syscalls: semop: Rename semop05.c X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Rename it to semop03.c. Signed-off-by: Viresh Kumar --- runtest/syscalls | 2 +- runtest/syscalls-ipc | 2 +- testcases/kernel/syscalls/ipc/semop/.gitignore | 2 +- testcases/kernel/syscalls/ipc/semop/{semop05.c => semop03.c} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename testcases/kernel/syscalls/ipc/semop/{semop05.c => semop03.c} (100%) diff --git a/runtest/syscalls b/runtest/syscalls index 99831f6aa36e..7bbf3a76611f 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1169,7 +1169,7 @@ semget06 semget06 semop01 semop01 semop02 semop02 -semop05 semop05 +semop03 semop03 send01 send01 diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc index 1a63071b22cf..690ccb214b15 100644 --- a/runtest/syscalls-ipc +++ b/runtest/syscalls-ipc @@ -44,7 +44,7 @@ semget06 semget06 semop01 semop01 semop02 semop02 -semop05 semop05 +semop03 semop03 shmat01 shmat01 shmat02 shmat02 diff --git a/testcases/kernel/syscalls/ipc/semop/.gitignore b/testcases/kernel/syscalls/ipc/semop/.gitignore index 35b7af66c465..bb57f08afda8 100644 --- a/testcases/kernel/syscalls/ipc/semop/.gitignore +++ b/testcases/kernel/syscalls/ipc/semop/.gitignore @@ -1,3 +1,3 @@ /semop01 /semop02 -/semop05 +/semop03 diff --git a/testcases/kernel/syscalls/ipc/semop/semop05.c b/testcases/kernel/syscalls/ipc/semop/semop03.c similarity index 100% rename from testcases/kernel/syscalls/ipc/semop/semop05.c rename to testcases/kernel/syscalls/ipc/semop/semop03.c From patchwork Wed Jul 29 07:55:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 1338182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=I0NhozcJ; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGm8l2sf1z9sRN for ; Wed, 29 Jul 2020 17:56:55 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D99C73C4C0E for ; Wed, 29 Jul 2020 09:56:52 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 45EFD3C5A22 for ; Wed, 29 Jul 2020 09:56:28 +0200 (CEST) Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 693EC1A01D2B for ; Wed, 29 Jul 2020 09:56:27 +0200 (CEST) Received: by mail-pg1-x544.google.com with SMTP id o13so13854326pgf.0 for ; Wed, 29 Jul 2020 00:56:27 -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 :in-reply-to:references; bh=3LRze7MFfQTHFPjWzmxLRYkouAjBOBpw/vjSrhPWDYk=; b=I0NhozcJ/hQyiS9n4UFFHGUsJK96MwtYyHLu30qXQixN3m6KXHRktd8SyeKDKrzB4b 2fUgf2ox21kh5AvhCfXw5ZVoo3Olerh9BWJi8U7CKh//0SWurx3yo3TlmaHvfHbmMubP 6j6NslD0Cgpi4LLkLsNSoicifKkleLAfjZdgwDLtQVnhN6Ayqp/hfO13XJ5Q0tpYZDRL u4yQ2FX9Kl43MspTQfJTPP44jMeGUrSxIwKkhUF9ekIAFKQYok6LMHEWqnxqfFQU9zNa oA5rOgDFJApg+BtEaswADuBcMR6k173Ugq0VnDAGzagxZTwJzRF+LGLS3XVBj3Lzvgt5 Z0hA== 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:in-reply-to:references; bh=3LRze7MFfQTHFPjWzmxLRYkouAjBOBpw/vjSrhPWDYk=; b=GlOm4yDWAt2RltcoeQrOW/LdCe6vAeib0dJvQC3EO185kEvZYDVr4EQ6BukmKoCNWd bbcRceLa8KO+bCDjF7gbSiHm+8mQpJ2Klo9VFyQT94Pz9sswSXBxcKuM/XXK0q2vwxex rne2Q9ggMmNPw7yKLSc9+Jx4L1INLq1gP6c5nj+ef6J6w1ZikEHUnDKirDu6xPUIMKhy IyQ6DP88chaTHjbNMviwJiSxjSYoQJp2vLvuaimuukexZA3MXBEyxfigRVEa08Cf3UXD LwNUDa402v+CH5KezP22vcYIzbjF7ZVOyUepVJnHLHWF93QhCfIiV2/AKD+N0YXe4psa tXrg== X-Gm-Message-State: AOAM531tpOgTn+weMJJUmkWHVIvuOgD3bxlKaVjwczZXGySIwCN6i6bR mpLGbPxLq/G1EXBS1GN1uCxlPgz9LRc= X-Google-Smtp-Source: ABdhPJwfGe79uvVByO+fsqF4zqzkbJQ8eyHqobRoFauTak/R2BEP+bK5DLXPSUDj5SBw0ztA++txJw== X-Received: by 2002:a05:6a00:158b:: with SMTP id u11mr27845539pfk.92.1596009385432; Wed, 29 Jul 2020 00:56:25 -0700 (PDT) Received: from localhost ([106.215.77.228]) by smtp.gmail.com with ESMTPSA id 76sm1361472pfu.139.2020.07.29.00.56.24 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jul 2020 00:56:24 -0700 (PDT) From: Viresh Kumar To: ltp@lists.linux.it Date: Wed, 29 Jul 2020 13:25:53 +0530 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.99.2 at in-3.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_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH V8 5/5] syscalls/semtimedop: Add support for semtimedop and its time64 version X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This adds support for semtimedop() and its time64 variant to the existing semop() syscall tests. Signed-off-by: Viresh Kumar --- testcases/kernel/syscalls/ipc/semop/semop.h | 55 +++++++++++++++++++++++++++ testcases/kernel/syscalls/ipc/semop/semop01.c | 14 ++++++- testcases/kernel/syscalls/ipc/semop/semop02.c | 15 +++++++- testcases/kernel/syscalls/ipc/semop/semop03.c | 16 +++++++- 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/semop/semop.h diff --git a/testcases/kernel/syscalls/ipc/semop/semop.h b/testcases/kernel/syscalls/ipc/semop/semop.h new file mode 100644 index 000000000000..584d12c68e0d --- /dev/null +++ b/testcases/kernel/syscalls/ipc/semop/semop.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef SEMOP_VAR__ +#define SEMOP_VAR__ + +#include +#include "tst_timer.h" + +static inline int sys_semtimedop(int semid, struct sembuf *sops, size_t nsops, + void *timeout) +{ + return tst_syscall(__NR_semtimedop, semid, sops, nsops, timeout); +} + +static inline int sys_semtimedop_time64(int semid, struct sembuf *sops, + size_t nsops, void *timeout) +{ + return tst_syscall(__NR_semtimedop_time64, semid, sops, nsops, timeout); +} + +struct test_variants { + int (*semop)(int semid, struct sembuf *sops, size_t nsops); + int (*semtimedop)(int semid, struct sembuf *sops, size_t nsops, void *timeout); + enum tst_ts_type type; + char *desc; +} variants[] = { + { .semop = semop, .type = TST_LIBC_TIMESPEC, .desc = "semop: vDSO or syscall"}, + +#if (__NR_semtimedop != __LTP__NR_INVALID_SYSCALL) + { .semtimedop = sys_semtimedop, .type = TST_KERN_OLD_TIMESPEC, .desc = "semtimedop: syscall with old kernel spec"}, +#endif + +#if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL) + { .semtimedop = sys_semtimedop_time64, .type = TST_KERN_TIMESPEC, .desc = "semtimedop: syscall time64 with kernel spec"}, +#endif +}; + +static inline int call_semop(struct test_variants *tv, int semid, + struct sembuf *sops, size_t nsops, struct tst_ts *timeout) +{ + if (tv->semop) + return tv->semop(semid, sops, nsops); + + return tv->semtimedop(semid, sops, nsops, tst_ts_get(timeout)); +} + +static inline void semop_supported_by_kernel(struct test_variants *tv) +{ + /* Check if the syscall is implemented on the platform */ + TEST(call_semop(tv, 0, NULL, 0, NULL)); + if (TST_RET == -1 && TST_ERR == ENOSYS) + tst_brk(TCONF, "Test not supported on kernel/platform"); +} + +#endif /* SEMOP_VAR__ */ diff --git a/testcases/kernel/syscalls/ipc/semop/semop01.c b/testcases/kernel/syscalls/ipc/semop/semop01.c index 19607ee6d653..c3443da58af4 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop01.c +++ b/testcases/kernel/syscalls/ipc/semop/semop01.c @@ -12,6 +12,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" #define NSEMS 4 /* the number of primitive semaphores to test */ @@ -23,11 +24,17 @@ static struct sembuf sops[PSEMS]; static void run(void) { + struct test_variants *tv = &variants[tst_variant]; union semun arr = { .val = 0 }; + struct tst_ts timeout; int fail = 0; int i; - TEST(semop(sem_id, sops, NSEMS)); + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + + TEST(call_semop(tv, sem_id, sops, NSEMS, &timeout)); if (TST_RET == -1) { tst_res(TFAIL | TTERRNO, "semop() failed"); } else { @@ -54,8 +61,12 @@ static void run(void) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; int i; + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + get_arr.array = malloc(sizeof(unsigned short int) * PSEMS); if (get_arr.array == NULL) tst_brk(TBROK, "malloc failed"); @@ -86,6 +97,7 @@ static void cleanup(void) static struct tst_test test = { .test_all = run, + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, diff --git a/testcases/kernel/syscalls/ipc/semop/semop02.c b/testcases/kernel/syscalls/ipc/semop/semop02.c index 7a49b2648b2b..1b9b768f5e63 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop02.c +++ b/testcases/kernel/syscalls/ipc/semop/semop02.c @@ -14,6 +14,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static int sem_id_1 = -1; /* a semaphore set with read & alter permissions */ static int sem_id_2 = -1; /* a semaphore set without read & alter permissions */ @@ -53,11 +54,15 @@ static struct test_case_t { static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; char nobody_uid[] = "nobody"; struct passwd *ltpuser; key_t semkey2; struct seminfo ipc_buf; + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + ltpuser = SAFE_GETPWNAM(nobody_uid); SAFE_SETUID(ltpuser->pw_uid); @@ -83,6 +88,13 @@ static void setup(void) static void run(unsigned int i) { + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; + + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + if (*tc[i].buf != faulty_buf) { arr.val = tc[i].arr_val; @@ -94,7 +106,7 @@ static void run(unsigned int i) s_buf[0].sem_num = tc[i].sem_num; } - TEST(semop(*(tc[i].semid), *tc[i].buf, tc[i].t_ops)); + TEST(call_semop(tv, *(tc[i].semid), *tc[i].buf, tc[i].t_ops, &timeout)); if (TST_RET != -1) { tst_res(TFAIL | TTERRNO, "call succeeded unexpectedly"); @@ -127,6 +139,7 @@ static void cleanup(void) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1, diff --git a/testcases/kernel/syscalls/ipc/semop/semop03.c b/testcases/kernel/syscalls/ipc/semop/semop03.c index df8ce7d16ee5..d0fea1ed1dd5 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop03.c +++ b/testcases/kernel/syscalls/ipc/semop/semop03.c @@ -15,6 +15,7 @@ #include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static key_t semkey; static int sem_id = -1; @@ -64,7 +65,14 @@ static inline int process_state_wait2(pid_t pid, const char state) static void do_child(int i) { - TEST(semop(sem_id, &s_buf, 1)); + struct test_variants *tv = &variants[tst_variant]; + struct tst_ts timeout; + + timeout.type = tv->type; + tst_ts_set_sec(&timeout, 1); + tst_ts_set_nsec(&timeout, 10000); + + TEST(call_semop(tv, sem_id, &s_buf, 1, &timeout)); if (TST_RET != -1) { tst_res(TFAIL, "call succeeded when error expected"); exit(-1); @@ -86,6 +94,11 @@ static void sighandler(int sig) static void setup(void) { + struct test_variants *tv = &variants[tst_variant]; + + tst_res(TINFO, "Testing variant: %s", tv->desc); + semop_supported_by_kernel(tv); + SAFE_SIGNAL(SIGHUP, sighandler); semkey = GETIPCKEY(); @@ -149,6 +162,7 @@ static void run(unsigned int i) static struct tst_test test = { .test = run, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir = 1,