1 | /*
|
---|
2 | * Test async syscalls
|
---|
3 | * Copyright (C) Volker Lendecke 2012
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "asys.h"
|
---|
20 | #include <stdio.h>
|
---|
21 | #include <string.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <errno.h>
|
---|
24 |
|
---|
25 | int main(int argc, const char *argv[])
|
---|
26 | {
|
---|
27 | struct asys_context *ctx;
|
---|
28 | int i, fd, ret;
|
---|
29 |
|
---|
30 | int *buf;
|
---|
31 |
|
---|
32 | int ntasks = 10;
|
---|
33 |
|
---|
34 | ret = asys_context_init(&ctx, 0);
|
---|
35 | if (ret != 0) {
|
---|
36 | perror("asys_context_create failed");
|
---|
37 | return 1;
|
---|
38 | }
|
---|
39 |
|
---|
40 | fd = open("asys_testfile", O_CREAT|O_RDWR, 0644);
|
---|
41 | if (fd == -1) {
|
---|
42 | perror("open failed");
|
---|
43 | return 1;
|
---|
44 | }
|
---|
45 |
|
---|
46 | buf = calloc(ntasks, sizeof(int));
|
---|
47 | if (buf == NULL) {
|
---|
48 | perror("calloc failed");
|
---|
49 | return 1;
|
---|
50 | }
|
---|
51 |
|
---|
52 | for (i=0; i<ntasks; i++) {
|
---|
53 | buf[i] = i;
|
---|
54 | }
|
---|
55 |
|
---|
56 | for (i=0; i<ntasks; i++) {
|
---|
57 | ret = asys_pwrite(ctx, fd, &buf[i], sizeof(int),
|
---|
58 | i * sizeof(int), &buf[i]);
|
---|
59 | if (ret != 0) {
|
---|
60 | errno = ret;
|
---|
61 | perror("asys_pwrite failed");
|
---|
62 | return 1;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | for (i=0; i<ntasks; i++) {
|
---|
67 | struct asys_result result;
|
---|
68 | int *pidx;
|
---|
69 |
|
---|
70 | ret = asys_results(ctx, &result, 1);
|
---|
71 | if (ret < 0) {
|
---|
72 | errno = -ret;
|
---|
73 | perror("asys_result failed");
|
---|
74 | return 1;
|
---|
75 | }
|
---|
76 | pidx = (int *)result.private_data;
|
---|
77 |
|
---|
78 | printf("%d returned %d\n", *pidx, (int)result.ret);
|
---|
79 | }
|
---|
80 |
|
---|
81 | ret = asys_context_destroy(ctx);
|
---|
82 | if (ret != 0) {
|
---|
83 | perror("asys_context_delete failed");
|
---|
84 | return 1;
|
---|
85 | }
|
---|
86 |
|
---|
87 | free(buf);
|
---|
88 |
|
---|
89 | return 0;
|
---|
90 | }
|
---|