[PATCH] tests: add getrusage.test

Dmitry V. Levin ldv at altlinux.org
Thu Feb 18 16:09:08 UTC 2016


On Thu, Feb 18, 2016 at 04:04:57PM +0800, Fei Jie wrote:
[...]
> diff --git a/tests/getrusage.c b/tests/getrusage.c
> new file mode 100644
> index 0000000..eea0168
> --- /dev/null
> +++ b/tests/getrusage.c
> @@ -0,0 +1,38 @@
> +#include "tests.h"
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_getrusage
> +
> +#include <sched.h>

Do you really need <sched.h> to test getrusage?

> +#include <stdio.h>
> +#include <sys/resource.h>
> +#include <unistd.h>

Please indent.

> +
> +int
> +main(void)
> +{
> +	struct rusage usage;
> +	int rc = syscall(__NR_getrusage, RUSAGE_SELF, &usage);
> +	printf("getrusage(RUSAGE_SELF, {ru_utime={%ld, %ld}"
> +	       ", ru_stime={%ld, %ld}, ru_maxrss=%ld, ru_ixrss=%ld"
> +	       ", ru_idrss=%ld, ru_isrss=%ld, ru_minflt=%ld"
> +	       ", ru_majflt=%ld, ru_nswap=%ld, ru_inblock=%ld"
> +	       ", ru_oublock=%ld, ru_msgsnd=%ld, ru_msgrcv=%ld"
> +	       ", ru_nsignals=%ld, ru_nvcsw=%ld, ru_nivcsw=%ld}) = %d\n",
> +	       usage.ru_utime.tv_sec, usage.ru_utime.tv_usec,
> +	       usage.ru_stime.tv_sec, usage.ru_stime.tv_usec,
> +	       usage.ru_maxrss, usage.ru_ixrss, usage.ru_idrss,
> +	       usage.ru_isrss, usage.ru_minflt, usage.ru_majflt,
> +	       usage.ru_nswap, usage.ru_inblock, usage.ru_oublock,
> +	       usage.ru_msgsnd, usage.ru_msgrcv, usage.ru_nsignals,
> +	       usage.ru_nvcsw, usage.ru_nivcsw, rc);

While all integer members of struct rusage have type "long",
I believe they should be printed using "%lu" format instead of "%ld".


-- 
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/20160218/7fb31068/attachment.bin>


More information about the Strace-devel mailing list