| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
import os |
| 15 |
import sys |
| 16 |
|
| 17 |
EXIT_SUCCESS = 0 |
| 18 |
|
| 19 |
ERROR_EXIT_CODE = 1 |
| 20 |
|
| 21 |
NUM_OF_LINES_TO_PRINT = 15 |
| 22 |
|
| 23 |
|
| 24 |
def find_log_file(path): |
| 25 |
for f in os.listdir(path): |
| 26 |
if "LastDynamicAnalysis" in f: |
| 27 |
return os.path.join(path, f) |
| 28 |
|
| 29 |
raise FileNotFoundError("LastDynamicAnalysis log file is not found!") |
| 30 |
|
| 31 |
|
| 32 |
def detect_leak(file): |
| 33 |
fd_leak_detected = False |
| 34 |
lines = file.readlines() |
| 35 |
for i in range(len(lines)): |
| 36 |
if "FILE DESCRIPTORS:" in lines[i]: |
| 37 |
|
| 38 |
line_elements = lines[i].split() |
| 39 |
open_fd_count = line_elements[line_elements.index("DESCRIPTORS:") + 1] |
| 40 |
std_fd_count = line_elements[line_elements.index("std)") - 1][1:] |
| 41 |
|
| 42 |
|
| 43 |
if int(open_fd_count) > int(std_fd_count) + 1: |
| 44 |
for j in range(NUM_OF_LINES_TO_PRINT): |
| 45 |
print(lines[i + j], end="") |
| 46 |
print() |
| 47 |
fd_leak_detected = True |
| 48 |
return fd_leak_detected |
| 49 |
|
| 50 |
|
| 51 |
def main(): |
| 52 |
|
| 53 |
print("############################################################################") |
| 54 |
print("################# Test for Leaking File Descriptors ########################") |
| 55 |
print("############################################################################") |
| 56 |
|
| 57 |
with open(find_log_file(sys.argv[1]), 'r') as file: |
| 58 |
if detect_leak(file): |
| 59 |
sys.exit(ERROR_EXIT_CODE) |
| 60 |
|
| 61 |
return EXIT_SUCCESS |
| 62 |
|
| 63 |
|
| 64 |
if __name__ == '__main__': |
| 65 |
main() |