diff options
author | Ivo De Decker <ivo.dedecker@ugent.be> | 2013-05-10 13:33:02 +0200 |
---|---|---|
committer | Ivo De Decker <ivo.dedecker@ugent.be> | 2013-05-10 13:33:02 +0200 |
commit | 31202ad025bcdeb2585d18dc3f4641b5cf9c0ec4 (patch) | |
tree | 32c20d66684ac97b86e55495146e9a676bfae85a /source3/lib/asys/tests.c | |
parent | 2865eba17fddda6c49f1209ca92d539111e7ff93 (diff) | |
download | samba-31202ad025bcdeb2585d18dc3f4641b5cf9c0ec4.tar.gz |
Imported Upstream version 4.0.0+dfsg1upstream/4.0.0+dfsg1
Diffstat (limited to 'source3/lib/asys/tests.c')
-rw-r--r-- | source3/lib/asys/tests.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/source3/lib/asys/tests.c b/source3/lib/asys/tests.c new file mode 100644 index 0000000000..354f1bfbdb --- /dev/null +++ b/source3/lib/asys/tests.c @@ -0,0 +1,92 @@ +/* + * Test async syscalls + * Copyright (C) Volker Lendecke 2012 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "asys.h" +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> + +int main(int argc, const char *argv[]) +{ + struct asys_context *ctx; + int i, fd, ret; + + int *buf; + + int ntasks = 10; + + ret = asys_context_init(&ctx, 0); + if (ret != 0) { + perror("asys_context_create failed"); + return 1; + } + + fd = open("asys_testfile", O_CREAT|O_RDWR, 0644); + if (fd == -1) { + perror("open failed"); + return 1; + } + + buf = calloc(ntasks, sizeof(int)); + if (buf == NULL) { + perror("calloc failed"); + return 1; + } + + for (i=0; i<ntasks; i++) { + buf[i] = i; + } + + for (i=0; i<ntasks; i++) { + ret = asys_pwrite(ctx, fd, &buf[i], sizeof(int), + i * sizeof(int), &buf[i]); + if (ret != 0) { + errno = ret; + perror("asys_pwrite failed"); + return 1; + } + } + + for (i=0; i<ntasks; i++) { + void *priv; + ssize_t retval; + int err; + int *pidx; + + ret = asys_result(ctx, &retval, &err, &priv); + if (ret == -1) { + errno = ret; + perror("asys_result failed"); + return 1; + } + pidx = (int *)priv; + + printf("%d returned %d\n", *pidx, (int)retval); + } + + ret = asys_context_destroy(ctx); + if (ret != 0) { + perror("asys_context_delete failed"); + return 1; + } + + free(buf); + + return 0; +} |