-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·105 lines (93 loc) · 3.36 KB
/
cli.js
File metadata and controls
executable file
·105 lines (93 loc) · 3.36 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env node
const logwrapper = require.resolve('../logger/logwrap.js');
const hbIdentifier = require('../hb/identifier');
const controller = require('../controller/controller');
const report = require('../report/report');
const suspicious = require('../suspicious/suspicious');
const foreground = require('foreground-child');
const sw = require('spawn-wrap');
const path = require('path');
const argv = require('yargs');
const sanitize = require('string-sanitizer').sanitize;
argv
.usage('Usage: $0 <command> [options]')
.command('log <testcommand>', 'run the test and log its trace (observation)', (yargs) => {
return yargs.option('config', {
alias: 'c',
describe: 'path to the config file',
nargs: 1
});
}, (argv) => {
let originalCommand = process.argv.slice(3); //remove script call and command
if (argv.config) {
originalCommand.pop(); //remove the config args from the command
originalCommand.pop();
}
sw([logwrapper], {
LOG_FOLDER: buildLogFolderPath(originalCommand),
COMMAND: originalCommand,
CONFIGFILE: argv.config && path.resolve(argv.config)
});
foreground(originalCommand, (done) => {
return done();
});
})
.command('hb <pathtologfile>', 'identify happens-before relations', (yargs) => {
return yargs
.option('image', { alias: 'i' })
.option('noglobal', { alias: 'ng' });
}, (argv) => {
hbIdentifier({
file: argv.pathtologfile,
image: argv.image || false,
noglobal: argv.noglobal || false
});
})
.command('control [options] <testcommand>', 'run tests with guided execution', (yargs) => {
return yargs
.option('strategy', {
alias: 's',
describe: 'define strategy for guided execution',
nargs: 1,
demand: true
})
.option('runs', {
alias: 'r',
describe: 'define number of runs',
nargs: 1,
demand: true
})
.option('hbfile', {
alias: 'h',
describe: 'define the happens-before file',
nargs: 1,
demand: true
});
}, (argv) => {
let originalCommand = process.argv.slice(9); //remove script call, command, and other options
controller({
strategy: argv.strategy,
runs: argv.runs,
file: argv.hbfile,
command: originalCommand
});
})
.command('report <pathtologfolder>', 'open a browser-based report', () => { }, (argv) => {
report({ dirpath: path.resolve(argv.pathtologfolder) });
})
.command('susp <hbfile>', 'print suspicious metrics', (yargs) => {
return yargs
.option('metric', { alias: 'm' });
}, (argv) => {
suspicious(argv.hbfile, argv.metric || '');
})
.argv;
if (process.argv.length <= 2)
argv.showHelp();
function buildLogFolderPath(command) {
let specName = command.join('_').split('/').join('_').split('.').join('_');
specName = sanitize(specName);
if (specName.length > 100)
specName = specName.substring(0, 20);
return path.join(process.cwd(), 'log', specName);
}