aboutsummaryrefslogtreecommitdiff
path: root/test/unit/test_c_api.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-11-10 15:27:35 +0100
committerGitHub <noreply@github.com>2021-11-10 15:27:35 +0100
commitac113a8898cded7f5359f1edd3abc17a78eee9b4 (patch)
treef2c959a125e8e94d06265d65816c50bfad603505 /test/unit/test_c_api.cpp
parentc20b3f6d1beaa7c5f1325d42e0f244ebaea52455 (diff)
parente29acba814738dedb3a9a0479371f896f4560c6a (diff)
downloadPROJ-ac113a8898cded7f5359f1edd3abc17a78eee9b4.tar.gz
PROJ-ac113a8898cded7f5359f1edd3abc17a78eee9b4.zip
Merge pull request #2934 from toonn/cross-platform-test
test: Make CApi test cross-platform
Diffstat (limited to 'test/unit/test_c_api.cpp')
-rw-r--r--test/unit/test_c_api.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/test/unit/test_c_api.cpp b/test/unit/test_c_api.cpp
index d3e81089..3548293d 100644
--- a/test/unit/test_c_api.cpp
+++ b/test/unit/test_c_api.cpp
@@ -47,6 +47,10 @@
#include <sqlite3.h>
+#if !defined(_WIN32)
+#include <sys/resource.h>
+#endif
+
#ifndef __MINGW32__
#include <thread>
#endif
@@ -6104,9 +6108,18 @@ TEST_F(CApi, open_plenty_of_contexts) {
// database
std::vector<FILE *> dummyFilePointers;
std::vector<PJ_CONTEXT *> ctxts;
- // 1024 is the number of file descriptors that can be opened simultaneously
- // by a Linux process (by default)
- for (int i = 0; i < 1024 - 50; i++) {
+ // The number of file descriptors that can be opened simultaneously by a
+ // process varies across platforms so we make use of getrlimit(2) to
+ // retrieve it.
+ struct rlimit open_max;
+ getrlimit(RLIMIT_NOFILE, &open_max);
+ // On some platforms fopen returned nullptrs before reaching limit - 50, we
+ // can avoid this by capping the limit to 1024.
+ if (open_max.rlim_cur > 1024) {
+ open_max.rlim_cur = 1024;
+ setrlimit(RLIMIT_NOFILE, &open_max);
+ }
+ for (rlim_t i = 0; i < open_max.rlim_cur - 50; i++) {
FILE *f = fopen("/dev/null", "rb");
ASSERT_TRUE(f != nullptr);
dummyFilePointers.push_back(f);