From patchwork Wed Nov 16 03:49:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Gongyi X-Patchwork-Id: 1704285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NBpz76pB6z23mL for ; Wed, 16 Nov 2022 14:52:35 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 37A4C3CD199 for ; Wed, 16 Nov 2022 04:52:32 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C09433CAFBA for ; Wed, 16 Nov 2022 04:52:29 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 76C3F600A13 for ; Wed, 16 Nov 2022 04:52:26 +0100 (CET) Received: from canpemm500005.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NBpyK43jgzHvrg for ; Wed, 16 Nov 2022 11:51:53 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.63) by canpemm500005.china.huawei.com (7.192.104.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 11:52:23 +0800 To: Date: Wed, 16 Nov 2022 11:49:10 +0800 Message-ID: <20221116034910.37030-1-zhaogongyi@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.63] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500005.china.huawei.com (7.192.104.229) X-CFilter-Loop: Reflected X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH] syscalls/nice01: Add test nice(-1) and nice(-50) 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: , X-Patchwork-Original-From: Zhao Gongyi via ltp From: Zhao Gongyi Reply-To: Zhao Gongyi Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 1. Add test verify that the errno is zero when callling of nice legitimately return -1.(nice(-1), the default nice is usally 0) 2. Add test verify that user of root can decrease the nice value of the process successfully by passing a lower increment value (< min. applicable limits) to nice() system call.(nice(-50)) Signed-off-by: Zhao Gongyi --- testcases/kernel/syscalls/nice/nice01.c | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/testcases/kernel/syscalls/nice/nice01.c b/testcases/kernel/syscalls/nice/nice01.c index 876246180..bc022a265 100644 --- a/testcases/kernel/syscalls/nice/nice01.c +++ b/testcases/kernel/syscalls/nice/nice01.c @@ -17,29 +17,31 @@ #include #include "tst_test.h" -#define NICEINC -12 -#define MIN_PRIO -20 +#define MIN_PRIO -20 -static void verify_nice(void) +static int nice_inc[] = {-1, -12, -50}; + +static void verify_nice(unsigned int i) { int new_nice; int orig_nice; int exp_nice; + int inc = nice_inc[i]; orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0); - TEST(nice(NICEINC)); + TEST(nice(inc)); - exp_nice = MAX(MIN_PRIO, (orig_nice + NICEINC)); + exp_nice = MAX(MIN_PRIO, (orig_nice + inc)); if (TST_RET != exp_nice) { tst_res(TFAIL | TTERRNO, "nice(%d) returned %li, expected %i", - NICEINC, TST_RET, exp_nice); + inc, TST_RET, exp_nice); return; } if (TST_ERR) { - tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC); + tst_res(TFAIL | TTERRNO, "nice(%d) failed", inc); return; } @@ -47,18 +49,19 @@ static void verify_nice(void) if (new_nice != exp_nice) { tst_res(TFAIL, "Process priority %i, expected %i", - new_nice, orig_nice + NICEINC); + new_nice, exp_nice); return; } - tst_res(TPASS, "nice(%d) passed", NICEINC); + tst_res(TPASS, "nice(%d) passed", inc); - TEST(nice(-NICEINC)); + TEST(setpriority(PRIO_PROCESS, 0, orig_nice)); if (TST_ERR) - tst_brk(TBROK | TTERRNO, "nice(%d) failed", -NICEINC); + tst_brk(TBROK | TTERRNO, "setpriority(%d) failed", orig_nice); } static struct tst_test test = { - .test_all = verify_nice, .needs_root = 1, + .test = verify_nice, + .tcnt = ARRAY_SIZE(nice_inc), };