diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2023-04-06 16:15:48 +0200 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2023-04-22 08:00:00 +0000 |
commit | 10aa58e55b7b3f7572777d888a218cc5e4318f61 (patch) | |
tree | 7151444808eb8356f6007dbef6331ae3e3389ba8 | |
parent | 67eb44c4de45e89af0e34937ff6a2ea1ebff14ae (diff) | |
download | strace-10aa58e55b7b3f7572777d888a218cc5e4318f61.tar.gz |
tests: expand link test, add link-P test
* tests/.gitignore: Add link-P.
* tests/Makefile.am (check_PROGRAMS): Likewise.
* tests/gen_tests.in (link): Add -a17 option.
(link-P): New test.
* tests/link-P.c: New file.
* tests/link.c: Add checks, print the output based on the presence
of the PATH_TRACING macro.
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/gen_tests.in | 3 | ||||
-rw-r--r-- | tests/link-P.c | 2 | ||||
-rw-r--r-- | tests/link.c | 46 |
5 files changed, 48 insertions, 5 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 83f1e96f6..eff845cdd 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -467,6 +467,7 @@ lchown lchown32 libtests.a link +link-P linkat list_sigaction_signum llseek diff --git a/tests/Makefile.am b/tests/Makefile.am index dfffb8c2c..6cb13c28f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -249,6 +249,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ ksysent \ landlock_create_ruleset-success \ landlock_create_ruleset-success-y \ + link-P \ list_sigaction_signum \ localtime \ looping_threads \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 6432e3409..cf5bf17b2 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -479,7 +479,8 @@ landlock_restrict_self -a29 landlock_restrict_self-y -a29 -y -e trace=landlock_restrict_self 7>/dev/full lchown -a30 lchown32 -a32 -link +link -a17 +link-P -a17 -e trace=link -P link_sample_old linkat linkat--secontext --secontext -e trace=linkat linkat--secontext_full --secontext=full -e trace=linkat diff --git a/tests/link-P.c b/tests/link-P.c new file mode 100644 index 000000000..08eb1f0e4 --- /dev/null +++ b/tests/link-P.c @@ -0,0 +1,2 @@ +#define PATH_TRACING +#include "link.c" diff --git a/tests/link.c b/tests/link.c index 468086fe5..299211e87 100644 --- a/tests/link.c +++ b/tests/link.c @@ -11,17 +11,55 @@ #ifdef __NR_link # include <stdio.h> +# include <string.h> # include <unistd.h> int main(void) { - static const char sample_1[] = "link_sample_old"; - static const char sample_2[] = "link_sample_new"; + static const char sample_1_str[] = "link_sample_old"; + static const char sample_2_str[] = "link_sample_new"; - long rc = syscall(__NR_link, sample_1, sample_2); + TAIL_ALLOC_OBJECT_CONST_ARR(char, sample_1, sizeof(sample_1_str)); + TAIL_ALLOC_OBJECT_CONST_ARR(char, sample_2, sizeof(sample_2_str)); + TAIL_ALLOC_OBJECT_CONST_ARR(char, short_1, sizeof(sample_1_str) - 1); + TAIL_ALLOC_OBJECT_CONST_ARR(char, short_2, sizeof(sample_2_str) - 1); + + long rc; + + memcpy(sample_1, sample_1_str, sizeof(sample_1_str)); + memcpy(sample_2, sample_2_str, sizeof(sample_2_str)); + memcpy(short_1, sample_1_str, sizeof(sample_1_str) - 1); + memcpy(short_2, sample_2_str, sizeof(sample_2_str) - 1); + + rc = syscall(__NR_link, NULL, NULL); +# ifndef PATH_TRACING + printf("link(NULL, NULL) = %ld %s (%m)\n", rc, errno2name()); +# endif + + rc = syscall(__NR_link, short_1, NULL); +# ifndef PATH_TRACING + printf("link(%p, NULL) = %ld %s (%m)\n", + short_1, rc, errno2name()); +# endif + + rc = syscall(__NR_link, NULL, sample_1); + printf("link(NULL, \"%s\") = %ld %s (%m)\n", + sample_1_str, rc, errno2name()); + + rc = syscall(__NR_link, sample_1, short_2); + printf("link(\"%s\", %p) = %ld %s (%m)\n", + sample_1_str, short_2, rc, errno2name()); + + rc = syscall(__NR_link, short_1, sample_2); +# ifndef PATH_TRACING + printf("link(%p, \"%s\") = %ld %s (%m)\n", + short_1, sample_2_str, rc, errno2name()); +# endif + + rc = syscall(__NR_link, sample_1, sample_2); printf("link(\"%s\", \"%s\") = %ld %s (%m)\n", - sample_1, sample_2, rc, errno2name()); + sample_1_str, sample_2_str, rc, errno2name()); puts("+++ exited with 0 +++"); return 0; |