diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2021-08-24 15:48:22 +0200 |
---|---|---|
committer | Eugene Syromyatnikov <evgsyr@gmail.com> | 2021-08-30 21:34:33 +0200 |
commit | 565eb1ff32257ba385890943ba8f0705a5f3d59d (patch) | |
tree | 570da4450ac83fda4a818b72e2d33d3f7c17ad8a | |
parent | b3224ff9d81b9e18729ab05155004b90369921db (diff) | |
download | strace-565eb1ff32257ba385890943ba8f0705a5f3d59d.tar.gz |
tests: add prlimit64-success and prlimit64-success--pidns-translation
These may be useful in cases where prlimit64 syscall is not available.
* tests/.gitignore: Add prlimit64-success
and prlimit64-success--pidns-translation.
* tests/Makefile.am (check_PROGRAMS): Likewise.
* tests/gen_tests.in (prlimit64-success,
prlimit64-success--pidns-translation): New tests.
* tests/prlimit64-success--pidns-translation.c: New file.
* tests/prlimit64-success.c: Likewise.
* tests/prlimit64.c: Update to accomodate output when return value
is injected.
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/gen_tests.in | 6 | ||||
-rw-r--r-- | tests/prlimit64-success--pidns-translation.c | 2 | ||||
-rw-r--r-- | tests/prlimit64-success.c | 2 | ||||
-rw-r--r-- | tests/prlimit64.c | 51 |
6 files changed, 49 insertions, 16 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 485e1ff6e..9501a8d86 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -691,6 +691,8 @@ printstrn-umoven-peekdata printstrn-umoven-undumpable prlimit64 prlimit64--pidns-translation +prlimit64-success +prlimit64-success--pidns-translation process_madvise process_madvise-y process_madvise-yy diff --git a/tests/Makefile.am b/tests/Makefile.am index 7216b80ce..5eddf2278 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -283,6 +283,8 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ print_maxfd \ print_ppid_tracerpid \ prlimit64--pidns-translation \ + prlimit64-success \ + prlimit64-success--pidns-translation \ process_vm_readv--pidns-translation \ process_vm_writev--pidns-translation \ qual_fault \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 281720c09..cafb4a708 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -656,8 +656,10 @@ printstr -e trace=writev printstrn-umoven -s4096 -e signal=none -e trace=add_key printstrn-umoven-peekdata -e signal=none -e trace=add_key printstrn-umoven-undumpable -e signal=none -e trace=add_key -prlimit64 -a36 "QUIRK:START-OF-TEST-OUTPUT:prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" -prlimit64--pidns-translation test_pidns -a36 -e trace=prlimit64 "QUIRK:START-OF-TEST-OUTPUT:prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" +prlimit64 -a36 "QUIRK:START-OF-TEST-OUTPUT:prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" +prlimit64--pidns-translation test_pidns -a36 -e trace=prlimit64 "QUIRK:START-OF-TEST-OUTPUT:prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" +prlimit64-success -a36 -einject=prlimit64:retval=42:when=256+ -etrace=prlimit64 "QUIRK:START-OF-TEST-OUTPUT:prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" +prlimit64-success--pidns-translation check_scno_tampering; test_pidns -a36 -einject=prlimit64:retval=42:when=256+ -etrace=prlimit64 "QUIRK:START-OF-TEST-OUTPUT:prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" process_madvise process_madvise-y --trace=process_madvise -y process_madvise-yy --trace=process_madvise -yy diff --git a/tests/prlimit64-success--pidns-translation.c b/tests/prlimit64-success--pidns-translation.c new file mode 100644 index 000000000..eb53c582e --- /dev/null +++ b/tests/prlimit64-success--pidns-translation.c @@ -0,0 +1,2 @@ +#define PIDNS_TRANSLATION +#include "prlimit64-success.c" diff --git a/tests/prlimit64-success.c b/tests/prlimit64-success.c new file mode 100644 index 000000000..4f7599ffa --- /dev/null +++ b/tests/prlimit64-success.c @@ -0,0 +1,2 @@ +#define RETVAL_INJECTED 1 +#include "prlimit64.c" diff --git a/tests/prlimit64.c b/tests/prlimit64.c index 41b0404a3..8febdaeea 100644 --- a/tests/prlimit64.c +++ b/tests/prlimit64.c @@ -14,6 +14,7 @@ #include <inttypes.h> #include <stdio.h> #include <stdint.h> +#include <stdlib.h> #include <sys/resource.h> #include <unistd.h> @@ -21,6 +22,17 @@ #include "xlat.h" #include "xlat/resources.h" +#ifndef RETVAL_INJECTED +# define RETVAL_INJECTED 0 +#endif + +#if RETVAL_INJECTED +# define INJ_STR " (INJECTED)" +#else +# define INJ_STR "" +#endif +#define INJECT_RETVAL 42 + static const char * sprint_rlim(uint64_t lim) { @@ -39,7 +51,7 @@ sprint_rlim(uint64_t lim) } int -main(void) +main(int argc, char *argv[]) { PIDNS_TEST_INIT; @@ -48,38 +60,49 @@ main(void) const char *pid_str = pidns_pid2str(PT_TGID); uint64_t *const rlimit = tail_alloc(sizeof(*rlimit) * 2); const struct xlat_data *xlat; + long rc; + unsigned long num_skip = 256; size_t i = 0; - long rc = syscall(__NR_prlimit64, 0, 16, 0, 0); - pidns_print_leader(); - printf("prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL) = %s\n", - sprintrc(rc)); + if (argc >= 2) + num_skip = strtoul(argv[1], NULL, 0); + + for (i = 0; i < num_skip; i++) { + long rc = syscall(__NR_prlimit64, 0, 16, 0, 0); + pidns_print_leader(); + printf("prlimit64(0, 0x10 /* RLIMIT_??? */, NULL, NULL)" + " = %s%s\n", + sprintrc(rc), rc == INJECT_RETVAL ? INJ_STR : ""); + } /* The shortest output */ rc = syscall(__NR_prlimit64, 0, RLIMIT_AS, 0, 0); pidns_print_leader(); - printf("prlimit64(0, RLIMIT_AS, NULL, NULL) = %s\n", sprintrc(rc)); + printf("prlimit64(0, RLIMIT_AS, NULL, NULL) = %s" INJ_STR "\n", + sprintrc(rc)); - for (xlat = resources->data; i < resources->size; ++xlat, ++i) { + for (i = 0, xlat = resources->data; i < resources->size; ++xlat, ++i) { if (!xlat->str) continue; unsigned long res = 0xfacefeed00000000ULL | xlat->val; rc = syscall(__NR_prlimit64, pid, res, 0, rlimit); pidns_print_leader(); - if (rc) - printf("prlimit64(%d%s, %s, NULL, %p) =" - " %ld %s (%m)\n", + if (!RETVAL_INJECTED && (rc < 0)) { + printf("prlimit64(%d%s, %s, NULL, %p) = %s\n", (unsigned) pid, pid_str, xlat->str, rlimit, - rc, errno2name()); - else + sprintrc(rc)); + } else { printf("prlimit64(%d%s, %s, NULL" - ", {rlim_cur=%s, rlim_max=%s}) = 0\n", + ", {rlim_cur=%s, rlim_max=%s})" + " = %d" INJ_STR "\n", (unsigned) pid, pid_str, xlat->str, sprint_rlim(rlimit[0]), - sprint_rlim(rlimit[1])); + sprint_rlim(rlimit[1]), + RETVAL_INJECTED ? INJECT_RETVAL : 0); + } } pidns_print_leader(); |