Home Corporate Contacts

TETware Knowledgebase


Products
Solutions

Information

Datasheet
Documentation
FAQ
Knowledgebase

Return to Knowledgebase Index

7. How to create a new process using tet_spawn() and tet_wait()

 

Question

Can you send me an example of how to use tet_spawn() and tet_wait().

 

Answer

Here is a trivial test case that uses tet_spawn(). The source file is called tc16.c. You should compile it, then link with tcm.o and libapi.a in the usual way. (Or tcm.obj and libapi.lib on Win32 systems.)


#include <stdlib.h>
#ifndef _WIN32
#  include <sys/wait.h>
#endif
#include "tet_api.h"

void (*tet_startup)() = TET_NULLFP, (*tet_cleanup)() = TET_NULLFP;
void tp1();

struct tet_testlist tet_testlist[] = { {tp1, 1}, {TET_NULLFP, 0} };

#ifndef _WIN32
extern char **environ;
#endif

void tp1()
{
	pid_t pid;
	int status;
	static char *argv[] = {
		"./tc16child",
		"an-argument-string",
		(char *) 0
	};

	tet_infoline("this is tc16 parent");

	if ((pid = tet_spawn(*argv, argv, environ)) == -1) {
		tet_printf("tet_spawn(%s) failed: tet_errno = %d",
			*argv, tet_errno);
		tet_result(TET_UNRESOLVED);
		return;
	}

	status = 0;
	if (tet_wait(pid, &status) == -1) {
		tet_printf("tet_wait(%ld) failed: tet_errno = %d",
			(long) pid, tet_errno);
		tet_result(TET_UNRESOLVED);
		return;
	}

#ifdef _WIN32
	if (status != 0) {
		tet_infoline("child process returned unexpected exit status");
		tet_printf("expected exit status 0, observed %d", status);
		tet_result(TET_FAIL);
	}
	else
		tet_infoline("child exit status = 0");
#else
	if (WIFEXITED(status)) {
		if (WEXITSTATUS(status) != 0) {
			tet_infoline("child process returned unexpected \
				exit status");
			tet_printf("expected exit status 0, observed %d",
				WEXITSTATUS(status));
			tet_result(TET_FAIL);
		}
		else
			tet_infoline("child exit status = 0");
	}
	else if (WIFSIGNALED(status)) {
		tet_printf("child process terminated with signal %d",
			WTERMSIG(status));
		tet_result(TET_UNRESOLVED);
	}
	else if (WIFSTOPPED(status)) {
		tet_printf("child process stopped by signal %d",
			WSTOPSIG(status));
		tet_result(TET_UNRESOLVED);
	}
	else {
		tet_printf("can't decode child process exit status (%#x)",
			status);
		tet_result(TET_UNRESOLVED);
	}
#endif

}



This is the child process that is launched by the call to tet_spawn() in tc16.c. The source file is called tc16child.c. You should compile it, then link with tcmchild.o and libapi.a. (Or tcmchild.obj and libapi.lib on Win32 systems.)

#include "tet_api.h"

int tet_main(argc, argv)
int argc;
char **argv;
{
	tet_infoline("this is tc16 child");
	if (argc > 1) {
		tet_printf("argument is \"%s\"", argv[1]);
		tet_result(TET_PASS);
	}
	else {
		tet_infoline("no arguments received");
		tet_result(TET_UNRESOLVED);
	}
	return(0);
}



Here is the journal that is generated when tc16 is run on a Win32 system:

0|3.2-lite 23:19:40 19970714|User: unknown TCC Start, \
	Command line: tcc -epl /ts/tc16
5|Windows_95 TEXEL 4 0 586|System Information
20|c:/tet3/suite/tetexec.cfg 1|Config Start
30||TET_EXEC_IN_PLACE=false
30||TET_API_COMPLIANT=True
30||TET_PASS_TC_NAME=False
30||TET_VERSION=3.2-lite
40||Config End
10|0 /ts/tc16 23:19:40|TC Start, scenario ref 1-0
15|0 3.2-lite 1|TCM Start
400|0 1 1 23:19:42|IC Start
200|0 1 23:19:42|TP Start
520|0 1 0004883443 1 1|this is tc16 parent
520|0 1 0001218837 2 1|this is tc16 child
520|0 1 0001218837 2 2|argument is "an-argument-string"
520|0 1 0004883443 3 1|child exit status = 0
220|0 1 0 23:19:42|PASS
410|0 1 1 23:19:42|IC End
80|0 0 23:19:43|TC End, scenario ref 1-0
900|23:19:43|TCC End

 

See also

  • "C language binding'' and "Generating and executing processes'' in the TETware Programmers Guide.

 


Home Contacts Legal Copyright Corporate News

Copyright © The Open Group 1995-2012, All Rights Reserved