[PATCH] tests: add chmod.test
Dmitry V. Levin
ldv at altlinux.org
Fri Mar 4 21:41:56 UTC 2016
On Fri, Mar 04, 2016 at 08:45:48PM +0000, Anchit Jain wrote:
[...]
> +#include "tests.h"
> +#include <assert.h>
As you no longer use assert, no need to include <assert.h>.
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include <sys/syscall.h>
> +
> +#if defined __NR_chmod
The only two headers that have to be included before __NR_chmod test
are "tests.h" and <sys/syscall.h>.
In case you are in pedantic mood, all the rest could be included
after __NR_chmod test, like in tests/alarm.c and many similar tests.
> +
> +int
> +main(void)
> +{
> + static const char fname[] = "chmod_test_file";
> + int fd = open(fname, O_CREAT|O_RDONLY, 0400);
> +
> + if (fd == -1)
> + perror_msg_and_fail("open");
> +
> + if (syscall(__NR_chmod, fname, 0600) != 0)
> + {
The opening brace should be placed on "if" line.
> + if (errno == ENOSYS)
> + perror_msg_and_fail("chmod ENOSYS");
If chmod has failed with ENOSYS, it might be a normal condition
on some architectures, so it shouldn't be treated as a test error.
Just print it using
printf("chmod(\"%s\", 0600) = -1 ENOENT (%m)\n", fname);
> + perror_msg_and_fail("chmod");
> + }
> + printf("chmod(\"%s\", 0600) = 0\n", fname);
> + int ret = unlink(fname);
> + if (ret == -1)
> + perror_msg_and_fail("unlink");
No need to save return value if there are no plans to use it.
The idiom for this kind of checks is
if (unlink(fname))
perror_msg_and_fail("unlink");
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160305/f8da0528/attachment.bin>
More information about the Strace-devel
mailing list