summaryrefslogtreecommitdiff
path: root/libaio-0.3.109/harness/cases/5.t
blob: 2b4b4bb44cc2d18a21b736630d9f911693b4e884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* 5.t
- Write from a mmap() of the same file. (5.t)
*/
#include "aio_setup.h"
#include <sys/mman.h>
#include <errno.h>

int test_main(void)
{
	int page_size = getpagesize();
#define SIZE	512
	char *buf;
	int rwfd;
	int	status = 0, res;

	rwfd = open("testdir/rwfile", O_RDWR);		assert(rwfd != -1);
	res = ftruncate(rwfd, 512);			assert(res == 0);

	buf = mmap(0, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, rwfd, 0);
	assert(buf != (char *)-1);

	status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, SIZE);
	status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, SIZE);

	res = munmap(buf, page_size);			assert(res == 0);
	buf = mmap(0, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, rwfd, 0);
	assert(buf != (char *)-1);

	status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, SIZE);
	status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, SIZE);

	res = munmap(buf, page_size);			assert(res == 0);
	buf = mmap(0, page_size, PROT_READ, MAP_SHARED, rwfd, 0);
	assert(buf != (char *)-1);

	status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, SIZE);
	status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, -EFAULT);

	res = munmap(buf, page_size);			assert(res == 0);
	buf = mmap(0, page_size, PROT_WRITE, MAP_SHARED, rwfd, 0);
	assert(buf != (char *)-1);

	status |= attempt_rw(rwfd, buf, SIZE,  0,  READ, SIZE);

	/* Whether PROT_WRITE is readable is arch-dependent.  So compare
	 * against read result. */
	res = read(rwfd, buf, SIZE);
	if (res < 0)
		res = -errno;
	status |= attempt_rw(rwfd, buf, SIZE,  0, WRITE, res);

	return status;
}