Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2179212rdb; Tue, 3 Oct 2023 12:43:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETzEJq69gO08gqj+lv0vwKo9xJpwKqbXeQ1lBToK646xEpqh3u+p/nSUgH36FwV18ti2BR X-Received: by 2002:a05:6830:3d09:b0:6b7:5687:8a9e with SMTP id eu9-20020a0568303d0900b006b756878a9emr259259otb.15.1696362230857; Tue, 03 Oct 2023 12:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696362230; cv=none; d=google.com; s=arc-20160816; b=047edcez67G/09hlGi/2KDqn/l78BQFDTXqbI/LqATDc+Xc4LF2Q5gu+sEk6jKA3yW Jicc5Jrl1sJymFkIT+g30qqj0sFd01uJVEmFM61SzinRb6hmxyAumtTai3tqorKcStpP Ts3jS46VMo1PsnoIIEqfleOoNQLR0UwSLin5IJc3sdulZQA0xRO8A/OrKmbqHBDGc8sq sSny58RgUZBWQF0SsWS80cECzmfF9NSE4Rs79XhMUNwhJiwLcKlaNNsYRhmPI4+8VQvB IgSyXR1h/k5SPQMNMr/GiMDXo3KxYVzZ6W+ZT1AIypK4utaVPXtol2cqMFNTKQKwfbET o57g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MbdHdhO4/8XQFhe6TXvhjzuMCQeWe1W0DXY8haIPqBM=; fh=k+B2xWjqMlLlsFAH07Y2GELuFDk86a3eGq1Y2r3rKDc=; b=ybbjD6VUlebMYejjLRUeZIyqW6jlYhwZopZy3yaetVNdTZXpko9VusArdpr/7+a/WP KLNZLzR17WJnpLhY783EpgkOfR1rwRxvXkn+AUiku6MYMArBqsx8KAswwgnptrlN0QGJ tI/zwKrdDh7PCGq2fai+lUeUmb9CPPGi5Qkr4LutPH28HzvETRHMP0uEa/0a4ftzzvGD o0DZ8FZB0EaG5UDHqkOc7JGxJUL01n3bh95EsNcjm50GfFUmoq3SFQJRjNaK+jqj148E pbsrKPYdI08psjAekj+FfWsJyTQFG4qtFlPtS6NkgHiCq93sz74rF34oJlQ0Zl/OrlH5 Y3zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WxJ3AYXt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l22-20020a63da56000000b00584af407e80si2013507pgj.293.2023.10.03.12.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:43:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WxJ3AYXt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8F2CB81A5AD3; Tue, 3 Oct 2023 12:43:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbjJCTng (ORCPT + 99 others); Tue, 3 Oct 2023 15:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjJCTnf (ORCPT ); Tue, 3 Oct 2023 15:43:35 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6332F93 for ; Tue, 3 Oct 2023 12:43:30 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bdf4752c3cso9618235ad.2 for ; Tue, 03 Oct 2023 12:43:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696362210; x=1696967010; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MbdHdhO4/8XQFhe6TXvhjzuMCQeWe1W0DXY8haIPqBM=; b=WxJ3AYXtIMg1vLvKxq21v3gu5ISmxMMRNS2lOFCiqM3k5uIHxya0gM2VoBt1TltyyV fAXm6af5nMm+63TU0XPuN3zwObIgjQ26daRciMWMzqiS+jYhMznRLY+AQasrO0FH3zgt 3nOUIqeaK5sufackU/6NI9BmI3IbOzNNUn5YFN40kiqNMjYU9eZRxWPohqC22yapoELs uet2BWPFfc0mxSv2YXtSf2G9xYaGUgNU5py1TNGQYj3aKq0D6Iu40RvBQ46D5nMY8Ffz 7mzYnHTFge5k6bR7hKrOyKwrfgWrSXTX6RRolUsS/XibWrjvoBd6oGiRdIdC58hqZ6Ao R5mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696362210; x=1696967010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MbdHdhO4/8XQFhe6TXvhjzuMCQeWe1W0DXY8haIPqBM=; b=w+MUgtWX9qOqX14+iR8yWx4+OkB/AsfV5WJ1dUobtIN0NSWAZSKay6Pm8bbOy/1qt2 0kX6TvY54/k1eNwnLulvm5zXpVrgikOOUf4CjOjK2i+WebazxxqbLawKJU66KNYOPPzT 0PxTl0mzxWXGrJBgM1xPmQkAFvz80P3AeAbM3Sg5O5nRvtHxnLoc18eHh1/zcCjtLXBg aLwQApJoqFwKwQZs8jtauBOBFHOJMdO50EKTmQGjwZHH3E80TvLLSh8h/0136FlK1MFd QvFp7/DKFuj0EXs2Ij6BI+40fGoYWADWDlxwb1Opr9Q+M1tEBH4MWPW9d2hBHK/+xU+c 7STg== X-Gm-Message-State: AOJu0YzIPxkb7wo5h8MxBR++O5DJiyasTfvqGoD8zbf6SmTeFRRlCwmA dJ1wTdVrhrKQoUEexGu/kUo= X-Received: by 2002:a17:902:d4cd:b0:1c4:3294:74ca with SMTP id o13-20020a170902d4cd00b001c4329474camr590332plg.17.1696362209640; Tue, 03 Oct 2023 12:43:29 -0700 (PDT) Received: from swarup-virtual-machine.localdomain ([171.76.87.78]) by smtp.gmail.com with ESMTPSA id l8-20020a170903244800b001bc2831e1a9sm1989965pls.90.2023.10.03.12.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:43:29 -0700 (PDT) From: Swarup Laxman Kotiaklapudi To: adobriyan@gmail.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, shuah@kernel.org, hughd@google.com, linux-kernel-mentees@lists.linuxfoundation.org Cc: swarupkotikalapudi@gmail.com Subject: [PATCH v2] selftests:proc Add /proc/$(pid)/statm output validation Date: Wed, 4 Oct 2023 01:13:19 +0530 Message-Id: <20231003194319.602646-1-swarupkotikalapudi@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 03 Oct 2023 12:43:48 -0700 (PDT) Add /proc/${pid}/statm validation /proc/$(pid)/statm output is expected to be: "0 0 0 * 0 0 0\n" Here * can be any value Read output of /proc/$(pid)/statm and check except for 4th position, all other positions have value zero. Signed-off-by: Swarup Laxman Kotiaklapudi --- Changes in V2: - 4th field if zero it will assert - field other than 4th field is checked for zero value - clean up of function test_proc_pid_statm() Changes in V1: - added new function test_proc_pid_statm() tools/testing/selftests/proc/proc-empty-vm.c | 57 ++++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/proc/proc-empty-vm.c b/tools/testing/selftests/proc/proc-empty-vm.c index b16c13688b88..1b5b48445e0f 100644 --- a/tools/testing/selftests/proc/proc-empty-vm.c +++ b/tools/testing/selftests/proc/proc-empty-vm.c @@ -302,6 +302,56 @@ static int test_proc_pid_smaps_rollup(pid_t pid) } } +static int test_proc_pid_statm(pid_t pid) +{ + char buf[4096]; + char *tok; + char *string; + int non_zero_value_indx = 4; + int i = 1; + + snprintf(buf, sizeof(buf), "/proc/%u/statm", pid); + + /* + * Output can be "0 0 0 2 0 0 0\n" where "2" can be anything. + */ + int fd = open(buf, O_RDONLY); + + if (fd == -1) { + if (errno == ENOENT) { + /* + * /proc/${pid}/statm is under CONFIG_PROC_PAGE_MONITOR, + * it doesn't necessarily exist. + */ + return EXIT_SUCCESS; + } + perror("open /proc/${pid}/statm"); + return EXIT_FAILURE; + } else { + ssize_t rv = read(fd, buf, sizeof(buf)); + + close(fd); + assert(rv); + string = buf; + + while ((tok = strsep(&string, " ")) != NULL) { + if (i == non_zero_value_indx) { + if (!strncmp(tok, "0", 1)) + goto err_statm; + } else { + if (strncmp(tok, "0", 1)) + goto err_statm; + } + i++; + } + } + + return EXIT_SUCCESS; + +err_statm: + assert(0); +} + int main(void) { int rv = EXIT_SUCCESS; @@ -388,11 +438,8 @@ int main(void) if (rv == EXIT_SUCCESS) { rv = test_proc_pid_smaps_rollup(pid); } - /* - * TODO test /proc/${pid}/statm, task_statm() - * ->start_code, ->end_code aren't updated by munmap(). - * Output can be "0 0 0 2 0 0 0\n" where "2" can be anything. - */ + if (rv == EXIT_SUCCESS) + rv = test_proc_pid_statm(pid); /* Cut the rope. */ int wstatus; -- 2.34.1