def decide(self): self.changed = False if (len(self.votes) == 0): return stats = counts_to_stats(self.counts) if (stats is None): throw_error("No votes") # For the program to vote, # require the number of appearances of the function # to be above the lower quartile, or 2, # whichever is larger (_, threshold, _, _) = stats if (threshold <= 1.0): threshold = 2.0 self.result = init_vote_result(self.stat_type, self.vote_ratio) bins = set() # For each vote, # only count programs with enough function appearances # towards the vote. for (key, votes) in self.votes.items(): if (not key is None): bins.add(to_label(key)) n_votes = 0 for (share, strength) in votes: if (strength >= threshold): n_votes += share self.result.count_vote(key, n_votes) # Check if there are too many bins. if (self.check_bins(bins, self.total_strength)): self.result.is_infallible = True return
def update(self, parsed_value): if (self.type_marker != parsed_value.type_marker): throw_error("Expected to add type " + \ "%s, but got %s"%(self.type_marker, \ parsed_value.type_marker)) updated_counts = self.typed_update(parsed_value) self.total_count += parsed_value.to_add return updated_counts
def initialize_raw_stat(type_marker, as_list=False): if (type_marker == BOOL_TYPE_START): return BooleanStat(as_list) elif (type_marker == PTR_TYPE_START): return PointerStat(as_list) elif (type_marker == INT_TYPE_START): return IntegerStat(as_list) else: throw_error("Unknown type " + type_marker)
def __init__(self, pre_segment, to_add=1): if (len(pre_segment.original) > 0): self.have_data = True self.function = pre_segment.function self.location = pre_segment.location value_pair = parse_value(pre_segment.value_str, to_add) if (value_pair is None): throw_error("Failed to parse return value, " + \ pre_segment.value_str) self.value = value_pair[1] else: self.have_data = False self.count = 0
def typed_update(self, parsed_value): value = parsed_value.pointer to_add = parsed_value.to_add updated_counts = [] if (value & PTR_UNKNOWN != value): throw_error("Unknown pointer value: %d" % value) if (value == PTR_NOT_NULL): self.not_null_count += to_add updated_counts.append(self.not_null_count) if (value == PTR_NULL): self.null_count += to_add updated_counts.append(self.null_count) if (value == PTR_UNKNOWN): self.unknown_count += to_add updated_counts.append(self.unknown_count) return updated_counts
def typed_update(self, parsed_value): value = parsed_value.boolean to_add = parsed_value.to_add updated_counts = [] if (value & BOOL_UNKNOWN != value): throw_error("Unknown boolean value: %d" % value) if (value == BOOL_TRUE): self.true_count += to_add updated_counts.append(self.true_count) if (value == BOOL_FALSE): self.false_count += to_add updated_counts.append(self.false_count) if (value == BOOL_UNKNOWN): self.unknown_count += to_add updated_counts.append(self.unknown_count) return updated_counts
def parse_spec_value(string): parts = string.split(SPEC_DELIM) name = parts[NAME_ID] type_marker = parts[TYPE_MARKER_ID] expression = parts[EXPRESSION_ID] if (expression == INFALLIBLE_MARKER): return (name, type_marker, None) value = None if (type_marker == BOOL_TYPE_START): value = BoolSpecValue(expression) elif (type_marker == PTR_TYPE_START): value = PtrSpecValue(expression) elif (type_marker == INT_TYPE_START): value = parse_int_spec_value(expression) else: throw_error("Unknown error specification type, " + type_marker) return (name, type_marker, value)
def _set_ranges(self, ranges, do_clone): self.ranges = [] for range_member in ranges: if (len(self.ranges) > 0): last = self.ranges[-1] most = last.most if (range_member.least <= most): throw_error("Overlapping or " + \ "out-ouf-order ranges, " + \ "%s and %s"%(last, \ range_member)) new_member = None if (do_clone): new_member = range_member.clone() else: new_member = range_member self.ranges += new_member.flatten() self.need_flatten = False
def typed_update(self, parsed_value): int_value = parsed_value.value to_add = parsed_value.to_add updated_counts = [] if (int_value == None): parsed_range_value = parsed_value.range_value if (parsed_range_value is None): self.range_list.increment(to_add) else: self.add_range_list(parsed_range_value) elif (int_value.__class__ == LiteralIntValue): value = int_value.value self.add_range_list(RangeList([RangeNode(value, value, \ to_add)], \ self.as_list)) elif (int_value.__class__ == AssignmentsIntValue): right = int_value.main_value.right if (right == None): self.range_list.increment(to_add) else: right_ranges = right.ranges new_ranges = [] for rr in right_ranges: new_ranges.append(RangeNode(rr[0], \ rr[1], \ to_add)) range_list = RangeList(new_ranges, \ self.as_list) if (len(new_ranges) == 0): range_list.increment(to_add) self.add_range_list(range_list) else: throw_error(str(int_value) + \ " is of unknown integer type, " + \ str(int_value.__class__)) if (len(self.range_list.ranges) == 0): rest_count = None if (self.range_list.as_list): rest_count = len(self.range_list.rest) else: rest_count = self.range_list.rest if (rest_count == 0): throw_error("No ranges added") return updated_counts
def generate_votes(self): need_any_count = True self.vote_points = [] most_exit_vote = ExtremeVote(False, self.high_ratio, \ allow_tie = self.rangify, \ only_threshold = self.rangify) # Process constraints to vote on them. index = 0 for (key, followers) in self.branch_stat: need_any_count = False original_count = len(followers) if (is_undefined(self.callee_type, key)): continue exit_count = 0 path_lengths = [] for follower in followers: if (follower.path.is_error_exit): exit_count += 1 path_lengths.append(follower.count) count = original_count - exit_count if (exit_count > 0): most_exit_vote.tally(index, exit_count) if (original_count > 0): (_, _, median_length, _) = \ counts_to_stats(path_lengths) point = VotePoint(count, median_length) self.vote_points.append((key, point)) index += 1 if (need_any_count): throw_error("Passed empty vote statistic") # Vote based on error exits. self.exit_votes = most_exit_vote.vote() # Vote based on path statistics. self.tally_threshold() if (not self.threshold_votes is None): for index in self.threshold_votes: self.vote_points[index][1].choose_threshold()
def get_overlaps(self, other): self_ordered = [] for entry in self: (key, value) = entry if (not self.key_is_unknown(key)): self_ordered.append(entry) other_ordered = [] for entry in other: (key, value) = entry if (not self.key_is_unknown(key)): other_ordered.append(entry) overlaps = [] for entry_i in range(len(self_ordered)): (self_key, self_value) = self_ordered[entry_i] (other_key, other_value) = other_ordered[entry_i] if (self_key != other_key): throw_error("Entry %d does not match: %s, %s", \ entry_i, self_key, other_key) if (self.gen_count(self_value) > 0 and \ self.gen_count(other_value) > 0): overlaps.append(key, (self_value, other_value)) return overlaps
"%s,%s,%s,%s\n"%(function, label, prediction, \ count) return "Normalized sums:\n" + sorted_string + \ "\nfunction,constraint,prediction,count\n" + \ classification_str + \ "\nReturn error specifications:\n" + \ str(self.error_specs) if __name__ == "__main__": OUTPUT_I = 1 INPUT_I = OUTPUT_I + 1 if (len(argv) <= OUTPUT_I): throw_error("Please enter the output file") output_name = argv[OUTPUT_I] output_file = open(output_name, "w") if (output_file is None): throw_error("Could not open %s for output file" % output_file) if (len(argv) > INPUT_I): input_name = argv[INPUT_I] input_file = open(input_name, "r") if (input_file is None): output_file.close() throw_error("Could not open " + input_file + \ " for input file") else: input_file = stdin
len(caller_report) == 0)): self.println("%s:\n%s"%(caller, \ caller_report)) n_reported += n_bugs self.println("Total: %d"%(n_reported)) return n_reported if __name__ == "__main__": OUT_I = 1 SUMMARY_I = OUT_I + 1 PROGRAMS_START = SUMMARY_I + 1 BUGS_SUFFIX = ".bugs" if (len(argv) <= PROGRAMS_START): throw_error("Usage [output directory] " + \ "[error specification] [log files]") summary_name = argv[SUMMARY_I] summary_file = open(summary_name, "r") if (summary_file is None): throw_error("Could not open summary file, %s"%summary_name) error_spec_parser = FullErrorSpec(summary_file) error_spec_parser.read_lines() summary_file.close() out_dir = argv[OUT_I] n_reported = 0 for log_in_name in argv[PROGRAMS_START : ]: start = time() bugs_out_name = out_dir + \