File: test-processrunner.cc

package info (click to toggle)
guessnet 0.42-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,000 kB
  • ctags: 1,252
  • sloc: cpp: 5,001; sh: 1,194; makefile: 133; perl: 118
file content (61 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download
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
#include "Environment.h"
#include "ProcessRunner.h"

#include <stdio.h>
#include <iostream>

#define DEBUG(args...) fprintf(stderr, ##args)
//#define DEBUG(args...) do {} while(0)

using namespace std;

class ProcessPrinter : public ProcessListener
{
public:
	virtual void handleTermination(const std::string& tag, int status) throw ()
	{
		cout << tag << ": terminated with status " << status << endl;
	}
};


int main(int argc, char* argv[])
{
	try {
		wibble::exception::InstallUnexpected installUnexpected;

		Environment::get().debug(true);

		{
			fprintf(stderr, "\t\tInitializing process runner...\n");
			ProcessRunner pr;
			fprintf(stderr, "\t\tInitialized process runner...\n");
		}

		fprintf(stderr, "\t\tReinitializing process runner...\n");
		ProcessPrinter pp;
		ProcessRunner pr;

		fprintf(stderr, "\t\tAdding processes...\n");
		pr.addProcess("test1", "sleep 1", &pp);
		pr.addProcess("test2", "sleep 2", &pp);
		pr.addProcess("test2a", "sleep 2", &pp);
		pr.addProcess("test0", "true", &pp);
		pr.addProcess("test3", "false", &pp);
		pr.addProcess("test2b", "sleep 2", &pp);
		pr.addProcess("test1a", "sleep 1", &pp);

		fprintf(stderr, "\t\tSleeping...\n");
		sleep(2);
		fprintf(stderr, "\t\tShutting down...\n");
		pr.shutdown();

		fprintf(stderr, "\t\tDone.\n");
	}
	catch (std::exception& e)
	{
		error("%s", e.what());
		return 1;
	}
	return 0;
}