lib: Remove messages_local
[Samba.git] / source3 / lib / asys / tests.c
blobe54e3ea2d22961d925f2260e4b5418c35fae4d06
1 /*
2 * Test async syscalls
3 * Copyright (C) Volker Lendecke 2012
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.
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.
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/>.
19 #include "asys.h"
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <errno.h>
25 int main(int argc, const char *argv[])
27 struct asys_context *ctx;
28 int i, fd, ret;
30 int *buf;
32 int ntasks = 10;
34 ret = asys_context_init(&ctx, 0);
35 if (ret != 0) {
36 perror("asys_context_create failed");
37 return 1;
40 fd = open("asys_testfile", O_CREAT|O_RDWR, 0644);
41 if (fd == -1) {
42 perror("open failed");
43 return 1;
46 buf = calloc(ntasks, sizeof(int));
47 if (buf == NULL) {
48 perror("calloc failed");
49 return 1;
52 for (i=0; i<ntasks; i++) {
53 buf[i] = i;
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;
66 for (i=0; i<ntasks; i++) {
67 struct asys_result result;
68 int *pidx;
70 ret = asys_results(ctx, &result, 1);
71 if (ret < 0) {
72 errno = -ret;
73 perror("asys_result failed");
74 return 1;
76 pidx = (int *)result.private_data;
78 printf("%d returned %d\n", *pidx, (int)result.ret);
81 ret = asys_context_destroy(ctx);
82 if (ret != 0) {
83 perror("asys_context_delete failed");
84 return 1;
87 free(buf);
89 return 0;