-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscript_run_exp.py
59 lines (49 loc) · 1.9 KB
/
script_run_exp.py
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
#!/usr/bin/python3
from os import walk
import os
import os.path
import shlex
import subprocess
import logging
logging.basicConfig(level=logging.DEBUG, filename='run_exp_data.log', filemode='w', format='%(process)d - [%(asctime)s] : %(levelname)s -> %(message)s')
"""
Usage mode:
1) all inputs should be inside of inputs directory
2) all inputs are executed 13 times
3) all outputs are save in the file called execution_log.txt
"""
BINARY_PROGRAM = "otimo"
INPUTS_FILE = "inputs"
TIMES_RUN = 13
PATH_FILES_INPUT_LIST = []
def list_files_input():
for (dirpath, dirnames, filenames) in walk(INPUTS_FILE):
for file in filenames:
full_path = os.path.abspath(dirpath) + "/" + file
PATH_FILES_INPUT_LIST.append(full_path)
def run_code():
logging.debug(f'Running the program with each input {TIMES_RUN} times')
for input in PATH_FILES_INPUT_LIST:
if not os.path.exists(input):
logging.error(f"Input file: {input} not found")
else:
cmd = shlex.split("./" + BINARY_PROGRAM + " " + input)
for count_time in range(TIMES_RUN):
logging.debug(f"Running input: {input} - Time {count_time}")
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
stdout, stderr = process.communicate()
if not stderr:
logging.debug(f"Program output: - Time {count_time}")
logging.debug(f"---------------------------")
logging.debug(stdout)
logging.debug(f"---------------------------")
def main():
logging.debug('Experiment script executed')
logging.debug('Listing input files to the program')
list_files_input()
run_code()
if __name__ == "__main__":
main()