* [LTP] [PATCH] Add test case to cover the setting resource limit64 for process @ 2025-02-18 2:31 chunfuwen 2025-02-18 11:44 ` Ricardo B. Marlière 0 siblings, 1 reply; 22+ messages in thread From: chunfuwen @ 2025-02-18 2:31 UTC (permalink / raw) To: ltp The test ensures that the process gets the correct signals in the correct order: First, it should get SIGXCPU after reaching the soft CPU time limit64. Then, if the CPU time exceeds the hard limit, it should receive SIGKILL Signed-off-by: chunfuwen <chwen@redhat.com> --- .../kernel/syscalls/setrlimit/setrlimit07.c | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit07.c b/testcases/kernel/syscalls/setrlimit/setrlimit07.c new file mode 100644 index 000000000..031d58c64 --- /dev/null +++ b/testcases/kernel/syscalls/setrlimit/setrlimit07.c @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2017 Red Hat Inc. All Rights Reserved. + * Author: Chunfu Wen <chwen@redhat.com> + */ + +/* + * Description: + * Set CPU time limit64 for a process and check its behavior + * after reaching CPU time limit64. + * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. + * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. + * + */ + +#define _GNU_SOURCE +#include <errno.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/wait.h> +#include <stdlib.h> +#include <stdint.h> +#include <sys/mman.h> +#include <inttypes.h> + +#include "tst_test.h" + +#include "lapi/syscalls.h" +#include "lapi/abisize.h" + +#ifndef HAVE_STRUCT_RLIMIT64 +struct rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; +#endif + +static int *end; + +static void sighandler(int sig) +{ + *end = sig; +} + +static void setup(void) +{ + SAFE_SIGNAL(SIGXCPU, sighandler); + + end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); +} + +static void cleanup(void) +{ + if (end) + SAFE_MUNMAP(end, sizeof(int)); +} + +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) +{ + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); +} + +static void verify_setrlimit64(void) +{ + int status; + pid_t pid; + struct rlimit64 rlim; + rlim.rlim_cur = 1; + rlim.rlim_max = 2; + + *end = 0; + + pid = SAFE_FORK(); + if (!pid) { + TEST(setrlimit_u64(RLIMIT_CPU, &rlim)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, + "setrlimit_u64(RLIMIT_CPU) failed"); + exit(1); + } + + alarm(20); + + while (1); + } + + SAFE_WAITPID(pid, &status, 0); + + if (WIFEXITED(status) && WEXITSTATUS(status) == 1) + return; + + if (WIFSIGNALED(status)) { + if (WTERMSIG(status) == SIGKILL && *end == SIGXCPU) { + tst_res(TPASS, + "Got SIGXCPU then SIGKILL after reaching both limit"); + return; + } + + if (WTERMSIG(status) == SIGKILL && !*end) { + tst_res(TFAIL, + "Got only SIGKILL after reaching both limit"); + return; + } + + if (WTERMSIG(status) == SIGALRM && *end == SIGXCPU) { + tst_res(TFAIL, + "Got only SIGXCPU after reaching both limit"); + return; + } + + if (WTERMSIG(status) == SIGALRM && !*end) { + tst_res(TFAIL, + "Got no signal after reaching both limit"); + return; + } + } + + tst_res(TFAIL, "Child %s", tst_strstatus(status)); +} + +static struct tst_test test = { + .test_all = verify_setrlimit64, + .setup = setup, + .cleanup = cleanup, + .forks_child = 1, +}; -- 2.43.5 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH] Add test case to cover the setting resource limit64 for process 2025-02-18 2:31 [LTP] [PATCH] Add test case to cover the setting resource limit64 for process chunfuwen @ 2025-02-18 11:44 ` Ricardo B. Marlière 2025-02-18 13:29 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 22+ messages in thread From: Ricardo B. Marlière @ 2025-02-18 11:44 UTC (permalink / raw) To: chunfuwen, ltp; +Cc: ltp Hello, A few comments in line. On Mon Feb 17, 2025 at 11:31 PM -03, chunfuwen wrote: > The test ensures that the process gets the correct signals in the correct order: > > First, it should get SIGXCPU after reaching the soft CPU time limit64. > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > > Signed-off-by: chunfuwen <chwen@redhat.com> > --- > .../kernel/syscalls/setrlimit/setrlimit07.c | 129 ++++++++++++++++++ > 1 file changed, 129 insertions(+) > create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c > > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit07.c b/testcases/kernel/syscalls/setrlimit/setrlimit07.c > new file mode 100644 > index 000000000..031d58c64 > --- /dev/null > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit07.c > @@ -0,0 +1,129 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2017 Red Hat Inc. All Rights Reserved. Is this an old source being sent upstream or can we bump this to 2025? > + * Author: Chunfu Wen <chwen@redhat.com> > + */ > + > +/* > + * Description: No need for this line. > + * Set CPU time limit64 for a process and check its behavior > + * after reaching CPU time limit64. > + * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. > + * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. > + * Trailing line should be removed. > + */ > + > +#define _GNU_SOURCE > +#include <errno.h> > +#include <sys/types.h> > +#include <unistd.h> > +#include <sys/time.h> > +#include <sys/resource.h> > +#include <sys/wait.h> > +#include <stdlib.h> > +#include <stdint.h> > +#include <sys/mman.h> > +#include <inttypes.h> > + > +#include "tst_test.h" > + > +#include "lapi/syscalls.h" > +#include "lapi/abisize.h" I was able to build using: #define _GNU_SOURCE #include <sys/resource.h> #include "tst_test.h" #include "lapi/syscalls.h" So, perhaps trim the includes down? > + > +#ifndef HAVE_STRUCT_RLIMIT64 > +struct rlimit64 { > + uint64_t rlim_cur; > + uint64_t rlim_max; > +}; > +#endif > + > +static int *end; > + > +static void sighandler(int sig) > +{ > + *end = sig; > +} > + > +static void setup(void) > +{ > + SAFE_SIGNAL(SIGXCPU, sighandler); > + > + end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, > + MAP_SHARED | MAP_ANONYMOUS, -1, 0); > +} > + > +static void cleanup(void) > +{ > + if (end) > + SAFE_MUNMAP(end, sizeof(int)); > +} > + > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > +{ > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); Please use tab instead of spaces. > +} > + > +static void verify_setrlimit64(void) > +{ > + int status; > + pid_t pid; > + struct rlimit64 rlim; > + rlim.rlim_cur = 1; > + rlim.rlim_max = 2; > + > + *end = 0; > + > + pid = SAFE_FORK(); > + if (!pid) { > + TEST(setrlimit_u64(RLIMIT_CPU, &rlim)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, > + "setrlimit_u64(RLIMIT_CPU) failed"); > + exit(1); > + } > + > + alarm(20); > + > + while (1); nit: Use the following to make checkpatch happy: while (1) ; > + } > + > + SAFE_WAITPID(pid, &status, 0); > + > + if (WIFEXITED(status) && WEXITSTATUS(status) == 1) > + return; > + > + if (WIFSIGNALED(status)) { > + if (WTERMSIG(status) == SIGKILL && *end == SIGXCPU) { > + tst_res(TPASS, > + "Got SIGXCPU then SIGKILL after reaching both limit"); > + return; > + } > + > + if (WTERMSIG(status) == SIGKILL && !*end) { > + tst_res(TFAIL, > + "Got only SIGKILL after reaching both limit"); > + return; > + } > + > + if (WTERMSIG(status) == SIGALRM && *end == SIGXCPU) { > + tst_res(TFAIL, > + "Got only SIGXCPU after reaching both limit"); > + return; > + } > + > + if (WTERMSIG(status) == SIGALRM && !*end) { > + tst_res(TFAIL, > + "Got no signal after reaching both limit"); > + return; > + } > + } > + > + tst_res(TFAIL, "Child %s", tst_strstatus(status)); > +} > + > +static struct tst_test test = { > + .test_all = verify_setrlimit64, > + .setup = setup, > + .cleanup = cleanup, > + .forks_child = 1, > +}; With those fixed: Reviewed-by: Ricardo B. Marlière <ricardo@marliere.net> Thank you, - Ricardo. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH] Add test case to cover the setting resource limit64 for process 2025-02-18 11:44 ` Ricardo B. Marlière @ 2025-02-18 13:29 ` Andrea Cervesato via ltp 2025-02-19 2:35 ` Chunfu Wen 2025-02-19 6:47 ` [LTP] [PATCH v2] " chunfuwen 0 siblings, 2 replies; 22+ messages in thread From: Andrea Cervesato via ltp @ 2025-02-18 13:29 UTC (permalink / raw) To: Ricardo B. Marlière, chunfuwen, ltp; +Cc: ltp Hi! The whole test is a duplication of the setrlimit06, so it's better to work on that one and to introduce the 64bits support using 64bit test variant. A couple of comments about the implementation: - we are already defining the "struct rlimit64" inside getrlimit03, so we need to create a new file lapi/resource.h where we move that struct, checking if HAVE_STRUCT_RLIMIT64 is not defined. I guess the same should be done for getrlimit_u64()/setrlimit_u64() syscalls definitions. Better to move them in there in case we will need it in the future . We can skip SAFE_* variants at the moment, since we are not using them around LTP test for now. - in both setrlimit06 and setrlimit07 we should probably use tst_buffers for safety reasons when passing the pointer to the rlimit/rlimit64 struct we are gonna use - it's worth to check if the other tests might introduce the same 64bit variants FYI i noticed that setrlimit06 description can't be fetched in the metadata because it's not initialized with /*\ . It also needs to be changed into the RST format instead of asciidoc. King regards, Andrea Cervesato -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH] Add test case to cover the setting resource limit64 for process 2025-02-18 13:29 ` Andrea Cervesato via ltp @ 2025-02-19 2:35 ` Chunfu Wen 2025-02-19 9:29 ` Andrea Cervesato via ltp 2025-02-19 6:47 ` [LTP] [PATCH v2] " chunfuwen 1 sibling, 1 reply; 22+ messages in thread From: Chunfu Wen @ 2025-02-19 2:35 UTC (permalink / raw) To: Andrea Cervesato; +Cc: ltp, ltp Hello, See inline comments. Best Regards, Chunfu Wen On Tue, Feb 18, 2025 at 9:29 PM Andrea Cervesato <andrea.cervesato@suse.com> wrote: > Hi! > > The whole test is a duplication of the setrlimit06, so it's better to > work on that one and to introduce the 64bits support using 64bit test > variant. > [chwen]Maybe it is a good idea to use separate setrlimit07.c file to > support using 64bit testing, since it can bring into two benefits. 1)align > with gettrlimit, it has separate file getrlimit03.c for 64bits, and it help > easily extend more scernao cases for 64bits 2) Putting them in separate > file is more convenient for users to select test case specfic 64bits > testing once users need that. > A couple of comments about the implementation: > > - we are already defining the "struct rlimit64" inside getrlimit03, so > we need to create a new file lapi/resource.h where we move that struct, > checking if HAVE_STRUCT_RLIMIT64 is not defined. I guess the same should > be done for getrlimit_u64()/setrlimit_u64() syscalls definitions. Better > to move them in there in case we will need it in the future . We can > skip SAFE_* variants at the moment, since we are not using them around > LTP test for now. > > - in both setrlimit06 and setrlimit07 we should probably use tst_buffers > for safety reasons when passing the pointer to the rlimit/rlimit64 > struct we are gonna use > > - it's worth to check if the other tests might introduce the same 64bit > variants > > FYI i noticed that setrlimit06 description can't be fetched in the > metadata because it's not initialized with /*\ . It also needs to be > changed into the RST format instead of asciidoc. > > King regards, > Andrea Cervesato > > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH] Add test case to cover the setting resource limit64 for process 2025-02-19 2:35 ` Chunfu Wen @ 2025-02-19 9:29 ` Andrea Cervesato via ltp 0 siblings, 0 replies; 22+ messages in thread From: Andrea Cervesato via ltp @ 2025-02-19 9:29 UTC (permalink / raw) To: Chunfu Wen; +Cc: ltp, ltp Hi, On 2/19/25 03:35, Chunfu Wen wrote: > Hello, > See inline comments. > Best Regards, > Chunfu Wen > > On Tue, Feb 18, 2025 at 9:29 PM Andrea Cervesato > <andrea.cervesato@suse.com> wrote: > > Hi! > > The whole test is a duplication of the setrlimit06, so it's better to > work on that one and to introduce the 64bits support using 64bit test > variant. > [chwen]Maybe it is a good idea to use separate setrlimit07.c file > to support using 64bit testing, since it can bring into two > benefits. 1)align with gettrlimit, it has separate > file getrlimit03.c for 64bits, and it help easily extend more > scernao cases for 64bits 2) Putting them in separate file is more > convenient for users to select test case specfic 64bits testing > once users need that. > If the goal is to generate a 64bit binary so users can easily run it without variants, you don't need a new file but to edit the Makefile adding: include $(abs_srcdir)/../utils/newer_64.mk %_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 In this way you will have a 64bit binary for each test in the folder. At that point, to switch between syscalls according to the 64bit architecture definition is easy and runtest file will need to be updated accordingly. If you take a look at the other test cases you will find many examples on this method. Andrea -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process 2025-02-18 13:29 ` Andrea Cervesato via ltp 2025-02-19 2:35 ` Chunfu Wen @ 2025-02-19 6:47 ` chunfuwen 2025-02-19 16:44 ` Petr Vorel 2025-02-19 16:50 ` [LTP] [PATCH v2] " Petr Vorel 1 sibling, 2 replies; 22+ messages in thread From: chunfuwen @ 2025-02-19 6:47 UTC (permalink / raw) To: ltp The test ensures that the process gets the correct signals in the correct order: First, it should get SIGXCPU after reaching the soft CPU time limit64. Then, if the CPU time exceeds the hard limit, it should receive SIGKILL Signed-off-by: chunfuwen <chwen@redhat.com> --- Changes in v2: - Romove test descriptions and trailing line as suggested by Ricardo B. Marlière - Added 2025 copyright as suggested by Ricardo B. Marlière - Trim down include files as suggested by Ricardo B. Marlière - Create new lapi/resource.h residing struct rlimit64 as suggested by Andrea - Move setrlimit_u64() syscalls definitions into lapi/resource.h as suggested by Andrea - Skip SAFE_* variants as suggested by Andrea - use tst_buffers when passing the pointeras suggested by Andrea - Link to v1:https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ --- include/lapi/resource.h | 26 ++++ .../kernel/syscalls/setrlimit/setrlimit07.c | 127 ++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 include/lapi/resource.h create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c diff --git a/include/lapi/resource.h b/include/lapi/resource.h new file mode 100644 index 000000000..3310bc934 --- /dev/null +++ b/include/lapi/resource.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. + * Author: Chunfu Wen <chwen@redhat.com> + */ + +#ifndef LAPI_RESOURCE_H__ +#define LAPI_RESOURCE_H__ + +#define _GNU_SOURCE + +#include "lapi/syscalls.h" + +#ifndef HAVE_STRUCT_RLIMIT64 +struct rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; +#endif + +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) +{ + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); +} + +#endif /* LAPI_RESOURCE_H__ */ diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit07.c b/testcases/kernel/syscalls/setrlimit/setrlimit07.c new file mode 100644 index 000000000..60a4580da --- /dev/null +++ b/testcases/kernel/syscalls/setrlimit/setrlimit07.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. + * Author: Chunfu Wen <chwen@redhat.com> + */ + +/* + * Set CPU time limit64 for a process and check its behavior + * after reaching CPU time limit64. + * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. + * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. + */ + +#define _GNU_SOURCE + +#include <sys/wait.h> + +#include "tst_test.h" + +#include "lapi/syscalls.h" + +#include "lapi/resource.h" + +#ifndef HAVE_STRUCT_RLIMIT64 +struct rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; +#endif + +static struct rlimit64*rlim; + +static int *end; + +static void sighandler(int sig) +{ + *end = sig; +} + +static void setup(void) +{ + signal(SIGXCPU, sighandler); + + end = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); +} + +static void cleanup(void) +{ + if (end) + munmap(end, sizeof(int)); +} +/* +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) +{ + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); +}*/ + +static void verify_setrlimit64(void) +{ + int status; + pid_t pid; + + rlim->rlim_cur = 1; + rlim->rlim_max = 2; + + *end = 0; + + pid = fork(); + if (!pid) { + TEST(setrlimit_u64(RLIMIT_CPU, rlim)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, + "setrlimit_u64(RLIMIT_CPU) failed"); + exit(1); + } + + alarm(20); + + while (1) + ; + } + + waitpid(pid, &status, 0); + + if (WIFEXITED(status) && WEXITSTATUS(status) == 1) + return; + + if (WIFSIGNALED(status)) { + if (WTERMSIG(status) == SIGKILL && *end == SIGXCPU) { + tst_res(TPASS, + "Got SIGXCPU then SIGKILL after reaching both limit"); + return; + } + + if (WTERMSIG(status) == SIGKILL && !*end) { + tst_res(TFAIL, + "Got only SIGKILL after reaching both limit"); + return; + } + + if (WTERMSIG(status) == SIGALRM && *end == SIGXCPU) { + tst_res(TFAIL, + "Got only SIGXCPU after reaching both limit"); + return; + } + + if (WTERMSIG(status) == SIGALRM && !*end) { + tst_res(TFAIL, + "Got no signal after reaching both limit"); + return; + } + } + + tst_res(TFAIL, "Child %s", tst_strstatus(status)); +} + +static struct tst_test test = { + .test_all = verify_setrlimit64, + .bufs = (struct tst_buffers []) { + {&rlim, .size = sizeof(*rlim)}, + {}, + }, + .setup = setup, + .cleanup = cleanup, + .forks_child = 1, +}; -- 2.43.5 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process 2025-02-19 6:47 ` [LTP] [PATCH v2] " chunfuwen @ 2025-02-19 16:44 ` Petr Vorel 2025-02-20 2:08 ` Li Wang ` (2 more replies) 2025-02-19 16:50 ` [LTP] [PATCH v2] " Petr Vorel 1 sibling, 3 replies; 22+ messages in thread From: Petr Vorel @ 2025-02-19 16:44 UTC (permalink / raw) To: chunfuwen; +Cc: Ricardo B. Marlière, ltp Hi Chunfu Wen, Besides Andrea's comments, there are other things to improve. > The test ensures that the process gets the correct signals in the correct order: > First, it should get SIGXCPU after reaching the soft CPU time limit64. > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > Signed-off-by: chunfuwen <chwen@redhat.com> > --- > Changes in v2: > - Romove test descriptions and trailing line as suggested by Ricardo B. Marlière > - Added 2025 copyright as suggested by Ricardo B. Marlière > - Trim down include files as suggested by Ricardo B. Marlière > - Create new lapi/resource.h residing struct rlimit64 as suggested by Andrea > - Move setrlimit_u64() syscalls definitions into lapi/resource.h as suggested by Andrea > - Skip SAFE_* variants as suggested by Andrea > - use tst_buffers when passing the pointeras suggested by Andrea > - Link to v1:https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ > --- > include/lapi/resource.h | 26 ++++ > .../kernel/syscalls/setrlimit/setrlimit07.c | 127 ++++++++++++++++++ > 2 files changed, 153 insertions(+) > create mode 100644 include/lapi/resource.h > create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c > diff --git a/include/lapi/resource.h b/include/lapi/resource.h > new file mode 100644 > index 000000000..3310bc934 > --- /dev/null > +++ b/include/lapi/resource.h > @@ -0,0 +1,26 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > + * Author: Chunfu Wen <chwen@redhat.com> > + */ > + > +#ifndef LAPI_RESOURCE_H__ > +#define LAPI_RESOURCE_H__ > + There should be at the top #include "config.h" otherwise #ifndef HAVE_STRUCT_RLIMIT64 is always false. > +#define _GNU_SOURCE > + > +#include "lapi/syscalls.h" This should include some header, I guess: #include <sys/resource.h> because there is already a check. AC_CHECK_TYPES([struct rlimit64],,,[ #define _LARGEFILE64_SOURCE #include <sys/resource.h> ]) NOTE: we prefer to uses libc headers instead of kernel headers if possible (e.g. not using <linux/resource.h>) due libc and kernel headers conflicts. https://sourceware.org/glibc/wiki/Synchronizing_Headers > + > +#ifndef HAVE_STRUCT_RLIMIT64 > +struct rlimit64 { > + uint64_t rlim_cur; > + uint64_t rlim_max; > +}; > +#endif > + > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > +{ > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); I suppose using raw syscall is really needed, right? C library/kernel ABI differences Since glibc 2.13, the glibc getrlimit() and setrlimit() wrapper functions no longer invoke the corresponding system calls, but instead employ prlimit(), for the reasons described in BUGS. The name of the glibc wrapper function is prlimit(); the underlying system call is prlimit64(). man getrlimit(2) says: https://man7.org/linux/man-pages/man2/getrlimit.2.html C library/kernel ABI differences Since glibc 2.13, the glibc getrlimit() and setrlimit() wrapper functions no longer invoke the corresponding system calls, but instead employ prlimit(), for the reasons described in BUGS. The name of the glibc wrapper function is prlimit(); the underlying system call is prlimit64(). ... Since glibc 2.13, glibc works around the limitations of the getrlimit() and setrlimit() system calls by implementing setrlimit() and getrlimit() as wrapper functions that call prlimit(). > +} > + > +#endif /* LAPI_RESOURCE_H__ */ I would probably separate adding the header into it's own commit, but it's ok to have everything in a single commit. > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit07.c b/testcases/kernel/syscalls/setrlimit/setrlimit07.c > new file mode 100644 > index 000000000..60a4580da > --- /dev/null > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit07.c > @@ -0,0 +1,127 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > + * Author: Chunfu Wen <chwen@redhat.com> > + */ > + > +/* > + * Set CPU time limit64 for a process and check its behavior > + * after reaching CPU time limit64. > + * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. > + * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. > + */ Please use docs like this: /*\ * Set CPU time limit64 for a process and check its behavior * after reaching CPU time limit64. * * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. */ /*\ is for docs to be parsed in metadata/ltp.json and included in https://linux-test-project.readthedocs.io/en/latest/users/test_catalog.html Extra space between list is needed to 1) and 2) be filtered as a list (not inline). Ideally you build the docs yourself https://linux-test-project.readthedocs.io/en/latest/developers/documentation.html#building-documentation and check the output in: doc/html/users/test_catalog.html#setrlimit07 > + > +#define _GNU_SOURCE > + > +#include <sys/wait.h> > + > +#include "tst_test.h" > + > +#include "lapi/syscalls.h" > + > +#include "lapi/resource.h" very nit: please remove blank lines between inludes > + > +#ifndef HAVE_STRUCT_RLIMIT64 > +struct rlimit64 { > + uint64_t rlim_cur; > + uint64_t rlim_max; > +}; > +#endif This is defined in lapi/resource.h which you include, no need to repeat it here. > + > +static struct rlimit64*rlim; > + > +static int *end; > + > +static void sighandler(int sig) > +{ > + *end = sig; > +} > + > +static void setup(void) > +{ > + signal(SIGXCPU, sighandler); > + > + end = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, > + MAP_SHARED | MAP_ANONYMOUS, -1, 0); Please use SAFE_MMAP(), otherwise there would have to be check: if (end == MAP_FAILED) tst_brk(TBROK | TERRNO, "mmap failed on nfildes"); > +} > + > +static void cleanup(void) > +{ > + if (end) > + munmap(end, sizeof(int)); We have SAFE_MUNMAP > +} > +/* > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > +{ > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > +}*/ Hm, commented out code, please remove it. > + > +static void verify_setrlimit64(void) > +{ > + int status; > + pid_t pid; > + > + rlim->rlim_cur = 1; > + rlim->rlim_max = 2; > + > + *end = 0; > + > + pid = fork(); > + if (!pid) { > + TEST(setrlimit_u64(RLIMIT_CPU, rlim)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, > + "setrlimit_u64(RLIMIT_CPU) failed"); We have TST_EXP_PASS() in tst_test_macros.h, please use it (or other if this is not appropriate. > + exit(1); > + } > + > + alarm(20); > + > + while (1) > + ; Why this? > + } > + > + waitpid(pid, &status, 0); Maybe SAFE_WAITPID() ? > + > + if (WIFEXITED(status) && WEXITSTATUS(status) == 1) > + return; > + > + if (WIFSIGNALED(status)) { > + if (WTERMSIG(status) == SIGKILL && *end == SIGXCPU) { > + tst_res(TPASS, > + "Got SIGXCPU then SIGKILL after reaching both limit"); > + return; > + } > + > + if (WTERMSIG(status) == SIGKILL && !*end) { > + tst_res(TFAIL, > + "Got only SIGKILL after reaching both limit"); > + return; > + } > + > + if (WTERMSIG(status) == SIGALRM && *end == SIGXCPU) { > + tst_res(TFAIL, > + "Got only SIGXCPU after reaching both limit"); > + return; > + } > + > + if (WTERMSIG(status) == SIGALRM && !*end) { > + tst_res(TFAIL, > + "Got no signal after reaching both limit"); > + return; > + } > + } > + > + tst_res(TFAIL, "Child %s", tst_strstatus(status)); > +} > + > +static struct tst_test test = { > + .test_all = verify_setrlimit64, > + .bufs = (struct tst_buffers []) { > + {&rlim, .size = sizeof(*rlim)}, > + {}, +1 for using guarded buffers. Please fix the indent. Last, but not least, code style: $ make check-setrlimit07 CHECK testcases/kernel/syscalls/setrlimit/setrlimit07.c setrlimit07.c:31: ERROR: "foo*bar" should be "foo *bar" setrlimit07.c:54: WARNING: Block comments use * on subsequent lines setrlimit07.c:57: WARNING: Block comments use a trailing */ on a separate line setrlimit07.c:120: ERROR: code indent should use tabs where possible setrlimit07.c:120: WARNING: please, no spaces at the start of a line setrlimit07.c:121: ERROR: code indent should use tabs where possible setrlimit07.c:121: WARNING: please, no spaces at the start of a line setrlimit07.c:122: ERROR: code indent should use tabs where possible setrlimit07.c:122: WARNING: please, no spaces at the start of a line Kind regards, Petr > + }, > + .setup = setup, > + .cleanup = cleanup, > + .forks_child = 1, > +}; -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process 2025-02-19 16:44 ` Petr Vorel @ 2025-02-20 2:08 ` Li Wang 2025-02-20 9:35 ` Petr Vorel 2025-02-20 8:01 ` Chunfu Wen 2025-02-20 8:35 ` [LTP] [PATCH v3] " Chunfu Wen 2 siblings, 1 reply; 22+ messages in thread From: Li Wang @ 2025-02-20 2:08 UTC (permalink / raw) To: Petr Vorel; +Cc: ltp, Ricardo B. Marlière On Thu, Feb 20, 2025 at 12:45 AM Petr Vorel <pvorel@suse.cz> wrote: > Hi Chunfu Wen, > > Besides Andrea's comments, there are other things to improve. > > > > The test ensures that the process gets the correct signals in the > correct order: > > > First, it should get SIGXCPU after reaching the soft CPU time limit64. > > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > > > Signed-off-by: chunfuwen <chwen@redhat.com> > > --- > > Changes in v2: > > - Romove test descriptions and trailing line as suggested by Ricardo B. > Marlière > > - Added 2025 copyright as suggested by Ricardo B. Marlière > > - Trim down include files as suggested by Ricardo B. Marlière > > - Create new lapi/resource.h residing struct rlimit64 as suggested by > Andrea > > - Move setrlimit_u64() syscalls definitions into lapi/resource.h as > suggested by Andrea > > - Skip SAFE_* variants as suggested by Andrea > > - use tst_buffers when passing the pointeras suggested by Andrea > > - Link to v1: > https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ > > --- > > include/lapi/resource.h | 26 ++++ > > .../kernel/syscalls/setrlimit/setrlimit07.c | 127 ++++++++++++++++++ > > 2 files changed, 153 insertions(+) > > create mode 100644 include/lapi/resource.h > > create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c > > > diff --git a/include/lapi/resource.h b/include/lapi/resource.h > > new file mode 100644 > > index 000000000..3310bc934 > > --- /dev/null > > +++ b/include/lapi/resource.h > > @@ -0,0 +1,26 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > > + * Author: Chunfu Wen <chwen@redhat.com> > > + */ > > + > > +#ifndef LAPI_RESOURCE_H__ > > +#define LAPI_RESOURCE_H__ > > + > There should be at the top > > #include "config.h" > otherwise #ifndef HAVE_STRUCT_RLIMIT64 is always false. > > > +#define _GNU_SOURCE > > + > > +#include "lapi/syscalls.h" > > This should include some header, I guess: > #include <sys/resource.h> > > because there is already a check. > AC_CHECK_TYPES([struct rlimit64],,,[ > #define _LARGEFILE64_SOURCE > #include <sys/resource.h> > ]) > > NOTE: we prefer to uses libc headers instead of kernel headers if possible > (e.g. not using <linux/resource.h>) due libc and kernel headers conflicts. > https://sourceware.org/glibc/wiki/Synchronizing_Headers > > > + > > +#ifndef HAVE_STRUCT_RLIMIT64 > > +struct rlimit64 { > > + uint64_t rlim_cur; > > + uint64_t rlim_max; > > +}; > > +#endif > > + > > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > > +{ > > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > I suppose using raw syscall is really needed, right? > Yes, using the raw syscall for prlimit64 is necessary in this case. From what I know, Chufu is working oin an environment where glibc's wrapper might interfere, using tst_syscall(__NR_prlimit64, ...) ensures that the raw syscall is executed without relying on glibc behavior. @chuwen, this new case is quite similar to setrlimit06.c, maybe we can combine into one and use .test_variants to traverse all syscalls. e.g. syscalls/stime/stime_var.h. -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process 2025-02-20 2:08 ` Li Wang @ 2025-02-20 9:35 ` Petr Vorel 0 siblings, 0 replies; 22+ messages in thread From: Petr Vorel @ 2025-02-20 9:35 UTC (permalink / raw) To: Li Wang; +Cc: ltp, Ricardo B. Marlière Hi Li, Chunfu Wen, ... > > > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > > > +{ > > > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > > I suppose using raw syscall is really needed, right? > Yes, using the raw syscall for prlimit64 is necessary in this case. > From what I know, Chufu is working oin an environment where glibc's > wrapper might interfere, using tst_syscall(__NR_prlimit64, ...) ensures > that the raw syscall is executed without relying on glibc behavior. Li, thanks for info. > @chuwen, this new case is quite similar to setrlimit06.c, maybe we > can combine into one and use .test_variants to traverse all syscalls. > e.g. syscalls/stime/stime_var.h. +1 Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process 2025-02-19 16:44 ` Petr Vorel 2025-02-20 2:08 ` Li Wang @ 2025-02-20 8:01 ` Chunfu Wen 2025-02-20 8:35 ` [LTP] [PATCH v3] " Chunfu Wen 2 siblings, 0 replies; 22+ messages in thread From: Chunfu Wen @ 2025-02-20 8:01 UTC (permalink / raw) To: Petr Vorel; +Cc: Ricardo B. Marlière, ltp Hello Petr, Thanks for reviewing. See inline comments. Chunfu Wen On Thu, Feb 20, 2025 at 12:45 AM Petr Vorel <pvorel@suse.cz> wrote: > Hi Chunfu Wen, > > Besides Andrea's comments, there are other things to improve. > [chwen] merge all things into setrlimit06.c, and delete setrlimit07.c > > > > The test ensures that the process gets the correct signals in the > correct order: > > > First, it should get SIGXCPU after reaching the soft CPU time limit64. > > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > > > Signed-off-by: chunfuwen <chwen@redhat.com> > > --- > > Changes in v2: > > - Romove test descriptions and trailing line as suggested by Ricardo B. > Marlière > > - Added 2025 copyright as suggested by Ricardo B. Marlière > > - Trim down include files as suggested by Ricardo B. Marlière > > - Create new lapi/resource.h residing struct rlimit64 as suggested by > Andrea > > - Move setrlimit_u64() syscalls definitions into lapi/resource.h as > suggested by Andrea > > - Skip SAFE_* variants as suggested by Andrea > > - use tst_buffers when passing the pointeras suggested by Andrea > > - Link to v1: > https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ > > --- > > include/lapi/resource.h | 26 ++++ > > .../kernel/syscalls/setrlimit/setrlimit07.c | 127 ++++++++++++++++++ > > 2 files changed, 153 insertions(+) > > create mode 100644 include/lapi/resource.h > > create mode 100644 testcases/kernel/syscalls/setrlimit/setrlimit07.c > > > diff --git a/include/lapi/resource.h b/include/lapi/resource.h > > new file mode 100644 > > index 000000000..3310bc934 > > --- /dev/null > > +++ b/include/lapi/resource.h > > @@ -0,0 +1,26 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > > + * Author: Chunfu Wen <chwen@redhat.com> > > + */ > > + > > +#ifndef LAPI_RESOURCE_H__ > > +#define LAPI_RESOURCE_H__ > > + > There should be at the top > > #include "config.h" > otherwise #ifndef HAVE_STRUCT_RLIMIT64 is always false. > [chwen] Done. > > > +#define _GNU_SOURCE > > + > > +#include "lapi/syscalls.h" > > This should include some header, I guess: > #include <sys/resource.h> > [chwen] added > > because there is already a check. > AC_CHECK_TYPES([struct rlimit64],,,[ > #define _LARGEFILE64_SOURCE > #include <sys/resource.h> > ]) > > NOTE: we prefer to uses libc headers instead of kernel headers if possible > (e.g. not using <linux/resource.h>) due libc and kernel headers conflicts. > https://sourceware.org/glibc/wiki/Synchronizing_Headers > > > + > > +#ifndef HAVE_STRUCT_RLIMIT64 > > +struct rlimit64 { > > + uint64_t rlim_cur; > > + uint64_t rlim_max; > > +}; > > +#endif > > + > > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > > +{ > > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > I suppose using raw syscall is really needed, right? > > C library/kernel ABI differences > Since glibc 2.13, the glibc getrlimit() and setrlimit() wrapper > functions no longer invoke the corresponding system calls, but instead > employ prlimit(), for the reasons described in BUGS. > > The name of the glibc wrapper function is prlimit(); the underlying > system call is prlimit64(). > > man getrlimit(2) says: > https://man7.org/linux/man-pages/man2/getrlimit.2.html > > C library/kernel ABI differences > Since glibc 2.13, the glibc getrlimit() and setrlimit() wrapper > functions no longer invoke the corresponding system calls, but > instead employ prlimit(), for the reasons described in BUGS. > > The name of the glibc wrapper function is prlimit(); the > underlying system call is prlimit64(). > > ... > Since glibc 2.13, glibc works around the limitations of the > getrlimit() and setrlimit() system calls by implementing > setrlimit() and getrlimit() as wrapper functions that call > prlimit(). > [chwen] See Wang Li' replied email > > +} > > + > > +#endif /* LAPI_RESOURCE_H__ */ > > I would probably separate adding the header into it's own commit, but it's > ok to > have everything in a single commit. > > > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit07.c > b/testcases/kernel/syscalls/setrlimit/setrlimit07.c > > new file mode 100644 > > index 000000000..60a4580da > > --- /dev/null > > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit07.c > > @@ -0,0 +1,127 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > > + * Author: Chunfu Wen <chwen@redhat.com> > > + */ > > + > > +/* > > + * Set CPU time limit64 for a process and check its behavior > > + * after reaching CPU time limit64. > > + * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. > > + * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. > > + */ > > Please use docs like this: > > /*\ > * Set CPU time limit64 for a process and check its behavior > * after reaching CPU time limit64. > * > * 1) Process got SIGXCPU after reaching soft limit of CPU time limit64. > * 2) Process got SIGKILL after reaching hard limit of CPU time limit64. > */ > > /*\ is for docs to be parsed in metadata/ltp.json and included in > https://linux-test-project.readthedocs.io/en/latest/users/test_catalog.html > > Extra space between list is needed to 1) and 2) be filtered as a list (not > inline). > > Ideally you build the docs yourself > > https://linux-test-project.readthedocs.io/en/latest/developers/documentation.html#building-documentation > > and check the output in: doc/html/users/test_catalog.html#setrlimit07 > [chwen] this is not a issue since merging into setrlimit06 > > + > > +#define _GNU_SOURCE > > + > > +#include <sys/wait.h> > > + > > +#include "tst_test.h" > > + > > +#include "lapi/syscalls.h" > > + > > +#include "lapi/resource.h" > > very nit: please remove blank lines between inludes > [chwen] Done > > + > > +#ifndef HAVE_STRUCT_RLIMIT64 > > +struct rlimit64 { > > + uint64_t rlim_cur; > > + uint64_t rlim_max; > > +}; > > +#endif > > This is defined in lapi/resource.h which you include, no need to repeat it > here. > [chwen] Done > > + > > +static struct rlimit64*rlim; > > + > > +static int *end; > > + > > +static void sighandler(int sig) > > +{ > > + *end = sig; > > +} > > + > > +static void setup(void) > > +{ > > + signal(SIGXCPU, sighandler); > > + > > + end = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, > > + MAP_SHARED | MAP_ANONYMOUS, -1, 0); > > Please use SAFE_MMAP(), otherwise there would have to be check: > [chwen] it is not a issue now since it is merged into setrlimit06.c > if (end == MAP_FAILED) > tst_brk(TBROK | TERRNO, "mmap failed on nfildes"); > > > +} > > + > > +static void cleanup(void) > > +{ > > + if (end) > > + munmap(end, sizeof(int)); > We have SAFE_MUNMAP > > > +} > > +/* > > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > > +{ > > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > > +}*/ > Hm, commented out code, please remove it. > [chwen] Done > > + > > +static void verify_setrlimit64(void) > > +{ > > + int status; > > + pid_t pid; > > + > > + rlim->rlim_cur = 1; > > + rlim->rlim_max = 2; > > + > > + *end = 0; > > + > > + pid = fork(); > > + if (!pid) { > > + TEST(setrlimit_u64(RLIMIT_CPU, rlim)); > > + if (TST_RET == -1) { > > + tst_res(TFAIL | TTERRNO, > > + "setrlimit_u64(RLIMIT_CPU) failed"); > We have TST_EXP_PASS() in tst_test_macros.h, please use it (or other if > this is > not appropriate. > > > + exit(1); > > > + } > > + > > + alarm(20); > > + > > + while (1) > > + ; > Why this? > [chwen] aims to Suppress make check warnging > > + } > > + > > + waitpid(pid, &status, 0); > Maybe SAFE_WAITPID() ? > > + > > + if (WIFEXITED(status) && WEXITSTATUS(status) == 1) > > + return; > > + > > + if (WIFSIGNALED(status)) { > > + if (WTERMSIG(status) == SIGKILL && *end == SIGXCPU) { > > + tst_res(TPASS, > > + "Got SIGXCPU then SIGKILL after reaching > both limit"); > > + return; > > + } > > + > > + if (WTERMSIG(status) == SIGKILL && !*end) { > > + tst_res(TFAIL, > > + "Got only SIGKILL after reaching both > limit"); > > + return; > > + } > > + > > + if (WTERMSIG(status) == SIGALRM && *end == SIGXCPU) { > > + tst_res(TFAIL, > > + "Got only SIGXCPU after reaching both > limit"); > > + return; > > + } > > + > > + if (WTERMSIG(status) == SIGALRM && !*end) { > > + tst_res(TFAIL, > > + "Got no signal after reaching both limit"); > > + return; > > + } > > + } > > + > > + tst_res(TFAIL, "Child %s", tst_strstatus(status)); > > +} > > + > > +static struct tst_test test = { > > + .test_all = verify_setrlimit64, > > + .bufs = (struct tst_buffers []) { > > + {&rlim, .size = sizeof(*rlim)}, > > + {}, > +1 for using guarded buffers. > Please fix the indent. > > Last, but not least, code style: > $ make check-setrlimit07 > CHECK testcases/kernel/syscalls/setrlimit/setrlimit07.c > setrlimit07.c:31: ERROR: "foo*bar" should be "foo *bar" > setrlimit07.c:54: WARNING: Block comments use * on subsequent lines > setrlimit07.c:57: WARNING: Block comments use a trailing */ on a separate > line > setrlimit07.c:120: ERROR: code indent should use tabs where possible > setrlimit07.c:120: WARNING: please, no spaces at the start of a line > setrlimit07.c:121: ERROR: code indent should use tabs where possible > setrlimit07.c:121: WARNING: please, no spaces at the start of a line > setrlimit07.c:122: ERROR: code indent should use tabs where possible > setrlimit07.c:122: WARNING: please, no spaces at the start of a line > > Kind regards, > Petr > > > + }, > > + .setup = setup, > > + .cleanup = cleanup, > > + .forks_child = 1, > > +}; > [chwen] all warning and error issue reported by make check-setrlimitxx > were addressed -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* [LTP] [PATCH v3] Add test case to cover the setting resource limit64 for process 2025-02-19 16:44 ` Petr Vorel 2025-02-20 2:08 ` Li Wang 2025-02-20 8:01 ` Chunfu Wen @ 2025-02-20 8:35 ` Chunfu Wen 2025-02-21 10:34 ` Andrea Cervesato via ltp 2 siblings, 1 reply; 22+ messages in thread From: Chunfu Wen @ 2025-02-20 8:35 UTC (permalink / raw) To: ltp From: chunfuwen <chwen@redhat.com> The test ensures that the process gets the correct signals in the correct order: First, it should get SIGXCPU after reaching the soft CPU time limit64. Then, if the CPU time exceeds the hard limit, it should receive SIGKILL Signed-off-by: chunfuwen <chwen@redhat.com> --- Changes in v3: - Add test logic into current existed file :setrlimit06.c - Remove setrlimit07.c file - Use test_variants to loop different types - Address review comments related to lapi/resurce.h - Fix make check issue:while (1) on previous setrlimit06.c file - Link to v1:https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ - Note: it looks like while (1) can not be replaced here after testing by either usleep() or TST_CHECKPOINT_WAKE --- include/lapi/resource.h | 28 +++++++++++++++ .../kernel/syscalls/setrlimit/setrlimit06.c | 34 +++++++++++++++---- 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 include/lapi/resource.h diff --git a/include/lapi/resource.h b/include/lapi/resource.h new file mode 100644 index 000000000..a9bc57a0a --- /dev/null +++ b/include/lapi/resource.h @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. + * Author: Chunfu Wen <chwen@redhat.com> + */ + +#ifndef LAPI_RESOURCE_H__ +#define LAPI_RESOURCE_H__ + +#define _GNU_SOURCE + +#include "config.h" +#include <sys/resource.h> +#include "lapi/syscalls.h" + +#ifndef HAVE_STRUCT_RLIMIT64 +struct rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; +#endif + +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) +{ + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); +} + +#endif /* LAPI_RESOURCE_H__ */ diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit06.c b/testcases/kernel/syscalls/setrlimit/setrlimit06.c index 9ff515d81..f40774de7 100644 --- a/testcases/kernel/syscalls/setrlimit/setrlimit06.c +++ b/testcases/kernel/syscalls/setrlimit/setrlimit06.c @@ -27,6 +27,12 @@ #include <sys/mman.h> #include "tst_test.h" +#include "lapi/resource.h" + +#define TEST_VARIANTS 2 + +static struct rlimit *rlim; +static struct rlimit64 *rlim_64; static int *end; @@ -37,6 +43,11 @@ static void sighandler(int sig) static void setup(void) { + rlim->rlim_cur = 1; + rlim->rlim_max = 2; + rlim_64->rlim_cur = 1; + rlim_64->rlim_max = 2; + SAFE_SIGNAL(SIGXCPU, sighandler); end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, @@ -58,12 +69,14 @@ static void verify_setrlimit(void) pid = SAFE_FORK(); if (!pid) { - struct rlimit rlim = { - .rlim_cur = 1, - .rlim_max = 2, - }; - - TEST(setrlimit(RLIMIT_CPU, &rlim)); + switch (tst_variant) { + case 0: + TEST(setrlimit(RLIMIT_CPU, rlim)); + break; + case 1: + TEST(setrlimit_u64(RLIMIT_CPU, rlim_64)); + break; + } if (TST_RET == -1) { tst_res(TFAIL | TTERRNO, "setrlimit(RLIMIT_CPU) failed"); @@ -72,7 +85,8 @@ static void verify_setrlimit(void) alarm(20); - while (1); + while (1) + ; } SAFE_WAITPID(pid, &status, 0); @@ -112,6 +126,12 @@ static void verify_setrlimit(void) static struct tst_test test = { .test_all = verify_setrlimit, .setup = setup, + .test_variants = TEST_VARIANTS, + .bufs = (struct tst_buffers []) { + {&rlim, .size = sizeof(*rlim)}, + {&rlim_64, .size = sizeof(*rlim_64)}, + {} + }, .cleanup = cleanup, .forks_child = 1, .tags = (const struct tst_tag[]) { -- 2.43.5 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v3] Add test case to cover the setting resource limit64 for process 2025-02-20 8:35 ` [LTP] [PATCH v3] " Chunfu Wen @ 2025-02-21 10:34 ` Andrea Cervesato via ltp 2025-02-24 3:06 ` Chunfu Wen 2025-02-24 3:07 ` [LTP] [PATCH v4] " Chunfu Wen 0 siblings, 2 replies; 22+ messages in thread From: Andrea Cervesato via ltp @ 2025-02-21 10:34 UTC (permalink / raw) To: Chunfu Wen, ltp Hi! Thanks for converting 64bit test into setrlimit06. Please take in consideration the reviews given in the v2 to process v4, unfortunately the reviews arrived slightly before this version. Kind regards, Andrea Cervesato On 2/20/25 09:35, Chunfu Wen wrote: > From: chunfuwen <chwen@redhat.com> > > The test ensures that the process gets the correct signals in the correct order: > > First, it should get SIGXCPU after reaching the soft CPU time limit64. > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > > Signed-off-by: chunfuwen <chwen@redhat.com> > --- > Changes in v3: > - Add test logic into current existed file :setrlimit06.c > - Remove setrlimit07.c file > - Use test_variants to loop different types > - Address review comments related to lapi/resurce.h > - Fix make check issue:while (1) on previous setrlimit06.c file > - Link to v1:https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ > - Note: it looks like while (1) can not be replaced here after testing by either usleep() or TST_CHECKPOINT_WAKE > --- > include/lapi/resource.h | 28 +++++++++++++++ > .../kernel/syscalls/setrlimit/setrlimit06.c | 34 +++++++++++++++---- > 2 files changed, 55 insertions(+), 7 deletions(-) > create mode 100644 include/lapi/resource.h > > diff --git a/include/lapi/resource.h b/include/lapi/resource.h > new file mode 100644 > index 000000000..a9bc57a0a > --- /dev/null > +++ b/include/lapi/resource.h > @@ -0,0 +1,28 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > + * Author: Chunfu Wen <chwen@redhat.com> > + */ > + > +#ifndef LAPI_RESOURCE_H__ > +#define LAPI_RESOURCE_H__ > + > +#define _GNU_SOURCE > + > +#include "config.h" > +#include <sys/resource.h> > +#include "lapi/syscalls.h" > + > +#ifndef HAVE_STRUCT_RLIMIT64 > +struct rlimit64 { > + uint64_t rlim_cur; > + uint64_t rlim_max; > +}; > +#endif > + > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > +{ > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > +} > + > +#endif /* LAPI_RESOURCE_H__ */ > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit06.c b/testcases/kernel/syscalls/setrlimit/setrlimit06.c > index 9ff515d81..f40774de7 100644 > --- a/testcases/kernel/syscalls/setrlimit/setrlimit06.c > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit06.c > @@ -27,6 +27,12 @@ > #include <sys/mman.h> > > #include "tst_test.h" > +#include "lapi/resource.h" > + > +#define TEST_VARIANTS 2 > + > +static struct rlimit *rlim; > +static struct rlimit64 *rlim_64; > > static int *end; > > @@ -37,6 +43,11 @@ static void sighandler(int sig) > > static void setup(void) > { > + rlim->rlim_cur = 1; > + rlim->rlim_max = 2; > + rlim_64->rlim_cur = 1; > + rlim_64->rlim_max = 2; > + > SAFE_SIGNAL(SIGXCPU, sighandler); > > end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, > @@ -58,12 +69,14 @@ static void verify_setrlimit(void) > > pid = SAFE_FORK(); > if (!pid) { > - struct rlimit rlim = { > - .rlim_cur = 1, > - .rlim_max = 2, > - }; > - > - TEST(setrlimit(RLIMIT_CPU, &rlim)); > + switch (tst_variant) { > + case 0: > + TEST(setrlimit(RLIMIT_CPU, rlim)); > + break; > + case 1: > + TEST(setrlimit_u64(RLIMIT_CPU, rlim_64)); > + break; > + } > if (TST_RET == -1) { > tst_res(TFAIL | TTERRNO, > "setrlimit(RLIMIT_CPU) failed"); > @@ -72,7 +85,8 @@ static void verify_setrlimit(void) > > alarm(20); > > - while (1); > + while (1) > + ; > } > > SAFE_WAITPID(pid, &status, 0); > @@ -112,6 +126,12 @@ static void verify_setrlimit(void) > static struct tst_test test = { > .test_all = verify_setrlimit, > .setup = setup, > + .test_variants = TEST_VARIANTS, > + .bufs = (struct tst_buffers []) { > + {&rlim, .size = sizeof(*rlim)}, > + {&rlim_64, .size = sizeof(*rlim_64)}, > + {} > + }, > .cleanup = cleanup, > .forks_child = 1, > .tags = (const struct tst_tag[]) { -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v3] Add test case to cover the setting resource limit64 for process 2025-02-21 10:34 ` Andrea Cervesato via ltp @ 2025-02-24 3:06 ` Chunfu Wen 2025-02-24 3:07 ` [LTP] [PATCH v4] " Chunfu Wen 1 sibling, 0 replies; 22+ messages in thread From: Chunfu Wen @ 2025-02-24 3:06 UTC (permalink / raw) To: Andrea Cervesato; +Cc: ltp Hello Andrea, Thank you for reviewing. I pasted your previous review comments here, and give some inline feedback. If I missed something, please let me know. Chunfu Wen - [Andrea]we are already defining the "struct rlimit64" inside getrlimit03, so we need to create a new file lapi/resource.h where we move that struct, checking if HAVE_STRUCT_RLIMIT64 is not defined. I guess the same should be done for getrlimit_u64()/setrlimit_u64() syscalls definitions. Better to move them in there in case we will need it in the future . We can skip SAFE_* variants at the moment, since we are not using them around LTP test for now. [chwen] - One file:resource.h was created newly, and struct rlimit64 and its related to setxx are moved into this file. - In terms of skip SAFE_* variants, I noticed Petr Vorel had a different opinion in a previous comment that suggested using SAFE_*, so I will keep them there. - [Andrea]in both setrlimit06 and setrlimit07 we should probably use tst_buffers for safety reasons when passing the pointer to the rlimit/rlimit64 struct we are gonna use [chwen]tst_buffers is already adopted in the patch - [Andrea]it's worth to check if the other tests might introduce the same 64bit variants [chwen] I ever grep source code under ltp, not finding that introduce the same 64bit variants [Andrea]FYI i noticed that setrlimit06 description can't be fetched in the metadata because it's not initialized with /*\ . It also needs to be changed into the RST format instead of asciidoc. [chwen] This is done in patch v4 On Fri, Feb 21, 2025 at 6:34 PM Andrea Cervesato <andrea.cervesato@suse.com> wrote: > Hi! > > Thanks for converting 64bit test into setrlimit06. Please take in > consideration the reviews given in the v2 to process v4, unfortunately > the reviews arrived slightly before this version. > > Kind regards, > Andrea Cervesato > > On 2/20/25 09:35, Chunfu Wen wrote: > > From: chunfuwen <chwen@redhat.com> > > > > The test ensures that the process gets the correct signals in the > correct order: > > > > First, it should get SIGXCPU after reaching the soft CPU time limit64. > > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > > > > Signed-off-by: chunfuwen <chwen@redhat.com> > > --- > > Changes in v3: > > - Add test logic into current existed file :setrlimit06.c > > - Remove setrlimit07.c file > > - Use test_variants to loop different types > > - Address review comments related to lapi/resurce.h > > - Fix make check issue:while (1) on previous setrlimit06.c file > > - Link to v1: > https://lore.kernel.org/all/20250218023107.1208990-1-chwen@redhat.com/ > > - Note: it looks like while (1) can not be replaced here after testing > by either usleep() or TST_CHECKPOINT_WAKE > > --- > > include/lapi/resource.h | 28 +++++++++++++++ > > .../kernel/syscalls/setrlimit/setrlimit06.c | 34 +++++++++++++++---- > > 2 files changed, 55 insertions(+), 7 deletions(-) > > create mode 100644 include/lapi/resource.h > > > > diff --git a/include/lapi/resource.h b/include/lapi/resource.h > > new file mode 100644 > > index 000000000..a9bc57a0a > > --- /dev/null > > +++ b/include/lapi/resource.h > > @@ -0,0 +1,28 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > > + * Author: Chunfu Wen <chwen@redhat.com> > > + */ > > + > > +#ifndef LAPI_RESOURCE_H__ > > +#define LAPI_RESOURCE_H__ > > + > > +#define _GNU_SOURCE > > + > > +#include "config.h" > > +#include <sys/resource.h> > > +#include "lapi/syscalls.h" > > + > > +#ifndef HAVE_STRUCT_RLIMIT64 > > +struct rlimit64 { > > + uint64_t rlim_cur; > > + uint64_t rlim_max; > > +}; > > +#endif > > + > > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > > +{ > > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > > +} > > + > > +#endif /* LAPI_RESOURCE_H__ */ > > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit06.c > b/testcases/kernel/syscalls/setrlimit/setrlimit06.c > > index 9ff515d81..f40774de7 100644 > > --- a/testcases/kernel/syscalls/setrlimit/setrlimit06.c > > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit06.c > > @@ -27,6 +27,12 @@ > > #include <sys/mman.h> > > > > #include "tst_test.h" > > +#include "lapi/resource.h" > > + > > +#define TEST_VARIANTS 2 > > + > > +static struct rlimit *rlim; > > +static struct rlimit64 *rlim_64; > > > > static int *end; > > > > @@ -37,6 +43,11 @@ static void sighandler(int sig) > > > > static void setup(void) > > { > > + rlim->rlim_cur = 1; > > + rlim->rlim_max = 2; > > + rlim_64->rlim_cur = 1; > > + rlim_64->rlim_max = 2; > > + > > SAFE_SIGNAL(SIGXCPU, sighandler); > > > > end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, > > @@ -58,12 +69,14 @@ static void verify_setrlimit(void) > > > > pid = SAFE_FORK(); > > if (!pid) { > > - struct rlimit rlim = { > > - .rlim_cur = 1, > > - .rlim_max = 2, > > - }; > > - > > - TEST(setrlimit(RLIMIT_CPU, &rlim)); > > + switch (tst_variant) { > > + case 0: > > + TEST(setrlimit(RLIMIT_CPU, rlim)); > > + break; > > + case 1: > > + TEST(setrlimit_u64(RLIMIT_CPU, rlim_64)); > > + break; > > + } > > if (TST_RET == -1) { > > tst_res(TFAIL | TTERRNO, > > "setrlimit(RLIMIT_CPU) failed"); > > @@ -72,7 +85,8 @@ static void verify_setrlimit(void) > > > > alarm(20); > > > > - while (1); > > + while (1) > > + ; > > } > > > > SAFE_WAITPID(pid, &status, 0); > > @@ -112,6 +126,12 @@ static void verify_setrlimit(void) > > static struct tst_test test = { > > .test_all = verify_setrlimit, > > .setup = setup, > > + .test_variants = TEST_VARIANTS, > > + .bufs = (struct tst_buffers []) { > > + {&rlim, .size = sizeof(*rlim)}, > > + {&rlim_64, .size = sizeof(*rlim_64)}, > > + {} > > + }, > > .cleanup = cleanup, > > .forks_child = 1, > > .tags = (const struct tst_tag[]) { > > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-21 10:34 ` Andrea Cervesato via ltp 2025-02-24 3:06 ` Chunfu Wen @ 2025-02-24 3:07 ` Chunfu Wen 2025-02-26 1:15 ` Chunfu Wen 2025-02-26 9:21 ` Li Wang 1 sibling, 2 replies; 22+ messages in thread From: Chunfu Wen @ 2025-02-24 3:07 UTC (permalink / raw) To: ltp From: chunfuwen <chwen@redhat.com> The test ensures that the process gets the correct signals in the correct order: First, it should get SIGXCPU after reaching the soft CPU time limit64. Then, if the CPU time exceeds the hard limit, it should receive SIGKILL Signed-off-by: chunfuwen <chwen@redhat.com> --- include/lapi/resource.h | 28 ++++++++++++ .../kernel/syscalls/setrlimit/setrlimit06.c | 44 ++++++++++++++----- 2 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 include/lapi/resource.h diff --git a/include/lapi/resource.h b/include/lapi/resource.h new file mode 100644 index 000000000..a9bc57a0a --- /dev/null +++ b/include/lapi/resource.h @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. + * Author: Chunfu Wen <chwen@redhat.com> + */ + +#ifndef LAPI_RESOURCE_H__ +#define LAPI_RESOURCE_H__ + +#define _GNU_SOURCE + +#include "config.h" +#include <sys/resource.h> +#include "lapi/syscalls.h" + +#ifndef HAVE_STRUCT_RLIMIT64 +struct rlimit64 { + uint64_t rlim_cur; + uint64_t rlim_max; +}; +#endif + +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) +{ + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); +} + +#endif /* LAPI_RESOURCE_H__ */ diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit06.c b/testcases/kernel/syscalls/setrlimit/setrlimit06.c index 9ff515d81..ded550973 100644 --- a/testcases/kernel/syscalls/setrlimit/setrlimit06.c +++ b/testcases/kernel/syscalls/setrlimit/setrlimit06.c @@ -4,12 +4,12 @@ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com> */ -/* - * Description: +/*\ * Set CPU time limit for a process and check its behavior - * after reaching CPU time limit. - * 1) Process got SIGXCPU after reaching soft limit of CPU time. - * 2) Process got SIGKILL after reaching hard limit of CPU time. + * after reaching CPU time limit + * + * - Process got SIGXCPU after reaching soft limit of CPU time + * - Process got SIGKILL after reaching hard limit of CPU time * * Note: * This is also a regression test for the following kernel bug: @@ -27,6 +27,12 @@ #include <sys/mman.h> #include "tst_test.h" +#include "lapi/resource.h" + +#define TEST_VARIANTS 2 + +static struct rlimit *rlim; +static struct rlimit64 *rlim_64; static int *end; @@ -37,6 +43,11 @@ static void sighandler(int sig) static void setup(void) { + rlim->rlim_cur = 1; + rlim->rlim_max = 2; + rlim_64->rlim_cur = 1; + rlim_64->rlim_max = 2; + SAFE_SIGNAL(SIGXCPU, sighandler); end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, @@ -58,12 +69,14 @@ static void verify_setrlimit(void) pid = SAFE_FORK(); if (!pid) { - struct rlimit rlim = { - .rlim_cur = 1, - .rlim_max = 2, - }; - - TEST(setrlimit(RLIMIT_CPU, &rlim)); + switch (tst_variant) { + case 0: + TEST(setrlimit(RLIMIT_CPU, rlim)); + break; + case 1: + TEST(setrlimit_u64(RLIMIT_CPU, rlim_64)); + break; + } if (TST_RET == -1) { tst_res(TFAIL | TTERRNO, "setrlimit(RLIMIT_CPU) failed"); @@ -72,7 +85,8 @@ static void verify_setrlimit(void) alarm(20); - while (1); + while (1) + ; } SAFE_WAITPID(pid, &status, 0); @@ -112,6 +126,12 @@ static void verify_setrlimit(void) static struct tst_test test = { .test_all = verify_setrlimit, .setup = setup, + .test_variants = TEST_VARIANTS, + .bufs = (struct tst_buffers []) { + {&rlim, .size = sizeof(*rlim)}, + {&rlim_64, .size = sizeof(*rlim_64)}, + {} + }, .cleanup = cleanup, .forks_child = 1, .tags = (const struct tst_tag[]) { -- 2.43.5 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-24 3:07 ` [LTP] [PATCH v4] " Chunfu Wen @ 2025-02-26 1:15 ` Chunfu Wen 2025-02-28 3:41 ` Li Wang 2025-02-26 9:21 ` Li Wang 1 sibling, 1 reply; 22+ messages in thread From: Chunfu Wen @ 2025-02-26 1:15 UTC (permalink / raw) To: ltp; +Cc: Charles Shi, Li Wang, Irene Diez Hello Maintainers, Could you please help me review the V4 patch when you have time? Best Regards, Chunfu Wen On Mon, Feb 24, 2025 at 11:07 AM Chunfu Wen <chwen@redhat.com> wrote: > From: chunfuwen <chwen@redhat.com> > > The test ensures that the process gets the correct signals in the correct > order: > > First, it should get SIGXCPU after reaching the soft CPU time limit64. > Then, if the CPU time exceeds the hard limit, it should receive SIGKILL > > Signed-off-by: chunfuwen <chwen@redhat.com> > --- > include/lapi/resource.h | 28 ++++++++++++ > .../kernel/syscalls/setrlimit/setrlimit06.c | 44 ++++++++++++++----- > 2 files changed, 60 insertions(+), 12 deletions(-) > create mode 100644 include/lapi/resource.h > > diff --git a/include/lapi/resource.h b/include/lapi/resource.h > new file mode 100644 > index 000000000..a9bc57a0a > --- /dev/null > +++ b/include/lapi/resource.h > @@ -0,0 +1,28 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2025 Red Hat Inc. All Rights Reserved. > + * Author: Chunfu Wen <chwen@redhat.com> > + */ > + > +#ifndef LAPI_RESOURCE_H__ > +#define LAPI_RESOURCE_H__ > + > +#define _GNU_SOURCE > + > +#include "config.h" > +#include <sys/resource.h> > +#include "lapi/syscalls.h" > + > +#ifndef HAVE_STRUCT_RLIMIT64 > +struct rlimit64 { > + uint64_t rlim_cur; > + uint64_t rlim_max; > +}; > +#endif > + > +static int setrlimit_u64(int resource, const struct rlimit64 *rlim) > +{ > + return tst_syscall(__NR_prlimit64, 0, resource, rlim, NULL); > +} > + > +#endif /* LAPI_RESOURCE_H__ */ > diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit06.c > b/testcases/kernel/syscalls/setrlimit/setrlimit06.c > index 9ff515d81..ded550973 100644 > --- a/testcases/kernel/syscalls/setrlimit/setrlimit06.c > +++ b/testcases/kernel/syscalls/setrlimit/setrlimit06.c > @@ -4,12 +4,12 @@ > * Author: Xiao Yang <yangx.jy@cn.fujitsu.com> > */ > > -/* > - * Description: > +/*\ > * Set CPU time limit for a process and check its behavior > - * after reaching CPU time limit. > - * 1) Process got SIGXCPU after reaching soft limit of CPU time. > - * 2) Process got SIGKILL after reaching hard limit of CPU time. > + * after reaching CPU time limit > + * > + * - Process got SIGXCPU after reaching soft limit of CPU time > + * - Process got SIGKILL after reaching hard limit of CPU time > * > * Note: > * This is also a regression test for the following kernel bug: > @@ -27,6 +27,12 @@ > #include <sys/mman.h> > > #include "tst_test.h" > +#include "lapi/resource.h" > + > +#define TEST_VARIANTS 2 > + > +static struct rlimit *rlim; > +static struct rlimit64 *rlim_64; > > static int *end; > > @@ -37,6 +43,11 @@ static void sighandler(int sig) > > static void setup(void) > { > + rlim->rlim_cur = 1; > + rlim->rlim_max = 2; > + rlim_64->rlim_cur = 1; > + rlim_64->rlim_max = 2; > + > SAFE_SIGNAL(SIGXCPU, sighandler); > > end = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, > @@ -58,12 +69,14 @@ static void verify_setrlimit(void) > > pid = SAFE_FORK(); > if (!pid) { > - struct rlimit rlim = { > - .rlim_cur = 1, > - .rlim_max = 2, > - }; > - > - TEST(setrlimit(RLIMIT_CPU, &rlim)); > + switch (tst_variant) { > + case 0: > + TEST(setrlimit(RLIMIT_CPU, rlim)); > + break; > + case 1: > + TEST(setrlimit_u64(RLIMIT_CPU, rlim_64)); > + break; > + } > if (TST_RET == -1) { > tst_res(TFAIL | TTERRNO, > "setrlimit(RLIMIT_CPU) failed"); > @@ -72,7 +85,8 @@ static void verify_setrlimit(void) > > alarm(20); > > - while (1); > + while (1) > + ; > } > > SAFE_WAITPID(pid, &status, 0); > @@ -112,6 +126,12 @@ static void verify_setrlimit(void) > static struct tst_test test = { > .test_all = verify_setrlimit, > .setup = setup, > + .test_variants = TEST_VARIANTS, > + .bufs = (struct tst_buffers []) { > + {&rlim, .size = sizeof(*rlim)}, > + {&rlim_64, .size = sizeof(*rlim_64)}, > + {} > + }, > .cleanup = cleanup, > .forks_child = 1, > .tags = (const struct tst_tag[]) { > -- > 2.43.5 > > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-26 1:15 ` Chunfu Wen @ 2025-02-28 3:41 ` Li Wang 2025-02-28 7:45 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 22+ messages in thread From: Li Wang @ 2025-02-28 3:41 UTC (permalink / raw) To: Chunfu Wen; +Cc: Charles Shi, Irene Diez, ltp On Wed, Feb 26, 2025 at 9:15 AM Chunfu Wen <chwen@redhat.com> wrote: > Hello Maintainers, > > Could you please help me review the V4 patch when you have time? > I helped resolve the code conflict and pushed, thanks! Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-28 3:41 ` Li Wang @ 2025-02-28 7:45 ` Andrea Cervesato via ltp 2025-02-28 8:39 ` Li Wang 0 siblings, 1 reply; 22+ messages in thread From: Andrea Cervesato via ltp @ 2025-02-28 7:45 UTC (permalink / raw) To: Li Wang, Chunfu Wen; +Cc: Charles Shi, ltp, Irene Diez Hi Li, thanks for checking, but we still missed a couple of things to fix, like infinite loop that might cause some issues and it should be replaced with checkpoints as pointed out by Petr. Best regards, Andrea Cervesato On 2/28/25 04:41, Li Wang wrote: > On Wed, Feb 26, 2025 at 9:15 AM Chunfu Wen <chwen@redhat.com> wrote: > >> Hello Maintainers, >> >> Could you please help me review the V4 patch when you have time? >> > I helped resolve the code conflict and pushed, thanks! > > Li Wang > -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-28 7:45 ` Andrea Cervesato via ltp @ 2025-02-28 8:39 ` Li Wang 2025-02-28 9:22 ` Li Wang 0 siblings, 1 reply; 22+ messages in thread From: Li Wang @ 2025-02-28 8:39 UTC (permalink / raw) To: Andrea Cervesato, Petr Vorel; +Cc: Charles Shi, ltp, Irene Diez Hi Andrea, Petr, On Fri, Feb 28, 2025 at 3:45 PM Andrea Cervesato <andrea.cervesato@suse.com> wrote: > Hi Li, > > thanks for checking, but we still missed a couple of things to fix, like > infinite loop that might cause some issues and it should be replaced > with checkpoints as pointed out by Petr. > Here I wouldn't suggest using the checkpoint. RLIMIT_CPU is a resource limit that controls the CPU time but not wall-clock time, if a process exceeds the soft limit it receives SIGXCPU. So the while(1) is a good choice unless I missed something. P.s. the patch caused a compiling error on Alpine I haven't figured out reason:). https://github.com/linux-test-project/ltp/actions/runs/13580985467/job/37966850497 Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-28 8:39 ` Li Wang @ 2025-02-28 9:22 ` Li Wang 2025-02-28 11:37 ` Petr Vorel 0 siblings, 1 reply; 22+ messages in thread From: Li Wang @ 2025-02-28 9:22 UTC (permalink / raw) To: Andrea Cervesato, Petr Vorel; +Cc: Charles Shi, ltp, Irene Diez Li Wang <liwan@redhat.com> wrote: > P.s. the patch caused a compiling error on Alpine I haven't figured out > reason:). > > https://github.com/linux-test-project/ltp/actions/runs/13580985467/job/37966850497 > Well, we have to enable _LARGEFILE64_SOURCE macro to tells glibc to expose 64-bit structures, see: $ cat /usr/include/bits/resource.h ... #ifdef __USE_LARGEFILE64 struct rlimit64 { /* The current (soft) limit. */ rlim64_t rlim_cur; /* The hard limit. */ rlim64_t rlim_max; }; #endif ... Sent a patch to resolve it: https://lists.linux.it/pipermail/ltp/2025-February/042497.html Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-28 9:22 ` Li Wang @ 2025-02-28 11:37 ` Petr Vorel 0 siblings, 0 replies; 22+ messages in thread From: Petr Vorel @ 2025-02-28 11:37 UTC (permalink / raw) To: Li Wang; +Cc: Charles Shi, ltp, Irene Diez > Li Wang <liwan@redhat.com> wrote: > > P.s. the patch caused a compiling error on Alpine I haven't figured out > > reason:). > > https://github.com/linux-test-project/ltp/actions/runs/13580985467/job/37966850497 > Well, we have to enable _LARGEFILE64_SOURCE macro to tells glibc > to expose 64-bit structures, see: > $ cat /usr/include/bits/resource.h > ... > #ifdef __USE_LARGEFILE64 > struct rlimit64 > { > /* The current (soft) limit. */ > rlim64_t rlim_cur; > /* The hard limit. */ > rlim64_t rlim_max; > }; > #endif > ... > Sent a patch to resolve it: > https://lists.linux.it/pipermail/ltp/2025-February/042497.html FYI patch already merged. Kind regards, Petr > Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v4] Add test case to cover the setting resource limit64 for process 2025-02-24 3:07 ` [LTP] [PATCH v4] " Chunfu Wen 2025-02-26 1:15 ` Chunfu Wen @ 2025-02-26 9:21 ` Li Wang 1 sibling, 0 replies; 22+ messages in thread From: Li Wang @ 2025-02-26 9:21 UTC (permalink / raw) To: Chunfu Wen; +Cc: ltp Patch v4 looks good, and next we can move getrlimit_u64() definition (from getrlimit03.c) to the lapi/resource.h, obviously this could be accomplished in a separate work. Reviewed-by: Li Wang <liwang@redhat.com> -- Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2] Add test case to cover the setting resource limit64 for process 2025-02-19 6:47 ` [LTP] [PATCH v2] " chunfuwen 2025-02-19 16:44 ` Petr Vorel @ 2025-02-19 16:50 ` Petr Vorel 1 sibling, 0 replies; 22+ messages in thread From: Petr Vorel @ 2025-02-19 16:50 UTC (permalink / raw) To: chunfuwen; +Cc: Ricardo B. Marlière, ltp Hi > + if (!pid) { > + TEST(setrlimit_u64(RLIMIT_CPU, rlim)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, > + "setrlimit_u64(RLIMIT_CPU) failed"); > + exit(1); > + } > + > + alarm(20); > + > + while (1) FYI we have TST_CHECKPOINT_WAKE() and others, please see "1.9 Fork() and Parent-child synchronization" in doc/old/C-Test-API.asciidoc or online https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#19-fork-and-parent-child-synchronization (still not yet converted docs to sphinx) Also worth to read if you have time (because people would put at least some usleep() instead of plain while(1); https://people.kernel.org/metan/why-sleep-is-almost-never-acceptable-in-tests Kind regards, Petr > + ; > + } > + -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2025-02-28 11:37 UTC | newest] Thread overview: 22+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-02-18 2:31 [LTP] [PATCH] Add test case to cover the setting resource limit64 for process chunfuwen 2025-02-18 11:44 ` Ricardo B. Marlière 2025-02-18 13:29 ` Andrea Cervesato via ltp 2025-02-19 2:35 ` Chunfu Wen 2025-02-19 9:29 ` Andrea Cervesato via ltp 2025-02-19 6:47 ` [LTP] [PATCH v2] " chunfuwen 2025-02-19 16:44 ` Petr Vorel 2025-02-20 2:08 ` Li Wang 2025-02-20 9:35 ` Petr Vorel 2025-02-20 8:01 ` Chunfu Wen 2025-02-20 8:35 ` [LTP] [PATCH v3] " Chunfu Wen 2025-02-21 10:34 ` Andrea Cervesato via ltp 2025-02-24 3:06 ` Chunfu Wen 2025-02-24 3:07 ` [LTP] [PATCH v4] " Chunfu Wen 2025-02-26 1:15 ` Chunfu Wen 2025-02-28 3:41 ` Li Wang 2025-02-28 7:45 ` Andrea Cervesato via ltp 2025-02-28 8:39 ` Li Wang 2025-02-28 9:22 ` Li Wang 2025-02-28 11:37 ` Petr Vorel 2025-02-26 9:21 ` Li Wang 2025-02-19 16:50 ` [LTP] [PATCH v2] " Petr Vorel
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.