From: Chunfu Wen <chwen@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] Add test case to cover the setting resource limit64 for process
Date: Thu, 20 Feb 2025 03:35:28 -0500 [thread overview]
Message-ID: <20250220083528.1361819-1-chwen@redhat.com> (raw)
In-Reply-To: <20250219164449.GB2590174@pevik>
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
next prev parent reply other threads:[~2025-02-20 8:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Chunfu Wen [this message]
2025-02-21 10:34 ` [LTP] [PATCH v3] " 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250220083528.1361819-1-chwen@redhat.com \
--to=chwen@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox