Esempio n. 1
0
def search_config(change_set, type_set, switch_set, group_set):
    # keep searching while the type set is not searched throughout
    while not utilities.is_empty(type_set):
        # search from bottom up
        to_2nd_highest_precision(change_set, type_set, switch_set)
        if not is_valid_config():
            dd_search_config(change_set, type_set, switch_set, group_set, 2)
        # remove types and switches that cannot be changed  ??????????????????????????
        # change_set[i]["type"] = "longdouble"
        # type_set[i] = ["float", "double", "longdouble"]
        # this means change_set[i] cannot be changed, so clear type_set[i] and switch_set[i]
        for i in range(len(change_set)):
            if len(type_set[i]
                   ) > 0 and change_set[i]["type"] == type_set[i][-1]:
                del type_set[i][:]
                if len(switch_set[i]) > 0:
                    del switch_set[i][:]
        # remove highest precision from each type vector
        for i in range(len(type_set)):
            type_vector = type_set[i]
            switch_vector = switch_set[i]
            if len(type_vector) > 0:
                type_vector.pop()
            if len(switch_vector) > 0:
                switch_vector.pop()
Esempio n. 2
0
def main():
  global search_counter
  bitcode = sys.argv[1]
  search_conf_file = sys.argv[2]
  original_conf_file = sys.argv[3]

  #
  # delete log file if exists
  #
  try:
    os.remove("log.dd")
  except OSError:
    pass

  #
  # parsing config files
  #
  search_conf = json.loads(open(search_conf_file, 'r').read())
  original_conf = json.loads(open(original_conf_file, 'r').read())
  search_changes = search_conf["config"]
  change_set = []
  type_set = []

  #
  # record the change set
  #
  for search_change in search_changes:
    type_vector = search_change.values()[0]["type"]
    if isinstance(type_vector, list):
      type_set.append(type_vector)
      change_set.append(search_change.values()[0])

  #
  # search for valid configuration
  #
  print "Searching for valid configuration using delta-debugging algorithm ..."

  # get original score
  utilities.to_highest_precision(change_set, type_set)
  utilities.run_config(search_conf, original_conf, bitcode, search_counter)
  original_score = utilities.get_dynamic_score(search_counter) * 1.05
  search_counter = search_counter + 1

  # keep searching while the type set is not searched throughout
  while not utilities.is_empty(type_set):
    search_config(change_set, type_set, search_conf, original_conf, bitcode, original_score)

  # get the score of modified program
  utilities.run_config(search_conf, original_conf, bitcode, search_counter)
  modified_score = utilities.get_dynamic_score(search_counter)
  search_counter = search_counter + 1

  if modified_score <= original_score:
    print "Check valid_" + bitcode + ".json for the valid configuration file"
    # print valid configuration file and diff file
    utilities.print_config(search_conf, "dd2_valid_" + bitcode + ".json")
    utilities.print_diff(search_conf, original_conf, "dd2_diff_" + bitcode + ".json")
  else:
    print "No configuration is found!"
Esempio n. 3
0
def main():
  global search_counter
  bitcode = sys.argv[1]
  search_conf_file = sys.argv[2]
  original_conf_file = sys.argv[3]

  #
  # delete log file if exists
  #
  try:
    os.remove("log.dd")
  except OSError:
    pass

  #
  # parsing config files
  #
  search_conf = json.loads(open(search_conf_file, 'r').read())
  original_conf = json.loads(open(original_conf_file, 'r').read())
  search_changes = search_conf["config"]
  change_set = []
  type_set = []

  #
  # record the change set
  #
  for search_change in search_changes:
    type_vector = search_change.values()[0]["type"]
    if isinstance(type_vector, list):
      type_set.append(type_vector)
      change_set.append(search_change.values()[0])


  # get original score
  utilities.to_highest_precision(change_set, type_set)
  utilities.run_config(search_conf, original_conf, bitcode, search_counter)
  original_score = utilities.get_dynamic_score(search_counter) * 1.05
  search_counter = search_counter + 1

  cpu_no = CPU_NO
  # multiprocessing.cpu_count()
  #
  # search for valid configuration
  #
  print "Searching for valid configuration using delta-debugging algorithm ..."
  # keep searching while the type set is not searched throughout
  while not utilities.is_empty(type_set):
    #
    # distribute change set
    #
    dis_no = ((len(change_set)-1)/cpu_no)+1
    queue = Queue()
    workers = []
    for i in xrange(cpu_no):
      workers.append(Process(target=search_config_dis, args=(
        change_set[i*dis_no:min((i+1)*dis_no, len(change_set))],
        type_set[i*dis_no:min((i+1)*dis_no, len(type_set))],
        search_conf, original_conf, bitcode, search_counter + i*dis_no*dis_no, i*dis_no, queue)))

    utilities.to_highest_precision(change_set, type_set)
    for w in workers:
      w.start()

    for w in workers:
      w.join()

    print len(type_set)
    while not queue.empty():
      inx = queue.get()
      print inx
      del(type_set[inx][:])

    j = 0
    while j < len(type_set):
      if len(type_set[j]) == 0:
        type_set.pop(j)
        change_set.pop(j)
      else:
        j += 1

    search_counter += cpu_no*dis_no*dis_no
    search_config(change_set, type_set, search_conf, original_conf, bitcode, original_score)

  # get the score of modified program
  utilities.run_config(search_conf, original_conf, bitcode, search_counter)
  modified_score = utilities.get_dynamic_score(search_counter)
  search_counter = search_counter + 1

  if modified_score <= original_score:
    print "Check valid_" + bitcode + ".json for the valid configuration file"
    # print valid configuration file and diff file
    utilities.print_config(search_conf, "dd2_valid_" + bitcode + ".json")
    utilities.print_diff(search_conf, original_conf, "dd2_diff_" + bitcode + ".json")
  else:
    print "No configuration is found!"
Esempio n. 4
0
def main():
    global search_counter
    bitcode = sys.argv[1]
    search_conf_file = sys.argv[2]
    original_conf_file = sys.argv[3]

    #
    # delete log file if exists
    #
    try:
        os.remove("log.dd")
    except OSError:
        pass

    #
    # parsing config files
    #
    search_conf = json.loads(open(search_conf_file, 'r').read())
    original_conf = json.loads(open(original_conf_file, 'r').read())
    search_changes = search_conf["config"]
    change_set = []
    type_set = []

    #
    # record the change set
    #
    for search_change in search_changes:
        type_vector = search_change.values()[0]["type"]
        if isinstance(type_vector, list):
            type_set.append(type_vector)
            change_set.append(search_change.values()[0])

    #
    # search for valid configuration
    #
    print "Searching for valid configuration using delta-debugging algorithm ..."

    # get original score
    utilities.to_highest_precision(change_set, type_set)
    utilities.run_config(search_conf, original_conf, bitcode, search_counter)
    original_score = utilities.get_dynamic_score(search_counter) * 1.05
    search_counter = search_counter + 1

    # keep searching while the type set is not searched throughout
    while not utilities.is_empty(type_set):
        search_config(change_set, type_set, search_conf, original_conf,
                      bitcode, original_score)

    # get the score of modified program
    utilities.run_config(search_conf, original_conf, bitcode, search_counter)
    modified_score = utilities.get_dynamic_score(search_counter)
    search_counter = search_counter + 1

    if modified_score <= original_score:
        print "Check valid_" + bitcode + ".json for the valid configuration file"
        # print valid configuration file and diff file
        utilities.print_config(search_conf, "dd2_valid_" + bitcode + ".json")
        utilities.print_diff(search_conf, original_conf,
                             "dd2_diff_" + bitcode + ".json")
    else:
        print "No configuration is found!"