From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/2] lib: Add .ulimit
Date: Wed, 25 Oct 2023 04:37:05 -0400 [thread overview]
Message-ID: <20231025083706.13767-2-wegao@suse.com> (raw)
In-Reply-To: <20231025083706.13767-1-wegao@suse.com>
Fixs: #530
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_test.h | 14 ++++++++++++++
lib/tst_test.c | 28 ++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/include/tst_test.h b/include/tst_test.h
index 75c2109b9..dcdbc71d7 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -15,6 +15,7 @@
#include <limits.h>
#include <string.h>
#include <errno.h>
+#include <sys/resource.h>
#include "tst_common.h"
#include "tst_res_flags.h"
@@ -148,6 +149,11 @@ extern unsigned int tst_variant;
#define TST_UNLIMITED_RUNTIME (-1)
+struct tst_ulimit_val {
+ int resource;
+ rlim_t rlim_cur;
+};
+
struct tst_test {
/* number of tests available in test() function */
unsigned int tcnt;
@@ -306,6 +312,11 @@ struct tst_test {
*/
const struct tst_path_val *save_restore;
+ /*
+ * {NULL, NULL} terminated array of (ulimit resource type and value)
+ */
+ const struct tst_ulimit_val *ulimit;
+
/*
* NULL terminated array of kernel config options required for the
* test.
@@ -392,6 +403,9 @@ int tst_validate_children_(const char *file, const int lineno,
#define tst_validate_children(child_count) \
tst_validate_children_(__FILE__, __LINE__, (child_count))
+#define tst_set_ulimit(conf) \
+ tst_set_ulimit_(__FILE__, __LINE__, (conf))
+
#ifndef TST_NO_DEFAULT_MAIN
static struct tst_test test;
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 2e58cad33..59eeda7e7 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1129,6 +1129,25 @@ static void do_cgroup_requires(void)
tst_cg_init();
}
+void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf)
+{
+ struct rlimit rlim;
+
+ SAFE_GETRLIMIT(conf->resource, &rlim);
+
+ if (conf->rlim_cur > rlim.rlim_max) {
+ rlim.rlim_max = conf->rlim_cur;
+ rlim.rlim_cur = conf->rlim_cur;
+ } else {
+ rlim.rlim_cur = conf->rlim_cur;
+ }
+
+ tst_res_(file, lineno, TINFO, "Set ulimit resource:%d rlim_cur:%lu rlim_max:%lu",
+ conf->resource, rlim.rlim_cur, rlim.rlim_max);
+
+ safe_setrlimit(file, lineno, conf->resource, &rlim);
+}
+
static void do_setup(int argc, char *argv[])
{
if (!tst_test)
@@ -1227,6 +1246,15 @@ static void do_setup(int argc, char *argv[])
}
}
+ if (tst_test->ulimit) {
+ const struct tst_ulimit_val *pvl = tst_test->ulimit;
+
+ while (pvl->resource) {
+ tst_set_ulimit(pvl);
+ pvl++;
+ }
+ }
+
if (tst_test->mntpoint)
SAFE_MKDIR(tst_test->mntpoint, 0777);
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-10-25 8:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-21 12:29 [LTP] [PATCH v1 0/2] Lib add .ulimit setting Wei Gao via ltp
2023-10-21 12:29 ` [LTP] [PATCH v1 1/2] lib: Add .ulimit Wei Gao via ltp
2023-10-23 11:03 ` Petr Vorel
2023-10-23 12:29 ` Cyril Hrubis
2023-10-23 12:32 ` Cyril Hrubis
2023-10-21 12:29 ` [LTP] [PATCH v1 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2023-10-23 11:26 ` Petr Vorel
2023-10-25 8:37 ` [LTP] [PATCH v2 0/2] Lib add .ulimit setting Wei Gao via ltp
2023-10-25 8:37 ` Wei Gao via ltp [this message]
2024-01-08 11:47 ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Petr Vorel
2023-10-25 8:37 ` [LTP] [PATCH v2 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2024-01-08 10:17 ` Petr Vorel
2024-01-09 6:59 ` [LTP] [PATCH v3 0/2] Lib add .ulimit setting Wei Gao via ltp
2024-01-09 6:59 ` [LTP] [PATCH v3 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-19 16:08 ` Cyril Hrubis
2024-01-23 7:57 ` Petr Vorel
2024-01-09 6:59 ` [LTP] [PATCH v3 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2024-01-19 16:09 ` Cyril Hrubis
2024-01-23 2:19 ` [LTP] [PATCH v4 0/2] Lib add .ulimit setting Wei Gao via ltp
2024-01-23 2:19 ` [LTP] [PATCH v4 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-23 8:36 ` Petr Vorel
2024-01-30 11:55 ` Petr Vorel
2024-01-23 2:19 ` [LTP] [PATCH v4 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231025083706.13767-2-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox