summaryrefslogtreecommitdiff
path: root/src/tet3/tcc/proctcd.c
blob: b517c35298e141fde94fdc2b8d4b6104e856c577 (plain)
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
/*
 *	SCCS: @(#)proctcd.c	1.7 (97/07/21)
 *
 *	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

#ifndef lint
static char sccsid[] = "@(#)proctcd.c	1.7 (97/07/21) TET3 release 3.3";
#endif

/************************************************************************

SCCS:   	@(#)proctcd.c	1.7 97/07/21 TETware release 3.3
NAME:		proctcd.c
PRODUCT:	TETware
AUTHOR:		Andrew Dingwall, UniSoft Ltd.
DATE CREATED:	August 1996

DESCRIPTION:
	testcase processing support functions called from proctc.c

MODIFICATIONS:

************************************************************************/

#ifndef TET_LITE	/* -START-LITE-CUT- */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#  include <unistd.h>
#include "dtmac.h"
#include "error.h"
#include "ltoa.h"
#include "servlib.h"
#include "tet3_config.h"
#include "scentab.h"
#include "proctab.h"
#include "systab.h"
#include "tcc.h"

#ifdef NEEDsrcFile
static char srcFile[] = __FILE__;	/* file name for error reporting */
#endif

/* static function declarations */
static int conf1tccd PROTOLIST((struct proctab *, int, int));
static void rm_snid PROTOLIST((struct proctab *));


/*
**	get_snid_xrid() - get a snid and an xrid for this proctab
**
**	return 0 if successful or -1 on error
*/

int get_snid_xrid(prp)
register struct proctab *prp;
{
	char *fname;

	TRACE2(tet_Ttcc, 6, "get_snid_xrid(%s)", tet_i2x(prp));

	/* get a sync ID from SYNCD */
	if ((prp->pr_snid = tet_sdsnget()) < 0L) {
		prperror(prp, -1, tet_sderrno, "can't get sync ID", (char *) 0);
		return(-1);
	}

	/* assign the system name list to it */
	if (tet_sdsnsys(prp->pr_snid, prp->pr_sys, prp->pr_nsys) < 0) {
		prperror(prp, -1, tet_sderrno,
			"can't send system list to SYNCD", (char *) 0);
		rm_snid(prp);
		return(-1);
	}

	/* generate a unique xres file name */
	if ((fname = jnl_tfname(resdirname(), "xr")) == (char *) 0) {
		rm_snid(prp);
		return(-1);
	}

	/* tell XRESD to open the file */
	if ((prp->pr_xrid = tet_xdxropen(fname)) < 0L) {
		prperror(prp, -1, tet_xderrno, "XRESD can't open", fname);
		rm_snid(prp);
		return(-1);
	}

	/* assign the system list to the xres file */
	if (tet_xdxrsys(prp->pr_xrid, prp->pr_sys, prp->pr_nsys) < 0) {
		prperror(prp, -1, tet_xderrno,
			"can't send system list to XRESD", (char *) 0);
		rm_snid_xrid(prp);
		(void) UNLINK(fname);
		return(-1);
	}

	/* all OK so store the xres file name and return */
	prp->pr_xfname = rstrstore(fname);
	TRACE5(tet_Ttcc, 6, "get_snid_xrid(%s) successful RETURN: snid = %s, xrid = %s, xfname = %s",
		tet_i2x(prp), tet_l2a(prp->pr_snid), tet_l2a(prp->pr_xrid),
		prp->pr_xfname);
	return(0);
}

/*
**	rm_snid_xrid() - remove a sync ID, close an XRES file
*/

void rm_snid_xrid(prp)
register struct proctab *prp;
{
	/* remove the sync ID */
	rm_snid(prp);

	/* close the XRES file */
	if (prp->pr_xrid > 0L && tet_xdxrclose(prp->pr_xrid) < 0)
		prperror(prp, -1, tet_xderrno, "tet_xdxrclose() failed on",
			prp->pr_xfname);
	prp->pr_xrid = -1L;
}

/*
**	rm_snid() - remove a sync ID
*/

static void rm_snid(prp)
register struct proctab *prp;
{
	if (prp->pr_snid > 0L && tet_sdsnrm(prp->pr_snid) < 0)
		prperror(prp, -1, tet_sderrno,
			"tet_sdsnrm() failed for sync ID",
			tet_l2a(prp->pr_snid));
	prp->pr_snid = -1L;
}

/*
**	setup_child_proctabs() - allocate a set of child proctabs for use
**		when processing a remote or distributed test case which
**		is to run on more than one system
**
**	note that these child proctabs never go on the runq
*/

void setup_child_proctabs(prp)
register struct proctab *prp;
{
	register struct proctab *child;
	register int *ip;
	struct proctab *lback = (struct proctab *) 0;

	ASSERT(prp->pr_nsys > 1);

	for (ip = prp->pr_sys; ip < prp->pr_sys + prp->pr_nsys; ip++) {
		child = pralloc();
		child->pr_parent = prp;
		child->pr_scen = prp->pr_scen;
		child->pr_exiclist = prp->pr_exiclist;
		child->pr_context = prp->pr_context;
		child->pr_sys = ip;
		child->pr_nsys = 1;
		if (lback)
			lback->pr_lforw = child;
		else
			prp->pr_child = child;
		lback = child;
		child->pr_flags |= PRF_TC_CHILD;
	}
}

/*
**	run_child_proctabs() - invoke the named function on each of
**		the child protcabs in turn
**
**	return 0 if successful or -1 if at least one function failed
*/

int run_child_proctabs(prp, func)
register struct proctab *prp;
int (*func) PROTOLIST((struct proctab *));
{
	register struct proctab *child;
	register int rc = 0;

	ASSERT(prp->pr_magic == PR_MAGIC);
	ASSERT((prp->pr_flags & PRF_TC_CHILD) == 0);

	for (child = prp->pr_child; child; child = child->pr_lforw) {
		ASSERT(child->pr_magic == PR_MAGIC);
		child->pr_tcstate = prp->pr_tcstate;
		child->pr_currmode = prp->pr_currmode;
		if ((*func)(child) < 0)
			rc = -1;
	}

	return(rc);
}

/*
**	child_proctabs_tstate() - return the number of this proctab's
**		children whose toolstate is in the specified state
*/

int child_proctabs_tstate(prp, state)
struct proctab *prp;
register int state;
{
	register struct proctab *child;
	register int count = 0;

	for (child = prp->pr_child; child; child = child->pr_lforw) {
		ASSERT(child->pr_magic == PR_MAGIC);
		if (child->pr_toolstate == state)
			count++;
	}

	return(count);
}

/*
**	unlink_xres() - unlink the xres file if nexessary
*/

void unlink_xres(prp)
struct proctab *prp;
{
	if (prp->pr_xfname) {
		(void) UNLINK(prp->pr_xfname);
		TRACE2(tet_Tbuf, 6, "free prp->pr_xfname = %s",
			tet_i2x(prp->pr_xfname));
		free(prp->pr_xfname);
		prp->pr_xfname = (char *) 0;
	}
}

/*
**	configure_tccd() - configure all the TCCDs for the current
**		mode of operation
**
**	return 0 if successful or -1 on error
*/

int configure_tccd(prp)
register struct proctab *prp;
{
	register int *ip;

	for (ip = prp->pr_sys; ip < prp->pr_sys + prp->pr_nsys; ip++)
		if (conf1tccd(prp, *ip, prp->pr_currmode) < 0)
			return(-1);

	return(0);
}

/*
**	conf1tccd() - configure a single TCCDs for a particular mode
**		of operation
**
**	return 0 if successful or -1 on error
*/

static int conf1tccd(prp, sysid, opmode)
struct proctab *prp;
int sysid, opmode;
{
	register struct systab *sp;
	register int cfmode, tc_cfmode;
	struct cflist *lp;

	/*
	** determine the config mode and TCCD config mode from the
	** current mode of operation
	*/
	cfmode = tcc2cfmode(opmode);
	switch (opmode) {
	case TCC_BUILD:
		tc_cfmode = TC_CONF_BUILD;
		break;
	case TCC_EXEC:
		tc_cfmode = TC_CONF_EXEC;
		break;
	case TCC_CLEAN:
		tc_cfmode = TC_CONF_CLEAN;
		break;
	default:
		/* this "can't happen" */
		fatal(0, "unexpected mode", prtccmode(opmode));
		/* NOTREACHED */
	}

	/* find the systab entry for this system */
	sp = syfind(sysid);
	ASSERT(sp);

	/*
	** configure the TCCD for the required mode if we haven't already
	** done so
	*/
	if ((sp->sy_cfmodes & opmode) == 0) {
		lp = &CFLIST(sp, cfmode);
		if (tet_tcconfigv(sysid, lp->cf_conf, lp->cf_nconf, tc_cfmode) < 0) {
			prperror(prp, sysid, tet_tcerrno,
				"can't assign config lines to TCCD for mode",
				tet_i2a(cfmode));
			return(-1);
		}
		sp->sy_cfmodes |= opmode;
		sp->sy_currcfmode = -1;
	}

	/* set TCCD's current configuration mode if necessary */
	if (sp->sy_currcfmode != tc_cfmode) {
		if (tet_tcsetconf(sysid, tc_cfmode) < 0) {
			prperror(prp, sysid, tet_tcerrno,
				"can't set TCCD config mode", (char *) 0);
			return(-1);
		}
		sp->sy_currcfmode = tc_cfmode;
	}

	/* all OK so return success */
	return(0);
}

#else	/* -END-LITE-CUT- */

int tet_proctcd_c_not_used;

#endif /* !TET_LITE */	/* -LITE-CUT-LINE- */