[PATCH v2] Add test for mincore syscall

Dmitry V. Levin ldv at altlinux.org
Fri Jan 29 11:29:24 UTC 2016


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
-------------- 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/20160129/ee109a72/attachment.bin>


More information about the Strace-devel mailing list