-
Notifications
You must be signed in to change notification settings - Fork 729
ci: add open fds valgrind check #4851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e6b8698
ci: add testing script for open-fds leak
2b30921
ci: add additional logic check to handle corner cases
add4c13
ci: only store information for leaking fds
104b0dc
Merge branch 'main' into open-fds-valgrind-check
ac9c9a8
ci: make fd_pattern regex more generic
d3e973b
ci: fix a typo for corner
546ac00
ci: address PR comments
029358b
ci: address PR comments
39456d8
ci: address PR comments
5158969
ci: Address PR comments
d888597
ci: address PR comments
9bb5d57
ci: add output snippet as comments on s2n_open_fds_test
8952b8f
address PR comments
03cc0c8
address PR comments
b611239
improve the script output format
d1c739a
address comments:
344d447
address PR comments:
fef7eb8
Merge branch 'main' into open-fds-valgrind-check
boquan-fang dc0e3d3
update Ubuntu version for pedantic valgrind to 24
fd4e9cf
Merge branch 'main' into open-fds-valgrind-check
boquan-fang 19135eb
Merge branch 'main' into open-fds-valgrind-check
boquan-fang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This script parses the LastDynamicAnalysis file generated by Valgrind running through CTest memcheck. | ||
# It identifies any leaking file descriptors and triggers an error when detected. | ||
# This enhances the capabilities of existing Valgrind checks. | ||
# Output snippet for open file descriptors: | ||
# ==6652== FILE DESCRIPTORS: 6 open (3 std) at exit. | ||
# ==6652== Open AF_INET socket 6: 127.0.0.1:36915 <-> unbound | ||
# ==6652== at 0x498B2EB: socket (syscall-template.S:120) | ||
# ==6652== by 0x16CD16: s2n_new_inet_socket_pair (s2n_self_talk_ktls_test.c:69) | ||
# ==6652== by 0x15DBB2: main (s2n_self_talk_ktls_test.c:168) | ||
# ==6652== | ||
import os | ||
jmayclin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import sys | ||
|
||
EXIT_SUCCESS = 0 | ||
# Exit with error code 1 if leaking fds are detected. | ||
ERROR_EXIT_CODE = 1 | ||
# This test is designed to be informational only, so we only print fifteen lines of error messages when a leak is detected. | ||
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() | ||
for i in range(len(lines)): | ||
jmayclin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if "FILE DESCRIPTORS:" in lines[i]: | ||
# Example line: `==6096== FILE DESCRIPTORS: 4 open (3 std) at exit.` | ||
line_elements = lines[i].split() | ||
open_fd_count = line_elements[line_elements.index("DESCRIPTORS:") + 1] | ||
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: | ||
for j in range(NUM_OF_LINES_TO_PRINT): | ||
print(lines[i + j], end="") | ||
print() | ||
fd_leak_detected = True | ||
return fd_leak_detected | ||
|
||
|
||
def main(): | ||
# Print banner of the test | ||
print("############################################################################") | ||
print("################# Test for Leaking File Descriptors ########################") | ||
print("############################################################################") | ||
|
||
with open(find_log_file(sys.argv[1]), 'r') as file: | ||
if detect_leak(file): | ||
sys.exit(ERROR_EXIT_CODE) | ||
|
||
return EXIT_SUCCESS | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.