forked from julasamer/swift-compiler-crashes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.get_crash_hash.sh
23 lines (22 loc) · 1.04 KB
/
test.get_crash_hash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# Definition of crash uniqueness (improvements welcome!) …
# A crash is treated as non-duplicate if it has an unique "crash hash" as computed by the following crash hash function:
get_crash_hash() {
local compilation_output
local unreachable_message
local assertion_message
local normalized_stack_trace
compilation_output="$1"
unreachable_message=$(grep "UNREACHABLE executed at " <<< "${compilation_output}" | head -1)
assertion_message=$(grep "Assertion " <<< "${compilation_output}" | tr ":" "\n" | grep "Assertion " | head -1)
normalized_stack_trace="${unreachable_message}${assertion_message}"
if [[ ${normalized_stack_trace} == "" ]]; then
normalized_stack_trace=$(grep --text -E '^#[0-9] 0x[0-9a-f]{16} ' <<< "${compilation_output}" | cut -f1 -d'/' | grep --text -E swift | head -1 | tr " " "\n" | grep --text -E '^0x[0-9a-f]{16}$' | head -1)
fi
if [[ ${normalized_stack_trace} == "" ]]; then
crash_hash=""
else
crash_hash=$(shasum <<< "${normalized_stack_trace}" | head -c10)
fi
echo -n "${crash_hash}"
}