From patchwork Fri Feb 2 11:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542776 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0627BC47DB3 for ; Fri, 2 Feb 2024 11:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15BCE6B0099; Fri, 2 Feb 2024 06:31:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B7756B009B; Fri, 2 Feb 2024 06:31:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7D46B009C; Fri, 2 Feb 2024 06:31:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BC66E6B0099 for ; Fri, 2 Feb 2024 06:31:51 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 950F8120E69 for ; Fri, 2 Feb 2024 11:31:51 +0000 (UTC) X-FDA: 81746649222.15.7A7CB4C Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf24.hostedemail.com (Postfix) with ESMTP id 7C83A18001F for ; Fri, 2 Feb 2024 11:31:49 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=4iURJocn; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf24.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873509; a=rsa-sha256; cv=none; b=Phk6gnkKA5Uk3kp7oasZ17fB5zDC9D4jzD/Cc+cnt1XK2t6ZyJ1/+NbNoB5tpkavRhzK7/ el9tsTKkUMaDYqIQsZAkyrhKTMrjXZLzh2sHEkgIgBAGCCh9V6dCDWP4vJpfXoZSq2OGEK x1y3cF12B3TIVuVyzcS8Pod/OrD3ie0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=4iURJocn; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf24.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873509; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=d6PKfMgckuxTwcBG16wC0ctq4RNtAQR5cQVEk/u50mQ=; b=k3dku6HcFRiZpVCJFXrGINfoV6w2q0nuHGkD8VdAeVD0M0ttQHEmvaIOBFkaglEdA4JWmV 271ZTBod5clVxR6OgKacQgIvJ/Y9VD01jzeDK52lBR4/bB0eSciGpq5yoZAGvcnDwuPUj7 /dz7aU1NYeP5UBM9WzoL3NLSc81afCc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873508; bh=Qz1hYpXZ0ZArWwJNMRoiOZt8O4/weesIABzDbZYxCC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=4iURJocnM0xIVlqP6lwnTgvP82VuqAWxM8CR5SMY9umKeiZMf+O641vLLvn4F9zVJ 0MCSIbL3dSV3Sdjefjzk8+pSzUgQU81mbDOekSG8RofKbOpDqwpjht66/FWqefPu8L tdbJRJ93MCoWbUWR8BxYzeWYCEHRT1GeEK1E6ygOlho2sW9g7IYvuknu0vFq62dxZh mp6wQotluB5pkXvZ8WQa+D7ZHiG3Mu5cPqjKq6+dI8d+8NgIHhSN/Ran+gadjQK6Wh TNsK6kLqZ7cI7qtN52hJN4RY/ypjQo1S/0wEb36trA41XeWHHGnD9C/2SpvjvPsVyp 2sLw1JjFkAcjA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (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) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 3A5DE37811CF; Fri, 2 Feb 2024 11:31:46 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/12] selftests/mm: thp_settings: conform to TAP format output Date: Fri, 2 Feb 2024 16:31:16 +0500 Message-ID: <20240202113119.2047740-10-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7C83A18001F X-Stat-Signature: rragcsqo13f8emyuwccb94ns71fd9fgm X-HE-Tag: 1706873509-357820 X-HE-Meta: U2FsdGVkX18XkHnH1L8XmwuQae+y1WUExJGSC1S/Z5XvH7HYMPVAlW8H1KQzP322XDK1PWlfd7Vg7wmj5j0NgG22XeS3GGFS/C/yD3Db5RRH1+BRgkFpHtO5q4d/7Db8yKl9Cd+AeoFe+jr0uUbKA909RTHKnBnVkxs86uw2WOdnFafqIp+BnyAIHkwRHek3KdN1mFvAGqJRqxifO0IroyDyaCR8oZ046C2MlFC6eug66/Qr5Zb54vBMKejUKttBsMGFS06YJK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@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/khugepaged.c | 3 +- tools/testing/selftests/mm/thp_settings.c | 123 ++++++++-------------- tools/testing/selftests/mm/thp_settings.h | 4 +- 3 files changed, 47 insertions(+), 83 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index d51fdaee7dc6a..3f202da0867c5 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -152,8 +152,7 @@ static void get_finfo(const char *dir) major(path_stat.st_dev), minor(path_stat.st_dev)) >= sizeof(path)) ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - if (read_file(path, buf, sizeof(buf)) < 0) - ksft_exit_fail_msg("read_file(read_num): %s\n", strerror(errno)); + read_file(path, buf, sizeof(buf)); if (strstr(buf, "DEVTYPE=disk")) { /* Found it */ diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/thp_settings.c index a4163438108ec..273a95d025285 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/thp_settings.c @@ -5,7 +5,9 @@ #include #include #include +#include +#include "../kselftest.h" #include "thp_settings.h" #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/" @@ -42,58 +44,45 @@ static const char * const shmem_enabled_strings[] = { NULL }; -int read_file(const char *path, char *buf, size_t buflen) +void read_file(const char *path, char *buf, size_t buflen) { int fd; ssize_t numread; fd = open(path, O_RDONLY); if (fd == -1) - return 0; + ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno)); numread = read(fd, buf, buflen - 1); if (numread < 1) { close(fd); - return 0; + ksft_exit_fail_msg("No data read\n"); } buf[numread] = '\0'; close(fd); - - return (unsigned int) numread; } -int write_file(const char *path, const char *buf, size_t buflen) +void write_file(const char *path, const char *buf, size_t buflen) { int fd; ssize_t numwritten; fd = open(path, O_WRONLY); - if (fd == -1) { - printf("open(%s)\n", path); - exit(EXIT_FAILURE); - return 0; - } + if (fd == -1) + ksft_exit_fail_msg("%s open failed\n", path); numwritten = write(fd, buf, buflen - 1); close(fd); - if (numwritten < 1) { - printf("write(%s)\n", buf); - exit(EXIT_FAILURE); - return 0; - } - - return (unsigned int) numwritten; + if (numwritten < 1) + ksft_exit_fail_msg("write failed (%s)\n", buf); } const unsigned long read_num(const char *path) { char buf[21]; - if (read_file(path, buf, sizeof(buf)) < 0) { - perror("read_file()"); - exit(EXIT_FAILURE); - } + read_file(path, buf, sizeof(buf)); return strtoul(buf, NULL, 10); } @@ -103,10 +92,7 @@ void write_num(const char *path, unsigned long num) char buf[21]; sprintf(buf, "%ld", num); - if (!write_file(path, buf, strlen(buf) + 1)) { - perror(path); - exit(EXIT_FAILURE); - } + write_file(path, buf, strlen(buf) + 1); } int thp_read_string(const char *name, const char * const strings[]) @@ -117,30 +103,22 @@ int thp_read_string(const char *name, const char * const strings[]) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - if (!read_file(path, buf, sizeof(buf))) { - perror(path); - exit(EXIT_FAILURE); - } + read_file(path, buf, sizeof(buf)); c = strchr(buf, '['); - if (!c) { - printf("%s: Parse failure\n", __func__); - exit(EXIT_FAILURE); - } + if (!c) + ksft_exit_fail_msg("%s: Parse failure\n", __func__); c++; memmove(buf, c, sizeof(buf) - (c - buf)); c = strchr(buf, ']'); - if (!c) { - printf("%s: Parse failure\n", __func__); - exit(EXIT_FAILURE); - } + if (!c) + ksft_exit_fail_msg("%s: Parse failure\n", __func__); + *c = '\0'; ret = 0; @@ -150,8 +128,8 @@ int thp_read_string(const char *name, const char * const strings[]) ret++; } - printf("Failed to parse %s\n", name); - exit(EXIT_FAILURE); + ksft_exit_fail_msg("Failed to parse %s\n", name); + return -1; } void thp_write_string(const char *name, const char *val) @@ -160,15 +138,10 @@ void thp_write_string(const char *name, const char *val) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - if (!write_file(path, val, strlen(val) + 1)) { - perror(path); - exit(EXIT_FAILURE); - } + write_file(path, val, strlen(val) + 1); } const unsigned long thp_read_num(const char *name) @@ -177,10 +150,9 @@ const unsigned long thp_read_num(const char *name) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); + return read_num(path); } @@ -190,10 +162,9 @@ void thp_write_num(const char *name, unsigned long num) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); + write_num(path, num); } @@ -275,29 +246,26 @@ void thp_write_settings(struct thp_settings *settings) struct thp_settings *thp_current_settings(void) { - if (!settings_index) { - printf("Fail: No settings set"); - exit(EXIT_FAILURE); - } + if (!settings_index) + ksft_exit_fail_msg("Fail: No settings set\n"); + return settings_stack + settings_index - 1; } void thp_push_settings(struct thp_settings *settings) { - if (settings_index >= MAX_SETTINGS_DEPTH) { - printf("Fail: Settings stack exceeded"); - exit(EXIT_FAILURE); - } + if (settings_index >= MAX_SETTINGS_DEPTH) + ksft_exit_fail_msg("Fail: Settings stack exceeded\n"); + settings_stack[settings_index++] = *settings; thp_write_settings(thp_current_settings()); } void thp_pop_settings(void) { - if (settings_index <= 0) { - printf("Fail: Settings stack empty"); - exit(EXIT_FAILURE); - } + if (settings_index <= 0) + ksft_exit_fail_msg("Fail: Settings stack empty\n"); + --settings_index; thp_write_settings(thp_current_settings()); } @@ -335,14 +303,11 @@ unsigned long thp_supported_orders(void) for (i = 0; i < NR_ORDERS; i++) { ret = snprintf(path, PATH_MAX, THP_SYSFS "hugepages-%ukB/enabled", (getpagesize() >> 10) << i); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - ret = read_file(path, buf, sizeof(buf)); - if (ret) - orders |= 1UL << i; + read_file(path, buf, sizeof(buf)); + orders |= 1UL << i; } return orders; diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h index 71cbff05f4c7f..04a6a7bbd08f8 100644 --- a/tools/testing/selftests/mm/thp_settings.h +++ b/tools/testing/selftests/mm/thp_settings.h @@ -56,8 +56,8 @@ struct thp_settings { struct hugepages_settings hugepages[NR_ORDERS]; }; -int read_file(const char *path, char *buf, size_t buflen); -int write_file(const char *path, const char *buf, size_t buflen); +void read_file(const char *path, char *buf, size_t buflen); +void write_file(const char *path, const char *buf, size_t buflen); const unsigned long read_num(const char *path); void write_num(const char *path, unsigned long num);