Skip to content

Commit

Permalink
address PR comments:
Browse files Browse the repository at this point in the history
* reduce the abstraction of main function
  • Loading branch information
Boquan Fang committed Nov 7, 2024
1 parent d1c739a commit 344d447
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions codebuild/bin/s2n_open_fds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
NUM_OF_LINES_TO_PRINT = 15


def find_log_file(path):
for f in os.listdir(path):
if "LastDynamicAnalysis" in f:
return os.path.join(path, f)

raise FileNotFoundError("LastDynamicAnalysis log file is not found!")


def detect_leak(file):
fd_leak_detected = False
lines = file.readlines()
Expand All @@ -32,7 +40,7 @@ def detect_leak(file):
std_fd_count = line_elements[line_elements.index("std)") - 1][1:]
# CTest memcheck writes to a LastDynamicAnslysis log file.
# We allow that fd to remain opened.
if int(open_fd_count) - int(std_fd_count) > 1:
if int(open_fd_count) > int(std_fd_count) + 1:
for j in range(NUM_OF_LINES_TO_PRINT):
print(lines[i + j], end="")
print()
Expand All @@ -46,16 +54,11 @@ def main():
print("################# Test for Leaking File Descriptors ########################")
print("############################################################################")

path = sys.argv[1]
for f in os.listdir(path):
if "LastDynamicAnalysis" in f:
with open(os.path.join(path, f), 'r') as file:
if detect_leak(file):
sys.exit(ERROR_EXIT_CODE)
else:
return EXIT_SUCCESS
with open(find_log_file(sys.argv[1]), 'r') as file:
if detect_leak(file):
sys.exit(ERROR_EXIT_CODE)

raise FileNotFoundError("LastDynamicAnalysis log file is not found!")
return EXIT_SUCCESS


if __name__ == '__main__':
Expand Down

0 comments on commit 344d447

Please sign in to comment.