provision: Make dsacl2fsacl() take a security.dom_sid, not str
[Samba/gebeck_regimport.git] / source3 / lib / asys / tests.c
blob354f1bfbdb58acee8f05b22b38d0fe5e4915f994
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 void *priv;
68 ssize_t retval;
69 int err;
70 int *pidx;
72 ret = asys_result(ctx, &retval, &err, &priv);
73 if (ret == -1) {
74 errno = ret;
75 perror("asys_result failed");
76 return 1;
78 pidx = (int *)priv;
80 printf("%d returned %d\n", *pidx, (int)retval);
83 ret = asys_context_destroy(ctx);
84 if (ret != 0) {
85 perror("asys_context_delete failed");
86 return 1;
89 free(buf);
91 return 0;