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