~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to test/os/atestosx.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1995-2005 European Southern Observatory (ESO)
 
3
 
 
4
  This program is free software; you can redistribute it and/or 
 
5
  modify it under the terms of the GNU General Public License as 
 
6
  published by the Free Software Foundation; either version 2 of 
 
7
  the License, or (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public 
 
15
  License along with this program; if not, write to the Free 
 
16
  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, 
 
17
  MA 02139, USA.
 
18
 
 
19
  Correspondence concerning ESO-MIDAS should be addressed as follows:
 
20
        Internet e-mail: midas@eso.org
 
21
        Postal address: European Southern Observatory
 
22
                        Data Management Division 
 
23
                        Karl-Schwarzschild-Strasse 2
 
24
                        D 85748 Garching bei Muenchen 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
.TYPE        Module
 
30
.NAME        atestosx.c
 
31
.LANGUAGE    C
 
32
.AUTHOR      Carlos Guirao. IPG-ESO Garching
 
33
.CATEGORY    Tests of host operating system interfaces. 
 
34
.COMMENTS    Automatic osx test. 
 
35
             This test exercises the functions of the module "osx".
 
36
        
 
37
.REMARKS     A hanged condition has been detected for this test. It happens
 
38
             when a procces is waiting for data to come from a socket, and
 
39
             the connection is already stablished with a sender. If the
 
40
             sender, for any reason, denies the data, the procces will hang
 
41
             forever (or CTRL-C). SIGALRM does not work for this porpose
 
42
             because the system call "read" ignores it when there is a 
 
43
             stablished connection.
 
44
.ENVIRONment UNIX
 
45
 
 
46
.VERSION 1.1 05-Jul-1990   Implementation     C. Guirao
 
47
051021          last modif
 
48
 
 
49
------------------------------------------------------------*/
 
50
 
 
51
#include <stdio.h>
 
52
#include <errno.h>
 
53
#include <signal.h>
 
54
#include <fcntl.h>
 
55
#include <sys/types.h>
 
56
#include <sys/stat.h>
 
57
#include <osparms.h>
 
58
 
 
59
#ifndef S_IFSOCK                /* defined in stat.h if Unix domain sockets */
 
60
  static char socket_name[] = "00";     /* for PC/SCO without local sockets */
 
61
# define OSX_OPEN_MODE NETW
 
62
#else
 
63
  static char socket_name[] = "/tmp/mtape";
 
64
# define OSX_OPEN_MODE LOCAL
 
65
#endif
 
66
 
 
67
#define LOWER 0
 
68
#define UPPER 1
 
69
 
 
70
#define PATTERNA '0'
 
71
#define PATTERNB 'a'
 
72
#define PATTERNC 'B'
 
73
#define PATTERND 'b'
 
74
 
 
75
char *osmsg();
 
76
 
 
77
#define PERROR { printf("\tERROR: %s\n",osmsg()); ospexit(1); }
 
78
#define PRINTF(string) { fflush(stdout); printf(string); fflush(stdout); sleep(1); }
 
79
 
 
80
#define SIZEBUF 1024
 
81
char *buf;
 
82
int sizebuf;
 
83
 
 
84
void timeout(k)
 
85
int  k;
 
86
{
 
87
        printf("(TIMEOUT)\n");
 
88
        exit(-1);
 
89
}
 
90
 
 
91
static int readn(fd, ptr, nbytes) 
 
92
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
93
.PURPOSE Read "n" bytest from a descriptor. Use in place of 
 
94
         read() when fd is a stream socket
 
95
.RETURNS If succesful, the number of bytes actaully read is 
 
96
         returned. Otherwise, a -1 is returned.
 
97
.REMARKS System dependencies:
 
98
 -- UNIX: read(2)
 
99
------------------------------------------------------------*/
 
100
register int fd;
 
101
register char *ptr;
 
102
register int nbytes;
 
103
{
 
104
        int nleft, nread;
 
105
        int st;
 
106
        
 
107
        nleft = nbytes;
 
108
        while (nleft > 0) {
 
109
                /*
 
110
                if ( (st = osxinfo(fd,0,0)) == -1) PERROR
 
111
                if (st == NODATA) break;
 
112
                */
 
113
                nread = osxread(fd, ptr, nleft);
 
114
                if (nread < 0)          /* error, return < 0 */
 
115
                        return(nread);
 
116
                
 
117
                nleft -= nread;
 
118
                ptr += nread;
 
119
        }
 
120
        return(nbytes - nleft);         /* return >= 0 */
 
121
}
 
122
 
 
123
 
 
124
main(argc,argv)
 
125
int argc;
 
126
int **argv;
 
127
{
 
128
 
 
129
        char input[80], name[80], *pname;
 
130
        int fdn, fd;
 
131
        int nbytes;
 
132
        static char *channame[2];
 
133
        static struct stat statbuf;
 
134
        int childpid;
 
135
        int st;
 
136
 
 
137
        channame[1]="localhost";
 
138
        signal(SIGALRM,timeout);
 
139
 
 
140
        printf("**********************************************\n");
 
141
        printf("****** AUTOMATIC TEST FOR OSX INTERFACE ******\n");
 
142
        printf("****** LOCAL MODE. USING SOCKETS.       ******\n");
 
143
        printf("**********************************************\n\n");
 
144
 
 
145
        printf("Deleting socket files: %s if existing... ", 
 
146
                socket_name);
 
147
        if (stat(socket_name,&statbuf) == 0 )
 
148
                if (unlink(socket_name) < 0)  PERROR
 
149
        PRINTF("OK\n");
 
150
 
 
151
        sizebuf=SIZEBUF;
 
152
        printf("Allocating memory for buffers...");
 
153
        if ( (buf = (char *)malloc((size_t)(sizebuf+1))) == (char *)0)  PERROR
 
154
        else    printf("OK\n");
 
155
 
 
156
        /* First step: open & close mode*/
 
157
        printf("\n************** Testing open & close\n");
 
158
 
 
159
        printf("Opening a normal file.... ");
 
160
        if ( (fdn = open(socket_name,O_CREAT,S_IREAD|S_IWRITE)) < 0) PERROR
 
161
        else    PRINTF("OK\n");
 
162
 
 
163
        printf("Opening a socket in READ mode, over a normal file.... ");
 
164
        channame[0]=socket_name;
 
165
        if ( (fd = osxopen(channame,LOCAL|IPC_READ)) != -1) {
 
166
                printf("ERROR: Return code != -1\n");
 
167
                osxclose(fd);
 
168
                ospexit(1);
 
169
                }
 
170
        else    PRINTF("OK\n");
 
171
 
 
172
        printf("Opening a socket in WRITE mode, over a normal file.... ");
 
173
        channame[0]=socket_name;
 
174
        if ( (fd = osxopen(channame,LOCAL|IPC_WRITE)) != -1) {
 
175
                printf("ERROR: Return code != -1\n");
 
176
                osxclose(fd);
 
177
                ospexit(1);
 
178
                }
 
179
        else    PRINTF("OK\n");
 
180
 
 
181
        printf("Closing and unlinking the normal file.... ");
 
182
        if ( close(fdn) < 0) PERROR 
 
183
        if (unlink(socket_name) < 0) PERROR
 
184
        PRINTF("OK\n");
 
185
 
 
186
        printf("\nOpening a socket in READ mode.... ");
 
187
        channame[0]=socket_name;
 
188
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
 
189
        else    PRINTF("OK\n");
 
190
 
 
191
        printf("Reading status from socket.... ");
 
192
        if ( (st = osxinfo(fd,0,0)) == -1) PERROR
 
193
        if (st == NOCONN) { PRINTF("OK\n"); }
 
194
        else printf("ERROR: Return code != %d\n",NOCONN);
 
195
 
 
196
        printf("Closing the socket in READ mode.... ");
 
197
        if ( osxclose(fd) == -1) PERROR
 
198
        else    PRINTF("OK\n");
 
199
 
 
200
        printf("\nTrying to open a socket in WRITE mode.... ");
 
201
        channame[0]=socket_name;
 
202
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) != -1) {
 
203
                printf("ERROR: Return code != -1\n");
 
204
                osxclose(fd);
 
205
                ospexit(1);
 
206
                }
 
207
        else    PRINTF("OK\n");
 
208
 
 
209
        printf("\nOpening a socket (once).... ");
 
210
        channame[0]=socket_name;
 
211
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
 
212
        else    PRINTF("OK\n");
 
213
 
 
214
        /* PC/SCO with NETW socket returns -1 Address already in use 
 
215
        printf("Trying to open the same socket mode (twice).... ");
 
216
        channame[0]=socket_name;
 
217
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
 
218
        else    PRINTF("OK\n");
 
219
        */
 
220
 
 
221
        printf("Closing the socket (once).... ");
 
222
        if ( osxclose(fd) == -1) PERROR
 
223
        else    PRINTF("OK\n");
 
224
 
 
225
        printf("Trying to close the same socket (twice).... ");
 
226
        if ( osxclose(fd) != -1) {
 
227
                PRINTF("ERROR: Return code != -1\n");
 
228
                ospexit(1);
 
229
                }
 
230
        else    PRINTF("OK\n");
 
231
 
 
232
        printf("\nOpening a socket in READ mode.... ");
 
233
        channame[0]=socket_name;
 
234
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) PERROR
 
235
        else    PRINTF("OK\n");
 
236
 
 
237
        printf("Trying to read something... ");
 
238
        fflush(stdout);
 
239
        alarm(5);
 
240
        if ( osxread(fd,buf,1) != -1) {
 
241
                PRINTF("ERROR: Return code != -1\n");
 
242
                ospexit(1);
 
243
                }
 
244
        else    PRINTF("OK\n");
 
245
        alarm(0);
 
246
 
 
247
        printf("Trying to write something... ");
 
248
        if ( osxwrite(fd,buf,1) != -1) {
 
249
                PRINTF("ERROR: Return code != -1n");
 
250
                ospexit(1);
 
251
                }
 
252
        else    PRINTF("OK\n");
 
253
 
 
254
        printf("Closing the socket in READ mode.... ");
 
255
        if ( osxclose(fd) == -1) PERROR
 
256
        else    PRINTF("OK\n");
 
257
        
 
258
        printf("\nDoing a fork for server & client \n");
 
259
        
 
260
        if ( (childpid = fork()) < 0) PERROR
 
261
        else if (childpid == 0) {
 
262
                child_task();
 
263
                ospexit(0);
 
264
                }
 
265
 
 
266
        father_task();
 
267
        printf("**********************************************\n");
 
268
        printf("****** END OF AUTOMATIC TEST FOR OSX    ******\n");
 
269
        printf("****** LOCAL MODE. USING SOCKETS.       ******\n");
 
270
        printf("**********************************************\n\n");
 
271
}
 
272
 
 
273
father_task()
 
274
{
 
275
        int fd;
 
276
        int nbytes;
 
277
        char *channame[2];
 
278
 
 
279
        /* This is the father procces */
 
280
        printf("I am the father.\n");
 
281
        channame[0]=socket_name;
 
282
        channame[1]="localhost";
 
283
 
 
284
        printf("\n************** Using client ---> server transfer\n");
 
285
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_READ)) == -1) {
 
286
                printf("Open socket in read mode... FAILED.\n");
 
287
                PERROR
 
288
                }
 
289
        else    printf("Open socket in read mode... OK\n");
 
290
 
 
291
        PRINTF("Waiting connection from client\n");
 
292
        alarm(10);
 
293
        while( osxinfo(fd,0,0) == NOCONN ) ;
 
294
        PRINTF("Connection from client... OK\n");
 
295
        alarm(0);
 
296
 
 
297
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNA,LOWER)) != SIZEBUF) {
 
298
                PRINTF("Reading pattern A in socket... FAILED.\n");
 
299
                if (nbytes != -1) 
 
300
                        printf("\tError: Only %d bytes read !!!\n",nbytes);
 
301
                ospexit(1);
 
302
                }
 
303
        else    PRINTF("Reading pattern A in socket... OK\n");
 
304
 
 
305
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNB,LOWER)) != SIZEBUF) {
 
306
                PRINTF("Reading pattern B in socket... FAILED.\n");
 
307
                if (nbytes != -1) 
 
308
                        printf("\tError: Only %d bytes read !!!\n",nbytes);
 
309
                ospexit(1);
 
310
                }
 
311
        else    PRINTF("Reading pattern B in socket... OK\n");
 
312
 
 
313
        if ( (nbytes=testread(fd,buf,SIZEBUF/2,PATTERNC,LOWER)) != SIZEBUF/2) {
 
314
                PRINTF("Reading (1/2) pattern C in socket... FAILED.\n");
 
315
                if (nbytes != -1)
 
316
                        printf("\tError: Only %d bytes read !!!\n",nbytes);
 
317
                ospexit(1);
 
318
                }
 
319
        else    PRINTF("Reading pattern C (1/2) in socket... OK\n");
 
320
 
 
321
        if ( (nbytes=testread(fd,buf,SIZEBUF/2,PATTERNC,LOWER)) != SIZEBUF/2) {
 
322
                PRINTF("Reading (2/2) pattern C in socket... FAILED.\n");
 
323
                if (nbytes != -1)
 
324
                        printf("\tError: Only %d bytes read !!!\n",nbytes);
 
325
                ospexit(1);
 
326
                }
 
327
        else    PRINTF("Reading pattern C (2/2) in socket... OK\n");
 
328
 
 
329
        if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNA,LOWER)) != SIZEBUF) {
 
330
                printf("Writting pattern A in socket... FAILED.\n");
 
331
                if (nbytes != -1)
 
332
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
333
                ospexit(1);
 
334
                }
 
335
        else    printf("Writting pattern A in socket... OK\n");
 
336
 
 
337
        alarm(10);
 
338
        if ( (nbytes = osxread(fd,buf,SIZEBUF)) != 0) {
 
339
                PRINTF("Reading EOF in socket... FAILED.\n");
 
340
                if (nbytes != -1)
 
341
                        printf("%d bytes read !!!\n",nbytes);
 
342
                else    PERROR
 
343
                ospexit(1);
 
344
                }
 
345
        else    PRINTF("Reading EOF in socket... OK\n");
 
346
        alarm(0);
 
347
 
 
348
        printf("\n************** Using server ---> client transfer\n");
 
349
 
 
350
        PRINTF("Waiting connection from client\n");
 
351
        alarm(10);
 
352
        while( osxinfo(fd,0,0) == NOCONN ) ;
 
353
        PRINTF("Connection from client... OK\n");
 
354
        alarm(0);
 
355
 
 
356
        if ((nbytes=testwrite(fd,buf,SIZEBUF/2,PATTERNA,LOWER)) != SIZEBUF/2) {
 
357
                printf("Writting pattern A (1/2) in socket... FAILED.\n");
 
358
                if (nbytes != -1)
 
359
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
360
                ospexit(1);
 
361
                }
 
362
        else    printf("Writting pattern A (1/2) in socket... OK\n");
 
363
 
 
364
        if ((nbytes=testwrite(fd,buf,SIZEBUF/2,PATTERNA,LOWER)) != SIZEBUF/2) {
 
365
                printf("Writting pattern A (2/2) in socket... FAILED.\n");
 
366
                if (nbytes != -1)
 
367
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
368
                ospexit(1);
 
369
                }
 
370
        else    printf("Writting pattern A (2/2) in socket... OK\n");
 
371
 
 
372
        if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNB,LOWER)) != SIZEBUF) {
 
373
                printf("Writting pattern B in socket... FAILED.\n");
 
374
                if (nbytes != -1)
 
375
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
376
                ospexit(1);
 
377
                }
 
378
        else    printf("Writting pattern B in socket... OK\n");
 
379
 
 
380
        if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNC,LOWER)) != SIZEBUF) {
 
381
                printf("Writting pattern C in socket... FAILED.\n");
 
382
                if (nbytes != -1)
 
383
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
384
                ospexit(1);
 
385
                }
 
386
        else    printf("Writting pattern C in socket... OK\n");
 
387
 
 
388
        alarm(10);
 
389
        if ( (nbytes = osxread(fd,buf,SIZEBUF)) != 0) {
 
390
                PRINTF("Reading EOF in socket... FAILED.\n");
 
391
                if (nbytes != -1)
 
392
                        printf("%d bytes read !!!\n",nbytes);
 
393
                else    PERROR
 
394
                ospexit(1);
 
395
                }
 
396
        else    PRINTF("Reading EOF in socket... OK\n");
 
397
        alarm(0);
 
398
 
 
399
        printf("\n************** Using server <--> client transfer\n");
 
400
        
 
401
        PRINTF("Waiting connection from client\n");
 
402
        alarm(10);
 
403
        while (osxinfo(fd,0,0) == NOCONN) ;
 
404
        PRINTF("Connection from client... OK\n");
 
405
        alarm(0);
 
406
 
 
407
        if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
 
408
                printf("Writting pattern B in socket... FAILED.\n");
 
409
                if (nbytes != -1) 
 
410
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
411
                ospexit(1);
 
412
                }
 
413
        else    printf("Writting pattern B in socket... OK\n");
 
414
 
 
415
        if ( (nbytes=testread(fd,buf,SIZEBUF,PATTERNC,LOWER)) != SIZEBUF) {
 
416
                PRINTF("Reading pattern C in socket... FAILED.\n");
 
417
                if (nbytes != -1)
 
418
                        printf("\tError: Only %d bytes read !!!\n",nbytes);
 
419
                ospexit(1);
 
420
                }
 
421
        else    PRINTF("Reading pattern C in socket... OK\n");
 
422
 
 
423
        if ( (nbytes=testread(fd,buf,SIZEBUF,PATTERNA,LOWER)) != SIZEBUF) {
 
424
                PRINTF("Reading pattern A in socket... FAILED.\n");
 
425
                if (nbytes != -1)
 
426
                        printf("\tError: Only %d bytes read !!!\n",nbytes);
 
427
                ospexit(1);
 
428
                }
 
429
        else    PRINTF("Reading pattern A in socket... OK\n");
 
430
 
 
431
        if ((nbytes=testwrite(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
 
432
                printf("Writting pattern C in socket... FAILED.\n");
 
433
                if (nbytes != -1) 
 
434
                        printf("\tError: only %d bytes written!!!\n",nbytes);
 
435
                ospexit(1);
 
436
                }
 
437
        else    printf("Writting pattern C in socket... OK\n");
 
438
 
 
439
        alarm(10);
 
440
        if ( (nbytes = osxread(fd,buf,SIZEBUF)) != 0) {
 
441
                PRINTF("Reading EOF in socket... FAILED.\n");
 
442
                if (nbytes != -1)
 
443
                        printf("%d bytes read !!!\n",nbytes);
 
444
                else    PERROR
 
445
                ospexit(1);
 
446
                }
 
447
        else    PRINTF("Reading EOF in socket... OK\n");
 
448
        alarm(0);
 
449
 
 
450
        if ( osxclose(fd) == -1) {
 
451
                printf("Closing socket write mode... FAILED.\n");
 
452
                PERROR
 
453
                }
 
454
        printf("Closing socket write mode... OK\n\n");
 
455
        sleep(2);
 
456
 
 
457
        /* Wait for child to finish */
 
458
        printf("****** Waiting for child proccess to die\n");
 
459
        wait(0);
 
460
        printf("****** End of father proccess\n");
 
461
}
 
462
 
 
463
child_task()
 
464
{
 
465
        int fd;
 
466
        int nbytes;
 
467
        char *channame[2];
 
468
 
 
469
        printf("I AM THE CHILD.\n");
 
470
        channame[0]=socket_name;
 
471
        channame[1]="localhost";
 
472
 
 
473
        alarm(10);
 
474
        while ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) ;
 
475
        alarm(0);
 
476
        printf("OPEN SOCKET IN WRITE MODE... OK\n");
 
477
 
 
478
        if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
 
479
                printf("WRITTING PATTERN A IN SOCKET... FAILED.\n");
 
480
                if (nbytes != -1)
 
481
                        printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
 
482
                ospexit(1);
 
483
        }
 
484
        else    printf("WRITTING PATTERN A IN SOCKET... OK\n");
 
485
        
 
486
        if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
 
487
                printf("WRITTING PATTERN B IN SOCKET... FAILED.\n");
 
488
                if (nbytes != -1) 
 
489
                        printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
 
490
                ospexit(1);
 
491
        }
 
492
        else    printf("WRITTING PATTERN B IN SOCKET... OK\n");
 
493
 
 
494
        if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
 
495
                printf("WRITTING PATTERN C IN SOCKET... FAILED.\n");
 
496
                if (nbytes != -1) 
 
497
                        printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
 
498
                ospexit(1);
 
499
                }
 
500
        else    printf("WRITTING PATTERN C IN SOCKET... OK\n");
 
501
 
 
502
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
 
503
                PRINTF("READING PATTERN A IN SOCKET... FAILED.\n");
 
504
                if (nbytes != -1) 
 
505
                        printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
 
506
                ospexit(1);
 
507
                }
 
508
        else    PRINTF("READING PATTERN A IN SOCKET... OK\n");
 
509
 
 
510
        if ( osxclose(fd) == -1) {
 
511
                printf("CLOSING THE SOCKET WRITE MODE ... FAILED.\n");
 
512
                PERROR
 
513
                }
 
514
        printf("CLOSING THE SOCKET WRITE MODE... OK\n");
 
515
 
 
516
        alarm(10);
 
517
        while ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) ;
 
518
        printf("OPEN SOCKET IN WRITE MODE... OK\n");
 
519
        alarm(0);
 
520
 
 
521
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
 
522
                PRINTF("READING PATTERN A IN SOCKET... FAILED.\n");
 
523
                if (nbytes != -1) 
 
524
                        printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
 
525
                ospexit(1);
 
526
                }
 
527
        else    PRINTF("READING PATTERN A IN SOCKET... OK\n");
 
528
 
 
529
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
 
530
                PRINTF("READING PATTERN B IN SOCKET... FAILED.\n");
 
531
                if (nbytes != -1) 
 
532
                        printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
 
533
                ospexit(1);
 
534
                }
 
535
        else    PRINTF("READING PATTERN B IN SOCKET... OK\n");
 
536
 
 
537
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
 
538
                PRINTF("READING PATTERN C IN SOCKET... FAILED.\n");
 
539
                if (nbytes != -1) 
 
540
                        printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
 
541
                ospexit(1);
 
542
                }
 
543
        else    PRINTF("READING PATTERN C IN SOCKET... OK\n");
 
544
 
 
545
        if ( osxclose(fd) == -1) {
 
546
                printf("CLOSING THE SOCKET WRITE MODE ... FAILED.\n");
 
547
                PERROR
 
548
                }
 
549
        printf("CLOSING THE SOCKET WRITE MODE... OK\n");
 
550
 
 
551
        /*
 
552
        alarm(10);
 
553
        PRINTF("WAITING DISCONNECTION FROM SERVER... ");
 
554
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) PERROR
 
555
        while( osxread(fd,buf,1) != -1 ) ;
 
556
        PRINTF("OK\n");
 
557
        alarm(0);
 
558
        */
 
559
 
 
560
        sleep(2);
 
561
        if ( (fd = osxopen(channame,OSX_OPEN_MODE|IPC_WRITE)) == -1) {
 
562
                printf("OPEN SOCKET IN WRITE MODE...  FAILED.\n");
 
563
                PERROR
 
564
                }
 
565
        else    printf("OPEN SOCKET 0 IN WRITE MODE... OK\n");
 
566
 
 
567
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNB,UPPER)) != SIZEBUF) {
 
568
                PRINTF("READING PATTERN B IN SOCKET... FAILED.\n");
 
569
                if (nbytes != -1) 
 
570
                        printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
 
571
                ospexit(1);
 
572
                }
 
573
        else    PRINTF("READING PATTERN B IN SOCKET... OK\n");
 
574
 
 
575
 
 
576
        if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
 
577
                printf("WRITTING PATTERN C IN SOCKET... FAILED.\n");
 
578
                if (nbytes != -1) 
 
579
                        printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
 
580
                ospexit(1);
 
581
                }
 
582
        else    printf("WRITTING PATTERN C IN SOCKET... OK\n");
 
583
 
 
584
        if ( (nbytes = testwrite(fd,buf,SIZEBUF,PATTERNA,UPPER)) != SIZEBUF) {
 
585
                printf("WRITTING PATTERN A IN SOCKET... FAILED.\n");
 
586
                if (nbytes != -1) 
 
587
                        printf("\tERROR: ONLY %d BYTES WRITTEN!!!\n",nbytes);
 
588
                ospexit(1);
 
589
                }
 
590
        else    printf("WRITTING PATTERN A IN SOCKET... OK\n");
 
591
 
 
592
        if ( (nbytes = testread(fd,buf,SIZEBUF,PATTERNC,UPPER)) != SIZEBUF) {
 
593
                PRINTF("READING PATTERN C IN SOCKET... FAILED.\n");
 
594
                if (nbytes != -1) 
 
595
                        printf("\tERROR: ONLY %d BYTES READ !!!\n",nbytes);
 
596
                ospexit(1);
 
597
                }
 
598
        else    PRINTF("READING PATTERN C IN SOCKET... OK\n");
 
599
 
 
600
        if ( osxclose(fd) == -1) {
 
601
                printf("CLOSING THE SOCKET WRITE MODE ... FAILED.\n");
 
602
                PERROR
 
603
                }
 
604
        printf("CLOSING THE SOCKET WRITE MODE... OK\n");
 
605
 
 
606
        sleep(2);
 
607
        printf("****** END OF CHILD PROCCESS\n");
 
608
}
 
609
 
 
610
 
 
611
testread(fd,buffer,size,pattern,type)
 
612
int fd;
 
613
char *buffer;
 
614
int size;
 
615
char pattern;
 
616
int type;
 
617
{
 
618
        int i, j, nbytes;
 
619
        for(i=0; i<size; i++) buffer[i] = 0;
 
620
 
 
621
        if ( (nbytes = readn(fd,buffer,size)) < 0) {    
 
622
                if (type == UPPER)
 
623
                        printf("\tERROR READING A BUFFER: %s\n",osmsg());
 
624
                else    printf("\tError reading a buffer: %s\n",osmsg());
 
625
                return(-1);
 
626
                }
 
627
        else    {
 
628
                for(i=0; i<nbytes; i++) {
 
629
                if ( buf[i] != pattern ) {
 
630
                        if (type == UPPER)
 
631
                                printf("\tPATTERN MISTMATCH: READ[%d]='%c'; EXPECTED '%c'\n", i, buf[i], pattern);
 
632
                        else
 
633
                                printf("\tPattern mistmatch: read[%d]='%c'; expected '%c'\n", i, buf[i], pattern);
 
634
                        return(-1);
 
635
                        }
 
636
                }
 
637
        }
 
638
        return(nbytes);
 
639
}
 
640
 
 
641
testwrite(fd,buffer,size,pattern,type)
 
642
int fd;
 
643
char *buffer;
 
644
int size;
 
645
char pattern;
 
646
int type;
 
647
{
 
648
        int i, j, nbytes;
 
649
        for(i=0; i<size; i++) buffer[i] = pattern;
 
650
 
 
651
        if ( (nbytes = osxwrite(fd,buffer,size)) != size) {     
 
652
                if (type == UPPER)
 
653
                        printf("\tERROR WRITTING A BUFFER: %s\n",osmsg());
 
654
                else    printf("\tError writting a buffer: %s\n",osmsg());
 
655
                return(-1);
 
656
                }
 
657
        return(nbytes);
 
658
}