3 Z>a_@sddlZddlZddlZddlZddlZddlZddlZddlmZej dZ ddZ ddZ dd Z ed krejd jejjed d e dS)N)load_json_config_fileZComputeConfigurationscCs tjdS)Na This script Generates Makefile.json from Configrations.json. Starting in the current directory, it walks down every subdirectory looking for Configurations.json files. Every found Configurations.json file is assumed to look similar to the following format: { "ENTRY": "ARPProcessPacket", "CBMCFLAGS": [ "--unwind 1", "--unwindset vARPRefreshCacheEntry.0:7,memcmp.0:17", "--nondet-static" ], "OBJS": [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto" ], "DEF": [ {"disableClashDetection": ["ipconfigARP_USE_CLASH_DETECTION=0"]}, {"enableClashDetection": ["ipconfigARP_USE_CLASH_DETECTION=1"]} ] } The format is mainly taken from the Makefile.json files. The only difference is that it expects a list of json object in the DEF section. This script will generate a Makefile.json in a subdirectory and copy the harness to each subdirectory. The key is later taken as the name for the configuration subdirectory prexied by 'config_'. So for the above script, we get two subdirectories: -config_disableClashDetection -config_enableClashDetection As an example, the resulting Makefile.json for the config_disableClashDetection directory will be: { "ENTRY": "ARPProcessPacket", "CBMCFLAGS": [ "--unwind 1", "--unwindset vARPRefreshCacheEntry.0:7,memcmp.0:17", "--nondet-static" ], "OBJS": [ "$(ENTRY)_harness.goto", "$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto" ], "DEF": [ "ipconfigARP_USE_CLASH_DETECTION=0" ] } These Makefile.json files then can be turned into Makefiles for running the proof by executing the make-proof-makefiles.py script. )textwrapdedentrrX/home/aniruddha/Desktop/UnitTestSetup/test/cbmc/proofs/make_configuration_directories.pyprolog%s;rc #Csttjj|d}y |d}Wntk r<tjddSXxr|D]h}tj|y"dd|j Dd}||}WnJt t fk r}z*tj|tjt j dtjd|dSd}~XnXtjj|d |}tj|jd d d d } x:|D]2} | jd rtjtjj|| tjj|| d } qW| sJtjd|tjddStj|} || d<d|j krx|d| d<nd | d<ttjj|dd} tj| | ddWdQRXqFWdS)NzConfigurations.jsonDEFz3Expected DEF as key in a Configurations.json files.cSsg|]}|dkr|qS)EXPECTEDr).0namerrr oszprocess..rar The expected layout for an entry in the Configurations.json file is a dictonary. Here is an example of the expected format: "DEF": [ {"disableClashDetection": ["ipconfigARP_USE_CLASH_DETECTION=0"]}, {"enableClashDetection": ["ipconfigARP_USE_CLASH_DETECTION=1"]} ] zThe offending entry is %sZconfig_T)exist_okparentsFz harness.cz&Could not find a harness in folder %s.z(This folder is not processed do the end!r z Makefile.jsonw)indent)rospathjoinKeyErrorLOGGERerrorloggingdebugkeysAttributeError IndexErrorrrpathlibZPathmkdirendswithshutilcopy collections OrderedDictopenjsondump) ZfolderfilesZ json_contentZdef_listconfigZ confignameZ configbodyeZnew_config_folderZharness_copiedfileZcurrent_configZ output_filerrrprocessdsN             r+cCs0x*tjdD]\}}}d|kr t||q WdS)N.zConfigurations.json)rwalkr+)Zfldr_Zfylesrrrmainsr/__main__z#{script}: %(levelname)s %(message)s)script)format)r"r%rrrr rmake_proof_makefilesr getLoggerrrr+r/__name__ basicConfigr2rbasename__file__rrrrs  ?6