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 usefull 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);//#define DEBUG
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 etat_t     {
106                 CLEAN,
107                 RDONLY,
108                 RESULTAT,
109                 WRONLY,
110                 SELECT,
111                 LOCK,
112                 SYNC,
113                 FIN,
114                 READLOCK,
115                 WRITELOCK,
116                 BYTELOCK,
117                 BYTELOCK_READ,
118                 BYTELOCK_WRITE
119 };
120 
121 /* Donnees communes aà tous les processu */
122 /* Public data */
123 struct donneesPub {
124     /* Nombre de clients */
125     /* Number of clients */
126     int nclnt;
127     /* Liste des clients (liste des tubes)*/
128     /* List of master to slave pipes */
129     int **lclnt;
130     /* Tube de communication avec le maitre */
131     /* Slave to master pipe */
132     int maitre[2];
133     /* Liste des threads */
134     /* Thread list */
135     pthread_t *lthreads;
136     /* nom du fichier test */
137     /* test file name */
138     char *fname;
139     /* descripteur du fichier test */
140     /* test file file-descriptor */
141     int fd;
142     /* Affichage des messages d'erreur */
143     /* Detailed error messages */
144     int verbose;
145 };
146 
147 /* Donnees privees aux processus */
148 /* private data */
149 struct donneesPriv {
150     /* Numero de thread. */
151     /* thread number */
152     int whoami;
153 };
154 
155 struct donneesFils{
156     struct donneesPub *dp;
157     struct donneesPriv *dpr;
158 };
159 
160 
161 struct s_test {
162     int test;
163     int type;
164     char *nom;
165     int resAtt;
166 
167 };
168 
169 
170 
171 
172 int configureServeur(int  max);
173 int configureClient(char *s);
174 
175 #endif
176