• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* *************************************************
2  * *********** README ******************************
3  * *************************************************
4  *
5  * COMPILE : make
6  * RUN : ./locktests -n <number of concurent process> -f <test file> [-P]
7  *
8  * GOAL : This test tries to stress the fcntl locking functions.  A
9  * master process sets a lock on a file region (this is called "byte
10  * range locking").  Some slave processes try to perform operations on
11  * this region, such as read, write, set a new lock ... The expected
12  * results of these operations are known.  If the operation's result is
13  * the same as the expected one, the test suceeds, else it fails.
14  *
15  * Slaves are either concurent processes or threads.
16  * -n <num>  : Number of threads to use (mandatory).
17  * -f <file> : Run the test on a test file defined by the -f option (mandatory).
18  * -T        : Use threads instead of processes (optional).
19  *
20  * HISTORY : This program has been written to stress NFSv4 locks. -P
21  * option was created to verify NFSv4 locking was thread-aware, and so,
22  * locking behaviour over NFSv4 was POSIX correct both using threads and
23  * process. This option may not be useful to stress.
24  *
25  * EXAMPLE : ./locktests -n 50 -f /file/system/to/test
26  *
27  *
28  * Vincent ROQUETA 2005 - vincent.roqueta@ext.bull.net
29  * BULL S.A.
30  */
31 
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdlib.h>
36 #include <signal.h>
37 #include <string.h>
38 #include <unistd.h>
39 #include <fcntl.h>
40 #include <errno.h>
41 #include <math.h>
42 #ifdef STDARG
43 #include <stdarg.h>
44 #endif
45 #include <sys/types.h>
46 #include <sys/wait.h>
47 #include <sys/param.h>
48 #include <sys/times.h>
49 #ifdef MMAP
50 #include <sys/mman.h>
51 #endif
52 #include <inttypes.h>
53 #include <pthread.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
56 #include <sys/select.h>
57 
58 #ifdef O_SYNC
59 #define OPENFLAGS       (O_CREAT | O_RDWR | O_SYNC )
60 #else
61 #define OPENFLAGS       (O_CREAT | O_RDWR )
62 #endif
63 #define OPENMODES       (0600)
64 #define MANDMODES       (0600)
65 /*(02666)*/
66 
67 #define SUCCES 1
68 #define ECHEC  0
69 
70 #define TRUE 1
71 #define FALSE 0
72 
73 #define PROCESS 0
74 #define THREAD 1
75 
76 
77 //#define DEBUG
78 #ifdef DEBUG
79         #define E(a)  perror(a)
80         #define P(a,b) printf(a,b)
81 #else
82         #define E(a)
83         #define P(a,b)
84 #endif
85 
86 
87 
88 #ifndef LOCKTESTS_H
89 #define LOCKTESTS_H
90 
91 #define M_SIZE 512
92 
93 int writeToAllClients(char *foo);
94 
95 int serverReceiveNet();
96 int clientReceiveNet();
97 int serverReceiveClient(int n);
98 int setupClients(int type, char *fname, int nThread);
99 int serverCloseConnection();
100 int getConfiguration(int *type, char *fname, int *nThread);
101 int readFromServer(char *message);
102 int serverSendClient(int n);
103 
104 
105 enum state_t     {
106                 CLEAN,
107                 RDONLY,
108                 RESULT,
109                 WRONLY,
110                 SELECT,
111                 LOCK,
112                 SYNC,
113                 END,
114                 READLOCK,
115                 WRITELOCK,
116                 BYTELOCK,
117                 BYTELOCK_READ,
118                 BYTELOCK_WRITE
119 };
120 
121 /* Public data */
122 struct dataPub {
123     /* Number of clients */
124     int nclnt;
125     /* List of master to slave pipes */
126     int **lclnt;
127     /* Slave to master pipe */
128     int master[2];
129     /* Thread list */
130     pthread_t *lthreads;
131     /* test file name */
132     char *fname;
133     /* test file file-descriptor */
134     int fd;
135     /* Detailed error messages */
136     int verbose;
137 };
138 
139 /* private data */
140 struct dataPriv {
141     /* thread number */
142     int whoami;
143 };
144 
145 struct dataChild{
146     struct dataPub *dp;
147     struct dataPriv *dpr;
148 };
149 
150 
151 struct s_test {
152     int test;
153     int type;
154     char *nom;
155     int resAtt;
156 
157 };
158 
159 
160 
161 
162 int configureServer(int  max);
163 int configureClient(char *s);
164 
165 #endif
166