Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251#!/bin/bashset -euo pipefail
cd "$(dirname "$0")/../.."unset BASH_ENVif [[ -z ${PARCEL_DEV_BINARY:-} ]]; then PARCEL_DEV_BINARY=$(Scripts/parcel-dev.sh --path)fiPARCEL_DEV_BINARY=$(realpath "$PARCEL_DEV_BINARY")export PARCEL_DEV_BINARYwork=$(mktemp -d "${TMPDIR:-/tmp}/parcel smoke tests.XXXXXX")checker=cleanup() { if [[ -n $checker ]]; then kill -TERM "$checker" 2>/dev/null || true wait "$checker" 2>/dev/null || true fi if [[ -f $work/launch.log ]]; then while IFS='|' read -r pid _; do if kill -0 "$pid" 2>/dev/null; then kill -KILL "$pid"; fi done < "$work/launch.log" fi rm -rf "$work"}trap cleanup EXITmkdir -p "$work/project/Scripts" "$work/bin" "$work/tmp"cp Scripts/product.env Scripts/version.sh Scripts/packaging-paths.sh Scripts/bundle-preflight.sh \ Scripts/parcel-dev.sh Scripts/check-bundle.sh Scripts/check-app-icons.sh "$work/project/Scripts/"mkdir -p "$work/project/Packaging/AlternateIcons"cp Packaging/AlternateIcons/IconTool.swift "$work/project/Packaging/AlternateIcons/"app="$work/project/build/Parcel.app"framework="$app/Contents/Frameworks/Sparkle.framework/Versions/B"mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources/bin" "$framework/XPCServices"for component in Sparkle Autoupdate Updater.app XPCServices/Installer.xpc XPCServices/Downloader.xpc; do touch "$framework/$component"doneditto Sources/ParcelUI/Resources/AppIcons "$app/Contents/Resources/Parcel_ParcelUI.bundle/Contents/Resources"cp Resources/Info.plist "$app/Contents/Info.plist"Scripts/parcel-dev.sh update-metadata configure "$app/Contents/Info.plist" debug
cat > "$work/fixture.c" <<'FIXTURE'#include <signal.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#ifdef LINKED_DEPENDENCYextern int smoke_dependency(void);#endifint main(int argc, char **argv) { FILE *log = fopen(getenv("TEST_LAUNCH_LOG"), "a"); if (!log) { return 90; } const char *binding = getenv("DYLD_BIND_AT_LAUNCH"); fprintf(log, "%d|%s|%s|%s\n", getpid(), argv[0], argc == 2 ? argv[1] : "invalid", binding ? binding : "unset"); if (fclose(log)) { return 91; } if (argc != 2) { return 92; } const char *mode; if (!strcmp(argv[1], "--version")) { mode = getenv("TEST_CLI_MODE"); if (!mode || !strcmp(mode, "success")) { puts("0.1.0"); return 0; } if (!strcmp(mode, "invalid")) { puts("not a version"); return 0; } } else if (!strcmp(argv[1], "--smoke")) { mode = getenv("TEST_APP_MODE"); if (!mode || !strcmp(mode, "success")) { return 0; } } else {#ifdef LINKED_DEPENDENCY return smoke_dependency();#else return 93;#endif } if (!strcmp(mode, "failure")) { fputs("Fixture launch failure\n", stderr); return 7; } if (!strcmp(mode, "dyld")) { fputs("dyld: Library not loaded: Fixture\n", stderr); return 127; } if (!strcmp(mode, "crash")) { raise(SIGKILL); return 94; } if (!strcmp(mode, "timeout")) { signal(SIGTERM, SIG_IGN); for (;;) { pause(); } } return 95;}FIXTURE/usr/bin/clang -Wall -Wextra -Werror -mmacosx-version-min=15.0 -Wl,-rpath,@executable_path/../Frameworks "$work/fixture.c" -o "$work/fixture"cp "$work/fixture" "$app/Contents/MacOS/Parcel"cp "$work/fixture" "$app/Contents/Resources/bin/prcl"cat > "$work/bin/codesign" <<'MOCK'#!/bin/bashset -euo pipefailprintf '%s\n' "$*" >> "$TEST_CODESIGN_LOG"case "${1:-}" in --verify) [[ ${TEST_FAIL_VERIFY:-0} != 1 ]] || exit 1 if [[ ${TEST_FAIL_RELOCATED_VERIFY:-0} == 1 && ${!#} == *parcel-smoke.* ]]; then exit 1; fi ;; -dv) [[ ${TEST_FAIL_SIGNATURE:-0} != 1 ]] || exit 1 if [[ ${TEST_TEAM:-not set} != missing ]]; then printf 'TeamIdentifier=%s\n' "${TEST_TEAM:-not set}" >&2; fi ;; -d) [[ $2 == --entitlements && $3 == - && $4 == --xml && ${TEST_FAIL_ENTITLEMENTS:-0} != 1 ]] || exit 1 case "${TEST_ENTITLEMENT:-true}" in absent) exit 0 ;; true) value='<true/>' ;; false) value='<false/>' ;; string) value='<string>true</string>' ;; integer) value='<integer>1</integer>' ;; malformed) printf 'not a plist\n'; exit 0 ;; *) exit 2 ;; esac printf '%s\n' '<?xml version="1.0"?><plist version="1.0"><dict>' \ "<key>com.apple.security.cs.disable-library-validation</key>$value" '</dict></plist>' ;; *) exit 2 ;;esacMOCKcat > "$work/bin/lipo" <<'MOCK'#!/bin/bashset -euo pipefail[[ $# == 4 && $2 == -verify_arch && $3 == arm64 && $4 == x86_64 ]]MOCKchmod +x "$work/bin/"*export PATH="$work/bin:$PATH" TMPDIR="$work/tmp"export TEST_LAUNCH_LOG="$work/launch.log" TEST_CODESIGN_LOG="$work/codesign.log"unset TEST_TEAM TEST_ENTITLEMENT TEST_APP_MODE TEST_CLI_MODEcount=0check() { if ! "$@"; then printf 'Smoke test failed: %s\n' "$*" >&2 exit 1 fi count=$((count + 1))}fails() { if "$@" > "$work/failure.log" 2>&1; then printf 'Expected failure at line %s: %s\n' "${BASH_LINENO[1]}" "$*" >&2 /bin/cat "$work/failure.log" >&2 return 1 fi}no_leftovers() { if [[ -f $TEST_LAUNCH_LOG ]]; then while IFS='|' read -r pid _; do if kill -0 "$pid" 2>/dev/null; then printf 'Smoke left process %s running.\n' "$pid" >&2 return 1 fi done < "$TEST_LAUNCH_LOG" fi [[ -z $(find "$TMPDIR" -mindepth 1 -print -quit) ]]}check_bundle="$work/project/Scripts/check-bundle.sh": > "$TEST_CODESIGN_LOG"printf 'Outside fixture, never mutate\n' > "$work/external-target"for attack in absolute relative fifo; do case $attack in absolute) ln -s "$work/external-target" "$app/Contents/unsafe" ;; relative) ln -s '../../../../external-target' "$app/Contents/unsafe" ;; fifo) mkfifo "$app/Contents/unsafe" ;; esac check fails "$check_bundle" --no-launch check grep -q 'Bundle preflight refused' "$work/failure.log" check test ! -s "$TEST_CODESIGN_LOG" check test ! -e "$TEST_LAUNCH_LOG" check no_leftovers rm "$app/Contents/unsafe"donemv "$work/project/build" "$work/project/saved-build"ln -s saved-build "$work/project/build"check fails "$check_bundle" --no-launchcheck grep -q 'symlinked build directory' "$work/failure.log"check test ! -s "$TEST_CODESIGN_LOG"check test ! -e "$TEST_LAUNCH_LOG"check no_leftoversrm "$work/project/build"mv "$work/project/saved-build" "$work/project/build"check "$check_bundle" --no-launchcheck test ! -e "$TEST_LAUNCH_LOG"for entitlement in absent false string integer malformed; do check fails env TEST_ENTITLEMENT="$entitlement" "$check_bundle" --no-launch check test ! -e "$TEST_LAUNCH_LOG"donecheck env TEST_TEAM=ABCDE12345 TEST_ENTITLEMENT=absent "$check_bundle" --no-launchfor entitlement in true false string integer; do check fails env TEST_TEAM=ABCDE12345 TEST_ENTITLEMENT="$entitlement" "$check_bundle" --no-launch check grep -q 'Team-signed apps must not carry' "$work/failure.log"donecheck fails env TEST_TEAM=missing "$check_bundle" --no-launchcheck grep -q 'no team identifier metadata' "$work/failure.log"for failure in TEST_FAIL_VERIFY TEST_FAIL_SIGNATURE TEST_FAIL_ENTITLEMENTS TEST_FAIL_RELOCATED_VERIFY; do check fails env "$failure=1" "$check_bundle" check test ! -e "$TEST_LAUNCH_LOG" check no_leftoversdonecheck "$check_bundle"check test "$(wc -l < "$TEST_LAUNCH_LOG" | tr -d ' ')" = 2check grep -Eq '\|.*/parcel-smoke\.[^/]+/Parcel.app/Contents/MacOS/Parcel\|--smoke\|1$' "$TEST_LAUNCH_LOG"check grep -Eq '\|.*/parcel-smoke\.[^/]+/Parcel.app/Contents/Resources/bin/prcl\|--version\|1$' "$TEST_LAUNCH_LOG"check grep -q -- '--verify --strict --deep .*parcel-smoke\.' "$TEST_CODESIGN_LOG"check no_leftoversfor mode in failure dyld crash timeout; do : > "$TEST_LAUNCH_LOG" check fails env TEST_APP_MODE="$mode" "$check_bundle" case "$mode" in failure) check grep -q 'status 7' "$work/failure.log"; check grep -q 'Fixture launch failure' "$work/failure.log" ;; dyld) check grep -q 'dyld: Library not loaded' "$work/failure.log" ;; crash) check grep -q 'status 137' "$work/failure.log" ;; timeout) check grep -q 'app timed out' "$work/failure.log" ;; esac check no_leftoversdonefor mode in failure invalid timeout; do : > "$TEST_LAUNCH_LOG" check fails env TEST_CLI_MODE="$mode" "$check_bundle" check test "$(wc -l < "$TEST_LAUNCH_LOG" | tr -d ' ')" = 1 if [[ $mode == timeout ]]; then check grep -q 'CLI timed out' "$work/failure.log"; fi check no_leftoversdone
# Like the app's chained fixups, this unused-on-smoke import must bind before main.printf 'int smoke_dependency(void) { return 0; }\n' > "$work/dependency.c"/usr/bin/clang -dynamiclib "$work/dependency.c" -Wl,-install_name,@rpath/SmokeDependency.dylib -o "$work/SmokeDependency.dylib"/usr/bin/clang -Wall -Wextra -Werror -mmacosx-version-min=15.0 -DLINKED_DEPENDENCY \ -Wl,-rpath,@executable_path/../Frameworks "$work/fixture.c" "$work/SmokeDependency.dylib" -o "$app/Contents/MacOS/Parcel": > "$TEST_LAUNCH_LOG"check fails "$check_bundle"check grep -q 'Library not loaded: @rpath/SmokeDependency.dylib' "$work/failure.log"check test "$(wc -l < "$TEST_LAUNCH_LOG" | tr -d ' ')" = 1check no_leftoversprintf 'int different_symbol(void) { return 0; }\n' > "$work/dependency.c"/usr/bin/clang -dynamiclib "$work/dependency.c" -Wl,-install_name,@rpath/SmokeDependency.dylib \ -o "$app/Contents/Frameworks/SmokeDependency.dylib": > "$TEST_LAUNCH_LOG"check fails "$check_bundle"check grep -qi 'symbol.*not found.*smoke_dependency' "$work/failure.log"check test "$(wc -l < "$TEST_LAUNCH_LOG" | tr -d ' ')" = 1check no_leftoverscp "$work/fixture" "$app/Contents/MacOS/Parcel"rm "$app/Contents/Frameworks/SmokeDependency.dylib"
: > "$TEST_LAUNCH_LOG"TEST_APP_MODE=timeout "$check_bundle" > "$work/interrupted.log" 2>&1 &checker=$!for (( tick=0; tick<100; tick++ )); do if [[ $(wc -l < "$TEST_LAUNCH_LOG" | tr -d ' ') == 2 ]]; then break; fi sleep 0.05donecheck test "$(wc -l < "$TEST_LAUNCH_LOG" | tr -d ' ')" = 2kill -TERM "$checker"status=0wait "$checker" || status=$?checker=check test "$status" = 143check no_leftoversprintf 'Smoke checks passed: %s\n' "$count"