1
1
#!/usr/bin/env node
2
2
3
3
let program = require ( 'commander' ) ;
4
- let execSync = require ( 'child_process' ) . execSync ;
4
+ let execFileSync = require ( 'child_process' ) . execFileSync ;
5
5
let fs = require ( 'fs' ) ;
6
6
7
7
// Parse options and launch jbmc
@@ -27,24 +27,27 @@ program
27
27
} )
28
28
. parse ( process . argv ) ;
29
29
30
- /// Convert the args to a string of the form "--arg-name arg-value ..."
31
- function argsToString ( args ) {
32
- let string = "" ;
30
+ /// Convert the args to an argument array
31
+ function argsToArray ( args ) {
32
+ let result = [ ] ;
33
33
const keys = Object . keys ( args ) ;
34
34
for ( let i = 0 ; i < keys . length ; i ++ ) {
35
35
if ( typeof args [ keys [ i ] ] === "boolean" ) {
36
36
if ( args [ keys [ i ] ] )
37
- string += ` --${ keys [ i ] } `;
37
+ result . push ( ` --${ keys [ i ] } `) ;
38
38
}
39
39
else if ( Array . isArray ( args [ keys [ i ] ] ) ) {
40
- for ( let j = 0 ; j < args [ keys [ i ] ] . length ; j ++ )
41
- string += ` --${ keys [ i ] } "${ args [ keys [ i ] ] [ j ] } "` ;
40
+ for ( let j = 0 ; j < args [ keys [ i ] ] . length ; j ++ ) {
41
+ result . push ( `--${ keys [ i ] } ` ) ;
42
+ result . push ( `${ args [ keys [ i ] ] [ j ] } ` ) ;
43
+ }
42
44
}
43
45
else {
44
- string += ` --${ keys [ i ] } "${ args [ keys [ i ] ] } "` ;
46
+ result . push ( `--${ keys [ i ] } ` ) ;
47
+ result . push ( `${ args [ keys [ i ] ] } ` ) ;
45
48
}
46
49
}
47
- return string ;
50
+ return result ;
48
51
}
49
52
50
53
/// Get the coverage info from the json output if available
@@ -92,18 +95,16 @@ function run(executable, modelsPath, argumentsFile, functionName,
92
95
// timeout isn't a jbmc option but only used by this script
93
96
const timeout = config . timeout ;
94
97
config [ 'timeout' ] = false ;
95
- commandLine = ` ${ executable } ${ classFile } ${ argsToString ( config ) } `
98
+ let command = [ executable , classFile , ... argsToArray ( config ) ] ;
96
99
const startTime = new Date ( ) ;
97
100
try {
98
- const timeCommand = "export TIME=\"%U\"; /usr/bin/time --quiet -o tmp_time.out "
99
- + commandLine ;
100
- const output =
101
- execSync ( timeCommand , { timeout : 1000 * timeout } ) . toString ( ) ;
101
+ const wrapper = __dirname + "/process_wrapper.sh" ;
102
+ const output = execFileSync ( wrapper , command , { timeout : 1000 * timeout } ) . toString ( ) ;
102
103
let execTime = fs . readFileSync ( 'tmp_time.out' , 'utf8' ) . split ( '\n' ) [ 0 ] ;
103
104
let result = {
104
105
classFile : classFile , function : functionName ,
105
106
execTime : execTime , success : true ,
106
- commandLine : commandLine
107
+ commandLine : command
107
108
}
108
109
if ( showProperties ) {
109
110
result . goals = readNumberOfGoals ( output ) ;
@@ -115,7 +116,7 @@ function run(executable, modelsPath, argumentsFile, functionName,
115
116
return JSON . stringify ( {
116
117
classFile : classFile , function : functionName ,
117
118
execTime : ( new Date ( ) - startTime ) / 1000 , success : false ,
118
- commandLine : commandLine
119
+ commandLine : command
119
120
} ) ;
120
121
}
121
122
}
0 commit comments