On 13/11/2026 15:31, Sendao Yan wrote:
alloc-pinned-{1,2,5}.c allocate three buffers of sysconf (_SC_PAGESIZE)
- 128 bytes each, needing five times that size in total, and abort in
CHECK_SIZE when RLIMIT_MEMLOCK is smaller. With 64 KiB pages the
requirement is just over 319 KiB, while 64 KiB is a common default for
the limit, so on such a machine these tests cannot run at all.
Add check_effective_target_omp_pinned_mem, which reads RLIMIT_MEMLOCK
and tests exactly the condition CHECK_SIZE tests, and require it from
those three tests. They are reported as unsupported only when the
limit is provably too small; if the limit cannot be read, or the
compiler is a cross compiler, they still run, and CHECK_SIZE keeps
failing the test for any other reason. The nvptx variant locks the
memory through CUDA, so the requirement is not applied to it.
I'm not able to approve this, but just to confirm, this feels like it is
keeping the intent of my tests intact. In particular, it does not
report PASS if it couldn't actually test properly.
Thanks for the patch.
Andrew
libgomp/ChangeLog:
* testsuite/lib/libgomp.exp (check_effective_target_omp_pinned_mem):
New procedure.
* testsuite/libgomp.c/alloc-pinned-1.c: Require it.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
---
libgomp/testsuite/lib/libgomp.exp | 28 ++++++++++++++++++++
libgomp/testsuite/libgomp.c/alloc-pinned-1.c | 2 ++
libgomp/testsuite/libgomp.c/alloc-pinned-2.c | 2 ++
libgomp/testsuite/libgomp.c/alloc-pinned-5.c | 2 ++
4 files changed, 34 insertions(+)
diff --git a/libgomp/testsuite/lib/libgomp.exp
b/libgomp/testsuite/lib/libgomp.exp
index 4987400f2a0..8b4e78cc774 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -395,6 +395,34 @@ proc check_effective_target_linux_futex_waitv { } {
[lsearch -exact $libgomp_config_path "linux/futex_waitv"] >= 0}]
}
+# Return 1 if the host lets a process lock as much memory as the alloc-pinned
+# tests need. Those tests abort in their own CHECK_SIZE when RLIMIT_MEMLOCK
+# is smaller than five pages (64 KiB is a common default, and with 64 KiB
+# pages five pages already exceed it), so report them as unsupported instead
+# of reporting a failure.
+proc check_effective_target_omp_pinned_mem { } {
+ # A cross-compiler says nothing about the machine the tests will run
+ # on; assume the limit is fine and let the test decide.
+ if { ![isnative] } {
+ return 1
+ }
+ return [check_runtime_nocache omp_pinned_mem {
+ #include <sys/resource.h>
+ #include <unistd.h>
+
+ int main (void)
+ {
+ struct rlimit limit;
+ long page = sysconf (_SC_PAGESIZE);
+ /* If the limit cannot be queried, let the test decide. */
+ if (getrlimit (RLIMIT_MEMLOCK, &limit) != 0 || page <= 128)
+ return 0;
+ /* This is the condition CHECK_SIZE tests in the tests themselves. */
+ return limit.rlim_cur > (rlim_t) (page - 128) * 5 ? 0 : 1;
+ }
+ }]
+}
+
# Return 1 if compiling for the specified offload target
# Takes -foffload=... into account by checking OFFLOAD_TARGET_NAMES=
# in the -v compiler output.
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
index 693f9032c8d..2121182d065 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c
@@ -2,6 +2,8 @@
/* { dg-skip-if "Pinning not implemented on this host" { ! *-*-linux-gnu* } } */
+/* { dg-require-effective-target omp_pinned_mem { target { ! offload_device_nvptx } } } */
+
/* { dg-additional-options -DOFFLOAD_DEVICE_NVPTX { target
offload_device_nvptx } } */
/* Test that pinned memory works. */
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
index e7ac64e911f..d8aa81f2b09 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c
@@ -2,6 +2,8 @@
/* { dg-skip-if "Pinning not implemented on this host" { ! *-*-linux-gnu* } } */
+/* { dg-require-effective-target omp_pinned_mem { target { ! offload_device_nvptx } } } */
+
/* { dg-additional-options -DOFFLOAD_DEVICE_NVPTX { target
offload_device_nvptx } } */
/* Test that pinned memory works (pool_size code path). */
diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
index cc7776409ff..6642c3276d0 100644
--- a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
+++ b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c
@@ -2,6 +2,8 @@
/* { dg-skip-if "Pinning not implemented on this host" { ! *-*-linux-gnu* } } */
+/* { dg-require-effective-target omp_pinned_mem { target { ! offload_device_nvptx } } } */
+
/* { dg-additional-options -DOFFLOAD_DEVICE_NVPTX { target
offload_device_nvptx } } */
/* Test that ompx_gnu_pinned_mem_alloc works. */