Message ID | 20231107105939.30659-1-kozlov@synopsys.com |
---|---|
State | Accepted |
Headers | show |
Series | [uclibc-ng-devel] misc: add tests for getrlimit/setrlimit/prlimit | expand |
Hi Pavel, thanks for providing a test case. I tried it with your prlimit patch, but it fails for some architectures like or1k, x86 and m68k. Do you have an idea why? best regards Waldemar Pavel Kozlov wrote, > From: Pavel Kozlov <pavel.kozlov@synopsys.com> > > Add tst-rlimit test to check setrlimit/getrlimit/prlimit and > setrlimit64/getrlimit64/prlimit64 functions. > Add tst-rlimit64 to check the 64-bit offset variant. > > Signed-off-by: Pavel Kozlov <pavel.kozlov@synopsys.com> > --- > test/misc/Makefile.in | 1 + > test/misc/tst-rlimit.c | 157 +++++++++++++++++++++++++++++++++++++++ > test/misc/tst-rlimit64.c | 1 + > 3 files changed, 159 insertions(+) > create mode 100644 test/misc/tst-rlimit.c > create mode 100644 test/misc/tst-rlimit64.c > > diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in > index a97b124e4a35..96c1fd976f0e 100644 > --- a/test/misc/Makefile.in > +++ b/test/misc/Makefile.in > @@ -8,6 +8,7 @@ TESTS_DISABLED += tst-inotify > endif > > CFLAGS_dirent64 := -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 > +CFLAGS_tst-rlimit64 := -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 > > DODIFF_dirent := 1 > DODIFF_dirent64 := 1 > diff --git a/test/misc/tst-rlimit.c b/test/misc/tst-rlimit.c > new file mode 100644 > index 000000000000..84aa465869da > --- /dev/null > +++ b/test/misc/tst-rlimit.c > @@ -0,0 +1,157 @@ > +/* > + * setrlimit/getrlimit/prlimit and setrlimit64/getrlimit64/prlimit64 functions > + * test for uClibc. > + * > + * The prlimit64 function is not called directly in this test, because it is a > + * new function for uclibc and can cause build problems with uclibc-ng <= 1.0.44. > + * With _FILE_OFFSET_BITS == 64 the prlimit call is redirected to the prlimit64 > + * call. > + */ > + > +#include <stdio.h> > +#include <stdlib.h> > +#include <string.h> > +#include <errno.h> > +#include <sys/resource.h> > + > +#define __ASSERT(x, f, l) \ > + if (!(x)) { \ > + fprintf(stderr, "%s: LINE %d: ASSERT: " #x "\n", f, l); \ > + exit(1); \ > + } > + > +#define ASSERT(x) __ASSERT(x, __FILE__, __LINE__) > + > +static int resources[] = { > + RLIMIT_CORE, > + RLIMIT_CPU, > + RLIMIT_DATA, > + RLIMIT_FSIZE, > + RLIMIT_NOFILE, > + RLIMIT_STACK, > + RLIMIT_AS > +}; > + > +#define nresources (sizeof (resources) / sizeof (resources[0])) > +#define TEST_VAL 0x11223344 > + > + > +static void test_getrlimit(int rnum, rlim_t exp_cur, rlim_t exp_max) > +{ > + struct rlimit r; > + > + ASSERT(getrlimit(rnum, &r) == 0); > + ASSERT(r.rlim_cur == exp_cur); > + ASSERT(r.rlim_max == exp_max); > +} > + > +static void test_setrlimit(int rnum, rlim_t new_cur, rlim_t new_max) > +{ > + struct rlimit r = {.rlim_cur = new_cur, .rlim_max = new_max}; > + > + ASSERT(setrlimit(rnum, &r) == 0); > +} > + > +static void test_prlimit_get(int rnum, rlim_t exp_cur, rlim_t exp_max) > +{ > + struct rlimit r; > + > + ASSERT(prlimit(0, rnum, NULL, &r) == 0); > + ASSERT(r.rlim_cur == exp_cur); > + ASSERT(r.rlim_max == exp_max); > +} > + > +static void test_prlimit_set(int rnum, rlim_t new_cur, rlim_t new_max) > +{ > + struct rlimit r = {.rlim_cur = new_cur, .rlim_max = new_max}; > + ASSERT(prlimit(0, rnum, &r, NULL) == 0); > +} > + > +#if defined(__USE_LARGEFILE64) > +static void test_getrlimit64(int rnum, rlim64_t exp_cur, rlim64_t exp_max) > +{ > + struct rlimit64 r; > + > + ASSERT(getrlimit64(rnum, &r) == 0); > + ASSERT(r.rlim_cur == exp_cur); > + ASSERT(r.rlim_max == exp_max); > +} > + > +static void test_setrlimit64(int rnum, rlim64_t new_cur, rlim64_t new_max) > +{ > + struct rlimit64 r = {.rlim_cur = new_cur, .rlim_max = new_max}; > + > + ASSERT(setrlimit64(rnum, &r) == 0); > +} > +#endif > + > +int main(void) > +{ > + int rnum = -1; > + struct rlimit rlim; > + int i, ret; > + > + /* Find a resource with hard limit set to infinity */ > + for (i = 0; i < nresources; ++i) { > + ret = getrlimit(resources[i], &rlim); > + if ((!ret) && (rlim.rlim_max == RLIM_INFINITY)) { > + rnum = resources[i]; > + break; > + } > + } > + > + /* Can't continue, return unsupported */ > + if (rnum == -1) > + return 23; > + > + /* Test cases */ > + test_setrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_setrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_prlimit_get(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_prlimit_set(rnum, TEST_VAL, RLIM_INFINITY); > + test_prlimit_get(rnum, TEST_VAL, RLIM_INFINITY); > + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_prlimit_set(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_prlimit_get(rnum, RLIM_INFINITY, RLIM_INFINITY); > + > +#if defined(__USE_LARGEFILE64) > + /* Check setrlim64 and getrlim64 in 32-bit offset LFS environment */ > + test_setrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); > + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); > + test_setrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > + test_prlimit_get(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > + > + test_setrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); > + test_prlimit_set(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > +#endif > + > + > +#if defined(__USE_LARGEFILE64) && _FILE_OFFSET_BITS == 64 > + /* Check setrlim64/getrlim64/prlimit64 in 64-bit offset environment */ > + test_setrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); > + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); > + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_setrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > + test_prlimit_get(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_prlimit_set(rnum, TEST_VAL, RLIM64_INFINITY); > + test_prlimit_get(rnum, TEST_VAL, RLIM64_INFINITY); > + test_prlimit_set(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); > + > + test_setrlimit(rnum, TEST_VAL, RLIM_INFINITY); > + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); > + test_prlimit_set(rnum, RLIM_INFINITY, RLIM_INFINITY); > + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); > +#endif > + > + return 0; > +} > diff --git a/test/misc/tst-rlimit64.c b/test/misc/tst-rlimit64.c > new file mode 100644 > index 000000000000..490c6c59022c > --- /dev/null > +++ b/test/misc/tst-rlimit64.c > @@ -0,0 +1 @@ > +#include "tst-rlimit.c" > -- > 2.25.1 > > _______________________________________________ > devel mailing list -- devel@uclibc-ng.org > To unsubscribe send an email to devel-leave@uclibc-ng.org >
Hi Waldemar, > Hi Pavel, > > thanks for providing a test case. > I tried it with your prlimit patch, but it fails for some > architectures like or1k, x86 and m68k. > > Do you have an idea why? Hmm, perhaps I missed something. I tested my last prlimit patch with buildroot environment, I checked i386, arm, aarch64 and arc on qemu and didn't see fails. I thought I tested all main cases. This morning I tried build with OpenADK and also haven't reproduced fail (I checked x86 and or1k). Can you share you setup? I tried it with my second prlimit patch applied: https://mailman.openadk.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/thread/NDND7DCUPAXLIFWXO3QLEROFLHLVDB2J/ |$ ./embedded-test.sh --libc=uclibc-ng --libc-source=~/snps/arc/src/extra/uclibc-ng --os=linux --arch=x86 --test=libc ... | Using QEMU as emulator | Starting test for uclibc-ng and x86 | Generating root filesystem for test run | Creating initramfs filesystem | 31557 blocks | Now running the test libc in qemu for architecture x86 and uclibc-ng | qemu-system-i386 -M pc -nographic -m 256 -initrd initramfs.x86 -kernel openadk/firmware/qemu-x86_uclibc-ng/qemu-x86-initramfsarchive-kernel -qmp tcp:127.0.0.1:4444,server,nowait -no-reboot | SeaBIOS (version rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org) | | iPXE (http://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+0EFD1040+0EF31040 CA00 | | Booting from ROM.. | [ 0.000000] Linux version 6.1.53-1 (pvk@SNPS-oOWW) (i686-openadk-linux-uclibc-gcc (GCC) 13.2.0, GNU ld (GNU Binutils) 2.41) #1 Fri Nov 10 10:37:16 +04 2023 ... | PASS tst-preadvwritev | PASS tst-rlimit | PASS tst-rlimit64 | PASS tst-scandir .. -Pavel > > best regards > Waldemar > > Pavel Kozlov wrote, > >> From: Pavel Kozlov <pavel.kozlov@synopsys.com> >> >> Add tst-rlimit test to check setrlimit/getrlimit/prlimit and >> setrlimit64/getrlimit64/prlimit64 functions. >> Add tst-rlimit64 to check the 64-bit offset variant. >> >> Signed-off-by: Pavel Kozlov <pavel.kozlov@synopsys.com> >> ---
Hi Pavel, Pavel Kozlov wrote, > Hi Waldemar, > > > Hi Pavel, > > > > thanks for providing a test case. > > I tried it with your prlimit patch, but it fails for some > > architectures like or1k, x86 and m68k. > > > > Do you have an idea why? > > Hmm, perhaps I missed something. > > I tested my last prlimit patch with buildroot environment, I checked > i386, arm, aarch64 and arc on qemu and didn't see fails. > I thought I tested all main cases. > > This morning I tried build with OpenADK and also haven't > reproduced fail (I checked x86 and or1k). > Can you share you setup? > > I tried it with my second prlimit patch applied: > https://mailman.openadk.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/thread/NDND7DCUPAXLIFWXO3QLEROFLHLVDB2J/ > > |$ ./embedded-test.sh --libc=uclibc-ng --libc-source=~/snps/arc/src/extra/uclibc-ng --os=linux --arch=x86 --test=libc > ... > | Using QEMU as emulator > | Starting test for uclibc-ng and x86 > | Generating root filesystem for test run > | Creating initramfs filesystem > | 31557 blocks > | Now running the test libc in qemu for architecture x86 and uclibc-ng > | qemu-system-i386 -M pc -nographic -m 256 -initrd initramfs.x86 -kernel openadk/firmware/qemu-x86_uclibc-ng/qemu-x86-initramfsarchive-kernel -qmp tcp:127.0.0.1:4444,server,nowait -no-reboot > | SeaBIOS (version rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org) > | > | iPXE (http://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+0EFD1040+0EF31040 CA00 > | > | Booting from ROM.. > | [ 0.000000] Linux version 6.1.53-1 (pvk@SNPS-oOWW) (i686-openadk-linux-uclibc-gcc (GCC) 13.2.0, GNU ld (GNU Binutils) 2.41) #1 Fri Nov 10 10:37:16 +04 2023 > ... > | PASS tst-preadvwritev > | PASS tst-rlimit > | PASS tst-rlimit64 > | PASS tst-scandir > .. You are right my openadk directory seemed to be using an old uclibc-ng version. I now checked x86 and or1k again with a fresh build and everything is fine. Thanks for double checking. best regards Waldemar
diff --git a/test/misc/Makefile.in b/test/misc/Makefile.in index a97b124e4a35..96c1fd976f0e 100644 --- a/test/misc/Makefile.in +++ b/test/misc/Makefile.in @@ -8,6 +8,7 @@ TESTS_DISABLED += tst-inotify endif CFLAGS_dirent64 := -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS_tst-rlimit64 := -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 DODIFF_dirent := 1 DODIFF_dirent64 := 1 diff --git a/test/misc/tst-rlimit.c b/test/misc/tst-rlimit.c new file mode 100644 index 000000000000..84aa465869da --- /dev/null +++ b/test/misc/tst-rlimit.c @@ -0,0 +1,157 @@ +/* + * setrlimit/getrlimit/prlimit and setrlimit64/getrlimit64/prlimit64 functions + * test for uClibc. + * + * The prlimit64 function is not called directly in this test, because it is a + * new function for uclibc and can cause build problems with uclibc-ng <= 1.0.44. + * With _FILE_OFFSET_BITS == 64 the prlimit call is redirected to the prlimit64 + * call. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <sys/resource.h> + +#define __ASSERT(x, f, l) \ + if (!(x)) { \ + fprintf(stderr, "%s: LINE %d: ASSERT: " #x "\n", f, l); \ + exit(1); \ + } + +#define ASSERT(x) __ASSERT(x, __FILE__, __LINE__) + +static int resources[] = { + RLIMIT_CORE, + RLIMIT_CPU, + RLIMIT_DATA, + RLIMIT_FSIZE, + RLIMIT_NOFILE, + RLIMIT_STACK, + RLIMIT_AS +}; + +#define nresources (sizeof (resources) / sizeof (resources[0])) +#define TEST_VAL 0x11223344 + + +static void test_getrlimit(int rnum, rlim_t exp_cur, rlim_t exp_max) +{ + struct rlimit r; + + ASSERT(getrlimit(rnum, &r) == 0); + ASSERT(r.rlim_cur == exp_cur); + ASSERT(r.rlim_max == exp_max); +} + +static void test_setrlimit(int rnum, rlim_t new_cur, rlim_t new_max) +{ + struct rlimit r = {.rlim_cur = new_cur, .rlim_max = new_max}; + + ASSERT(setrlimit(rnum, &r) == 0); +} + +static void test_prlimit_get(int rnum, rlim_t exp_cur, rlim_t exp_max) +{ + struct rlimit r; + + ASSERT(prlimit(0, rnum, NULL, &r) == 0); + ASSERT(r.rlim_cur == exp_cur); + ASSERT(r.rlim_max == exp_max); +} + +static void test_prlimit_set(int rnum, rlim_t new_cur, rlim_t new_max) +{ + struct rlimit r = {.rlim_cur = new_cur, .rlim_max = new_max}; + ASSERT(prlimit(0, rnum, &r, NULL) == 0); +} + +#if defined(__USE_LARGEFILE64) +static void test_getrlimit64(int rnum, rlim64_t exp_cur, rlim64_t exp_max) +{ + struct rlimit64 r; + + ASSERT(getrlimit64(rnum, &r) == 0); + ASSERT(r.rlim_cur == exp_cur); + ASSERT(r.rlim_max == exp_max); +} + +static void test_setrlimit64(int rnum, rlim64_t new_cur, rlim64_t new_max) +{ + struct rlimit64 r = {.rlim_cur = new_cur, .rlim_max = new_max}; + + ASSERT(setrlimit64(rnum, &r) == 0); +} +#endif + +int main(void) +{ + int rnum = -1; + struct rlimit rlim; + int i, ret; + + /* Find a resource with hard limit set to infinity */ + for (i = 0; i < nresources; ++i) { + ret = getrlimit(resources[i], &rlim); + if ((!ret) && (rlim.rlim_max == RLIM_INFINITY)) { + rnum = resources[i]; + break; + } + } + + /* Can't continue, return unsupported */ + if (rnum == -1) + return 23; + + /* Test cases */ + test_setrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_setrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit_get(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit_set(rnum, TEST_VAL, RLIM_INFINITY); + test_prlimit_get(rnum, TEST_VAL, RLIM_INFINITY); + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_prlimit_set(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit_get(rnum, RLIM_INFINITY, RLIM_INFINITY); + +#if defined(__USE_LARGEFILE64) + /* Check setrlim64 and getrlim64 in 32-bit offset LFS environment */ + test_setrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); + test_setrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); + test_prlimit_get(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); + + test_setrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); + test_prlimit_set(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); +#endif + + +#if defined(__USE_LARGEFILE64) && _FILE_OFFSET_BITS == 64 + /* Check setrlim64/getrlim64/prlimit64 in 64-bit offset environment */ + test_setrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); + test_getrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_setrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); + test_prlimit_get(rnum, RLIM64_INFINITY, RLIM64_INFINITY); + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_prlimit_set(rnum, TEST_VAL, RLIM64_INFINITY); + test_prlimit_get(rnum, TEST_VAL, RLIM64_INFINITY); + test_prlimit_set(rnum, RLIM64_INFINITY, RLIM64_INFINITY); + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); + test_getrlimit(rnum, RLIM_INFINITY, RLIM_INFINITY); + + test_setrlimit(rnum, TEST_VAL, RLIM_INFINITY); + test_getrlimit64(rnum, TEST_VAL, RLIM64_INFINITY); + test_prlimit_set(rnum, RLIM_INFINITY, RLIM_INFINITY); + test_getrlimit64(rnum, RLIM64_INFINITY, RLIM64_INFINITY); +#endif + + return 0; +} diff --git a/test/misc/tst-rlimit64.c b/test/misc/tst-rlimit64.c new file mode 100644 index 000000000000..490c6c59022c --- /dev/null +++ b/test/misc/tst-rlimit64.c @@ -0,0 +1 @@ +#include "tst-rlimit.c"