xref: /inferno-os/appl/lib/itslib.b (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1implement Itslib;
2
3include "sys.m";
4	sys: Sys;
5include "itslib.m";
6include "env.m";
7	env: Env;
8
9
10init(): ref Tconfig
11{
12	sys = load Sys Sys->PATH;
13	tc := ref Tconfig(-1, sys->fildes(2));
14	env = load Env Env->PATH;
15	if (env == nil)
16		sys->fprint(sys->fildes(2), "Failed to load %s\n", Env->PATH);
17	else {
18		vstr := env->getenv(ENV_VERBOSITY);
19		mstr := env->getenv(ENV_MFD);
20		if (vstr != nil && mstr != nil) {
21			tc.verbosity = int vstr;
22			tc.mfd = sys->fildes(int mstr);
23		}
24	}
25	if (tc.verbosity >= 0)
26		tc.report(S_STIME, 0, sys->sprint("%d", sys->millisec()));
27	else
28		sys->fprint(sys->fildes(2), "Test is running standalone\n");
29	return tc;
30}
31
32Tconfig.report(tc: self ref Tconfig, sev: int, verb: int, msg: string)
33{
34	if (sev < 0 || sev > S_ETIME) {
35		sys->fprint(sys->fildes(2), "Tconfig.report: Bad severity code: %d\n", sev);
36		sev = 0;
37	}
38	if (tc.mfd != nil && sys->fprint(tc.mfd, "%d%d%s\n", sev, verb, msg) <=0)
39		tc.mfd = nil;		# Master test process was probably killed
40}
41
42Tconfig.done(tc: self ref Tconfig)
43{
44	tc.report(S_ETIME, 0, sys->sprint("%d", sys->millisec()));
45}
46