File: aio.c

package info (click to toggle)
systemtap 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,860 kB
  • ctags: 12,513
  • sloc: cpp: 58,610; ansic: 58,189; exp: 37,322; sh: 10,633; xml: 7,771; perl: 2,252; python: 2,066; tcl: 1,305; makefile: 969; lisp: 105; java: 100; awk: 94; asm: 91; sed: 16
file content (154 lines) | stat: -rw-r--r-- 4,183 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* COVERAGE: io_setup io_submit io_getevents io_cancel io_destroy */

#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/aio_abi.h>
#include <fcntl.h>
#include <string.h>
#include <inttypes.h>


int main() {
	aio_context_t ctx;
	struct iocb cb;
	struct iocb *cbs[1];
	char data[8];
	struct io_event events[1];
	int ret;
	int fd;

	fd = open("testfile", O_RDWR | O_CREAT, 0644);
	ctx = 0;

	// ----- test normal operation

	ret = syscall(__NR_io_setup, 128, &ctx);
	//staptest// io_setup (128, XXXX) = NNNN
	if (ret < 0) {
		perror("io_setup failed");
		return -1;
	}

	strcpy(data, "testdata");
	memset(&cb, 0, sizeof(cb));
	cb.aio_fildes = fd;
	cb.aio_lio_opcode = IOCB_CMD_PWRITE;
	cb.aio_buf = (unsigned long)data;
	cb.aio_offset = 0;
	cb.aio_nbytes = 8;
	cbs[0] = &cb;

	ret = syscall(__NR_io_submit, ctx, 1, cbs);
        //staptest// io_submit (NNNN, 1, XXXX) = NNNN
	if (ret != 1) {
		perror("io_sumbit failed");
		return  -1;
	}

	ret = syscall(__NR_io_getevents, ctx, 1, 1, events, NULL);
        //staptest// io_getevents (NNNN, 1, 1, XXXX, NULL) = NNNN
	printf("%d\n", ret);

	ret = syscall(__NR_io_destroy, ctx);
        //staptest// io_destroy (NNNN) = NNNN
	if (ret < 0) {
		perror("io_destroy failed");
		return -1;
	}


	// ----- test nasty things

        syscall(__NR_io_setup, (unsigned)-1, &ctx);
        //staptest// io_setup (4294967295, XXXX) = NNNN

        syscall(__NR_io_setup, 1, (aio_context_t *)-1);
#ifdef __s390__
        //staptest// io_setup (1, 0x[7]?[f]+) = NNNN
#else
        //staptest// io_setup (1, 0x[f]+) = NNNN
#endif

        syscall(__NR_io_submit, (aio_context_t)-1, 1, cbs);
#if __WORDSIZE == 64
        //staptest// io_submit (18446744073709551615, 1, XXXX) = NNNN
#else
        //staptest// io_submit (4294967295, 1, XXXX) = NNNN
#endif

        syscall(__NR_io_submit, 0, (long)-1, cbs);
        //staptest// io_submit (0, -1, XXXX) = NNNN

        syscall(__NR_io_submit, 0, 1, (struct iocb **)-1);
#ifdef __s390__
        //staptest// io_submit (0, 1, 0x[7]?[f]+) = NNNN
#else
        //staptest// io_submit (0, 1, 0x[f]+) = NNNN
#endif

        syscall(__NR_io_getevents, (aio_context_t)-1, 1, 1, events, NULL);
#if __WORDSIZE == 64
        //staptest// io_getevents (18446744073709551615, 1, 1, XXXX, NULL) = NNNN
#else
        //staptest// io_getevents (4294967295, 1, 1, XXXX, NULL) = NNNN
#endif

        syscall(__NR_io_getevents, 0, (long)-1, 1, events, NULL);
        //staptest// io_getevents (0, -1, 1, XXXX, NULL) = NNNN

        syscall(__NR_io_getevents, 0, 1, (long)-1, events, NULL);
        //staptest// io_getevents (0, 1, -1, XXXX, NULL) = NNNN

        syscall(__NR_io_getevents, 0, 1, 1, (struct io_event *)-1, NULL);
#ifdef __s390__
        //staptest// io_getevents (0, 1, 1, 0x[7]?[f]+, NULL) = NNNN
#else
        //staptest// io_getevents (0, 1, 1, 0x[f]+, NULL) = NNNN
#endif

        syscall(__NR_io_getevents, 0, 1, 1, events, (struct timespec *)-1);
#ifdef __s390__
        //staptest// io_getevents (0, 1, 1, XXXX, 0x[7]?[f]+) = NNNN
#else
        //staptest// io_getevents (0, 1, 1, XXXX, 0x[f]+) = NNNN
#endif

        syscall(__NR_io_cancel, 1, (struct iocb *)1, (struct io_event *)1);
        //staptest// io_cancel (1, 0x1, 0x1) = NNNN

        syscall(__NR_io_cancel, (aio_context_t)-1, (struct iocb *)1, (struct io_event *)1);
#if __WORDSIZE == 64
        //staptest// io_cancel (18446744073709551615, 0x1, 0x1) = NNNN
#else
        //staptest// io_cancel (4294967295, 0x1, 0x1) = NNNN
#endif

        syscall(__NR_io_cancel, 1, (struct iocb *)-1, (struct io_event *)1);
#ifdef __s390__
        //staptest// io_cancel (1, 0x[7]?[f]+, 0x1) = NNNN
#else
        //staptest// io_cancel (1, 0x[f]+, 0x1) = NNNN
#endif

        syscall(__NR_io_cancel, 1, (struct iocb *)1, (struct io_event *)-1);
#ifdef __s390__
        //staptest// io_cancel (1, 0x1, 0x[7]?[f]+) = NNNN
#else
        //staptest// io_cancel (1, 0x1, 0x[f]+) = NNNN
#endif

	ret = syscall(__NR_io_destroy, (aio_context_t)-1);
#if __WORDSIZE == 64
        //staptest// io_destroy (18446744073709551615) = NNNN
#else
        //staptest// io_destroy (4294967295) = NNNN
#endif

	close(fd);

	return 0;
}