summaryrefslogtreecommitdiffstats
path: root/browser/test/bootstrap.js
blob: 1aeacf017b3e04c8741cb5f9b001ec04f38e3e11 (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
const { spawn, fork } = require('child_process');
if (process.argv.length < 5 || process.argv[2] == '--help') {
	console.debug('bootstrap.js <ssl_true_or_false> <abs_top_builddir> <abs_srcdir>');
	process.exit(0);
}
const ssl_flag = process.argv[2];
const top_builddir = process.argv[3];
const srcdir = process.argv[4];
const typing_speed = process.argv[5];
const single_view = process.argv[6];
const typing_duration = process.argv[7];
const inspect = process.argv[8];
const recordStats = process.argv[9];
/* dont use the default port (9980)*/
const port = '9999';
let args = [
	`--o:sys_template_path=${top_builddir}/systemplate`,
	'--o:security.capabilities=false',
	`--o:child_root_path=${top_builddir}/jails`,
	'--o:storage.filesystem[@allow]=true',
	'--o:admin_console.username=admin --o:admin_console.password=admin',
	'--o:logging.file[@enable]=true --o:logging.level=warning',
	'--o:trace_event[@enable]=true',
	`--port=${port}`
];

let ssl_args = [
	`--o:ssl.cert_file_path=${top_builddir}/etc/cert.pem`,
	`--o:ssl.key_file_path=${top_builddir}/etc/key.pem`,
	`--o:ssl.ca_file_path=${top_builddir}/etc/ca-chain.cert.pem`,
];

if (ssl_flag === 'true')
	args = [...args, ...ssl_args];

const loolwsd = spawn(`${top_builddir}/loolwsd`, args);
/*
loolwsd.stdout.on('data', (data) => {
	//console.log(`stdout: ${data}`);
});

loolwsd.stderr.on('data', (data) => {
	//console.error(`stderr: ${data}`);
});
*/
loolwsd.on('exit', (code) => {
	console.log(`loolwsd process exited with code ${code}`);
});

let childNodes = [];

let execArgs = [];
if (inspect === 'true')
	execArgs.push('--inspect');
childNodes.push(
	fork(`${srcdir}/test/load.js`, [ssl_flag, top_builddir, `${top_builddir}/test/data/perf-test-edit.odt`, `testEdit_1`, `${port}`, `${typing_speed}`, `${typing_duration}`, `${recordStats}`, `${single_view}`], {execArgv: execArgs})
);
if(single_view !== "true") {
	for (let i = 2; i <= 6; i++) {
		childNodes.push(
			fork(`${srcdir}/test/load.js`, [ssl_flag, top_builddir, `${top_builddir}/test/data/perf-test-edit.odt`, `testEdit_${i}`, `${port}`, `${typing_speed}`, `${typing_duration}`, 'false', 'false'])
		);
	}
}

function vacuumCleaner(kill, message, code) {
		console.log(message);
		childNodes.forEach(n => n.kill(kill));
		loolwsd.kill(kill);
		console.log(`Process exited with code ${code}`);
}

function exitHandler(options, exitCode) {
	if (options.cleanup) {
		vacuumCleaner('SIGKILL', 'cleaning up...', exitCode)
	}
	if (options.exit) {
		vacuumCleaner('SIGINT', 'exiting...', exitCode)
	}
}

//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup: true}));

//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit: true}));

//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));