summaryrefslogtreecommitdiff
path: root/source3/lib/asys/tests.c
blob: 354f1bfbdb58acee8f05b22b38d0fe5e4915f994 (plain)
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
/*
 * 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;
}