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