run generation passes pic through cli subproces, generation fork restored

master
JoYo 2016-07-20 22:08:33 -04:00
parent 5c9b93479b
commit 96d22098df
2 changed files with 39 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h>
int reproduce(unsigned char *pic_address, int pic_size) int reproduce(unsigned char *pic_address, int pic_size)
{ {
@ -14,8 +15,6 @@ int reproduce(unsigned char *pic_address, int pic_size)
printf("%02X", pic_address[iter]); printf("%02X", pic_address[iter]);
} }
printf("\n");
return_value = 1; return_value = 1;
CLONE_CLEANUP: CLONE_CLEANUP:
if (NULL != pic_address) if (NULL != pic_address)
@ -113,14 +112,19 @@ int main(int argc, const char **argv)
char *hex_string = argv[1]; char *hex_string = argv[1];
int rand_offset = atoi(argv[2]); int rand_offset = atoi(argv[2]);
char rand_flip = atoi(argv[3]); char rand_flip = atoi(argv[3]);
pid_t process_id;
int return_value = 0; int return_value = 0;
process_id = fork();
if(0 == process_id)
{
return_value = generation(hex_string, rand_offset, rand_flip); return_value = generation(hex_string, rand_offset, rand_flip);
if (!return_value) if (return_value)
{ {
exit(1); exit(1);
} }
}
return 0; return 0;
} }

40
run.py
View File

@ -4,13 +4,15 @@ import logging
import os import os
import shutil import shutil
import subprocess import subprocess
import binascii
import random
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(( self.logger.info('run: {}'.format((
(parent, seed, run_dir)) (parent, seed, run_dir))
)) ))
@ -34,17 +36,26 @@ class Sins():
self.logger.info('parsed\n {}'.format((parsed))) self.logger.info('parsed\n {}'.format((parsed)))
paths = (self.seed) paths = (self.seed)
children = 0
while True: while True:
for path in paths: for path in paths:
scrap_path = os.path.join(self.run_dir, path) scrap_path = os.path.join(self.run_dir, path)
if os.path.isfile(scrap_path): if os.path.isfile(scrap_path):
children += self.execute( with open(scrap_path, 'rb') as scrap_file:
scrap_bin = scrap_file.read()
scrap_hex = binascii.b2a_hex(scrap_bin).upper()
child = self.generation(
self.parent, self.parent,
scrap_path, scrap_hex,
str(random.randint(0, len(scrap_hex))),
str(random.randint(0, 255)),
self.run_dir self.run_dir
) )
self.logger.info('"children": "{}",'.format(children))
if child:
raise Exception(child)
paths = sorted(os.listdir(self.run_dir)) paths = sorted(os.listdir(self.run_dir))
def scrap_recent(self, run_dir): def scrap_recent(self, run_dir):
@ -55,11 +66,18 @@ class Sins():
return None return None
def execute(self, parent, scrap, cwd): def generation(self, parent, scrap, offset, flip, cwd):
self.logger.debug('execute\n {}'.format(((parent, scrap, cwd)))) self.logger.debug(
proc = subprocess.run([parent, scrap], cwd=cwd, stdout=subprocess.PIPE) 'generation: {}'.format((parent, scrap, offset, flip, cwd))
)
proc = subprocess.run(
[parent, scrap, offset, flip],
cwd=cwd,
stdout=subprocess.PIPE
)
children = proc.stdout children = proc.stdout
return int(children) return children
def hex_dumps(scrap_dir): def hex_dumps(scrap_dir):
@ -97,9 +115,9 @@ if __name__ == '__main__':
parser.add_argument('-provision', action='store_true', parser.add_argument('-provision', action='store_true',
help='provision ubuntu for run, exit.') help='provision ubuntu for run, exit.')
parser.add_argument('-logfile', help='log to file.') parser.add_argument('-logfile', help='log to file.')
parser.add_argument('-seed', default='build/scrap.asm.2.o', parser.add_argument('-seed', default='build/seed.asm.2.o',
help='path to PIC image.') help='path to PIC image.')
parser.add_argument('-parent', default='build/sins', parser.add_argument('-parent', default='build/generation',
help='path to parent process.') help='path to parent process.')
parser.add_argument('-dir', default='sandbox', parser.add_argument('-dir', default='sandbox',
help='path to execution directory.') help='path to execution directory.')