Windows: Cleanup build scripts; no include\afs or include\rx
[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 #include <afs/stds.h>
34
35 #include "rpc_test_procs.h"
36
37 #include <stdio.h>
38 #include <sys/types.h>
39 #include <string.h>
40 #include <sys/stat.h>
41 #include <errno.h>
42 #include <signal.h>
43 #include <afs/vice.h>
44 #include <afs/cmd.h>
45 #include <afs/auth.h>
46 #include <afs/cellconfig.h>
47 #include <afs/com_err.h>
48 #ifdef HAVE_DIRENT_H
49 #include <dirent.h>
50 #endif
51 #ifdef HAVE_DIRECT_H
52 #include <direct.h>
53 #endif
54 #ifdef AFS_DARWIN_ENV
55 #include <sys/malloc.h>
56 #else
57 #include <malloc.h>
58 #endif
59 #include <afs/errors.h>
60 #include <afs/sys_prototypes.h>
61 #include <rx/rx_prototypes.h>
62 #ifdef AFS_PTHREAD_ENV
63 #include <assert.h>
64 #endif
65
66 const char *prog = "lockharness";
67
68 #ifndef AFS_PTHREAD_ENV
69 #error compilation without pthreads is not supported
70 #endif
71
72
73 int
74 main(int argc, char **argv)
75 {
76     int i, code;
77     rpc_test_request_ctx *c1, *c2;
78     AFSFetchStatus outstatus;
79
80     printf("%s: start\n", prog);
81
82     code = rpc_test_PkgInit();
83
84     /* replace with appropriate test addresses */
85     code = init_fs_channel(&c1, "eth0", "10.1.1.213", "24",
86                            "10.1.1.81", /* fs */ RPC_TEST_REQ_CTX_FLAG_NONE);
87     code = init_fs_channel(&c2, "eth0", "10.1.1.213", "24",
88                            "10.1.1.81" /* fs */, RPC_TEST_REQ_CTX_FLAG_XCB);
89
90     printf("%s: channels initialized\n", prog);
91
92     i = 0;
93 repeat:
94     {
95         /* XXXX fid members should be...dynamic */
96         AFSFid fid = { 536870915, 12, 4016};
97         code = rpc_test_afs_fetch_status(c1, &fid, &outstatus);
98         printf("%s: c1 call returned %d\n", prog, code);
99     }
100
101     {
102         /* XXXX fid members should be...dynamic */
103         AFSFid fid = { 536870915, 12, 4016};
104         code = rpc_test_afs_fetch_status(c2, &fid, &outstatus);
105         printf("%s: c2 call returned %d\n", prog, code);
106     }
107
108     /* force bcb at c1 */
109     {
110         AFSFid fid = { 536870915, 12, 4016};
111         AFSStoreStatus instatus;
112         instatus.Mask = 0;
113         instatus.SegSize = 0;
114         instatus.Owner = outstatus.Owner;
115         instatus.Group = outstatus.Group;
116         instatus.UnixModeBits = outstatus.UnixModeBits;
117         instatus.ClientModTime = time(NULL);
118         code = rpc_test_afs_store_status(c2, &fid, &instatus, &outstatus);
119         printf("%s: c2 store status returned %d\n", prog, code);
120     }
121
122     /* force bcb at c2 */
123     {
124         AFSFid fid = { 536870915, 12, 4016};
125         AFSStoreStatus instatus;
126         instatus.Mask = 0;
127         instatus.SegSize = 0;
128         instatus.Owner = outstatus.Owner;
129         instatus.Group = outstatus.Group;
130         instatus.UnixModeBits = outstatus.UnixModeBits;
131         instatus.ClientModTime = time(NULL);
132         code = rpc_test_afs_store_status(c1, &fid, &instatus, &outstatus);
133         printf("%s: c1 store status returned %d\n", prog, code);
134     }
135     i++;
136     if (i < 10)
137         goto repeat;
138
139 #if defined(AFS_BYTE_RANGE_FLOCKS)
140     /* set a lock on c1 */
141     {
142         AFSFid fid = { 536870915, 12, 4016};
143         AFSByteRangeLock lock;
144         memset(&lock, 0, sizeof(AFSByteRangeLock));
145         lock.Fid = fid;
146         lock.Type = LockWrite;
147         lock.Flags = 0;
148         lock.Owner = 1001;
149         lock.Uniq = 1;
150         lock.Offset = 50;
151         lock.Length = 100;
152         code = rpc_test_afs_set_byterangelock(c1, &lock);
153         printf("%s: c1 set lock returned %d\n", prog, code);
154     }
155
156     /* try to set the same lock in c2 (should FAIL) */
157     {
158         AFSFid fid = { 536870915, 12, 4016};
159         AFSByteRangeLock lock;
160         memset(&lock, 0, sizeof(AFSByteRangeLock));
161         lock.Fid = fid;
162         lock.Type = LockWrite;
163         lock.Flags = 0;
164         lock.Owner = 1002;
165         lock.Uniq = 2;
166         lock.Offset = 50;
167         lock.Length = 100;
168         code = rpc_test_afs_set_byterangelock(c2, &lock);
169         printf("%s: c2 set lock returned %d\n", prog, code);
170     }
171
172     /* release lock on c1 */
173     {
174         AFSFid fid = { 536870915, 12, 4016};
175         AFSByteRangeLock lock;
176         memset(&lock, 0, sizeof(AFSByteRangeLock));
177         lock.Fid = fid;
178         lock.Type = LockWrite;
179         lock.Flags = 0;
180         lock.Owner = 1001;
181         lock.Uniq = 1;
182         lock.Offset = 50;
183         lock.Length = 100;
184         code = rpc_test_afs_release_byterangelock(c1, &lock);
185         printf("%s: c1 set lock returned %d\n", prog, code);
186     }
187 #endif /* AFS_BYTE_RANGE_FLOCKS */
188
189     printf("%s: wait %d sec for processing\n", prog, 5);
190     sleep(5);
191
192     code = destroy_fs_channel(c1);
193     code = destroy_fs_channel(c2);
194
195     rpc_test_PkgShutdown();
196
197     printf("%s: finish\n", prog);
198
199     exit (0);
200
201 }        /* main */