-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript-run-all-mand.sh
More file actions
executable file
·88 lines (72 loc) · 3 KB
/
Copy pathscript-run-all-mand.sh
File metadata and controls
executable file
·88 lines (72 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# Path to your minishell executable
MINISHELL_PATH="./minishell"
# Check if minishell exists and is executable
if [ ! -x "$MINISHELL_PATH" ]; then
echo "Minishell executable not found or not executable at $MINISHELL_PATH"
exit 1
fi
# Base directory for command files
COMMANDS_DIR=./42_minishell_tester/cmds/mand
# Check if the command directory exists
if [ ! -d "$COMMANDS_DIR" ]; then
echo "Command directory not found at $COMMANDS_DIR"
exit 1
fi
# Track commands with leaks
LEAKY_COMMANDS=()
# Loop through each file in the cmds/mand directory
for COMMANDS_FILE in "$COMMANDS_DIR"/*; do
# Check if the file is readable
if [ ! -f "$COMMANDS_FILE" ] || [ ! -r "$COMMANDS_FILE" ]; then
echo "Cannot read file $COMMANDS_FILE, skipping..."
continue
fi
echo "Processing file: $COMMANDS_FILE"
# Read each command from the current file and execute it with Valgrind
while IFS= read -r command; do
# Skip empty lines and comments
[[ -z "$command" || "$command" =~ ^# ]] && continue
echo "Running command: $command"
TEMP_OUTPUT=$(mktemp)
# Run Valgrind with the command piped to minishell and capture the output
valgrind --leak-check=full --trace-children=yes --gen-suppressions=all --show-leak-kinds=all \
--track-fds=yes --suppressions=vg.supp "$MINISHELL_PATH" <<< "$command" &> "$TEMP_OUTPUT"
# Check the output for signs of memory leaks
if grep -Eq "definitely lost: [1-9]|indirectly lost: [1-9]|possibly lost: [1-9]|still reachable: [1-9]" "$TEMP_OUTPUT"; then
echo "Leak detected for command: $command in file: $COMMANDS_FILE"
LEAKY_COMMANDS+=("File: $COMMANDS_FILE | Command: $command")
cat "$TEMP_OUTPUT"
fi
# Check for file descriptor inconsistencies
FD_LINE=$(grep -Eo "FILE DESCRIPTORS: [0-9]+ open \([0-9]+ std\)" "$TEMP_OUTPUT")
if [[ "$FD_LINE" =~ ([0-9]+)\ open\ \(([0-9]+)\ std ]]; then
TOTAL_FD="${BASH_REMATCH[1]}"
STD_FD="${BASH_REMATCH[2]}"
if [ "$TOTAL_FD" -ne "$STD_FD" ]; then
echo "File descriptor mismatch detected for command: $command in file: $COMMANDS_FILE"
FD_ISSUE_COMMANDS+=("File: $COMMANDS_FILE | Command: $command | Total FD: $TOTAL_FD, STD FD: $STD_FD")
cat "$TEMP_OUTPUT"
fi
fi
rm "$TEMP_OUTPUT"
done < "$COMMANDS_FILE"
done
# Display all commands with leaks at the end
if [ ${#LEAKY_COMMANDS[@]} -gt 0 ]; then
echo -e "\nCommands with memory leaks:"
for entry in "${LEAKY_COMMANDS[@]}"; do
echo "$entry"
done
else
echo -e "\nNo memory leaks detected in any commands."
fi
# Display all commands with file descriptor issues
if [ ${#FD_ISSUE_COMMANDS[@]} -gt 0 ]; then
echo -e "\nCommands with file descriptor issues:"
for entry in "${FD_ISSUE_COMMANDS[@]}"; do
echo "$entry"
done
else
echo -e "\nNo file descriptor issues detected in any commands."
fi