|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 | + |
| 7 | +number_of_breaks=2000 |
| 8 | +package_dir=$(cd "${1-"$here/.."}" && pwd -P) |
| 9 | +files=( "$package_dir"/Sources/*/*.swift "$package_dir"/Tests/*/*.swift ) |
| 10 | + |
| 11 | +function random_array_element() { |
| 12 | + arr=("${!1}") |
| 13 | + echo ${arr["$[RANDOM % ${#arr[@]}]"]} |
| 14 | +} |
| 15 | +
|
| 16 | +function number_of_lines() { |
| 17 | + wc -l < "$1" |
| 18 | +} |
| 19 | +
|
| 20 | +function random_line_number() { |
| 21 | + echo $(( 1 + ( RANDOM % $(number_of_lines "$1") ) )) |
| 22 | +} |
| 23 | +
|
| 24 | +echo "Package dir: $package_dir" |
| 25 | +( set -eux && cd "$package_dir" && swift build --build-tests ) |
| 26 | +xctest_bundle=( "$package_dir/.build/debug"/*PackageTests.xctest ) |
| 27 | +echo "xctest bundle: $xctest_bundle" |
| 28 | +
|
| 29 | +if [[ ! -e "$xctest_bundle" ]]; then |
| 30 | + echo >&2 "ERROR: Couldn't find xctest bundle at $xctest_bundle" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | +run_command=() |
| 34 | +if [[ "$(uname -s)" == Darwin ]]; then |
| 35 | + xctest=$(xcrun -f xctest) |
| 36 | + run_command+=( "$xctest" "$xctest_bundle" ) |
| 37 | +else |
| 38 | + run_command+=( "$xctest_bundle" ) |
| 39 | +fi |
| 40 | +
|
| 41 | +lldb_file=() |
| 42 | +for f in $(seq "$number_of_breaks"); do |
| 43 | + file=$(random_array_element "files[@]") |
| 44 | + line=$(random_line_number "$file") |
| 45 | +
|
| 46 | + lldb_file+=( "break set -o true -f '$file' -l '$line'" ) |
| 47 | +done |
| 48 | +lldb_file+=( run ) |
| 49 | +for f in $(seq "$number_of_breaks"); do |
| 50 | + lldb_file+=( 'frame variable --show-all-children' ) |
| 51 | +
|
| 52 | + lldb_file+=( cont ) |
| 53 | +done |
| 54 | +
|
| 55 | +lldb_response_file=$(mktemp /tmp/lldb-smoker_XXXXXX) |
| 56 | +for command in "${lldb_file[@]}"; do |
| 57 | + echo "$command" >> "$lldb_response_file" |
| 58 | +done |
| 59 | +
|
| 60 | +echo "LLDB response file: $lldb_response_file" |
| 61 | +sleep 0.5 |
| 62 | +lldb_command=( lldb --batch --source "$lldb_response_file" -- \ |
| 63 | + "${run_command[@]}" ) |
| 64 | +
|
| 65 | +set +e |
| 66 | +set -x |
| 67 | +"${lldb_command[@]}" |
| 68 | +set +x |
| 69 | +set -e |
| 70 | +
|
| 71 | +echo "LLDB response file: $lldb_response_file" |
| 72 | +echo "LLDB command: ${lldb_command[*]}" |
0 commit comments