Linux: define llseek operations
[openafs.git] / tests / rpctestlib / rpc_test_main.c
1 /*
2  * Copyright (c) 2010, Linux Box Corporation.
3  * All Rights Reserved.
4  *
5  * Portions Copyright (c) 2007, Hartmut Reuter,
6  * RZG, Max-Planck-Institut f. Plasmaphysik.
7  * All Rights Reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  *   1. Redistributions of source code must retain the above copyright
13  *      notice, this list of conditions and the following disclaimer.
14  *   2. Redistributions in binary form must reproduce the above copyright
15  *      notice, this list of conditions and the following disclaimer in
16  *      the documentation and/or other materials provided with the
17  *      distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <afsconfig.h>
32 #include <afs/param.h>
33
34 #include <roken.h>
35
36 #include <afs/stds.h>
37
38 #include "rpc_test_procs.h"
39
40 #include <stdio.h>
41 #include <sys/types.h>
42 #include <string.h>
43 #include <sys/stat.h>
44 #include <errno.h>
45 #include <signal.h>
46 #include <afs/vice.h>
47 #include <afs/cmd.h>
48 #include <afs/auth.h>
49 #include <afs/cellconfig.h>
50 #include <afs/com_err.h>
51 #ifdef HAVE_DIRENT_H
52 #include <dirent.h>
53 #endif
54 #ifdef HAVE_DIRECT_H
55 #include <direct.h>
56 #endif
57 #ifdef AFS_DARWIN_ENV
58 #include <sys/malloc.h>
59 #else
60 #include <malloc.h>
61 #endif
62 #include <afs/errors.h>
63 #include <afs/sys_prototypes.h>
64 #include <rx/rx_prototypes.h>
65 #ifdef AFS_PTHREAD_ENV
66 #include <assert.h>
67 #endif
68
69 const char *prog = "lockharness";
70
71 #ifndef AFS_PTHREAD_ENV
72 #error compilation without pthreads is not supported
73 #endif
74
75
76 int
77 main(int argc, char **argv)
78 {
79     int i, code;
80     rpc_test_request_ctx *c1, *c2;
81     AFSFetchStatus outstatus;
82
83     printf("%s: start\n", prog);
84
85     code = rpc_test_PkgInit();
86
87     /* replace with appropriate test addresses */
88     code = init_fs_channel(&c1, "eth0", "10.1.1.213", "24",
89                            "10.1.1.81", /* fs */ RPC_TEST_REQ_CTX_FLAG_NONE);
90     code = init_fs_channel(&c2, "eth0", "10.1.1.213", "24",
91                            "10.1.1.81" /* fs */, RPC_TEST_REQ_CTX_FLAG_XCB);
92
93     printf("%s: channels initialized\n", prog);
94
95     i = 0;
96 repeat:
97     {
98         /* XXXX fid members should be...dynamic */
99         AFSFid fid = { 536870915, 12, 4016};
100         code = rpc_test_afs_fetch_status(c1, &fid, &outstatus);
101         printf("%s: c1 call returned %d\n", prog, code);
102     }
103
104     {
105         /* XXXX fid members should be...dynamic */
106         AFSFid fid = { 536870915, 12, 4016};
107         code = rpc_test_afs_fetch_status(c2, &fid, &outstatus);
108         printf("%s: c2 call returned %d\n", prog, code);
109     }
110
111     /* force bcb at c1 */
112     {
113         AFSFid fid = { 536870915, 12, 4016};
114         AFSStoreStatus instatus;
115         instatus.Mask = 0;
116         instatus.SegSize = 0;
117         instatus.Owner = outstatus.Owner;
118         instatus.Group = outstatus.Group;
119         instatus.UnixModeBits = outstatus.UnixModeBits;
120         instatus.ClientModTime = time(NULL);
121         code = rpc_test_afs_store_status(c2, &fid, &instatus, &outstatus);
122         printf("%s: c2 store status returned %d\n", prog, code);
123     }
124
125     /* force bcb at c2 */
126     {
127         AFSFid fid = { 536870915, 12, 4016};
128         AFSStoreStatus instatus;
129         instatus.Mask = 0;
130         instatus.SegSize = 0;
131         instatus.Owner = outstatus.Owner;
132         instatus.Group = outstatus.Group;
133         instatus.UnixModeBits = outstatus.UnixModeBits;
134         instatus.ClientModTime = time(NULL);
135         code = rpc_test_afs_store_status(c1, &fid, &instatus, &outstatus);
136         printf("%s: c1 store status returned %d\n", prog, code);
137     }
138     i++;
139     if (i < 10)
140         goto repeat;
141
142 #if defined(AFS_BYTE_RANGE_FLOCKS)
143     /* set a lock on c1 */
144     {
145         AFSFid fid = { 536870915, 12, 4016};
146         AFSByteRangeLock lock;
147         memset(&lock, 0, sizeof(AFSByteRangeLock));
148         lock.Fid = fid;
149         lock.Type = LockWrite;
150         lock.Flags = 0;
151         lock.Owner = 1001;
152         lock.Uniq = 1;
153         lock.Offset = 50;
154         lock.Length = 100;
155         code = rpc_test_afs_set_byterangelock(c1, &lock);
156         printf("%s: c1 set lock returned %d\n", prog, code);
157     }
158
159     /* try to set the same lock in c2 (should FAIL) */
160     {
161         AFSFid fid = { 536870915, 12, 4016};
162         AFSByteRangeLock lock;
163         memset(&lock, 0, sizeof(AFSByteRangeLock));
164         lock.Fid = fid;
165         lock.Type = LockWrite;
166         lock.Flags = 0;
167         lock.Owner = 1002;
168         lock.Uniq = 2;
169         lock.Offset = 50;
170         lock.Length = 100;
171         code = rpc_test_afs_set_byterangelock(c2, &lock);
172         printf("%s: c2 set lock returned %d\n", prog, code);
173     }
174
175     /* release lock on c1 */
176     {
177         AFSFid fid = { 536870915, 12, 4016};
178         AFSByteRangeLock lock;
179         memset(&lock, 0, sizeof(AFSByteRangeLock));
180         lock.Fid = fid;
181         lock.Type = LockWrite;
182         lock.Flags = 0;
183         lock.Owner = 1001;
184         lock.Uniq = 1;
185         lock.Offset = 50;
186         lock.Length = 100;
187         code = rpc_test_afs_release_byterangelock(c1, &lock);
188         printf("%s: c1 set lock returned %d\n", prog, code);
189     }
190 #endif /* AFS_BYTE_RANGE_FLOCKS */
191
192     printf("%s: wait %d sec for processing\n", prog, 5);
193     sleep(5);
194
195     code = destroy_fs_channel(c1);
196     code = destroy_fs_channel(c2);
197
198     rpc_test_PkgShutdown();
199
200     printf("%s: finish\n", prog);
201
202     exit (0);
203
204 }        /* main */