static void si_procrun()
{
	extern struct ptab *tet_ptab;
	register struct ptab *pp;
	register int done;

	TRACE2(tet_Tloop, 8, "si_procrun START: tet_ptab = %s",
		tet_i2x(tet_ptab));

	do {
		TRACE2(tet_Tloop, 8, "si_procrun RESTART: tet_ptab = %s",
			tet_i2x(tet_ptab));
		done = 1;
		for (pp = tet_ptab; pp; pp = pp->pt_next) {
			TRACE3(tet_Tloop, 8, "pp = %s, next = %s",
				tet_i2x(pp), tet_i2x(pp->pt_next));
			ASSERT(pp->pt_magic == PT_MAGIC);
			if (pp->pt_flags & PF_ATTENTION) {
				pp->pt_flags &= ~PF_ATTENTION;
				tet_si_service(pp);
				done = 0;
				break;
			}
		}
	} while (!done);

	TRACE2(tet_Tloop, 8, "si_procrun END: tet_ptab = %s",
		tet_i2x(tet_ptab));

	/* call the server-specific end-procrun routine */
	tet_ss_procrun();
}
Exemple #2
0
static void rescode_distribute()
{
	register int sysid, sysmax;
	FILE *fp;
	char line[LBUFLEN];
	char **lines = (char **) 0;
	int llines = 0, nlines = 0;
	register char *p, **lp;
	register struct systab *sp;
	int rc = 0;

	TRACE1(tet_Ttcc, 4, "rescode_distribute()");

	/* open the master results code file */
	if ((fp = fopen(rcftmp, "r")) == (FILE *) 0)
		fatal(errno, "can't open", rcftmp);

	/* read in all the lines */
	while (fgets(line, sizeof line, fp) != (char *) 0) {
		for (p = line; *p; p++)
			if (*p == '\n') {
				*p = '\0';
				break;
			}
		RBUFCHK((char **) &lines, &llines, (int) ((nlines + 1) * sizeof *lines));
		*(lines + nlines++) = rstrstore(line);
	}

	(void) fclose(fp);

	/* distribute the lines to each remote system */
	for (sysid = 1, sysmax = symax(); sysid <= sysmax; sysid++)
		if ((sp = syfind(sysid)) != (struct systab *) 0 &&
			rdist2(sp, lines, nlines) < 0)
				rc = -1;

	/* free storage allocated here */
	for (lp = lines; lp < lines + nlines; lp++) {
		TRACE2(tet_Tbuf, 6, "free rescode line = %s", tet_i2x(*lp));
		free(*lp);
		*lp = (char *) 0;
	}
	TRACE2(tet_Tbuf, 6, "free rescode list = %s", tet_i2x(lines));
	free((char *) lines);

	if (rc < 0)
		tcc_exit(1);
}
Exemple #3
0
TET_IMPORT struct ptab *tet_ptalloc()
{
	register struct ptab *pp;

	/* allocate transport-independent data area */
	errno = 0;
	if ((pp = (struct ptab *) malloc(sizeof *pp)) == (struct ptab *) 0) {
		error(errno, "can't malloc ptab entry", (char *) 0);
		return((struct ptab *) 0);
	}
	TRACE2(tet_Tbuf, 6, "allocate ptab = %s", tet_i2x(pp));
	bzero((char *) pp, sizeof *pp);

	/* call the routine to allocate transport-specific data */
	if (tet_ts_ptalloc(pp) < 0) {
		tet_ptfree(pp);
		return((struct ptab *) 0);
	}

	/* call the routine to allocate server-specific data space */
	if (tet_ss_ptalloc(pp) < 0) {
		tet_ptfree(pp);
		return((struct ptab *) 0);
	}

	/* initialise variables */
	pp->pt_next = pp->pt_last = (struct ptab *) 0;
	pp->pt_magic = PT_MAGIC;
	pp->ptr_sysid = -1;
	pp->ptr_pid = -1L;
	pp->ptr_ptype = PT_NOPROC;
	pp->pt_state = PS_IDLE;

	return(pp);
}
void tet_si_serverloop()
{
	register struct ptab *pp;
	register time_t timeout;
	register int delay, rc;
	extern struct ptab *tet_ptab;

	/* see how long it is to the next timeout */
	timeout = INFINITY;
	for (pp = tet_ptab; pp; pp = pp->pt_next) {
		ASSERT(pp->pt_magic == PT_MAGIC);
		if (pp->pt_timeout && pp->pt_timeout < timeout)
			timeout = pp->pt_timeout;
	}
	if (timeout == INFINITY)
		delay = tet_ptab ? LONGDELAY : SHORTDELAY;
	else if ((delay = (int) (timeout - time((time_t *) 0))) < 0 ||
		delay > LONGDELAY)
			delay = LONGDELAY;

	TRACE3(tet_Tloop, 2,
		"tet_si_serverloop TOP: tet_ptab = %s, poll timeout = %s",
		tet_i2x(tet_ptab), tet_i2a(delay));

#ifndef NOTRACE
	if (tet_Tloop) {
		TRACE2(tet_Tloop, 10, "process table:%s",
			tet_ptab ? "" : " empty");
		for (pp = tet_ptab; pp; pp = pp->pt_next)
			TRACE6(tet_Tloop, 10,
		"pp = %s, next = %s, proc = %s, state = %s, flags = %s",
				tet_i2x(pp), tet_i2x(pp->pt_next),
				tet_r2a(&pp->pt_rid),
				tet_ptstate(pp->pt_state),
				tet_ptflags(pp->pt_flags));
	}
#endif

	/* perform the main loop */
	if ((rc = tet_ts_poll(tet_ptab, delay)) > 0)
		si_procrun();
	else if (rc < 0)
		exit(1);
	if (si_timeouts() > 0)
		si_procrun();
}
Exemple #5
0
struct rtab *tet_rtalloc()
{
    register struct rtab *rp;
    static int remoteid;

    errno = 0;
    if ((rp = (struct rtab *) malloc(sizeof *rp)) == (struct rtab *) 0) {
        error(errno, "can't allocate rtab element", (char *) 0);
        return((struct rtab *) 0);
    }
    TRACE2(tet_Tbuf, 6, "allocate rtab element = %s", tet_i2x(rp));
    bzero((char *) rp, sizeof *rp);

    rp->rt_sysid = -1;
    rp->rt_pid = -1L;
    rp->rt_magic = RT_MAGIC;
    rp->rt_remoteid = ++remoteid;

    return(rp);
}
struct xtab *xtalloc()
{
	register struct xtab *xp;
	static long xrid;

	/* allocate a new XRES ID */
	if (++xrid < 0L) {
		error(0, "too many XRES IDs", (char *) 0);
		return((struct xtab *) 0);
	}

	/* allocate memory for the xtab element and fill it in */
	errno = 0;
	if ((xp = (struct xtab *) malloc(sizeof *xp)) == (struct xtab *) 0) {
		error(errno, "can't allocate xtab element", (char *) 0);
		return((struct xtab *) 0);
	}
	TRACE2(tet_Tbuf, 6, "allocate xtab = %s", tet_i2x(xp));
	bzero((char *) xp, sizeof *xp);

	xp->xt_xrid = xrid;

	return(xp);
}
Exemple #7
0
int proc2sclist()
{
	struct scentab *sctmp;
	register struct scentab *ep;
	struct scentab *q;
	register int skip;

	/*
	** sclist is a LIFO stack -
	** it is in reverse order so we must invert it
	*/
	TRACE1(tet_Tscen, 1, "proc2sclist(): inverting the element list");
	sctmp = (struct scentab *) 0;
	while ((ep = scpop(&sclist)) != (struct scentab *) 0)
		scpush(ep, &sctmp);
	sclist = sctmp;

	/* build the tree */
	TRACE1(tet_Tscen, 1, "proc2sclist(): building the scenario tree");
	skip = 0;
	while ((ep = scpop(&sclist)) != (struct scentab *) 0) {
		if (skip) {
			if (ep->sc_type == SC_SCENARIO)
				skip = 0;
			else
				continue;
		}
		ASSERT(ep->sc_type == SC_SCENARIO);
		if (find2scen(ep->sc_scenario)) {
			scenerror(ep->sc_scenario, "is multiply defined",
				ep->sc_lineno, ep->sc_fname);
			skip = 1;
			continue;
		}
		if (!sctree)
			sctree = ep;
		else { 
			ASSERT(sctmp);
			sctmp->sc_forw = ep; 
			ep->sc_back = sctmp; 
		} 
		sctmp = ep ; 
		if (proc2scen(sctmp) < 0) 
			return(-1);
	}
	if (scenerrors)
		return(0);

	/*
	**	now, perform various checks and manipulations on the tree
	*/

	/* check for valid scenario names in the top row of the tree */
	TRACE1(tet_Tscen, 1, "proc2sclist(): checking scenario names");
	for (ep = sctree; ep; ep = ep->sc_forw) {
		ASSERT(ep->sc_magic == SC_MAGIC);
		ASSERT(ep->sc_type == SC_SCENARIO);
		check_valid_scen_name(ep);
	}
	if (scenerrors)
		return(0);

	/*
	** traverse the tree:
	**	check for valid test case names
	**	check for duplicate sysids in SD_REMOTE and SD_DISTRIBUTED
	*/
	TRACE1(tet_Tscen, 1,
		"proc2sclist(): checking test case names and sysids");
	for (ep = sctree; ep; ep = ep->sc_forw)
		check_tc_sys(ep->sc_child);
	if (scenerrors)
		return(0);

	/*
	** traverse the tree, resolving referenced scenario names
	** and checking for scenario reference loops
	**
	** each time we pass through a scenario header it is pushed on to
	** the stack at sctmp
	**
	** initially, the stack only contains the header for the scenario
	** that we are checking
	**
	** each time we encounter a referenced scenario name we look
	** back up the stack to see if we have been there before -
	** if we have we report a loop, otherwise we push the curent
	** header on to the stack and continue down the referenced scenario
	** tree
	**
	** the stack is unwound as we come back up the tree
	*/
	TRACE1(tet_Tscen, 1,
		"proc2sclist(): resolving referenced scenario names");
	for (ep = sctree; ep; ep = ep->sc_forw)
		ep->sc_flags &= ~SCF_PROCESSED;
	sctmp = (struct scentab *) 0;
	for (ep = sctree; ep; ep = ep->sc_forw) {
		if (ep->sc_flags & SCF_PROCESSED)
			continue;
		TRACE3(tet_Tscen, 4, "resolve loop TOP: descend tree below scenario %s at %s",
			ep->sc_scenario, tet_i2x(ep));
		scpush(ep, &sctmp);
		resolv_scenptr(ep->sc_child, &sctmp);
		q = scpop(&sctmp);
		ASSERT(q == ep);
		q = scpop(&sctmp);
		ASSERT(q == (struct scentab *) 0);
		ep->sc_flags |= SCF_PROCESSED;
	}
	if (scenerrors)
		return(0);

	/* traverse the tree, fixing up PARALLEL directives in etet mode */
	if (tet_compat != COMPAT_DTET) {
		TRACE1(tet_Tscen, 1,
			"proc2sclist(): fixing up etet-parallel directives");
		for (ep = sctree; ep; ep = ep->sc_forw) {
			TRACE3(tet_Tscen, 4, "etet fix loop TOP: descend tree below scenario %s at %s",
				ep->sc_scenario, tet_i2x(ep));
			etet_fix(ep->sc_child);
		}
		if (scenerrors)
			return(0);
	}

	/*
	** traverse the tree, checking for violations of the
	** directive nesting rules
	**
	** each time we pass through a directive it is pushed on to
	** the stack at sctmp
	**
	** initially the stack is empty
	**
	** each time we find a directive we check to see if the current
	** directive is valid within each of the enclosing directives
	** which are on the stack, then the current directive is pushed
	** on to the stack and we continue down the tree below the
	** current directive
	**
	** the stack is unwound as we come back up the tree
	*/
	TRACE1(tet_Tscen, 1, "proc2sclist(): checking directive nesting rules");
	for (ep = sctree; ep; ep = ep->sc_forw)
		ep->sc_flags &= ~SCF_PROCESSED;
	sctmp = (struct scentab *) 0;
	for (ep = sctree; ep; ep = ep->sc_forw) {
		if (ep->sc_flags & SCF_PROCESSED)
			continue;
		TRACE3(tet_Tscen, 4, "nesting loop TOP: descend tree below scenario %s at %s",
			ep->sc_scenario, tet_i2x(ep));
		check_nesting(ep->sc_child, &sctmp);
		q = scpop(&sctmp);
		ASSERT(q == (struct scentab *) 0);
		ep->sc_flags |= SCF_PROCESSED;
	}
	if (scenerrors)
		return(0);

	/*
	** traverse the tree, checking for empty timed_loops -
	** we do this check otherwise we could use up a LOT of cpu
	** time later
	*/
	TRACE1(tet_Tscen, 1, "proc2sclist(): checking for empty timed loops");
	for (ep = sctree; ep; ep = ep->sc_forw)
		ep->sc_flags &= ~SCF_PROCESSED;
	for (ep = sctree; ep; ep = ep->sc_forw) {
		if (ep->sc_flags & SCF_PROCESSED)
			continue;
		TRACE3(tet_Tscen, 4, "tloop check loop TOP: descend tree below scenario %s at %s",
			ep->sc_scenario, tet_i2x(ep));
		(void) check_timed_loops(ep->sc_child);
	}
	if (scenerrors)
		return(0);

	return(0);
}
TET_IMPORT void tet_config()
{
	FILE *fp;
	char *file;
	int err;
	char buf[1024];
	register char *p;
	char **vp;
	int lcount;
	static char fmt[] = "ignored bad format configuration variable assignment at line %d in file %.*s";
	char msg[MAXPATH + LNUMSZ + sizeof fmt];

	/* determine the config file name from the environment */
	file = getenv("TET_CONFIG");
	if (file == NULL || *file == '\0')
		return;

	/* open the file */
	if ((fp = fopen(file, "r")) == (FILE *) 0) {
		err = errno;
		sprintf(msg, "could not open config file \"%.*s\"",
			MAXPATH, file);
		tet_error(err, msg);
		return;
	}

	/* free any existing allocated string storage */
	if (nvarptrs > 0)
		for (vp = varptrs; vp < varptrs + nvarptrs; vp++)
			if (*vp) {
				TRACE2(tet_Tbuf, 6, "free *vp = %s",
					tet_i2x(*vp));
				free(*vp);
			}

	lcount = nvarptrs = 0;
	while (fgets(buf, sizeof buf, fp) != (char *) 0) {
		lcount++;
		for (p = buf; *p; p++)
			if (*p == '\r' || *p == '\n' || *p == '#') {
				*p = '\0';
				break;
			}
		while (--p >= buf)
			if (isspace(*p))
				*p = '\0';
			else
				break;
		if (p < buf)
			continue;
		if (!tet_equindex(buf)) {
			sprintf(msg, fmt, lcount, MAXPATH, file);
			tet_error(0, msg);
			continue;
		}
		if (BUFCHK((char **) &varptrs, &lvarptrs,
			   (nvarptrs + 2) * (int) sizeof *varptrs) < 0)
			break;
		if ((p = tet_strstore(buf)) == (char *) 0)
			break;
		*(varptrs + nvarptrs++) = p;
		*(varptrs + nvarptrs) = (char *) 0;
	}

	/* finally, close the file and return */
	fclose(fp);
}