summaryrefslogblamecommitdiffstats
path: root/private/os2/client/os2que.c
blob: d5f6d8793829621dc417b229299bdfb6016a832e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631






















































































































































































































































































































































































































































































































































































































































                                                                       
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    os2que.c

Abstract:

    This is a test OS/2 application to test the Queue component of OS/2

Author:

    Mark Lucovsky (markl) 10-Jul-1990

Environment:

    User Mode Only

Revision History:

--*/

#define OS2_API32
#define INCL_OS2V20_ERRORS
#define INCL_OS2V20_MEMORY
#define INCL_OS2V20_QUEUES
#define INCL_OS2V20_TASKING
#define INCL_OS2V20_SEMAPHORES
#include <os2.h>

BOOLEAN
Queue1()

{
    APIRET rc;
    HQUEUE Queue1,Queue2,Queue3;
    PID Owner;
    PNT_TIB NtTib;
    PPIB Pib;

    DbgPrint( "*** Queue1 ***\n" );


    rc = DosGetThreadInfo(&NtTib,&Pib);
    ASSERT(rc == NO_ERROR);

    //
    // Good create
    //

    DbgPrint( "(1)\n" );
    rc = DosCreateQueue(&Queue1,QUE_FIFO,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);

    //
    // Create Duplicate
    //

    DbgPrint( "(2)\n" );
    rc = DosCreateQueue(&Queue2,QUE_FIFO,"\\queues\\testq");
    ASSERT(rc == ERROR_QUE_DUPLICATE);

    //
    // invalid prefix
    //

    DbgPrint( "(3)\n" );
    rc = DosCreateQueue(&Queue2,QUE_FIFO,"\\xqueues\\testq");
    ASSERT(rc == ERROR_QUE_INVALID_NAME);

    //
    // invalid priority
    //

    DbgPrint( "(4)\n" );
    rc = DosCreateQueue(&Queue2,4,"\\queues\\xue");
    ASSERT(rc == ERROR_QUE_INVALID_PRIORITY);

    //
    // bad address for queue handle
    //

    DbgPrint( "(5)\n" );
    rc = DosCreateQueue((PHQUEUE)1,QUE_FIFO,"\\queues\\xue");
    ASSERT(rc == ERROR_INVALID_PARAMETER);

    //
    // bad address for queue name
    //

    DbgPrint( "(6)\n" );
    rc = DosCreateQueue(&Queue2,QUE_FIFO,(PSZ) 1);
    ASSERT(rc == ERROR_QUE_INVALID_NAME);

    //
    // open of previous good queue
    //

    DbgPrint( "(7)\n" );
    rc = DosOpenQueue(&Owner,&Queue3,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);
    ASSERT(Queue1 == Queue3);
    ASSERT(Owner == Pib->ProcessId);

    //
    // open of non-existent queue
    //

    DbgPrint( "(8)\n" );
    rc = DosOpenQueue(&Owner,&Queue2,"\\queues\\xx");
    ASSERT(rc == ERROR_QUE_NAME_NOT_EXIST);

    //
    // re-open of good queue
    //

    DbgPrint( "(9)\n" );
    Queue3 = NULL;
    Owner = 0;
    rc = DosOpenQueue(&Owner,&Queue3,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);
    ASSERT(Queue1 == Queue3);
    ASSERT(Owner == Pib->ProcessId);

    //
    // Good close. Should do this 3 times...
    //

    DbgPrint( "(10)\n" );
    rc = DosCloseQueue(Queue3);
    ASSERT(rc == NO_ERROR);
    DbgPrint( "(10a)\n" );
    rc = DosOpenQueue(&Owner,&Queue2,"\\queues\\testq");
    ASSERT(rc == ERROR_QUE_NAME_NOT_EXIST);

    //
    // Close bad handle
    //

    rc = DosCloseQueue((HQUEUE)0x10000);
    ASSERT(rc == ERROR_QUE_INVALID_HANDLE);

    DbgPrint( "*** Exiting Queue1 ***\n" );
    return( TRUE );
}

BOOLEAN
Queue2()

{
    APIRET rc;
    HQUEUE Queue1,Queue2;
    PID Owner;
    ULONG QueryCount;
    PNT_TIB NtTib;
    PPIB Pib;

    DbgPrint( "*** Queue2 ***\n" );


    rc = DosGetThreadInfo(&NtTib,&Pib);
    ASSERT(rc == NO_ERROR);

    //
    // Good create
    //

    DbgPrint( "(1)\n" );
    rc = DosCreateQueue(&Queue1,QUE_FIFO,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);


    //
    // Good Write
    //

    DbgPrint( "(2)\n" );
    rc = DosWriteQueue(Queue1,1,0x00001111,(PVOID)0x11110001,0x0);
    ASSERT(rc == NO_ERROR);

    //
    // Query should be 1
    //

    DbgPrint( "(3)\n" );
    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 1);

    //
    // Good Write
    //

    DbgPrint( "(4)\n" );
    rc = DosWriteQueue(Queue1,1,0x00002222,(PVOID)0x22220001,0x0);
    ASSERT(rc == NO_ERROR);
    rc = DosWriteQueue(Queue1,1,0x00003333,(PVOID)0x33330001,0x0);
    ASSERT(rc == NO_ERROR);

    //
    // Query should be 3
    //

    DbgPrint( "(5)\n" );
    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 3);

    //
    // Purge and then check query. Should be 0
    //

    DbgPrint( "(6)\n" );
    rc = DosPurgeQueue(Queue1);
    ASSERT(rc == NO_ERROR);
    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 0);
    rc = DosCloseQueue(Queue1);
    ASSERT(rc == NO_ERROR);

    DbgPrint( "*** Exiting Queue2 ***\n" );
    return( TRUE );
}

BOOLEAN
Queue3()

{
    APIRET rc;
    HQUEUE Queue1;
    ULONG QueryCount;
    REQUESTDATA RequestInfo;
    ULONG DataLength;
    ULONG Data;
    ULONG ReadPosition;
    BOOL32 NoWait;
    BYTE ElementPriority;

    DbgPrint( "*** Queue3 ***\n" );


    //
    // Good create
    //

    DbgPrint( "(1)\n" );
    rc = DosCreateQueue(&Queue1,QUE_FIFO,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);


    //
    // Good Write
    //

    DbgPrint( "(2)\n" );
    rc = DosWriteQueue(Queue1,1,0x00001111,(PVOID)0x11110001,0x3);
    ASSERT(rc == NO_ERROR);

    //
    // Good Read
    //

    DbgPrint( "(3)\n" );
    rc = DosReadQueue(
            Queue1,
            &RequestInfo,
            &DataLength,
            &Data,
            0,
            DCWW_NOWAIT,
            &ElementPriority,
            NULL
            );
    ASSERT( rc == NO_ERROR );
    ASSERT( DataLength == 0x00001111);
    ASSERT( Data == 0x11110001);
    ASSERT( ElementPriority == 0x0);
    DbgPrint( "(3a)\n" );
    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 0);

    //
    // Good Write
    //

    DbgPrint( "(4)\n" );
    rc = DosWriteQueue(Queue1,1,0x00001111,(PVOID)0x11110001,0x3);
    ASSERT(rc == NO_ERROR);
    rc = DosWriteQueue(Queue1,1,0x00002222,(PVOID)0x22220001,0x4);
    ASSERT(rc == NO_ERROR);
    rc = DosWriteQueue(Queue1,1,0x00003333,(PVOID)0x33330001,0x5);
    ASSERT(rc == NO_ERROR);

    //
    // Good Read using element number
    //

    DbgPrint( "(4a)\n" );
    rc = DosReadQueue(
            Queue1,
            &RequestInfo,
            &DataLength,
            &Data,
            3,
            DCWW_NOWAIT,
            &ElementPriority,
            NULL
            );
    ASSERT( rc == NO_ERROR );
    ASSERT( DataLength == 0x00002222);
    ASSERT( Data == 0x22220001);
    ASSERT( ElementPriority == 0x0);
    DbgPrint( "(4b)\n" );
    rc = DosReadQueue(
            Queue1,
            &RequestInfo,
            &DataLength,
            &Data,
            4,
            DCWW_NOWAIT,
            &ElementPriority,
            NULL
            );
    ASSERT( rc == NO_ERROR );
    ASSERT( DataLength == 0x00003333);
    ASSERT( Data == 0x33330001);
    ASSERT( ElementPriority == 0x0);
    DbgPrint( "(4c)\n" );
    rc = DosReadQueue(
            Queue1,
            &RequestInfo,
            &DataLength,
            &Data,
            2,
            DCWW_NOWAIT,
            &ElementPriority,
            NULL
            );
    ASSERT( rc == NO_ERROR );
    ASSERT( DataLength == 0x00001111);
    ASSERT( Data == 0x11110001);
    ASSERT( ElementPriority == 0x0);

    rc = DosCloseQueue(Queue1);
    ASSERT( rc == NO_ERROR);

    DbgPrint( "*** Exiting Queue3 ***\n" );
    return( TRUE );
}

VOID
Queue4Reader( IN ULONG QueueHandle )
{
    APIRET rc;
    REQUESTDATA RequestInfo;
    ULONG DataLength;
    ULONG Data;
    BYTE ElementPriority;
    PNT_TIB NtTib;
    POS2_TIB Tib;
    PPIB Pib;

    rc = DosGetThreadInfo(&NtTib,&Pib);
    ASSERT(rc == NO_ERROR);
    Tib = (POS2_TIB)NtTib->SubSystemTib;

    DbgPrint( "++Queue4Reader++ %d\n",Tib->ThreadId );
    rc = DosReadQueue(
            (HQUEUE) QueueHandle,
            &RequestInfo,
            &DataLength,
            &Data,
            0,
            DCWW_WAIT,
            &ElementPriority,
            NULL
            );
    ASSERT( rc == NO_ERROR );
    ASSERT( DataLength == 0x00001111);
    ASSERT( Data == (ULONG)(Tib->ThreadId));
    ASSERT( ElementPriority == 0x0);
    DbgPrint( "--Queue4Reader-- %d\n",Tib->ThreadId );
    DosExit( EXIT_THREAD, rc );
}

BOOLEAN
Queue4()

{
    APIRET rc;
    HQUEUE Queue1;
    ULONG QueryCount;
    REQUESTDATA RequestInfo;
    ULONG DataLength;
    ULONG Data;
    ULONG ReadPosition;
    BOOL32 NoWait;
    BYTE ElementPriority;
    TID Tid1,Tid2;

    DbgPrint( "*** Queue4 ***\n" );


    //
    // Good create
    //

    DbgPrint( "(1)\n" );
    rc = DosCreateQueue(&Queue1,QUE_FIFO,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);

    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 0);

    rc = DosCreateThread(&Tid1,Queue4Reader,(ULONG)Queue1,FALSE,1);
    ASSERT( rc == NO_ERROR );

    DosSleep(1000);

    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 0);
NtPartyByNumber(6,1);
    //
    // Good Write
    //

    DbgPrint( "(3)\n" );
    rc = DosWriteQueue(Queue1,1,0x00001111,(PVOID)Tid1,0x3);
    ASSERT(rc == NO_ERROR);
    DbgPrint( "(3a)\n" );
    rc = DosWaitThread(&Tid1,DCWW_WAIT);
    ASSERT( rc == NO_ERROR || rc == ERROR_INVALID_THREADID );
    DbgPrint( "(3b)\n" );

    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 0);

    rc = DosCreateThread(&Tid1,Queue4Reader,(ULONG)Queue1,FALSE,1);
    ASSERT( rc == NO_ERROR );
    rc = DosCreateThread(&Tid2,Queue4Reader,(ULONG)Queue1,FALSE,1);
    ASSERT( rc == NO_ERROR );

    DosSleep(1000);

    //
    // Good Write
    //

    rc = DosQueryQueue(Queue1,&QueryCount);
    ASSERT(rc == NO_ERROR);
    ASSERT(QueryCount == 0);

    DbgPrint( "(4)\n" );
    rc = DosWriteQueue(Queue1,1,0x00001111,(PVOID)Tid1,0x3);
    ASSERT(rc == NO_ERROR);
    rc = DosWriteQueue(Queue1,2,0x00001111,(PVOID)Tid2,0x3);
    ASSERT(rc == NO_ERROR);
    DbgPrint( "(4a)\n" );
    rc = DosWaitThread(&Tid1,DCWW_WAIT);
    ASSERT( rc == NO_ERROR || rc == ERROR_INVALID_THREADID );
    DbgPrint( "(4b)\n" );
    rc = DosWaitThread(&Tid2,DCWW_WAIT);
    ASSERT( rc == NO_ERROR || rc == ERROR_INVALID_THREADID );



    rc = DosCloseQueue(Queue1);
    ASSERT( rc == NO_ERROR);

    DbgPrint( "*** Exiting Queue4 ***\n" );
    return( TRUE );
}


VOID
Queue5Writer( IN ULONG QueueHandle )
{
    APIRET rc;
    REQUESTDATA RequestInfo;
    ULONG DataLength;
    ULONG Data;
    BYTE ElementPriority;
    PNT_TIB NtTib;
    PPIB Pib;
    POS2_TIB Tib;


    rc = DosGetThreadInfo(&NtTib,&Pib);
    ASSERT(rc == NO_ERROR);
    Tib = (POS2_TIB)NtTib->SubSystemTib;

    DbgPrint( "++Queue5Writer++ %d\n",Tib->ThreadId );
    DosSleep(1000);
    rc = DosWriteQueue((HQUEUE)QueueHandle,1,0x00001111,
	(PVOID)Tib->ThreadId,0x3);
    ASSERT(rc == NO_ERROR);
    DbgPrint( "--Queue5Writer-- %d\n",Tib->ThreadId );
    DosExit( EXIT_THREAD, rc );
}

BOOLEAN
Queue5()

{
    APIRET rc;
    HQUEUE Queue1;
    HSEM Sem;
    ULONG QueryCount;
    REQUESTDATA RequestInfo;
    ULONG DataLength;
    ULONG Data;
    ULONG ReadPosition;
    BOOL32 NoWait;
    BYTE ElementPriority;
    TID Tid1,Tid2;

    DbgPrint( "*** Queue5 ***\n" );


    //
    // Good create
    //

    DbgPrint( "(1)\n" );
    rc = DosCreateQueue(&Queue1,QUE_FIFO,"\\queues\\testq");
    ASSERT(rc == NO_ERROR);
    DbgPrint( "(1a)\n" );
    rc = DosCreateEventSem(NULL,&Sem,DC_SEM_SHARED,FALSE);
    ASSERT(rc == NO_ERROR);

    //
    // Create a writer thread
    //

    DbgPrint( "(1b)\n" );
    rc = DosCreateThread(&Tid1,Queue5Writer,(ULONG)Queue1,FALSE,1);
    ASSERT( rc == NO_ERROR );

    //
    // Issue a no wait read with a semaphore handle
    //

    DbgPrint( "(1c)\n" );
    rc = DosReadQueue(
            Queue1,
            &RequestInfo,
            &DataLength,
            &Data,
            0,
            DCWW_NOWAIT,
            &ElementPriority,
            Sem
            );
    ASSERT( rc == ERROR_QUE_EMPTY );

    //
    // Wait on the semaphore and then read again
    //

    DbgPrint( "(1d)\n" );
    rc = DosWaitEventSem(Sem,SEM_INDEFINITE_WAIT);
    ASSERT(rc == NO_ERROR);

    DbgPrint( "(1e)\n" );
    rc = DosReadQueue(
            Queue1,
            &RequestInfo,
            &DataLength,
            &Data,
            0,
            DCWW_WAIT,
            &ElementPriority,
            NULL
            );
    ASSERT(rc == NO_ERROR);
    ASSERT( DataLength == 0x00001111);
    ASSERT( Data == (ULONG)Tid1);
    ASSERT( ElementPriority == 0x0);

    DbgPrint( "(1f)\n" );
    rc = DosWaitThread(&Tid1,DCWW_WAIT);
    ASSERT( rc == NO_ERROR || rc == ERROR_INVALID_THREADID );

    DbgPrint( "*** Exiting Queue5 ***\n" );
    return( TRUE );
}






int
main(
    int argc,
    char *argv[],
    char *envp[]
    )
{

    BOOLEAN ret;

    DbgPrint( "*** Entering OS/2 Queue Test Application\n" );
#ifndef MIPS
NtPartyByNumber(6,8);

    ret = Queue1();
    ASSERT(ret);

    ret = Queue2();
    ASSERT(ret);

    ret = Queue3();
    ASSERT(ret);

    ret = Queue4();
    ASSERT(ret);

    ret = Queue5();
    ASSERT(ret);
#endif // MIPS
    DbgPrint( "*** Exiting OS/2 Queues Test Application\n" );
    return( 0 );
}