forked from NodeOS/NodeOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unified execution code for
test
and start
scripts
- Loading branch information
Showing
5 changed files
with
154 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* NodeOS | ||
* | ||
* @copyright 2013-2017 Jacob Groundwater, Jesús Leganés-Combarro 'piranna' | ||
* and other contributors | ||
* | ||
* @license MIT | ||
*/ | ||
|
||
const fs = require('fs') | ||
const join = require('path').join | ||
|
||
const processArguments = require('nodeos-barebones/scripts/processArguments') | ||
|
||
|
||
function prepareCommandLine(argv, output) | ||
{ | ||
const args = processArguments(argv) | ||
const link = fs.readlinkSync('out/latest').split('/') || [] | ||
|
||
const cpu_family = args.cpu_family || link[link.length-3] | ||
const machine = args.machine || link[link.length-2] | ||
const platform = args.platform || link[link.length-1] | ||
|
||
const cpu = args.cpu | ||
|
||
let command = 'qemu-system-'+cpu_family | ||
|
||
argv = | ||
[ | ||
'-machine', machine, | ||
'-m', '256M', | ||
'-vga', 'std', | ||
'-net', 'nic', | ||
'-net', 'user,id=eth0,hostfwd=tcp::50080-:80', | ||
'-net', 'user,id=eth1,hostfwd=tcp::50443-:443' | ||
] | ||
|
||
switch(output) | ||
{ | ||
case 'curses' : argv.push('-curses') ; break | ||
case 'nographic': argv.push('-nographic'); break | ||
} | ||
|
||
// check if kvm is supported | ||
let contents = "" | ||
|
||
try | ||
{ | ||
contents = fs.readFileSync('/proc/cpuinfo'); | ||
} catch(e){ | ||
if(e.code !== 'ENOENT') throw(e) | ||
} | ||
|
||
if(/(vmx|svm)/.test(contents) !== false) argv.push('-enable-kvm') | ||
|
||
// CWD | ||
const cwd = join('out', cpu_family, machine, platform) | ||
|
||
switch(platform) | ||
{ | ||
case 'disk': | ||
argv.push('-hda', 'disk.img') | ||
break | ||
|
||
case 'docker': | ||
command = 'docker' | ||
argv = | ||
[ | ||
'run', '-it', | ||
'--cap-add', 'SYS_ADMIN', | ||
'--security-opt=apparmor:unconfined', | ||
'--device', '/dev/fuse', | ||
'nodeos/nodeos', | ||
// '-v', 'usersfs:/tmp' | ||
] | ||
break | ||
|
||
case 'img': | ||
argv.push('-hda', 'bootfs.img', | ||
'-hdb', 'usersfs.img') | ||
break | ||
|
||
case 'iso': | ||
argv.push('-cdrom', 'bootfs.iso', | ||
'-hda' , 'usersfs.img') | ||
break | ||
|
||
case 'qemu': | ||
const append = | ||
[ | ||
'root=/dev/sda', | ||
'ip=dhcp' | ||
] | ||
|
||
switch(output) | ||
{ | ||
case 'nographic': | ||
append.push('console=ttyS0') // redirect to terminal | ||
break | ||
|
||
case 'curses': | ||
append.push('vga=extended') // 80x50 | ||
break | ||
|
||
default: | ||
append.push('vga=0x344') // 1024x768x32 | ||
} | ||
|
||
argv.push('--kernel', 'kernel', | ||
'--initrd', 'initramfs.cpio.gz', | ||
'-drive', `file=usersfs.img,format=raw,index=0`, | ||
'-append', append.join(' ')) | ||
break | ||
|
||
case 'tar': | ||
case 'vagga': break | ||
|
||
default: | ||
throw 'Unknown platform "'+platform+'"' | ||
} | ||
|
||
return {command, argv, cwd, platform} | ||
} | ||
|
||
|
||
module.exports = prepareCommandLine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.