On Wed, Jan 27, 2016 at 11:01:53AM +0800, Fei Jie wrote:
> Check how mincore syscall is traced.
[...]
> +int main(void)
> +{
> +     char file_name[] = "mincore_XXXXXX";
> +     int pg_size = getpagesize();
> +     int global_len = pg_size * 2;
> +     char *buf = (char *)malloc(global_len);
> +     char *global_pointer = NULL;
> +     int file_desc, res;
> +     memset(buf, 42, global_len);
> +
> +     if ((file_desc = mkstemp(file_name)) == -1) {
> +              perror_msg_and_fail("Error while creating temporary file");
> +     }
> +
> +     if (write(file_desc, buf, global_len) == -1) {
> +             perror_msg_and_fail("Error while writing to temporary file");
> +     }
> +     free(buf);
> +
> +     global_pointer = (char *)mmap(NULL, global_len,
> +             PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, file_desc, 0);
> +     if (global_pointer == MAP_FAILED) {
> +             perror_msg_and_fail("Temporary file could not be mmapped");
> +     }

What was the reason to do a file backed mmap instead of an anonymous one?

> +     unsigned char *global_vec = malloc((global_len + pg_size - 1) / 
> pg_size);
> +     res = mincore(global_pointer, global_len, global_vec);
> +     if (res == -1) {
> +             perror_msg_and_fail("mincore fail!\n");
> +     }
> +     printf("mincore\\(%p, %d, \[[0-1]*\\.\\.\\.]\\) = %d\n",
> +            global_pointer, global_len, res);

What I don't like in this test is that it doesn't test the only part
of mincore parser that is buggy and has to be tested first of all --
the way how the result vector is printed.  Haven't you noticed that
mincore parser prints a lot of garbage after the real data returned
by the kernel?

I've pushed commit v4.11-185-gdfea1da to address this.


-- 
ldv

Attachment: pgpBWyt0fsrIv.pgp
Description: PGP signature

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to