[PATCH v2 3/3] tests: add acct.test
Dmitry V. Levin
ldv at altlinux.org
Mon Mar 7 23:11:01 UTC 2016
On Mon, Mar 07, 2016 at 11:32:03AM +0800, Fei Jie wrote:
> --- /dev/null
> +++ b/tests/acct.c
> @@ -0,0 +1,37 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_acct
> +
> +# define TMP_FILE "acct_tmpfile"
> +
> +# include <errno.h>
> +# include <stdio.h>
> +# include <unistd.h>
> +int
> +main(void)
Please move definition of a local macro after inclusion of system headers.
Please add an empty line after headers and before the function.
> +{
> + int rc = syscall(__NR_acct, TMP_FILE);
> + const char *errno_text;
> + switch(errno) {
> + case EPERM:
> + errno_text = "EPERM";
> + break;
> + case ENOSYS:
> + errno_text = "ENOSYS";
> + break;
> + default:
> + errno_text = "ENOENT";
> + }
> + printf("acct(\"%s\") = %d %s (%m)\n",
> + TMP_FILE, rc, errno_text);
errno has a meaning here only if the syscall has failed.
You rightfully assume that acct will fail, i.e. rc == -1,
otherwise the test is not going to produce correct results.
I think some kind of check for syscall return code should be added here
for consistency, e.g.
assert(syscall(__NR_acct, TMP_FILE) == -1);
--
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/20160308/0173fe02/attachment.bin>
More information about the Strace-devel
mailing list