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
|
/*
* SCCS: @(#)service.c 1.3 (96/11/04)
*
* UniSoft Ltd., London, England
*
* (C) Copyright 1996 X/Open Company Limited
*
* All rights reserved. No part of this source code may be reproduced,
* stored in a retrieval system, or transmitted, in any form or by any
* means, electronic, mechanical, photocopying, recording or otherwise,
* except as stated in the end-user licence agreement, without the prior
* permission of the copyright owners.
* A copy of the end-user licence agreement is contained in the file
* Licence which accompanies this distribution.
*
* X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
* the UK and other countries.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/************************************************************************
SCCS: @(#)service.c 1.3 96/11/04 TETware release 3.3
NAME: service.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: August 1996
DESCRIPTION:
the tcc execution engine
MODIFICATIONS:
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include "dtmac.h"
#include "error.h"
#include "proctab.h"
#include "scentab.h"
#include "dirtab.h"
#include "tcc.h"
#include "tet_api.h"
#ifndef NOTRACE
#include "ltoa.h"
#endif
/* static function declarations */
static void proc_directive PROTOLIST((struct proctab *));
static void proc_n2 PROTOLIST((struct proctab *));
static void proc_next PROTOLIST((struct proctab *));
static void proc_process PROTOLIST((struct proctab *));
static void proc_sceninfo PROTOLIST((struct proctab *));
static void proc_wait PROTOLIST((struct proctab *));
static void tcc_service PROTOLIST((struct proctab *));
static void wakeup PROTOLIST((struct proctab *));
/*
** tcc_sloop() - TCC service loop
**
** service all entries in the run queue which need attention
*/
int tcc_sloop()
{
register struct proctab *prp, *rqforw;
register int done;
int status = TET_EXIT_SUCCESS;
TRACE1(tet_Texec, 2, "tcc_sloop() START");
do {
TRACE1(tet_Texec, 2, "tcc_sloop() RESTART");
exec_block_signals();
done = 1;
for (prp = runq; prp; prp = rqforw) {
rqforw = prp->pr_rqforw;
if (prp->pr_flags & PRF_ATTENTION) {
prp->pr_flags &= ~PRF_ATTENTION;
tcc_service(prp);
status = tet_addstatus(status,
prp->pr_jnlstatus);
done = 0;
}
}
exec_unblock_signals();
} while (!done);
TRACE1(tet_Texec, 2, "tcc_sloop() END");
return status;
}
/*
** tcc_timeouts() - set the ATTENTION flag in each proctab on the runq
** whose timeout has expired
**
** return the number of proctabs which need attention
*/
int tcc_timeouts(now)
time_t now;
{
register int count = 0;
register struct proctab *prp;
TRACE1(tet_Texec, 2, "tcc_timeouts() START");
/*
** look down the runq and set the attention flag on proctabs whose
** timeouts have expired
*/
for (prp = runq; prp; prp = prp->pr_rqforw)
if (prp->pr_nextattn > 0)
if (prp->pr_nextattn <= now) {
prp->pr_nextattn = 0;
prp->pr_flags |= PRF_ATTENTION;
count++;
}
TRACE2(tet_Texec, 2, "tcc_timeouts() RETURN; count = %s",
tet_i2a(count));
return(count);
}
/*
** tcc_service() - service a single entry in the run queue
** whose ATTENTION flag is set
*/
static void tcc_service(prp)
struct proctab *prp;
{
TRACE4(tet_Texec, 3, "tcc_service(%s): state = %s, flags = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags));
/* process the entry according to its state */
switch (prp->pr_state) {
case PRS_PROCESS:
proc_process(prp);
break;
case PRS_NEXT:
proc_next(prp);
break;
case PRS_SLEEP:
wakeup(prp);
break;
case PRS_WAIT:
proc_wait(prp);
break;
default:
/* this "can't happen" */
fatal(0, "unexpected state", prpstate(prp->pr_state));
/* NOTREACHED */
}
TRACE4(tet_Texec, 3, "tcc_service(%s) RETURN: state = %s, flags = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags));
}
/*
** proc_process() - process an entry on the run queue
** whose state is PRS_PROCESS
*/
static void proc_process(prp)
struct proctab *prp;
{
register struct scentab *ep = prp->pr_scen;
TRACE5(tet_Texec, 4,
"proc_process(%s): state = %s, flags = %s, currmode = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags),
prtccmode(prp->pr_currmode));
ASSERT(ep->sc_magic == SC_MAGIC);
/* process the element */
switch (ep->sc_type) {
case SC_DIRECTIVE:
proc_directive(prp);
break;
case SC_TESTCASE:
proc_testcase(prp);
break;
case SC_SCENINFO:
proc_sceninfo(prp);
break;
default:
/* this "can't happen" */
fatal(0, "unexpected type", prsctype(ep->sc_type));
/* NOTREACHED */
}
TRACE4(tet_Texec, 4, "proc_process(%s) RETURN: state = %s, flags = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags));
}
/*
** proc_directive() - process a directive on the run queue
** whose state is PRS_PROCESS
*/
static void proc_directive(prp)
register struct proctab *prp;
{
register struct scentab *ep = prp->pr_scen;
TRACE3(tet_Texec, 4, "proc_directive(%s): directive = %s",
tet_i2x(prp), prscdir(ep->sc_directive));
/* report a directive start */
if (prp->pr_currmode == TCC_START)
switch (ep->sc_directive) {
case SD_PARALLEL:
jnl_par_start(prp);
break;
case SD_SEQUENTIAL:
jnl_seq_start(prp);
break;
case SD_REPEAT:
jnl_rpt_start(prp);
break;
case SD_TIMED_LOOP:
jnl_tloop_start(prp);
break;
case SD_RANDOM:
jnl_rnd_start(prp);
break;
case SD_VARIABLE:
jnl_var_start(prp);
break;
#ifndef TET_LITE /* -START-LITE-CUT- */
case SD_REMOTE:
jnl_rmt_start(prp);
break;
case SD_DISTRIBUTED:
jnl_dist_start(prp);
break;
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
default:
/* this "can't happen" */
fatal(0, "unexpected directive",
prscdir(ep->sc_directive));
/* NOTREACHED */
}
/* move on to the next scenario element if there are no elements
below this one */
if (ep->sc_child)
ASSERT(ep->sc_child->sc_magic == SC_MAGIC);
else {
TRACE1(tet_Texec, 4,
"proc_directive(): empty directive RETURN");
prp->pr_state = PRS_NEXT;
prp->pr_flags |= PRF_ATTENTION;
return;
}
/* otherwise, process the directive */
switch (ep->sc_directive) {
case SD_PARALLEL:
proc_parallel(prp);
break;
case SD_SEQUENTIAL:
proc_sequential(prp);
break;
case SD_REPEAT:
case SD_TIMED_LOOP:
proc_rtloop(prp);
break;
case SD_RANDOM:
proc_random(prp);
break;
case SD_VARIABLE:
proc_variable(prp);
break;
#ifndef TET_LITE /* -START-LITE-CUT- */
case SD_REMOTE:
case SD_DISTRIBUTED:
proc_rdist(prp);
break;
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
default:
/* this "can't happen" */
fatal(0, "unexpected directive", prscdir(ep->sc_directive));
/* NOTREACHED */
}
TRACE3(tet_Texec, 4, "proc_directive(%s) RETURN: directive = %s",
tet_i2x(prp), prscdir(ep->sc_directive));
}
/*
** proc_sceninfo() - process a scenario line on the run queue
** whose state is PRS_PROCESS
*/
static void proc_sceninfo(prp)
register struct proctab *prp;
{
TRACE2(tet_Texec, 4, "proc_sceninfo(%s)", tet_i2x(prp));
/* output the line to the journal file */
jnl_sceninfo(prp, prp->pr_scen->sc_sceninfo);
/* move on to the next scenario element */
prp->pr_state = PRS_NEXT;
prp->pr_flags |= PRF_ATTENTION;
TRACE2(tet_Texec, 4, "proc_sceninfo(%s) RETURN", tet_i2x(prp));
}
/*
** proc_wait() - process an entry on the run queue whose state
** is PRS_WAIT
*/
static void proc_wait(prp)
struct proctab *prp;
{
register struct scentab *ep = prp->pr_scen;
TRACE5(tet_Texec, 4,
"proc_wait(%s): state = %s, flags = %s, currmode = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags),
prtccmode(prp->pr_currmode));
ASSERT(ep->sc_magic == SC_MAGIC);
/* process the element */
switch (ep->sc_type) {
case SC_TESTCASE:
proc_tcwait(prp);
break;
default:
/* this "can't happen" */
fatal(0, "unexpected type", prsctype(ep->sc_type));
/* NOTREACHED */
}
TRACE4(tet_Texec, 4, "proc_wait(%s) RETURN: state = %s, flags = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags));
}
/*
** proc_next() - step on to the next action when state is PRS_NEXT
*/
static void proc_next(prp)
struct proctab *prp;
{
#ifndef NOTRACE
register struct scentab *ep = prp->pr_scen;
TRACE5(tet_Texec, 4,
"proc_next(%s): prflags = %s, scentype = %s, currmode = %s",
tet_i2x(prp), prpflags(prp->pr_flags), prsctype(ep->sc_type),
prtccmode(prp->pr_currmode));
switch (ep->sc_type) {
case SC_DIRECTIVE:
TRACE2(tet_Texec, 4, "\tdirective = %s",
prscdir(ep->sc_directive));
break;
case SC_TESTCASE:
TRACE3(tet_Texec, 4, "\ttcname = %s, tcstate = %s",
ep->sc_tcname, prtcstate(prp->pr_tcstate));
break;
}
#endif
proc_n2(prp);
#ifndef NOTRACE
ep = prp->pr_scen;
TRACE5(tet_Texec, 4, "proc_next(%s) RETURN: prflags = %s, scentype = %s, currmode = %s",
tet_i2x(prp), prpflags(prp->pr_flags), prsctype(ep->sc_type),
prtccmode(prp->pr_currmode));
switch (ep->sc_type) {
case SC_DIRECTIVE:
TRACE2(tet_Texec, 4, "\tdirective = %s",
prscdir(ep->sc_directive));
break;
case SC_TESTCASE:
TRACE3(tet_Texec, 4, "\ttcname = %s, tcstate = %s",
ep->sc_tcname, prtcstate(prp->pr_tcstate));
break;
}
#endif
}
/*
** proc_n2() - extend the proc_next() processing
*/
static void proc_n2(prp)
register struct proctab *prp;
{
register struct scentab *ep = prp->pr_scen;
/*
** determine whether we must re-visit the current element
** or move on to the next element
*/
switch (ep->sc_type) {
case SC_DIRECTIVE:
switch (ep->sc_directive) {
case SD_PARALLEL:
case SD_REPEAT:
case SD_TIMED_LOOP:
if (prp->pr_currmode != TCC_END) {
prp->pr_state = PRS_PROCESS;
prp->pr_flags |= PRF_ATTENTION;
return;
}
break;
case SD_VARIABLE:
/* XXX restore previous configurations here */
break;
}
break;
case SC_TESTCASE:
if (prp->pr_currmode != TCC_END) {
prp->pr_state = PRS_PROCESS;
prp->pr_flags |= PRF_ATTENTION;
return;
}
break;
case SC_SCENINFO:
break;
default:
fatal(0, "unexpected type", prsctype(prp->pr_scen->sc_type));
/* NOTREACHED */
}
/*
** here to stop processing the current scenario element -
** free any child proctabs
*/
prcfree(prp);
/* make a directive 'end' entry in the journal */
if (ep->sc_type == SC_DIRECTIVE)
switch (ep->sc_directive) {
case SD_PARALLEL:
jnl_par_end(prp);
break;
case SD_SEQUENTIAL:
jnl_seq_end(prp);
break;
case SD_REPEAT:
jnl_rpt_end(prp);
break;
case SD_TIMED_LOOP:
jnl_tloop_end(prp);
break;
case SD_RANDOM:
jnl_rnd_end(prp);
break;
case SD_VARIABLE:
jnl_var_end(prp);
break;
#ifndef TET_LITE /* -START-LITE-CUT- */
case SD_REMOTE:
jnl_rmt_end(prp);
break;
case SD_DISTRIBUTED:
jnl_dist_end(prp);
break;
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
default:
/* this "can't happen" */
fatal(0, "unexpected directive",
prscdir(ep->sc_directive));
/* NOTREACHED */
}
/* free the per-proctab alternate scenario tree if there is one */
if (prp->pr_altscen) {
register struct scentab *ep2, *child;
TRACE1(tet_Texec, 8,
"proc_n2(): freeing the alternate scenario tree");
for (ep2 = prp->pr_altscen; ep2; ep2 = child) {
child = ep2->sc_child;
scfree(ep2);
}
prp->pr_altscen = (struct scentab *) 0;
}
/*
** if
** abort has not been called
** and
** we are not single-stepping
** and
** there is another scenario element at this level:
** move on to the next scenario element;
** otherwise, come off the run queue and wake up the parent
*/
if (
(tcc_modes & TCC_ABORT) == 0 &&
(prp->pr_flags & PRF_STEP) == 0 &&
ep->sc_forw
) {
prp->pr_scen = ep->sc_forw;
prp->pr_exiclist = (char *) 0;
prp->pr_numtc = 0;
prp->pr_starttime = time((time_t *) 0);
prp->pr_tcstate = TCS_START;
prp->pr_currmode = TCC_START;
prp->pr_activity = -1;
prp->pr_modes &= ~TCC_ABORT;
prp->pr_state = PRS_PROCESS;
prp->pr_flags |= PRF_ATTENTION;
}
else {
prp->pr_state = PRS_IDLE;
runqrm(prp);
wakeup(prp->pr_parent);
}
}
/*
** wakeup() - see if any child proctab elements are still on the
** run queue
**
** if none of the child proctabs are still on the run queue,
** move on to the next stage of processing
*/
static void wakeup(prp)
struct proctab *prp;
{
register struct proctab *child;
TRACE5(tet_Texec, 4, "wakeup(%s): child = %s, state = %s, flags = %s",
tet_i2x(prp), tet_i2x(prp ? prp->pr_child : 0),
prp ? prpstate(prp->pr_state) : "0",
prpflags(prp ? prp->pr_flags : 0));
if (prp)
ASSERT(prp->pr_magic == PR_MAGIC);
else
return;
/* see of any of the child proctabs are on the run queue */
for (child = prp->pr_child; child; child = child->pr_lforw) {
ASSERT(child->pr_magic == PR_MAGIC);
if (child->pr_flags & PRF_RUNQ)
break;
}
/* if there aren't, arrange to move on to the next processing stage */
if (!child) {
prp->pr_state = PRS_NEXT;
prp->pr_flags |= PRF_ATTENTION;
}
TRACE4(tet_Texec, 4, "wakeup(%s) RETURN: state = %s, flags = %s",
tet_i2x(prp), prpstate(prp->pr_state), prpflags(prp->pr_flags));
}
/*
** nextmode() - return the next processing mode, given a set of modes
** of operation and the current mode
*/
int nextmode(modes, currmode)
register int modes, currmode;
{
if (modes & TCC_ABORT)
return(TCC_END);
switch (currmode) {
case TCC_START:
if (modes & TCC_BUILD)
return(TCC_BUILD);
/* else fall through */
case TCC_BUILD:
if (modes & TCC_EXEC)
return(TCC_EXEC);
/* else fall through */
case TCC_EXEC:
if (modes & TCC_CLEAN)
return(TCC_CLEAN);
/* else fall through */
case TCC_CLEAN:
return(TCC_END);
default:
/* this "can't happen" */
fatal(0, "unexpected mode", prtccmode(currmode));
/* NOTREACHED */
}
}
|