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),