def gen_smv_process(name, content, name_add=""): smv_file = SMV_FILE_DIR + hashlib.md5(content).hexdigest() + name_add + '.smv' if os.path.isfile(smv_file) and smv_file in smv_process_pool: smv_pool[name] = smv_file else: with open(smv_file, 'w') as f: f.write(content) smv_pool[name] = smv_file if __verbose: print "Start to compute reachable set" smv = SMV(SMV_PATH, smv_file, timeout=TIME_OUT) smv_process_pool[smv_file] = smv smv.go_and_compute_reachable()
def gen_smv_process(name, content, ord_str, name_add=""): smv_file = SMV_FILE_DIR + hashlib.md5( content).hexdigest() + name_add + '.smv' if os.path.isfile(smv_file) and smv_file in smv_process_pool: smv_pool[name] = smv_file else: with open(smv_file, 'w') as f: f.write(content) ord_file = None if ord_str: ord_file = SMV_FILE_DIR + hashlib.md5( content).hexdigest() + name_add + '.ord' with open(ord_file, 'w') as f: f.write(ord_str) smv_pool[name] = smv_file if __verbose: print "Start to compute reachable set" smv = SMV(SMV_PATH, smv_file, ord_file, timeout=TIME_OUT) smv_process_pool[smv_file] = smv smv.go_and_compute_reachable()
cmd = data.split(',') res = None if __verbose: sys.stdout.write(data[:10240]) sys.stdout.flush() if cmd[0] == COMPUTE_REACHABLE: """ In this case, cmd should be [length, command, command_id, name, smv file content] """ # There are many ',' in smv file, so should concat the parts splited name = cmd[2] content = ','.join(cmd[3:]) new_smv_file, smv_file = gen_smv_file(name, content) if new_smv_file or name not in smv_pool: if __verbose: print "Start to compute reachable set" smv = SMV(SMV_PATH, smv_file, timeout=TIME_OUT) if name in smv_pool: smv_pool[name].exit() smv_pool[name] = smv res = smv.go_and_compute_reachable() conn.sendall(OK) elif cmd[0] == QUERY_REACHABLE: """ In this case, cmd should be [length, command, command_id, name] """ if cmd[2] in smv_pool: res = smv_pool[cmd[2]].query_reachable() conn.sendall(','.join([OK, res]) if res else WAITING) else: conn.sendall(ERROR) elif cmd[0] == CHECK_INV: """
del smv_process_pool[smv_pool[cmd[2]]] del smv_pool[cmd[2]] conn.sendall(OK) else: conn.sendall(ERROR) elif cmd[0] == GO_BMC: """ In this case, cmd should be [length, command, command_id, name, smv file content] """ # There are many ',' in smv file, so should concat the parts splited name = cmd[2] content = ','.join(cmd[3:]) new_smv_file, smv_file = gen_smv_file(name, content, name_add='.bmc') if new_smv_file or name not in smv_bmc_pool: if __verbose: print "Go to bmc checking of NuSMV" smv = SMV(SMV_PATH, smv_file, timeout=TIME_OUT) if name in smv_bmc_pool: smv_bmc_pool[name].exit() smv_bmc_pool[name] = smv res = smv.go_bmc() conn.sendall(OK) elif cmd[0] == CHECK_INV_BMC: """ In this case, cmd should be [length, command, command_id, name, inv] """ if cmd[2] in smv_bmc_pool: res = smv_bmc_pool[cmd[2]].check_bmc(cmd[3]) conn.sendall(','.join([OK, res])) else: conn.sendall(ERROR) elif cmd[0] == SMV_BMC_QUIT: """