Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#4561 from Pinata-Consulting/d…
Browse files Browse the repository at this point in the history
…elta-debug-fix-nits

deltaDebug: fix nits
  • Loading branch information
maliberty authored Jan 22, 2024
2 parents 63d17a0 + 7ffa528 commit 354fb0a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions etc/deltaDebug.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
################################
# You need to provide the script with 3 main arguments
# --base_db_path <the relative path to the db file to perform the step on>
# --error_string <the output that indicates a target error has occured>
# --error_string <the output that indicates a target error has occurred>
# --step <Command used to perform a step on the base_db file>
# You also have 1 additional argument
# --persistence <a value in [1,6] indicating maximum granularity where maximum granularity = 2^persistence>
Expand All @@ -11,11 +11,11 @@
# EXAMPLE COMMAND:
# Assuming running in a directory with the following files in:
# deltaDebug.py base.odb step.sh
# openroad -python deltaDebug.py --base_db_path base.odb --error_string <any_possible_error> --step './step.sh'
# --persistence 5 --use_stdout --dump_def
# openroad -python deltaDebug.py --base_db_path base.odb --error_string <any_possible_error> --step './step.sh'
# --persistence 5 --use_stdout --dump_def

# N.B: step.sh shall read base.odb (or base.def in case the flag dump_def = 1) and operate on it
# where the script manipulates base.odb between steps to reduce its size.
# where the script manipulates base.odb between steps to reduce its size.
################################

import odb
Expand All @@ -36,7 +36,7 @@

parser = argparse.ArgumentParser('Arguments for delta debugging')
parser.add_argument('--base_db_path', type=str, help='Path to the db file to perform the step on')
parser.add_argument('--error_string', type=str, help='The output that indicates target error has occured')
parser.add_argument('--error_string', type=str, help='The output that indicates target error has occurred')
parser.add_argument('--step', type=str, help='Command used to perform step on the input odb file')
parser.add_argument('--start', type=int, default=persistence_start_range[0],
choices=persistence_start_range,
Expand Down Expand Up @@ -99,19 +99,19 @@ def __init__(self, opt):
# A variable to hold the base_db
self.base_db = None

# Debugging level
# Debugging level
# cutLevel.Insts starts with inst then nets, cutLevel.Nets cuts nets only.
self.cut_level = cutLevel.Insts

# step command
self.step = opt.step

def debug(self):
# copy original base db file to avoid overwritting it
# copy original base db file to avoid overwriting it
print("Backing up original base file.")
shutil.copy(self.base_db_file, self.original_base_db_file)

# Rename the base db file to a temp name to keep it from overwritting across the two steps cut
# Rename the base db file to a temp name to keep it from overwriting across the two steps cut
os.rename(self.base_db_file, self.temp_base_db_file)

# Perform a step with no cuts to measure timeout
Expand Down Expand Up @@ -160,7 +160,7 @@ def debug(self):
if os.path.exists(self.temp_base_db_file):
os.rename(self.temp_base_db_file, self.deltaDebug_result_base_file)

# Restoring the original base_db file
# Restoring the original base_db file
if os.path.exists(self.original_base_db_file):
os.rename(self.original_base_db_file, self.base_db_file)

Expand All @@ -169,13 +169,13 @@ def debug(self):
print("Delta Debugging Done!")

# A function that do a cut in the db, writes the base db to disk
# and calls the step funtion, then returns the stderr of the step.
# and calls the step function, then returns the stderr of the step.
def perform_step(self, cut_index=-1):
# read base db in memory
self.base_db = odb.dbDatabase.create()
self.base_db = odb.read_db(self.base_db, self.temp_base_db_file)

# Cut the block with the given step index.
# Cut the block with the given step index.
# if cut index of -1 is provided it means
# that no cut will be made.
if (cut_index != -1):
Expand All @@ -198,13 +198,13 @@ def perform_step(self, cut_index=-1):
if (cut_index != -1):
self.step_count += 1

# Perform step, and check the error code
# Perform step, and check the error code
start_time = time.time()
error_string = self.run_command(self.step)
end_time = time.time()

# Handling timeout so as not to run the code for time
# that is more than the original buggy code or a
# that is more than the original buggy code or a
# buggy cut.
if (error_string is not None):
self.timeout = max(120, 1.2 * (end_time - start_time))
Expand Down Expand Up @@ -249,7 +249,7 @@ def poll(self, process, poll_obj, start_time):
# to avoid busywaiting
if poll_obj.poll(1):
if (self.use_stdout == 0):
output = process.stderr.readline()
output = process.stderr.readline()
else:
output = process.stdout.readline()

Expand Down Expand Up @@ -297,7 +297,7 @@ def clear_dont_touch_net(self, net):

# A function that cuts the block according to the given direction
# and ratio. It also uses the class cut level to identify
# whehter to cut Insts or Nets.
# whether to cut Insts or Nets.
def cut_block(self, index=0):
block = self.base_db.getChip().getBlock()
message = [f"Step {self.step_count}"]
Expand Down

0 comments on commit 354fb0a

Please sign in to comment.