From patchwork Mon Dec 20 13:10:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1571039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=OjbID88G; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JHg2Z5bylz9sCD for ; Tue, 21 Dec 2021 00:11:17 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4A02F3C9175 for ; Mon, 20 Dec 2021 14:11:13 +0100 (CET) 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]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 140DA3C0B96 for ; Mon, 20 Dec 2021 14:11:11 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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-4.smtp.seeweb.it (Postfix) with ESMTPS id 6348A100115B for ; Mon, 20 Dec 2021 14:11:11 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8913F1F381; Mon, 20 Dec 2021 13:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640005870; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Pnl6jgot6NNUHpAxZqsAI61lTgsYbYexc0mjxmnoPFw=; b=OjbID88G4FwyrTVIH+tY7HXQKv1OShdpaxXDmDkigmqw0Pg+wFyUwvyewc9JiAX/9XXe/k LpA22U/rOJ8EwT1CdNYt4Q/IVpcngj8kxuqWO5G5OL1I46Qsgn5BfGJVhp6fa6jj/5YXFp ce70kIeNhw3xdvS8vYcxw80LLYiIWHA= Received: from g78.suse.de (unknown [10.163.24.42]) by relay2.suse.de (Postfix) with ESMTP id 56F76A3B81; Mon, 20 Dec 2021 13:11:10 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 20 Dec 2021 13:10:41 +0000 Message-Id: <20211220131043.18894-1-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 1/3] API/cgroup: Add safe_cgroup_lines_scanf 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Similar to file_lines_scanf. Allows us to read a particular key-value pair from a controller file. Can replace kselftest's cg_read_key_* when converting tests. Signed-off-by: Richard Palethorpe Reviewed-by: Cyril Hrubis --- include/tst_cgroup.h | 12 +++++++++++- lib/tst_cgroup.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h index 632050e86..561216296 100644 --- a/include/tst_cgroup.h +++ b/include/tst_cgroup.h @@ -188,9 +188,19 @@ void safe_cgroup_printf(const char *const file, const int lineno, void safe_cgroup_scanf(const char *file, const int lineno, const struct tst_cgroup_group *const cg, const char *const file_name, - const char *fmt, ...) + const char *const fmt, ...) __attribute__ ((format (scanf, 5, 6), nonnull)); +#define SAFE_CGROUP_LINES_SCANF(cg, file_name, fmt, ...) \ + safe_cgroup_lines_scanf(__FILE__, __LINE__, \ + (cg), (file_name), (fmt), __VA_ARGS__) + +void safe_cgroup_lines_scanf(const char *const file, const int lineno, + const struct tst_cgroup_group *const cg, + const char *const file_name, + const char *const fmt, ...) + __attribute__ ((format (scanf, 5, 6), nonnull)); + #define SAFE_CGROUP_OCCURSIN(cg, file_name, needle) \ safe_cgroup_occursin(__FILE__, __LINE__, \ (cg), (file_name), (needle)) diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index c08ff2f20..961596256 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -1161,6 +1161,39 @@ void safe_cgroup_scanf(const char *const file, const int lineno, file_name, buf, fmt, ret, conv_cnt); } +void safe_cgroup_lines_scanf(const char *const file, const int lineno, + const struct tst_cgroup_group *const cg, + const char *const file_name, + const char *const fmt, ...) +{ + va_list va; + char buf[BUFSIZ]; + ssize_t len = safe_cgroup_read(file, lineno, + cg, file_name, buf, sizeof(buf)); + const int conv_cnt = tst_count_scanf_conversions(fmt); + int ret = 0; + char *line; + + if (len < 1) + return; + + line = strtok(buf, "\n"); + while (line && ret != conv_cnt) { + va_start(va, fmt); + ret = vsscanf(line, fmt, va); + va_end(va); + + line = strtok(NULL, "\n"); + } + + if (conv_cnt == ret) + return; + + tst_brk_(file, lineno, TBROK, + "'%s': vsscanf('%s', '%s', ..): Less conversions than expected: %d != %d", + file_name, buf, fmt, ret, conv_cnt); +} + int safe_cgroup_occursin(const char *const file, const int lineno, const struct tst_cgroup_group *const cg, const char *const file_name, From patchwork Mon Dec 20 13:10:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1571041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=bAumr9kp; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JHg2v6Wygz9sCD for ; Tue, 21 Dec 2021 00:11:35 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E621C3C916A for ; Mon, 20 Dec 2021 14:11:32 +0100 (CET) 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 [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 28B193C915D for ; Mon, 20 Dec 2021 14:11:11 +0100 (CET) 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-4.smtp.seeweb.it (Postfix) with ESMTPS id 7E941100119C for ; Mon, 20 Dec 2021 14:11:11 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D54ED212C2; Mon, 20 Dec 2021 13:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640005870; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=34iGibGZeZewa2hFIZVMSJM4C3h4SeIHSk/6Mk5FFtc=; b=bAumr9kp6Ru5O0I52wQZ8rbT8J6HQ8qgV/meJIHqz4SF80MBBdDNEkFE5c7M5DkL95Szvj n4I01B/d9mjObcqP3BspKpzlwmr9xYpavN73gKqs/LPZLcT284oMLA5uIrocqYniv9G3FR 2DZgEK+NV9x/SfLIfxTWcy0+FmBlQA4= Received: from g78.suse.de (unknown [10.163.24.42]) by relay2.suse.de (Postfix) with ESMTP id 9879FA3B81; Mon, 20 Dec 2021 13:11:10 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 20 Dec 2021 13:10:42 +0000 Message-Id: <20211220131043.18894-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211220131043.18894-1-rpalethorpe@suse.com> References: <20211220131043.18894-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 2/3] API/cgroup: Add memory.stat 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Richard Palethorpe Reviewed-by: Cyril Hrubis --- lib/tst_cgroup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c index 961596256..cda1d39f7 100644 --- a/lib/tst_cgroup.c +++ b/lib/tst_cgroup.c @@ -153,6 +153,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { static const struct cgroup_file memory_ctrl_files[] = { { "memory.current", "memory.usage_in_bytes", CTRL_MEMORY }, { "memory.max", "memory.limit_in_bytes", CTRL_MEMORY }, + { "memory.stat", "memory.stat", CTRL_MEMORY }, { "memory.swappiness", "memory.swappiness", CTRL_MEMORY }, { "memory.swap.current", "memory.memsw.usage_in_bytes", CTRL_MEMORY }, { "memory.swap.max", "memory.memsw.limit_in_bytes", CTRL_MEMORY }, From patchwork Mon Dec 20 13:10:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1571040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=qt8Wn+fT; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JHg2k63Rsz9sCD for ; Tue, 21 Dec 2021 00:11:26 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2B9B93C9169 for ; Mon, 20 Dec 2021 14:11:23 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 243133C6EA0 for ; Mon, 20 Dec 2021 14:11:12 +0100 (CET) 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-5.smtp.seeweb.it (Postfix) with ESMTPS id 85FDB600F10 for ; Mon, 20 Dec 2021 14:11:11 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 2A89D218F3; Mon, 20 Dec 2021 13:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640005871; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yEE8+Qu4pdp/7+VEAL7BYTtjssyqim93rR+z0Cxp0UM=; b=qt8Wn+fTZHs3CR1D1CRLxZrmnwaibg/zm10aHwCrdf3gF0OyqFul8cSBaoT/Nl6mHkNB1v DEs0+nfVap1veYMEU1YiZepVpUMHzx9d2eEKLXnPR9fpq1eU6oCPArFozDrkh6TcHKuCdD IUM9qNTBrBUiubBRKvyFKpDL7pYSpq4= Received: from g78.suse.de (unknown [10.163.24.42]) by relay2.suse.de (Postfix) with ESMTP id ED951A3B85; Mon, 20 Dec 2021 13:11:10 +0000 (UTC) To: ltp@lists.linux.it Date: Mon, 20 Dec 2021 13:10:43 +0000 Message-Id: <20211220131043.18894-3-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211220131043.18894-1-rpalethorpe@suse.com> References: <20211220131043.18894-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 3/3] cgroup: Add memcontrol02 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Conversion of the second kself test. Signed-off-by: Richard Palethorpe --- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../kernel/controllers/memcg/memcontrol02.c | 151 ++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/memcontrol02.c diff --git a/runtest/controllers b/runtest/controllers index 2b41a94d3..09e0107e4 100644 --- a/runtest/controllers +++ b/runtest/controllers @@ -18,6 +18,7 @@ memcg_control memcg_control_test.sh # kselftest ports memcontrol01 memcontrol01 +memcontrol02 memcontrol02 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset diff --git a/testcases/kernel/controllers/memcg/.gitignore b/testcases/kernel/controllers/memcg/.gitignore index c3565f85c..f7de40d53 100644 --- a/testcases/kernel/controllers/memcg/.gitignore +++ b/testcases/kernel/controllers/memcg/.gitignore @@ -6,3 +6,4 @@ /regression/memcg_test_4 /stress/memcg_process_stress memcontrol01 +memcontrol02 diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c new file mode 100644 index 000000000..002637db0 --- /dev/null +++ b/testcases/kernel/controllers/memcg/memcontrol02.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0 +/*\ + * + * [Description] + * + * Conversion of second kself test in cgroup/test_memcontrol.c. + * + * This test creates a memory cgroup, allocates some anonymous memory + * and some pagecache and check memory.current and some memory.stat + * values. + * + * Note that the V1 rss and cache counters were renamed to anon and + * file in V2. Besides error reporting, this test mainly differs from + * the kselftest in that it supports V1. + */ +#define _GNU_SOURCE + +#include +#include + +#include "tst_test.h" +#include "tst_cgroup.h" + +#define MB(x) (x << 20) + +static size_t page_size; +static const struct tst_cgroup_group *cg_test; +static int is_v1_memcg; +static struct tst_cgroup_group *cg_child; +static int fd; + +/* + * Checks if two given values differ by less than err% of their sum. + */ +static inline int values_close(const ssize_t a, + const ssize_t b, + const ssize_t err) +{ + return labs(a - b) <= (a + b) / 100 * err; +} + +static void alloc_anon_50M_check(void) +{ + const ssize_t size = MB(50); + char *buf, *ptr; + ssize_t anon, current; + const char *const anon_key_fmt = is_v1_memcg ? "rss %zd" : "anon %zd"; + + buf = SAFE_MALLOC(size); + for (ptr = buf; ptr < buf + size; ptr += page_size) + *ptr = 0; + + SAFE_CGROUP_SCANF(cg_child, "memory.current", "%zd", ¤t); + TST_EXP_POSITIVE(current >= size, + "(memory.current=%zd) >= (size=%zd)", current, size); + + SAFE_CGROUP_LINES_SCANF(cg_child, "memory.stat", anon_key_fmt, &anon); + + TST_EXP_POSITIVE(anon > 0, "(memory.stat.anon=%zd) > 0", anon); + + TST_EXP_POSITIVE(values_close(size, current, 3), + "(size=%zd) ~= (memory.stat.anon=%zd)", size, current); + TST_EXP_POSITIVE(values_close(anon, current, 3), + "(memory.current=%zd) ~= (memory.stat.anon=%zd)", + current, anon); +} + +static void alloc_pagecache(const int fd, size_t size) +{ + char buf[BUFSIZ]; + struct stat st; + size_t i; + + SAFE_FSTAT(fd, &st); + size += st.st_size; + + SAFE_FTRUNCATE(fd, size); + + for (i = 0; i < size; i += sizeof(buf)) + SAFE_READ(0, fd, buf, sizeof(buf)); +} + +static void alloc_pagecache_50M_check(void) +{ + const size_t size = MB(50); + size_t current, file; + const char *const file_key_fmt = is_v1_memcg ? "cache %zd" : "file %zd"; + + fd = SAFE_OPEN("page_cache", O_RDWR | O_CREAT); + alloc_pagecache(fd, size); + + SAFE_CGROUP_SCANF(cg_child, "memory.current", "%zu", ¤t); + TST_EXP_POSITIVE(current >= size, + "(memory.current=%zu) >= (size=%zu)", current, size); + + SAFE_CGROUP_LINES_SCANF(cg_child, "memory.stat", file_key_fmt, &file); + TST_EXP_POSITIVE(file > 0, "(memory.stat.file=%zd) > 0", file); + + TST_EXP_POSITIVE(values_close(file, current, 10), + "(memory.current=%zd) ~= (memory.stat.file=%zd)", + current, file); + + SAFE_CLOSE(fd); +} + +static void test_memcg_current(unsigned int n) +{ + size_t current; + + cg_child = tst_cgroup_group_mk(cg_test, "child"); + SAFE_CGROUP_SCANF(cg_child, "memory.current", "%zu", ¤t); + TST_EXP_POSITIVE(current == 0, "(current=%zu) == 0", current); + + if (!SAFE_FORK()) { + SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid()); + if (!n) + alloc_anon_50M_check(); + else + alloc_pagecache_50M_check(); + } else { + tst_reap_children(); + cg_child = tst_cgroup_group_rm(cg_child); + } +} + +static void setup(void) +{ + page_size = SAFE_SYSCONF(_SC_PAGESIZE); + + tst_cgroup_require("memory", NULL); + cg_test = tst_cgroup_get_test_group(); + + is_v1_memcg = TST_CGROUP_VER(cg_test, "memory") == TST_CGROUP_V1; +} + +static void cleanup(void) +{ + if (cg_child) + cg_child = tst_cgroup_group_rm(cg_child); + + tst_cgroup_cleanup(); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .tcnt = 2, + .test = test_memcg_current, + .needs_tmpdir = 1, + .forks_child = 1, +}; From patchwork Thu Dec 30 10:37:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1574138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=KDUmG4KI; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JPl8x1dhXz9sRK for ; Thu, 30 Dec 2021 21:37:53 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BEB933C2B0E for ; Thu, 30 Dec 2021 11:37:50 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 1A2FB3C0BA7 for ; Thu, 30 Dec 2021 11:37:38 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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-3.smtp.seeweb.it (Postfix) with ESMTPS id 5538E1A00A28 for ; Thu, 30 Dec 2021 11:37:38 +0100 (CET) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DFB7E1F37D; Thu, 30 Dec 2021 10:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1640860657; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tDrlg63aYaYp4lQyECEMO94a5pm+D5a+6bqGtj2RcjA=; b=KDUmG4KImc0XJ7TGJNxXtZOwsW8pKtTFgA08F07KAJMYkCkEIRdI7F4Z2huwyiBIKRxndp H46GRcDQMTqvMrNjbQEYlggQZyicX8sNdvDks3ETGGJXSwnWNkh4RFZgZu7PGnyvSEPfe5 23OsAIxf213yvRgA5xCEWHIOPXNtkgQ= Received: from g78.suse.de (rpalethorpe.udp.ovpn1.nue.suse.de [10.163.24.42]) by relay2.suse.de (Postfix) with ESMTP id A77BBA3B83; Thu, 30 Dec 2021 10:37:37 +0000 (UTC) To: ltp@lists.linux.it Date: Thu, 30 Dec 2021 10:37:17 +0000 Message-Id: <20211230103718.369-4-rpalethorpe@suse.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211230103718.369-1-rpalethorpe@suse.com> References: <20211220131043.18894-1-rpalethorpe@suse.com> <20211230103718.369-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/5] API: Add TST_EXP_EXPR macro 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: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Simplifies evaluating an arbitrary expression or statement which is not a syscall. Signed-off-by: Richard Palethorpe --- include/tst_test_macros.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h index 5dea1aabd..ec8c38523 100644 --- a/include/tst_test_macros.h +++ b/include/tst_test_macros.h @@ -195,4 +195,7 @@ extern void *TST_RET_PTR; #define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__) +#define TST_EXP_EXPR(EXPR, FMT, ...) \ + tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: " FMT, ##__VA_ARGS__); + #endif /* TST_TEST_MACROS_H__ */