From patchwork Wed Aug 9 13:18:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1819317 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=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=hzngr1Jw; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Kpjjvgk9; 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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RLVy75MGFz1yfB for ; Wed, 9 Aug 2023 23:19:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A524C3CD0D3 for ; Wed, 9 Aug 2023 15:19:09 +0200 (CEST) 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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id DB0313CACD6 for ; Wed, 9 Aug 2023 15:18:53 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id EB15964027B for ; Wed, 9 Aug 2023 15:18:52 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 771CA21853 for ; Wed, 9 Aug 2023 13:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691587132; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HYkBl4Vi+Xoc8Eezh2TBRey5ouix5YuWeeBRVrk8uZQ=; b=hzngr1JwKxhW4GpApsaCpIipxD6ofua10PTYjOIZ20VTYxTyOn3TtCIHQ0i7qJGt1m+SE5 /d1rAZsIbrGrOUpI0wppiWZtMPD/JhS8aOLuZX+TUmyjRg+fqe/PfXv3mIHQD0yNqve+PI fEBXJEiYYV9qYrFqdJnupn0fqkYNujY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691587132; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HYkBl4Vi+Xoc8Eezh2TBRey5ouix5YuWeeBRVrk8uZQ=; b=Kpjjvgk9wi18gt3ORFjaadgkdXihJQTDDrYXQILl5BG3xydER8KaAZ2SI5SV2uFHGN6XSp 8gDdP6oi/21xt+Dw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 28C3E13251 for ; Wed, 9 Aug 2023 13:18:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IKraADyS02TXCgAAMHmgww (envelope-from ) for ; Wed, 09 Aug 2023 13:18:52 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Wed, 9 Aug 2023 18:48:46 +0530 Message-ID: <20230809131847.10914-2-akumar@suse.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230809131847.10914-1-akumar@suse.de> References: <20230809131847.10914-1-akumar@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-2.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,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/2] sbrk02.c: Refactor the test using new LTP API 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Avinesh Kumar --- testcases/kernel/syscalls/sbrk/sbrk02.c | 101 ++++++------------------ 1 file changed, 26 insertions(+), 75 deletions(-) diff --git a/testcases/kernel/syscalls/sbrk/sbrk02.c b/testcases/kernel/syscalls/sbrk/sbrk02.c index 84744ef90..7fccc4d3a 100644 --- a/testcases/kernel/syscalls/sbrk/sbrk02.c +++ b/testcases/kernel/syscalls/sbrk/sbrk02.c @@ -1,101 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2014 Fujitsu Ltd. * Author: Zeng Linggang - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Copyright (c) 2023 SUSE LLC Avinesh Kumar */ -/* - * DESCRIPTION - * Check sbrk() with error condition that should produce ENOMEM. - */ - -#include -#include -#include "test.h" -#define INC 16*1024*1024 +/*\ + * [Description] + * + * Verify that sbrk() on failure sets errno to ENOMEM. + */ -char *TCID = "sbrk02"; -int TST_TOTAL = 1; -static void setup(void); -static void sbrk_verify(void); -static void cleanup(void); +#include "tst_test.h" +#define INC (16*1024*1024) static long increment = INC; -int main(int argc, char *argv[]) +static void run(void) { - int lc; - int i; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); + TESTPTR(sbrk(increment)); - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) - sbrk_verify(); + if (TST_RET_PTR != (void *)-1) { + tst_res(TFAIL, "sbrk(%ld) unexpectedly passed and returned %p, " + "expected (void *)-1 with errno=%d", + increment, TST_RET_PTR, ENOMEM); + return; } - cleanup(); - tst_exit(); + if (TST_ERR == ENOMEM) + tst_res(TPASS | TTERRNO, "sbrk(%ld) failed as expected", increment); + else + tst_res(TFAIL | TTERRNO, "sbrk(%ld) failed but unexpected errno, " + "expected errno=%d - %s", + increment, ENOMEM, strerror(ENOMEM)); } static void setup(void) { void *ret = NULL; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* call sbrk until it fails or increment overflows */ while (ret != (void *)-1 && increment > 0) { ret = sbrk(increment); increment += INC; } - tst_resm(TINFO | TERRNO, "setup() bailing inc: %ld, ret: %p, sbrk: %p", - increment, ret, sbrk(0)); - - errno = 0; -} - -static void sbrk_verify(void) -{ - void *tret; - - tret = sbrk(increment); - TEST_ERRNO = errno; - - if (tret != (void *)-1) { - tst_resm(TFAIL, - "sbrk(%ld) returned %p, expected (void *)-1, errno=%d", - increment, tret, ENOMEM); - return; - } - - if (TEST_ERRNO == ENOMEM) { - tst_resm(TPASS | TTERRNO, "sbrk(%ld) failed as expected", - increment); - } else { - tst_resm(TFAIL | TTERRNO, - "sbrk(%ld) failed unexpectedly; expected: %d - %s", - increment, ENOMEM, strerror(ENOMEM)); - } } -static void cleanup(void) -{ -} +static struct tst_test test = { + .test_all = run, + .setup = setup +};