aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-08-18 10:41:40 +0200
committerKarel Kočí <cynerd@email.cz>2015-08-18 10:53:52 +0200
commit125a8b082b10348dfeb15b25e6697f770d1d20f4 (patch)
tree76a224271e8ed649adbd23796388343c4cd79813
parent383e0cd365818982b2dadddafa44b97033e9a12f (diff)
downloadlinux-conf-perf-125a8b082b10348dfeb15b25e6697f770d1d20f4.tar.gz
linux-conf-perf-125a8b082b10348dfeb15b25e6697f770d1d20f4.tar.bz2
linux-conf-perf-125a8b082b10348dfeb15b25e6697f770d1d20f4.zip
Generate configuration as ditionary in picosat function
Picosat output is parsed and automatically is resolved to dictionary with configuration option name as key and boolean value. This makes all configurations in script of same type. All are dictionaries this way.
-rw-r--r--scripts/configurations.py50
1 files changed, 28 insertions, 22 deletions
diff --git a/scripts/configurations.py b/scripts/configurations.py
index aae7a6f..f7f1694 100644
--- a/scripts/configurations.py
+++ b/scripts/configurations.py
@@ -36,7 +36,7 @@ def __buildtempcnf__(variable_count, files, strlines):
wfile.close()
return wfile.name
-def __exec_sat__(file, args):
+def __exec_sat__(file, args, conf_num):
"""Executes SAT solver and returns configuration."""
picosat_cmd = [sf(conf.picosat), file]
picosat_cmd += conf.picosat_args
@@ -63,34 +63,40 @@ def __exec_sat__(file, args):
rtn.append(solut)
except ValueError:
pass
- return rtn
-
-def __txt_config__(con, conf_num):
# Ensure smap existence
utils.build_symbol_map()
- # Write temporally file
+ # Translate to dict
+ con = list()
+ for rt in rtn:
+ cond = dict()
+ for r in rt:
+ if r < 0:
+ val = False
+ r *= -1
+ else:
+ val = True
+ if r > int(conf_num):
+ break;
+ if 'NONAMEGEN' in utils.smap[r]: # ignore generated names
+ continue
+ cond[utils.smap[r]] = val
+ con.append(cond)
+ return con
+
+def __txt_config__(con):
txt = ''
- for s in con:
- if s < 0:
- nt = True
- s *= -1
- else:
- nt = False
- if s > int(conf_num):
- break;
- if 'NONAMEGEN' in utils.smap[s]: # ignore generated names
- continue
- txt += 'CONFIG_' + utils.smap[s] + '='
- if not nt:
+ for key, val in con.items():
+ txt += 'CONFIG_' + key + '='
+ if val:
txt += 'y'
else:
txt += 'n'
txt += '\n'
return txt
-def __write_temp_config_file__(con, conf_num):
+def __write_temp_config_file__(con):
wfile = tempfile.NamedTemporaryFile(delete=False)
- txt = __txt_config__(con, conf_num)
+ txt = __txt_config__(con)
wfile.write(bytes(txt, sys.getdefaultencoding()))
wfile.close()
return wfile.name
@@ -149,7 +155,7 @@ def __calchash_file__(file):
def __register_conf__(con, conf_num, generator):
dtb = database.database()
# Solution to configuration
- txtconfig = __txt_config__(con, conf_num)
+ txtconfig = __txt_config__(con)
hsh = __calchash__(con)
cconf = dtb.get_configration(hsh)
for cc in cconf:
@@ -182,7 +188,7 @@ def __generate_single__(var_num, conf_num):
for ln in measure_list:
fo.write(str(ln) + '\n')
try:
- confs = __exec_sat__(tfile, ['-i', '0'])
+ confs = __exec_sat__(tfile, ['-i', '0'], conf_num)
for con in confs:
__register_conf__(con, conf_num, 'single-sat')
except exceptions.NoSolution:
@@ -194,7 +200,7 @@ def __generate_single__(var_num, conf_num):
def __generate_random__(var_num, conf_num):
tfile = __buildtempcnf__(var_num, (sf(conf.rules_file), sf(conf.fixed_file)), set())
try:
- confs = __exec_sat__(tfile, ['-i', '3'])
+ confs = __exec_sat__(tfile, ['-i', '3'], conf_num)
for con in confs:
if not __register_conf__(con, conf_num, 'random-sat'):
__generate_random__(var_num, conf_num)