Changeset a35b458 in mainline for tools/checkers
- Timestamp:
 - 2018-03-02T20:10:49Z (8 years ago)
 - Branches:
 - lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
 - Children:
 - f1380b7
 - Parents:
 - 3061bc1
 - git-author:
 - Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
 - git-committer:
 - Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
 - Location:
 - tools/checkers
 - Files:
 - 
      
- 4 edited
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
tools/checkers/clang.py
r3061bc1 ra35b458 46 46 def clang(root, job): 47 47 "Run Clang on a jobfile" 48 48 49 49 inname = os.path.join(root, job) 50 50 51 51 if (not os.path.isfile(inname)): 52 52 print("Unable to open %s" % inname) 53 53 print("Did you run \"make precheck\" on the source tree?") 54 54 return False 55 55 56 56 inf = open(inname, "r") 57 57 records = inf.read().splitlines() 58 58 inf.close() 59 59 60 60 for record in records: 61 61 arg = jobfile.parse_arg(record) 62 62 if (not arg): 63 63 return False 64 64 65 65 if (len(arg) < 6): 66 66 print("Not enough jobfile record arguments") 67 67 return False 68 68 69 69 srcfname = arg[0] 70 70 tgtfname = arg[1] … … 73 73 base = arg[4] 74 74 options = arg[5].split() 75 75 76 76 srcfqname = os.path.join(base, srcfname) 77 77 if (not os.path.isfile(srcfqname)): 78 78 print("Source %s not found" % srcfqname) 79 79 return False 80 80 81 81 # Only C files are interesting for us 82 82 if (tool != "cc"): 83 83 continue 84 84 85 85 args = ['clang', '-Qunused-arguments', '--analyze', 86 86 '-Xanalyzer', '-analyzer-opt-analyze-headers', … … 88 88 args.extend(options) 89 89 args.extend(['-o', tgtfname, srcfname]) 90 90 91 91 cwd = os.getcwd() 92 92 os.chdir(base) 93 93 retval = subprocess.Popen(args).wait() 94 94 os.chdir(cwd) 95 95 96 96 if (retval != 0): 97 97 return False 98 98 99 99 return True 100 100 … … 103 103 usage(sys.argv[0]) 104 104 return 105 105 106 106 rootdir = os.path.abspath(sys.argv[1]) 107 107 config = os.path.join(rootdir, "HelenOS.config") 108 108 109 109 if (not os.path.isfile(config)): 110 110 print("%s not found." % config) 111 111 print("Please specify the path to HelenOS build tree root as the first argument.") 112 112 return 113 113 114 114 for job in jobs: 115 115 if (not clang(rootdir, job)): … … 117 117 print("Failed job: %s" % job) 118 118 return 119 119 120 120 print 121 121 print("All jobs passed")  - 
      
tools/checkers/jobfile.py
r3061bc1 ra35b458 32 32 def parse_arg(record): 33 33 "Parse jobfile line arguments" 34 34 35 35 arg = [] 36 36 i = 0 … … 38 38 nil = True 39 39 inside = False 40 40 41 41 while (i < len(record)): 42 42 if (inside): … … 56 56 print("Unexpected '%s'" % record[i]) 57 57 return False 58 58 59 59 i += 1 60 60 61 61 if (not nil): 62 62 arg.append(current) 63 63 64 64 return arg  - 
      
tools/checkers/stanse.py
r3061bc1 ra35b458 47 47 def stanse(root, job): 48 48 "Run Stanse on a jobfile" 49 49 50 50 # Convert generic jobfile to Stanse-specific jobfile format 51 51 52 52 inname = os.path.join(root, job) 53 53 outname = os.path.join(root, "_%s" % os.path.basename(job)) 54 54 55 55 if (not os.path.isfile(inname)): 56 56 print("Unable to open %s" % inname) 57 57 print("Did you run \"make precheck\" on the source tree?") 58 58 return False 59 59 60 60 inf = open(inname, "r") 61 61 records = inf.read().splitlines() 62 62 inf.close() 63 63 64 64 output = [] 65 65 for record in records: … … 67 67 if (not arg): 68 68 return False 69 69 70 70 if (len(arg) < 6): 71 71 print("Not enough jobfile record arguments") 72 72 return False 73 73 74 74 srcfname = arg[0] 75 75 tgtfname = arg[1] … … 78 78 base = arg[4] 79 79 options = arg[5] 80 80 81 81 srcfqname = os.path.join(base, srcfname) 82 82 if (not os.path.isfile(srcfqname)): 83 83 print("Source %s not found" % srcfqname) 84 84 return False 85 85 86 86 # Only C files are interesting for us 87 87 if (tool != "cc"): 88 88 continue 89 89 90 90 output.append([srcfname, tgtfname, base, options]) 91 91 92 92 outf = open(outname, "w") 93 93 for record in output: 94 94 outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3])) 95 95 outf.close() 96 96 97 97 # Run Stanse 98 98 99 99 retval = subprocess.Popen(['stanse', '--checker', 'ReachabilityChecker', '--jobfile', outname]).wait() 100 100 101 101 # Cleanup 102 102 103 103 os.remove(outname) 104 104 for record in output: … … 106 106 if (os.path.isfile(tmpfile)): 107 107 os.remove(tmpfile) 108 108 109 109 if (retval == 0): 110 110 return True 111 111 112 112 return False 113 113 … … 116 116 usage(sys.argv[0]) 117 117 return 118 118 119 119 rootdir = os.path.abspath(sys.argv[1]) 120 120 config = os.path.join(rootdir, "HelenOS.config") 121 121 122 122 if (not os.path.isfile(config)): 123 123 print("%s not found." % config) 124 124 print("Please specify the path to HelenOS build tree root as the first argument.") 125 125 return 126 126 127 127 for job in jobs: 128 128 if (not stanse(rootdir, job)): … … 130 130 print("Failed job: %s" % job) 131 131 return 132 132 133 133 print 134 134 print("All jobs passed")  - 
      
tools/checkers/vcc.py
r3061bc1 ra35b458 53 53 def cygpath(upath): 54 54 "Convert Unix (Cygwin) path to Windows path" 55 55 56 56 return subprocess.Popen(['cygpath', '--windows', '--absolute', upath], stdout = subprocess.PIPE).communicate()[0].strip() 57 57 58 58 def preprocess(srcfname, tmpfname, base, options): 59 59 "Preprocess source using GCC preprocessor and compatibility tweaks" 60 60 61 61 global specification 62 62 63 63 args = ['gcc', '-E'] 64 64 args.extend(options.split()) 65 65 args.extend(['-DCONFIG_VERIFY_VCC=1', srcfname]) 66 66 67 67 # Change working directory 68 68 69 69 cwd = os.getcwd() 70 70 os.chdir(base) 71 71 72 72 preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0] 73 73 74 74 tmpf = open(tmpfname, "w") 75 75 tmpf.write(specification) 76 76 77 77 for line in preproc.splitlines(): 78 78 79 79 # Ignore preprocessor directives 80 80 81 81 if (line.startswith('#')): 82 82 continue 83 83 84 84 # Remove __attribute__((.*)) GCC extension 85 85 86 86 line = re.sub(re_attribute, "", line) 87 87 88 88 # Ignore unsupported __builtin_va_list type 89 89 # (a better solution replacing __builrin_va_list with 90 90 # an emulated implementation is needed) 91 91 92 92 line = re.sub(re_va_list, "void *", line) 93 93 94 94 tmpf.write("%s\n" % line) 95 95 96 96 tmpf.close() 97 97 98 98 os.chdir(cwd) 99 99 100 100 return True 101 101 102 102 def vcc(vcc_path, root, job): 103 103 "Run Vcc on a jobfile" 104 104 105 105 # Parse jobfile 106 106 107 107 inname = os.path.join(root, job) 108 108 109 109 if (not os.path.isfile(inname)): 110 110 print("Unable to open %s" % inname) 111 111 print("Did you run \"make precheck\" on the source tree?") 112 112 return False 113 113 114 114 inf = open(inname, "r") 115 115 records = inf.read().splitlines() 116 116 inf.close() 117 117 118 118 for record in records: 119 119 arg = jobfile.parse_arg(record) 120 120 if (not arg): 121 121 return False 122 122 123 123 if (len(arg) < 6): 124 124 print("Not enough jobfile record arguments") 125 125 return False 126 126 127 127 srcfname = arg[0] 128 128 tgtfname = arg[1] … … 131 131 base = arg[4] 132 132 options = arg[5] 133 133 134 134 srcfqname = os.path.join(base, srcfname) 135 135 if (not os.path.isfile(srcfqname)): 136 136 print("Source %s not found" % srcfqname) 137 137 return False 138 138 139 139 tmpfname = "%s.preproc" % srcfname 140 140 tmpfqname = os.path.join(base, tmpfname) 141 141 142 142 vccfname = "%s.i" % srcfname 143 143 vccfqname = os.path.join(base, vccfname); 144 144 145 145 # Only C files are interesting for us 146 146 if (tool != "cc"): 147 147 continue 148 148 149 149 # Preprocess sources 150 150 151 151 if (not preprocess(srcfname, tmpfname, base, options)): 152 152 return False 153 153 154 154 # Run Vcc 155 155 print(" -- %s --" % srcfname) 156 156 retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait() 157 157 158 158 if (retval != 0): 159 159 return False 160 160 161 161 # Cleanup, but only if verification was successful 162 162 # (to be able to examine the preprocessed file) 163 163 164 164 if (os.path.isfile(tmpfqname)): 165 165 os.remove(tmpfqname) 166 166 os.remove(vccfqname) 167 167 168 168 return True 169 169 170 170 def main(): 171 171 global specification 172 172 173 173 if (len(sys.argv) < 2): 174 174 usage(sys.argv[0]) 175 175 return 176 176 177 177 rootdir = os.path.abspath(sys.argv[1]) 178 178 if (len(sys.argv) > 2): … … 180 180 else: 181 181 vcc_path = "/cygdrive/c/Program Files (x86)/Microsoft Research/Vcc/Binaries/vcc" 182 182 183 183 if (not os.path.isfile(vcc_path)): 184 184 print("%s is not a binary." % vcc_path) 185 185 print("Please supply the full Cygwin path to Vcc as the second argument.") 186 186 return 187 187 188 188 config = os.path.join(rootdir, "HelenOS.config") 189 189 190 190 if (not os.path.isfile(config)): 191 191 print("%s not found." % config) 192 192 print("Please specify the path to HelenOS build tree root as the first argument.") 193 193 return 194 194 195 195 specpath = os.path.join(rootdir, "tools/checkers/vcc.h") 196 196 if (not os.path.isfile(specpath)): 197 197 print("%s not found." % config) 198 198 return 199 199 200 200 specfile = file(specpath, "r") 201 201 specification = specfile.read() 202 202 specfile.close() 203 203 204 204 for job in jobs: 205 205 if (not vcc(vcc_path, rootdir, job)): … … 207 207 print("Failed job: %s" % job) 208 208 return 209 209 210 210 print() 211 211 print("All jobs passed")  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.
  