1515 try :
1616 zip_path , _ = urllib .request .urlretrieve (juliet_url )
1717 with zipfile .ZipFile (zip_path , "r" ) as f :
18- f .extractall ()
18+ f .extractall ()
1919 except urllib .error .HTTPError :
2020 os .system ('echo "FAILURE: Download url invalid."' )
2121 quit ()
3131 path = sys .argv [1 ] # path + '/' + sys.argv[1]
3232 # Checking if the path is valid
3333 if not os .path .exists (juliet_path ):
34- os .system ('echo "PATH NOT FOUND: "' + path )
34+ os .system ('echo "PATH NOT FOUND: "' + path )
3535elif len (sys .argv ) != 1 :
3636 os .system ('echo "FAILURE: Run script with no arguments to run on all testcases or add path to a specific testcases folder (that has individual cases or folders containing testcases)."' )
3737 quit ()
4242
4343# The definitive function that performs all the main operations:
4444# - Takes current working directory and HTML contents as input
45- # - Finds valid C files for Goblint in that dir and establishes
45+ # - Finds valid C files for Goblint in that dir and establishes
4646# other potential sub-directories for the future
4747# - Runs Goblint on valid test cases if they exist
4848# - Generates HTML table with new results from those cases
@@ -57,30 +57,30 @@ def goblint_analyse(current_directory, HTML_info):
5757 HTML_info [0 ] = files_output_to_HTML (valid_files , current_directory , HTML_info [0 ])
5858 HTML_info [1 ].append (current_directory )
5959 return pot_directories , HTML_info
60-
61- # Goes through all the files in given path, returns all suitable testcase files and
60+
61+ # Goes through all the files in given path, returns all suitable testcase files and
6262# all directories that might potentially contain testcases1
6363def check_path (filepath ):
6464 files = os .listdir (filepath )
6565 v_files = [] # Valid files
6666 dirs = [] # Directories
6767 for f in files :
6868 if re .search ('^CWE' , f ) != None and re .search ('[0-9]{2}a?\.c$' , f ) != None and re .search ('w32' , f ) == None : v_files .append (f )
69- elif os .path .isdir (filepath + '/' + f ):
69+ elif os .path .isdir (filepath + '/' + f ):
7070 dirs .append (f )
7171 return v_files , dirs
72-
72+
7373# Runs Goblint to process a testcase function, testcase function will be either
7474# '_good' or '_bad' determined by input parameter 'mode'
7575def goblint_cmd (filepath , filename , mode ):
7676 func = re .sub ('a?\.c$' , mode , filename ) # File ending is cut and replaced by mode
77- cmd = goblint_path + ' ' + filepath + ' ' + testsupport_files + ' -I ' + testsupport_path + ' --sets "mainfun[+]" ' + func + ' --enable dbg.print_dead_code --enable dbg. debug --enable printstats'
77+ cmd = goblint_path + ' ' + filepath + ' ' + testsupport_files + ' -I ' + testsupport_path + ' --sets "mainfun[+]" ' + func + ' --enable dbg.debug --enable printstats'
7878 print (filename + ' -- ' + mode [1 :] + ' ' , end = '\r ' )
7979 process = subprocess .run (cmd , shell = True , check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE , universal_newlines = True )
8080 #title = '#####################\n' + mode.upper() + '\n#####################\n\n'
8181 return cmd + "\n \n " + process .stdout + process .stderr
82-
83- # Takes a list of testcase files as input and iterates through them to analyze
82+
83+ # Takes a list of testcase files as input and iterates through them to analyze
8484# outputs for both 'good' and 'bad' function. Generates an HTML table based on outputs.
8585def files_output_to_HTML (testcases , filepath , html_table ):
8686 # Creating column headers for the table
@@ -92,14 +92,14 @@ def files_output_to_HTML(testcases, filepath, html_table):
9292 html_table += " <th>{0}</th>\n " .format (column .strip ())
9393 html_table += " </tr>\n "
9494 # Going through valid testcase files
95- testcases .sort ()
95+ testcases .sort ()
9696 for t in testcases :
9797 f_path = filepath + '/' + t
9898 v_good = '-' # Vulnerabilities in 'good', initial value: nothing found
9999 v_bad = '-' # Vulnerabilities in 'bad', initial value: nothing found
100100 output_good = 'Function missing / Error unrelated to Goblint\n ' # initial value
101101 output_bad = 'Function missing / Error unrelated to Goblint\n ' # initial value
102- # The upcoming 'try' statements are used because at least one test case
102+ # The upcoming 'try' statements are used because at least one test case
103103 #from Juliet suite does not contain both functions.
104104 try :
105105 output_good = goblint_cmd (f_path , t , '_good' ) # 'good' function
@@ -111,7 +111,7 @@ def files_output_to_HTML(testcases, filepath, html_table):
111111 if re .search (v_detection , output_bad ) != None :
112112 v_bad = 'X'
113113 except : v_bad = '?'
114-
114+
115115 # Generating .txt file for the output
116116 title = t + '\n \n '
117117 good_title = '#####################\n _GOOD\n #####################\n \n '
@@ -134,9 +134,9 @@ def files_output_to_HTML(testcases, filepath, html_table):
134134
135135# # # MAIN PROCEDURES # # #
136136
137- # Regex string that is used to confirm that vulnerabilities were detected
137+ # Regex string that is used to confirm that vulnerabilities were detected
138138v_detection = 'is dead!|Summary for all memory locations:'
139-
139+
140140# Blanks for HTML content
141141# '' - empty string for HTML table that will contain results from Goblint
142142# [] - empty array for href values that will be used for table of contents
@@ -153,7 +153,7 @@ def files_output_to_HTML(testcases, filepath, html_table):
153153current_dir = path
154154# Running Goblint on current directory and getting new potential sub-directories
155155directories , HTML = goblint_analyse (current_dir , HTML )
156-
156+
157157# Going through the main CWE directories if present
158158directories .sort ()
159159for d in directories :
@@ -166,7 +166,7 @@ def files_output_to_HTML(testcases, filepath, html_table):
166166 current_subdir = current_dir + '/' + s
167167 # Running Goblint, max depth achieved so no sub-directories
168168 goblint_analyse (current_subdir , HTML )
169-
169+
170170
171171# Generating content for HTML
172172HTML_content = '<p id="top" style="font-size:30px">RESULTS</p>\n '
@@ -177,7 +177,7 @@ def files_output_to_HTML(testcases, filepath, html_table):
177177for href in HTML [1 ]:
178178 HTML_content += '<a href="#' + href + '">' + href + '</a><br>\n '
179179# Adding table of contents and results table together
180- HTML_content = HTML_content + '<br><hr><br>\n ' + HTML [0 ] + '<a href="#top">Go to top</a>'
180+ HTML_content = HTML_content + '<br><hr><br>\n ' + HTML [0 ] + '<a href="#top">Go to top</a>'
181181# Creating HTML file
182182with open ('summary_table.html' , 'w' , encoding = 'utf-8' ) as file :
183183 file .write (HTML_content )
0 commit comments