[GSOC][PATCH] tests/fcntl.c: add test for struct f_owner_ex
Dmitry V. Levin
ldv at altlinux.org
Mon Mar 26 04:13:22 UTC 2018
On Sun, Mar 25, 2018 at 10:28:26PM +0800, Zhibin Li wrote:
> Signed-off-by: Zhibin Li <08826794brmt at gmail.com>
> ---
> tests/fcntl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 74 insertions(+)
>
> diff --git a/tests/fcntl.c b/tests/fcntl.c
> index 4f62ca2a..17a30336 100644
> --- a/tests/fcntl.c
> +++ b/tests/fcntl.c
> @@ -36,6 +36,10 @@
> # include "struct_flock.c"
>
> # define TEST_FLOCK64_EINVAL(cmd) test_flock64_einval(cmd, #cmd)
> +# define TEST_F_OWNER_EX_ESRCH(cmd) test_f_owner_ex_esrch(cmd, #cmd)
> +
> +typedef struct f_owner_ex struct_kernel_f_owner_ex;
> +typedef struct struct_kernel_f_owner_ex struct_f_owner_ex;
The second typedef looks odd. Fortunately, it's not used.
>
> static void
> test_flock64_einval(const int cmd, const char *name)
> @@ -69,12 +73,82 @@ test_flock64(void)
> #endif
> }
>
> +static void
> +test_f_owner_ex_esrch(const int cmd, const char *name)
> +{
> + struct_kernel_f_owner_ex fo[] = {
> + { .type = F_OWNER_TID, .pid = 1234567890 },
> + { .type = F_OWNER_PID, .pid = 1234567890 },
> + { .type = F_OWNER_PGRP, .pid = -1234567890 }
> + };
> +
> + long rc;
> +
> + rc = invoke_test_syscall(cmd, &fo[0]);
> + printf("%s(0, %s, {type=F_OWNER_TID, pid=%d}) = %s\n",
> + TEST_SYSCALL_STR, name, (__kernel_pid_t) fo[0].pid, sprintrc(rc));
> +
> + rc = invoke_test_syscall(cmd, &fo[1]);
> + printf("%s(0, %s, {type=F_OWNER_PID, pid=%d}) = %s\n",
> + TEST_SYSCALL_STR, name, (__kernel_pid_t) fo[1].pid, sprintrc(rc));
> +
> + rc = invoke_test_syscall(cmd, &fo[2]);
> + printf("%s(0, %s, {type=F_OWNER_PGRP, pid=%d}) = %s\n",
> + TEST_SYSCALL_STR, name, (__kernel_pid_t) fo[2].pid, sprintrc(rc));
> +
> +}
This version of test_f_owner_ex_esrch contains the same code repeated
thrice, it would be better if this unnecessary duplication was avoided,
e.g. (untested):
static void
test_f_owner_ex_esrch_type_pid(const int cmd, const char *const cmd_name,
const int type, const char *const type_name,
const pid_t pid)
{
struct_kernel_f_owner_ex fo = { .type = type, .pid = pid };
long rc = invoke_test_syscall(cmd, &fo);
printf("%s(0, %s, {type=%s, pid=%d}) = %s\n",
TEST_SYSCALL_STR, cmd_name, type_name, pid, sprintrc(rc));
}
static void
test_f_owner_ex_esrch(const int cmd, const char *const cmd_name)
{
test_f_owner_ex_esrch_type_pid(cmd, cmd_name,
ARG_STR(F_OWNER_TID), 1234567890);
test_f_owner_ex_esrch_type_pid(cmd, cmd_name,
ARG_STR(F_OWNER_PID), 1234567890);
test_f_owner_ex_esrch_type_pid(cmd, cmd_name,
ARG_STR(F_OWNER_PGRP), -1234567890);
}
> +
> +static void
> +test_f_owner_ex(void)
> +{
> + TEST_F_OWNER_EX_ESRCH(F_SETOWN_EX);
> +
> + struct_kernel_f_owner_ex fo[] = {
> + { .type = F_OWNER_TID, .pid = 20 }, //magic, need reconsidering
> + { .type = F_OWNER_PID, .pid = 30 },
> + { .type = F_OWNER_PGRP, .pid = 40 }
> + };
> +
> + long rc;
> + rc = invoke_test_syscall(F_SETOWN_EX, &fo[0]);
> + printf("%s(0, F_SETOWN, {type=F_OWNER_TID, pid=%d}) = 0\n",
> + TEST_SYSCALL_STR, (__kernel_pid_t) fo[0].pid);
> + if (rc)
> + return;
> +
> + invoke_test_syscall(F_GETOWN, &fo[0]);
> + printf("%s(0, F_GETOWN, {type=F_OWNER_TID, pid=%d}) = 0\n",
> + TEST_SYSCALL_STR, (__kernel_pid_t) fo[0].pid);
> +
> + rc = invoke_test_syscall(F_SETOWN_EX, &fo[1]);
> + printf("%s(0, F_SETOWN, {type=F_OWNER_PID, pid=%d}) = 0\n",
> + TEST_SYSCALL_STR, (__kernel_pid_t) fo[1].pid);
> + if (rc)
> + return;
> +
> + invoke_test_syscall(F_GETOWN, &fo[1]);
> + printf("%s(0, F_GETOWN, {type=F_OWNER_PID, pid=%d}) = 0\n",
> + TEST_SYSCALL_STR, (__kernel_pid_t) fo[1].pid);
> +
> + rc = invoke_test_syscall(F_SETOWN_EX, &fo[2]);
> + printf("%s(0, F_SETOWN, {type=F_OWNER_PGRP, pid=%d}) = 0\n",
> + TEST_SYSCALL_STR, (__kernel_pid_t) fo[2].pid);
> + if (rc)
> + return;
> +
> + invoke_test_syscall(F_GETOWN, &fo[2]);
> + printf("%s(0, F_GETOWN, {type=F_OWNER_PGRP, pid=%d}) = 0\n",
> + TEST_SYSCALL_STR, (__kernel_pid_t) fo[2].pid);
> +
> +}
Likewise, the same code is repeated thrice.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180326/f3bc9a4a/attachment.bin>
More information about the Strace-devel
mailing list