added provisioning, clang compiler, minor tweaks

master
JoYo 2016-07-17 22:04:39 -04:00
parent a882cdca9e
commit 91874aebd7
4 changed files with 46 additions and 25 deletions

5
Vagrantfile vendored Normal file
View File

@ -0,0 +1,5 @@
# -*- mode: ruby -*-
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
end

2
provision-ubuntu.sh Normal file
View File

@ -0,0 +1,2 @@
#! /usr/bin/env sh
apt-get install -y build-essential libssl-dev nasm

48
run.py
View File

@ -3,30 +3,30 @@
import os import os
import logging import logging
import subprocess import subprocess
import json
class Sins(): class Sins():
logger = logging.getLogger() logger = logging.getLogger()
def __init__(self, parent, seed=None, run_dir=None): def __init__(self, parent, seed=None, run_dir=None):
self.logger.info('execute\n{}'.format(json.dumps( self.logger.info('execute\n{}'.format((
(parent, seed, run_dir)) (parent, seed, run_dir))
)) ))
if os.path.isdir(run_dir): self.parent = os.path.abspath(parent)
self.run_dir = os.path.abspath(run_dir)
self.seed = os.path.abspath(seed)
parent = os.path.abspath(parent)
if not os.path.isfile(parent): if not os.path.isfile(parent):
raise ValueError('Invalid executable image path.') raise ValueError('Invalid executable image path.')
self.parent = parent self.seed = os.path.abspath(seed)
if os.path.isdir(run_dir):
self.run_dir = os.path.abspath(run_dir)
shutil.copy2(args.seed, args.dir)
else:
self.run_dir = os.path.dirname(self.seed)
parsed = self.parent, self.seed, self.run_dir parsed = self.parent, self.seed, self.run_dir
self.logger.info('parsed\n{}'.format(json.dumps(parsed))) self.logger.info('parsed\n{}'.format((parsed)))
while True: while True:
self.execute(self.parent, self.seed, self.run_dir) self.execute(self.parent, self.seed, self.run_dir)
@ -49,9 +49,7 @@ class Sins():
return None return None
def execute(self, parent, scrap, cwd): def execute(self, parent, scrap, cwd):
self.logger.info('execute\n{}'.format( self.logger.info('execute\n{}'.format(((parent, scrap, cwd))))
json.dumps((parent, scrap, cwd))
))
subprocess.run([parent, scrap], cwd=cwd) subprocess.run([parent, scrap], cwd=cwd)
@ -81,16 +79,18 @@ def hex_dumps(scrap_dir):
if __name__ == '__main__': if __name__ == '__main__':
import argparse import argparse
import shutil
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(filename='sins.log') # handler = logging.FileHandler(filename='sins.log')
handler = logging.StreamHandler()
formatter = logging.Formatter( formatter = logging.Formatter(
'#%(asctime)s %(name)s %(levelname)s\n##%(message)s\n' '#%(asctime)s %(name)s %(levelname)s\n##%(message)s\n'
) )
file_handler.setFormatter(formatter) handler.setFormatter(formatter)
logger.addHandler(file_handler) logger.addHandler(handler)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-seed', default='build/scrap.asm.2.o') parser.add_argument('-seed', default='build/scrap.asm.2.o')
@ -98,14 +98,22 @@ if __name__ == '__main__':
parser.add_argument('-dir', default='sandbox') parser.add_argument('-dir', default='sandbox')
parser.add_argument('-dumps', action='store_true') parser.add_argument('-dumps', action='store_true')
parser.add_argument('-build', action='store_true') parser.add_argument('-build', action='store_true')
parser.add_argument('-provision', action='store_true')
args = parser.parse_args() args = parser.parse_args()
if args.build: if args.provision:
waf = ['python3', 'waf.py', 'configure', 'build'] provision = ['sudo', 'sh', 'provision-ubuntu.sh']
waf_proc = subprocess.run(waf, stdout=subprocess.PIPE) prov_proc = subprocess.run(provision)
elif args.build:
import sys
os.environ['CC'] = 'clang'
waf = [sys.executable, 'waf.py', 'configure', 'build']
waf_proc = subprocess.run(waf)
logger.info(waf_proc.stdout) logger.info(waf_proc.stdout)
if args.dumps: elif args.dumps:
hex_dumps(args.dir) hex_dumps(args.dir)
else: else:
sins = Sins(parent=args.parent, seed=args.seed, run_dir=args.dir) sins = Sins(parent=args.parent, seed=args.seed, run_dir=args.dir)

16
sins.c
View File

@ -34,6 +34,9 @@ int main(int argc, const char **argv)
struct process_list scraps; struct process_list scraps;
struct process_list *iter = NULL; struct process_list *iter = NULL;
pid_t process_id; pid_t process_id;
int status = 0;
int count = 0;
int return_value = 0;
INIT_LIST_HEAD(&scraps.list); INIT_LIST_HEAD(&scraps.list);
@ -42,9 +45,9 @@ int main(int argc, const char **argv)
while (1) while (1)
{ {
process_id = fork(); process_id = fork();
iter = (struct process_list*)malloc(sizeof(struct process_list)); iter = (struct process_list *)malloc(sizeof(struct process_list));
iter->process_id = process_id; iter->process_id = process_id;
list_add_tail( &(iter->list), &(scraps.list) ); list_add_tail(&(iter->list), &(scraps.list));
if (process_id == 0) if (process_id == 0)
{ {
@ -54,16 +57,19 @@ int main(int argc, const char **argv)
if (process_id < 0) if (process_id < 0)
{ {
sleep(1); count = 0;
list_for_each_entry(iter, &scraps.list, list) list_for_each_entry(iter, &scraps.list, list)
{ {
continue; /* @todo clean up pids */ count++; /* @todo clean up pids */
return_value = waitpid(iter->process_id, &status, 0);
return_value = WEXITSTATUS(return_value);
} }
break; break;
} }
} }
return 1; return count;
} }
int generation(char *seed_path) int generation(char *seed_path)