* [LTP] [PATCH v1 0/2] Lib add .ulimit setting
@ 2023-10-21 12:29 Wei Gao via ltp
2023-10-21 12:29 ` [LTP] [PATCH v1 1/2] lib: Add .ulimit Wei Gao via ltp
` (2 more replies)
0 siblings, 3 replies; 23+ messages in thread
From: Wei Gao via ltp @ 2023-10-21 12:29 UTC (permalink / raw)
To: ltp
Wei Gao:
lib: Add .ulimit
execl01.c: set stack to unlimited
include/tst_test.h | 6 ++++++
include/tst_ulimit.h | 18 +++++++++++++++++
lib/tst_test.c | 9 +++++++++
lib/tst_ulimit.c | 24 +++++++++++++++++++++++
testcases/kernel/syscalls/execl/execl01.c | 4 ++++
5 files changed, 61 insertions(+)
create mode 100644 include/tst_ulimit.h
create mode 100644 lib/tst_ulimit.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v1 1/2] lib: Add .ulimit
2023-10-21 12:29 [LTP] [PATCH v1 0/2] Lib add .ulimit setting Wei Gao via ltp
@ 2023-10-21 12:29 ` Wei Gao via ltp
2023-10-23 11:03 ` Petr Vorel
2023-10-23 12:29 ` Cyril Hrubis
2023-10-21 12:29 ` [LTP] [PATCH v1 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2023-10-25 8:37 ` [LTP] [PATCH v2 0/2] Lib add .ulimit setting Wei Gao via ltp
2 siblings, 2 replies; 23+ messages in thread
From: Wei Gao via ltp @ 2023-10-21 12:29 UTC (permalink / raw)
To: ltp
Fix: #530
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_test.h | 6 ++++++
include/tst_ulimit.h | 18 ++++++++++++++++++
lib/tst_test.c | 9 +++++++++
lib/tst_ulimit.c | 24 ++++++++++++++++++++++++
4 files changed, 57 insertions(+)
create mode 100644 include/tst_ulimit.h
create mode 100644 lib/tst_ulimit.c
diff --git a/include/tst_test.h b/include/tst_test.h
index 75c2109b9..79abc2773 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -34,6 +34,7 @@
#include "tst_get_bad_addr.h"
#include "tst_path_has_mnt_flags.h"
#include "tst_sys_conf.h"
+#include "tst_ulimit.h"
#include "tst_coredump.h"
#include "tst_buffers.h"
#include "tst_capability.h"
@@ -306,6 +307,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.
diff --git a/include/tst_ulimit.h b/include/tst_ulimit.h
new file mode 100644
index 000000000..b4f97670a
--- /dev/null
+++ b/include/tst_ulimit.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (c) 2023 Wei Gao <wegao@suse.com>
+ */
+
+#ifndef TST_ULIMIT_H__
+#define TST_ULIMIT_H__
+
+#include <sys/resource.h>
+
+struct tst_ulimit_val {
+ int resource;
+ struct rlimit rlim;
+};
+
+void tst_ulimit_conf(const struct tst_ulimit_val *conf);
+
+#endif
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 2e58cad33..a8c7c7ba6 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1227,6 +1227,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_ulimit_conf(pvl);
+ pvl++;
+ }
+ }
+
if (tst_test->mntpoint)
SAFE_MKDIR(tst_test->mntpoint, 0777);
diff --git a/lib/tst_ulimit.c b/lib/tst_ulimit.c
new file mode 100644
index 000000000..1249d65d8
--- /dev/null
+++ b/lib/tst_ulimit.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023 Wei Gao <wegao@suse.com>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_ulimit.h"
+
+struct tst_ulimit_conf {
+ int resource;
+ struct rlimit rlim;
+};
+
+void tst_ulimit_conf(const struct tst_ulimit_val *conf)
+{
+ struct rlimit rlim;
+
+ rlim.rlim_cur = conf->rlim.rlim_cur;
+ rlim.rlim_max = conf->rlim.rlim_max;
+
+ tst_res(TINFO, "Set ulimit resource:%d rlim_cur:%ld rlim_max:%ld", conf->resource, rlim.rlim_cur, rlim.rlim_max);
+ SAFE_SETRLIMIT(conf->resource, &rlim);
+}
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v1 2/2] execl01.c: set stack to unlimited
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-21 12:29 ` 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
2 siblings, 1 reply; 23+ messages in thread
From: Wei Gao via ltp @ 2023-10-21 12:29 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/execl/execl01.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/execl/execl01.c b/testcases/kernel/syscalls/execl/execl01.c
index 9268d4976..5cdd84656 100644
--- a/testcases/kernel/syscalls/execl/execl01.c
+++ b/testcases/kernel/syscalls/execl/execl01.c
@@ -35,4 +35,8 @@ static struct tst_test test = {
.forks_child = 1,
.child_needs_reinit = 1,
.test_all = verify_execl,
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, {RLIM_INFINITY, RLIM_INFINITY}},
+ {}
+ },
};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v1 1/2] lib: Add .ulimit
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
1 sibling, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2023-10-23 11:03 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
> Fix: #530
very nit: Although this works, we usually use:
Fixes: #530
...
> /*
> * NULL terminated array of kernel config options required for the
> * test.
> diff --git a/include/tst_ulimit.h b/include/tst_ulimit.h
> new file mode 100644
> index 000000000..b4f97670a
> --- /dev/null
> +++ b/include/tst_ulimit.h
I wonder if it's worth to add new header and C source just for single struct and
function. We might do so, but I consider that as a bad habit. I'd move that to
tst_test.{c,h}. But maybe others see it differently.
> @@ -0,0 +1,18 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
Why v2 only? We use GLP v2+ for new code.
SPDX-License-Identifier: GPL-2.0-or-later
> + *
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +#ifndef TST_ULIMIT_H__
> +#define TST_ULIMIT_H__
> +
> +#include <sys/resource.h>
> +
> +struct tst_ulimit_val {
> + int resource;
> + struct rlimit rlim;
> +};
> +
> +void tst_ulimit_conf(const struct tst_ulimit_val *conf);
> +
> +#endif
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 2e58cad33..a8c7c7ba6 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1227,6 +1227,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_ulimit_conf(pvl);
> + pvl++;
> + }
> + }
> +
> if (tst_test->mntpoint)
> SAFE_MKDIR(tst_test->mntpoint, 0777);
> diff --git a/lib/tst_ulimit.c b/lib/tst_ulimit.c
> new file mode 100644
> index 000000000..1249d65d8
> --- /dev/null
> +++ b/lib/tst_ulimit.c
> @@ -0,0 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0-only
Again, v2+ please.
> +/*
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +#include "tst_ulimit.h"
Again, please IMHO this should be in tst_test.c.
> +
> +struct tst_ulimit_conf {
> + int resource;
> + struct rlimit rlim;
> +};
> +
> +void tst_ulimit_conf(const struct tst_ulimit_val *conf)
> +{
> + struct rlimit rlim;
> +
> + rlim.rlim_cur = conf->rlim.rlim_cur;
> + rlim.rlim_max = conf->rlim.rlim_max;
> +
> + tst_res(TINFO, "Set ulimit resource:%d rlim_cur:%ld rlim_max:%ld", conf->resource, rlim.rlim_cur, rlim.rlim_max);
nit: Could we improve formatting (spaces, commas):
tst_res(TINFO, "Set ulimit resource: %d, rlim_cur: %ld, rlim_max: %ld",
conf->resource, rlim.rlim_cur, rlim.rlim_max);
First I thought all library code should use tst_res_(), so that we get file and
line of the original call, not the place in the library. But in code is used
only in the library thus tst_res() is ok.
> + SAFE_SETRLIMIT(conf->resource, &rlim);
Also here is probably ok that SAFE_SETRLIMIT() is correct (not
safe_setrlimit()).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v1 2/2] execl01.c: set stack to unlimited
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
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2023-10-23 11:26 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
It would be also here mention
https://github.com/linux-test-project/ltp/issues/530
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> testcases/kernel/syscalls/execl/execl01.c | 4 ++++
> 1 file changed, 4 insertions(+)
> diff --git a/testcases/kernel/syscalls/execl/execl01.c b/testcases/kernel/syscalls/execl/execl01.c
> index 9268d4976..5cdd84656 100644
> --- a/testcases/kernel/syscalls/execl/execl01.c
> +++ b/testcases/kernel/syscalls/execl/execl01.c
> @@ -35,4 +35,8 @@ static struct tst_test test = {
> .forks_child = 1,
> .child_needs_reinit = 1,
> .test_all = verify_execl,
BTW #530 mentions execve(). Is it ok that we use it on execl()?
The difference is not big (all glibc wrappers use SYS_execve syscall
internally), so that it might be OK, but how about also add it to some test
which uses execve() + SAFE_FORK()/.fork_child (e.g. execve01.c).
Kind regards,
Petr
> + .ulimit = (const struct tst_ulimit_val[]) {
> + {RLIMIT_STACK, {RLIM_INFINITY, RLIM_INFINITY}},
> + {}
> + },
> };
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v1 1/2] lib: Add .ulimit
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
1 sibling, 1 reply; 23+ messages in thread
From: Cyril Hrubis @ 2023-10-23 12:29 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> + /*
> + * {NULL, NULL} terminated array of (ulimit resource type and value)
^
That's technically {0, NULL} or maybe we can just start
using the newer syntax with just {}
> + */
> + const struct tst_ulimit_val *ulimit;
> +
> /*
> * NULL terminated array of kernel config options required for the
> * test.
> diff --git a/include/tst_ulimit.h b/include/tst_ulimit.h
> new file mode 100644
> index 000000000..b4f97670a
> --- /dev/null
> +++ b/include/tst_ulimit.h
> @@ -0,0 +1,18 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +#ifndef TST_ULIMIT_H__
> +#define TST_ULIMIT_H__
> +
> +#include <sys/resource.h>
> +
> +struct tst_ulimit_val {
> + int resource;
> + struct rlimit rlim;
> +};
> +
> +void tst_ulimit_conf(const struct tst_ulimit_val *conf);
Maybe tst_ulimit_set()?
> +#endif
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 2e58cad33..a8c7c7ba6 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1227,6 +1227,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_ulimit_conf(pvl);
> + pvl++;
> + }
> + }
> +
> if (tst_test->mntpoint)
> SAFE_MKDIR(tst_test->mntpoint, 0777);
>
> diff --git a/lib/tst_ulimit.c b/lib/tst_ulimit.c
> new file mode 100644
> index 000000000..1249d65d8
> --- /dev/null
> +++ b/lib/tst_ulimit.c
> @@ -0,0 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +#include "tst_ulimit.h"
> +
> +struct tst_ulimit_conf {
> + int resource;
> + struct rlimit rlim;
> +};
This structure is defined in header already.
> +void tst_ulimit_conf(const struct tst_ulimit_val *conf)
> +{
> + struct rlimit rlim;
> +
> + rlim.rlim_cur = conf->rlim.rlim_cur;
> + rlim.rlim_max = conf->rlim.rlim_max;
I wonder if we should adjust the max only if it's smallre than the
requested value.
> + tst_res(TINFO, "Set ulimit resource:%d rlim_cur:%ld rlim_max:%ld", conf->resource, rlim.rlim_cur, rlim.rlim_max);
> + SAFE_SETRLIMIT(conf->resource, &rlim);
> +}
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v1 1/2] lib: Add .ulimit
2023-10-23 12:29 ` Cyril Hrubis
@ 2023-10-23 12:32 ` Cyril Hrubis
0 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2023-10-23 12:32 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> > +void tst_ulimit_conf(const struct tst_ulimit_val *conf)
> > +{
> > + struct rlimit rlim;
> > +
> > + rlim.rlim_cur = conf->rlim.rlim_cur;
> > + rlim.rlim_max = conf->rlim.rlim_max;
>
> I wonder if we should adjust the max only if it's smallre than the
> requested value.
Looking again we store both values in the structure. I wonder if we need
to set both, maybe we just need the rlim_cur value in the tst_ulimit_val
structure and we would attempt to adjust rlim_max only if its smaller
than rlim_cur. That would allow us to use the API even for tests that
does not require root to raise limits within the permitted maxium.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 0/2] Lib add .ulimit setting
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-21 12:29 ` [LTP] [PATCH v1 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
@ 2023-10-25 8:37 ` Wei Gao via ltp
2023-10-25 8:37 ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 23+ messages in thread
From: Wei Gao via ltp @ 2023-10-25 8:37 UTC (permalink / raw)
To: ltp
Wei Gao (2):
lib: Add .ulimit
execl01.c: set stack to unlimited
include/tst_test.h | 14 ++++++++++++
lib/tst_test.c | 28 +++++++++++++++++++++++
testcases/kernel/syscalls/execl/execl01.c | 4 ++++
3 files changed, 46 insertions(+)
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 1/2] lib: Add .ulimit
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
2024-01-08 11:47 ` Petr Vorel
2023-10-25 8:37 ` [LTP] [PATCH v2 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2024-01-09 6:59 ` [LTP] [PATCH v3 0/2] Lib add .ulimit setting Wei Gao via ltp
2 siblings, 1 reply; 23+ messages in thread
From: Wei Gao via ltp @ 2023-10-25 8:37 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 2/2] execl01.c: set stack to unlimited
2023-10-25 8:37 ` [LTP] [PATCH v2 0/2] Lib add .ulimit setting Wei Gao via ltp
2023-10-25 8:37 ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Wei Gao via ltp
@ 2023-10-25 8:37 ` 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
2 siblings, 1 reply; 23+ messages in thread
From: Wei Gao via ltp @ 2023-10-25 8:37 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/execl/execl01.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/execl/execl01.c b/testcases/kernel/syscalls/execl/execl01.c
index 9268d4976..dfefd1fa8 100644
--- a/testcases/kernel/syscalls/execl/execl01.c
+++ b/testcases/kernel/syscalls/execl/execl01.c
@@ -35,4 +35,8 @@ static struct tst_test test = {
.forks_child = 1,
.child_needs_reinit = 1,
.test_all = verify_execl,
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, RLIM_INFINITY},
+ {}
+ },
};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 2/2] execl01.c: set stack to unlimited
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
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2024-01-08 10:17 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 1/2] lib: Add .ulimit
2023-10-25 8:37 ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Wei Gao via ltp
@ 2024-01-08 11:47 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2024-01-08 11:47 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei, Cyril,
> 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();
> }
This patch requires manual adjustments (it does not apply to the master any more).
Also, this should be documented in doc/C-Test-API.asciidoc.
> +void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf)
$ cd lib && make check-tst_test
...
tst_test.c:1150:13: warning: LTP-003: Symbol 'tst_set_ulimit_' has the LTP public library prefix, but is static (private).
If we want to use also in the tests (like tst_validate_children), the function
signature should be also in the header, e.g.:
include/tst_test.h
...
void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf);
#define tst_set_ulimit(conf) \
tst_set_ulimit_(__FILE__, __LINE__, (conf))
And, because offered to use in th tests, the function would deserve 1) comment
in include/tst_test.h.
But because tst_set_ulimit_() is just a wrapper over safe_setrlimit(), I don't
think it's needed to be called in the tests directly. Therefore the
#define tst_set_ulimit(conf) definition in the header is IMHO not needed
and tst_set_ulimit_() in lib/tst_test.c could be tst_set_ulimit() (without
underscore) and with static keyword.
> +{
> + struct rlimit rlim;
> +
> + SAFE_GETRLIMIT(conf->resource, &rlim);
When function has file and line, you want to use it for all library functions,
thus:
safe_getrlimit(file, lineno, conf->resource, &rlim);
NOTE: some functions in tst_test.c calls SAFE_() macros, which is wrong. I'll
send patch after this is fixed.
> +
> + 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;
> + }
rlim.rlim_cur is set twice, why not just:
rlim.rlim_cur = conf->rlim_cur;
if (conf->rlim_cur > rlim.rlim_max)
rlim.rlim_max = conf->rlim_cur;
> +
> + tst_res_(file, lineno, TINFO, "Set ulimit resource:%d rlim_cur:%lu rlim_max:%lu",
nit: space after ':' helps readability:
> + 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);
I suggest to merge with following changes.
@Cyril: feel free to improve the description.
diff --git doc/C-Test-API.asciidoc doc/C-Test-API.asciidoc
index db16be36e..c42a9754c 100644
--- doc/C-Test-API.asciidoc
+++ doc/C-Test-API.asciidoc
@@ -2426,6 +2426,24 @@ Test can be skipped on various conditions: on enabled SecureBoot
('.skip_in_secureboot = 1'), lockdown ('.skip_in_lockdown = 1') or in 32-bit
compat mode ('.skip_in_compat = 1').
+1.43 Set resource limits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+'.ulimit' allows to set resource limits on particular resource. NOTE: It sets 'rlim_cur'
+only if it's higher than 'rlim_cur'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct tst_test test = {
+ ...
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, RLIM_INFINITY},
+ {}
+ },
+};
+
2. Common problems
------------------
diff --git include/tst_test.h include/tst_test.h
index bbcfb308d..42c348906 100644
--- include/tst_test.h
+++ include/tst_test.h
@@ -314,7 +314,7 @@ struct tst_test {
const struct tst_path_val *save_restore;
/*
- * {NULL, NULL} terminated array of (ulimit resource type and value)
+ * {} terminated array of ulimit resource type and value.
*/
const struct tst_ulimit_val *ulimit;
@@ -404,9 +404,6 @@ 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 lib/tst_test.c lib/tst_test.c
index d2f967ade..6c81b9b02 100644
--- lib/tst_test.c
+++ lib/tst_test.c
@@ -1147,20 +1147,24 @@ 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)
+#define tst_set_ulimit(conf) \
+ tst_set_ulimit_(__FILE__, __LINE__, (conf))
+
+/*
+ * Set resource limits.
+ */
+static void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf)
{
struct rlimit rlim;
- SAFE_GETRLIMIT(conf->resource, &rlim);
+ safe_getrlimit(file, lineno, conf->resource, &rlim);
- if (conf->rlim_cur > rlim.rlim_max) {
+ rlim.rlim_cur = conf->rlim_cur;
+
+ 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",
+ 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);
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v3 0/2] Lib add .ulimit setting
2023-10-25 8:37 ` [LTP] [PATCH v2 0/2] Lib add .ulimit setting Wei Gao via ltp
2023-10-25 8:37 ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Wei Gao via ltp
2023-10-25 8:37 ` [LTP] [PATCH v2 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
@ 2024-01-09 6:59 ` Wei Gao via ltp
2024-01-09 6:59 ` [LTP] [PATCH v3 1/2] lib: Add .ulimit Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 23+ messages in thread
From: Wei Gao via ltp @ 2024-01-09 6:59 UTC (permalink / raw)
To: ltp
Wei Gao (2):
lib: Add .ulimit
execl01.c: set stack to unlimited
doc/C-Test-API.asciidoc | 18 +++++++++++++
include/tst_test.h | 16 ++++++++++++
lib/tst_test.c | 32 +++++++++++++++++++++++
testcases/kernel/syscalls/execl/execl01.c | 4 +++
4 files changed, 70 insertions(+)
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v3 1/2] lib: Add .ulimit
2024-01-09 6:59 ` [LTP] [PATCH v3 0/2] Lib add .ulimit setting Wei Gao via ltp
@ 2024-01-09 6:59 ` Wei Gao via ltp
2024-01-19 16:08 ` Cyril Hrubis
2024-01-09 6:59 ` [LTP] [PATCH v3 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2024-01-23 2:19 ` [LTP] [PATCH v4 0/2] Lib add .ulimit setting Wei Gao via ltp
2 siblings, 1 reply; 23+ messages in thread
From: Wei Gao via ltp @ 2024-01-09 6:59 UTC (permalink / raw)
To: ltp
Fixs: #530
Signed-off-by: Wei Gao <wegao@suse.com>
---
doc/C-Test-API.asciidoc | 18 ++++++++++++++++++
include/tst_test.h | 16 ++++++++++++++++
lib/tst_test.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+)
diff --git a/doc/C-Test-API.asciidoc b/doc/C-Test-API.asciidoc
index db16be36e..c42a9754c 100644
--- a/doc/C-Test-API.asciidoc
+++ b/doc/C-Test-API.asciidoc
@@ -2426,6 +2426,24 @@ Test can be skipped on various conditions: on enabled SecureBoot
('.skip_in_secureboot = 1'), lockdown ('.skip_in_lockdown = 1') or in 32-bit
compat mode ('.skip_in_compat = 1').
+1.43 Set resource limits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+'.ulimit' allows to set resource limits on particular resource. NOTE: It sets 'rlim_cur'
+only if it's higher than 'rlim_cur'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct tst_test test = {
+ ...
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, RLIM_INFINITY},
+ {}
+ },
+};
+
2. Common problems
------------------
diff --git a/include/tst_test.h b/include/tst_test.h
index 0c3171e5b..374a8615c 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"
@@ -149,6 +150,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;
@@ -307,6 +313,11 @@ struct tst_test {
*/
const struct tst_path_val *save_restore;
+ /*
+ * {} 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.
@@ -393,6 +404,11 @@ int tst_validate_children_(const char *file, const int lineno,
#define tst_validate_children(child_count) \
tst_validate_children_(__FILE__, __LINE__, (child_count))
+/*
+ * Set system resource limits
+ */
+void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf);
+
#ifndef TST_NO_DEFAULT_MAIN
static struct tst_test test;
diff --git a/lib/tst_test.c b/lib/tst_test.c
index bcf2c4555..f5037330a 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1147,6 +1147,29 @@ static void do_cgroup_requires(void)
tst_cg_init();
}
+#define tst_set_ulimit(conf) \
+ tst_set_ulimit_(__FILE__, __LINE__, (conf))
+
+/*
+ * Set resource limits.
+ */
+void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf)
+{
+ struct rlimit rlim;
+
+ safe_getrlimit(file, lineno, conf->resource, &rlim);
+
+ rlim.rlim_cur = conf->rlim_cur;
+
+ if (conf->rlim_cur > rlim.rlim_max)
+ rlim.rlim_max = 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[])
{
char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
@@ -1252,6 +1275,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
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v3 2/2] execl01.c: set stack to unlimited
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-09 6:59 ` 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
2 siblings, 1 reply; 23+ messages in thread
From: Wei Gao via ltp @ 2024-01-09 6:59 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/execl/execl01.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/execl/execl01.c b/testcases/kernel/syscalls/execl/execl01.c
index 9268d4976..dfefd1fa8 100644
--- a/testcases/kernel/syscalls/execl/execl01.c
+++ b/testcases/kernel/syscalls/execl/execl01.c
@@ -35,4 +35,8 @@ static struct tst_test test = {
.forks_child = 1,
.child_needs_reinit = 1,
.test_all = verify_execl,
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, RLIM_INFINITY},
+ {}
+ },
};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v3 1/2] lib: Add .ulimit
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
0 siblings, 1 reply; 23+ messages in thread
From: Cyril Hrubis @ 2024-01-19 16:08 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> +1.43 Set resource limits
> +~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +'.ulimit' allows to set resource limits on particular resource. NOTE: It sets 'rlim_cur'
^
rlim_max?
> +only if it's higher than 'rlim_cur'.
> +
> +[source,c]
> +-------------------------------------------------------------------------------
> +#include "tst_test.h"
> +
> +static struct tst_test test = {
> + ...
> + .ulimit = (const struct tst_ulimit_val[]) {
> + {RLIMIT_STACK, RLIM_INFINITY},
> + {}
> + },
> +};
> +
> 2. Common problems
> ------------------
>
> diff --git a/include/tst_test.h b/include/tst_test.h
> index 0c3171e5b..374a8615c 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"
> @@ -149,6 +150,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;
> @@ -307,6 +313,11 @@ struct tst_test {
> */
> const struct tst_path_val *save_restore;
>
> + /*
> + * {} 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.
> @@ -393,6 +404,11 @@ int tst_validate_children_(const char *file, const int lineno,
> #define tst_validate_children(child_count) \
> tst_validate_children_(__FILE__, __LINE__, (child_count))
>
> +/*
> + * Set system resource limits
> + */
> +void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf);
> +
> #ifndef TST_NO_DEFAULT_MAIN
>
> static struct tst_test test;
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index bcf2c4555..f5037330a 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1147,6 +1147,29 @@ static void do_cgroup_requires(void)
> tst_cg_init();
> }
>
> +#define tst_set_ulimit(conf) \
> + tst_set_ulimit_(__FILE__, __LINE__, (conf))
If we want this to be part of the API, i.e. allow tests to call this
function directly this should be in the tst_test.h header.
If not, the function should be static and only used in the tst_test.c
> +/*
> + * Set resource limits.
> + */
> +void tst_set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf)
> +{
> + struct rlimit rlim;
> +
> + safe_getrlimit(file, lineno, conf->resource, &rlim);
> +
> + rlim.rlim_cur = conf->rlim_cur;
> +
> + if (conf->rlim_cur > rlim.rlim_max)
> + rlim.rlim_max = 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[])
> {
> char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
> @@ -1252,6 +1275,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);
The rest looks good.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v3 2/2] execl01.c: set stack to unlimited
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
0 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2024-01-19 16:09 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> Signed-off-by: Wei Gao <wegao@suse.com>
The previous version was reviewed by Peter, so this should have included
his reviewed-by line...
> ---
> testcases/kernel/syscalls/execl/execl01.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/execl/execl01.c b/testcases/kernel/syscalls/execl/execl01.c
> index 9268d4976..dfefd1fa8 100644
> --- a/testcases/kernel/syscalls/execl/execl01.c
> +++ b/testcases/kernel/syscalls/execl/execl01.c
> @@ -35,4 +35,8 @@ static struct tst_test test = {
> .forks_child = 1,
> .child_needs_reinit = 1,
> .test_all = verify_execl,
> + .ulimit = (const struct tst_ulimit_val[]) {
> + {RLIMIT_STACK, RLIM_INFINITY},
> + {}
> + },
> };
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v4 0/2] Lib add .ulimit setting
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-09 6:59 ` [LTP] [PATCH v3 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
@ 2024-01-23 2:19 ` Wei Gao via ltp
2024-01-23 2:19 ` [LTP] [PATCH v4 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-23 2:19 ` [LTP] [PATCH v4 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2 siblings, 2 replies; 23+ messages in thread
From: Wei Gao via ltp @ 2024-01-23 2:19 UTC (permalink / raw)
To: ltp
Wei Gao (2):
lib: Add .ulimit
execl01.c: set stack to unlimited
doc/C-Test-API.asciidoc | 18 +++++++++++++
include/tst_test.h | 11 ++++++++
lib/tst_test.c | 32 +++++++++++++++++++++++
testcases/kernel/syscalls/execl/execl01.c | 4 +++
4 files changed, 65 insertions(+)
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v4 1/2] lib: Add .ulimit
2024-01-23 2:19 ` [LTP] [PATCH v4 0/2] Lib add .ulimit setting Wei Gao via ltp
@ 2024-01-23 2:19 ` Wei Gao via ltp
2024-01-23 8:36 ` Petr Vorel
2024-01-23 2:19 ` [LTP] [PATCH v4 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
1 sibling, 1 reply; 23+ messages in thread
From: Wei Gao via ltp @ 2024-01-23 2:19 UTC (permalink / raw)
To: ltp
Fixs: #530
Signed-off-by: Wei Gao <wegao@suse.com>
---
doc/C-Test-API.asciidoc | 18 ++++++++++++++++++
include/tst_test.h | 11 +++++++++++
lib/tst_test.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
v4->v3:
To fix following warning when make check-tst_test, i rename tst_set_ulimit_ -> set_ulimit_ and add static key word.
tst_test.c:1156:13: warning: LTP-003: Symbol 'tst_set_ulimit_' has the LTP public library prefix, but is static (private).
diff --git a/doc/C-Test-API.asciidoc b/doc/C-Test-API.asciidoc
index db16be36e..e3891d5e8 100644
--- a/doc/C-Test-API.asciidoc
+++ b/doc/C-Test-API.asciidoc
@@ -2426,6 +2426,24 @@ Test can be skipped on various conditions: on enabled SecureBoot
('.skip_in_secureboot = 1'), lockdown ('.skip_in_lockdown = 1') or in 32-bit
compat mode ('.skip_in_compat = 1').
+1.43 Set resource limits
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+'.ulimit' allows to set resource limits on particular resource. NOTE: It sets 'rlim_max'
+only if it's higher than 'rlim_cur'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct tst_test test = {
+ ...
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, RLIM_INFINITY},
+ {}
+ },
+};
+
2. Common problems
------------------
diff --git a/include/tst_test.h b/include/tst_test.h
index fda696eeb..47b5902f9 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"
@@ -150,6 +151,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;
@@ -308,6 +314,11 @@ struct tst_test {
*/
const struct tst_path_val *save_restore;
+ /*
+ * {} 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.
diff --git a/lib/tst_test.c b/lib/tst_test.c
index bcf2c4555..f9a6f1ae0 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1147,6 +1147,29 @@ static void do_cgroup_requires(void)
tst_cg_init();
}
+#define tst_set_ulimit(conf) \
+ set_ulimit_(__FILE__, __LINE__, (conf))
+
+/*
+ * Set resource limits.
+ */
+static void set_ulimit_(const char *file, const int lineno, const struct tst_ulimit_val *conf)
+{
+ struct rlimit rlim;
+
+ safe_getrlimit(file, lineno, conf->resource, &rlim);
+
+ rlim.rlim_cur = conf->rlim_cur;
+
+ if (conf->rlim_cur > rlim.rlim_max)
+ rlim.rlim_max = 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[])
{
char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
@@ -1252,6 +1275,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
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v4 2/2] execl01.c: set stack to unlimited
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 2:19 ` Wei Gao via ltp
1 sibling, 0 replies; 23+ messages in thread
From: Wei Gao via ltp @ 2024-01-23 2:19 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/syscalls/execl/execl01.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/testcases/kernel/syscalls/execl/execl01.c b/testcases/kernel/syscalls/execl/execl01.c
index 9268d4976..dfefd1fa8 100644
--- a/testcases/kernel/syscalls/execl/execl01.c
+++ b/testcases/kernel/syscalls/execl/execl01.c
@@ -35,4 +35,8 @@ static struct tst_test test = {
.forks_child = 1,
.child_needs_reinit = 1,
.test_all = verify_execl,
+ .ulimit = (const struct tst_ulimit_val[]) {
+ {RLIMIT_STACK, RLIM_INFINITY},
+ {}
+ },
};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v3 1/2] lib: Add .ulimit
2024-01-19 16:08 ` Cyril Hrubis
@ 2024-01-23 7:57 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2024-01-23 7:57 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi,
...
> > +++ b/lib/tst_test.c
> > @@ -1147,6 +1147,29 @@ static void do_cgroup_requires(void)
> > tst_cg_init();
> > }
> > +#define tst_set_ulimit(conf) \
> > + tst_set_ulimit_(__FILE__, __LINE__, (conf))
> If we want this to be part of the API, i.e. allow tests to call this
> function directly this should be in the tst_test.h header.
> If not, the function should be static and only used in the tst_test.c
Thanks! I tried to explain it in v2, but was not able to express it clearly.
https://lore.kernel.org/ltp/20240108114738.GC1565258@pevik/
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v4 1/2] lib: Add .ulimit
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
0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2024-01-23 8:36 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
> Fixs: #530
^ typo, it should have been
Fixes: #530
Fortunately github formats properly even there is a typo:
https://github.com/pevik/ltp/commit/2e6289d26c325db796cde27765b6765217541d24
But it would not close the ticket.
Also people sometimes do 'git log --grep=Fixes:' to see changes.
...
> diff --git a/doc/C-Test-API.asciidoc b/doc/C-Test-API.asciidoc
> index db16be36e..e3891d5e8 100644
> --- a/doc/C-Test-API.asciidoc
> +++ b/doc/C-Test-API.asciidoc
> @@ -2426,6 +2426,24 @@ Test can be skipped on various conditions: on enabled SecureBoot
> ('.skip_in_secureboot = 1'), lockdown ('.skip_in_lockdown = 1') or in 32-bit
> compat mode ('.skip_in_compat = 1').
> +1.43 Set resource limits
> +~~~~~~~~~~~~~~~~~~~~~~~~
> +
> +'.ulimit' allows to set resource limits on particular resource. NOTE: It sets 'rlim_max'
> +only if it's higher than 'rlim_cur'.
> +
> +[source,c]
> +-------------------------------------------------------------------------------
> +#include "tst_test.h"
> +
> +static struct tst_test test = {
> + ...
> + .ulimit = (const struct tst_ulimit_val[]) {
> + {RLIMIT_STACK, RLIM_INFINITY},
> + {}
> + },
> +};
Here is missing separator, which is required to end formatting, otherwise page
would be horribly broken:
-------------------------------------------------------------------------------
Have look at my fork how it looks like and please, next time test formatting of
doc changes yourself in your fork (preview is enough to see the problems):
https://github.com/pevik/ltp/wiki/TEST#143-set-resource-limits
Both issues can be fixed before merge.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Unless Cyril or Li acks this to be merged before the release, it will be merged
after the release (not a fix).
Kind regards,
Petr
> +
> 2. Common problems
> ------------------
...
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v4 1/2] lib: Add .ulimit
2024-01-23 8:36 ` Petr Vorel
@ 2024-01-30 11:55 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2024-01-30 11:55 UTC (permalink / raw)
To: Wei Gao, ltp
Hi Wei,
thanks, patchset merged!
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2024-01-30 11:55 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-08 11:47 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox