From 9be02da4ece87b6acc1ee73766c46a307f6ae0a8 Mon Sep 17 00:00:00 2001 From: Noah Martin Date: Fri, 8 Aug 2025 15:58:51 -0400 Subject: [PATCH] Relax debugger check to device only --- Sources/EMGFaultOrdering/Constructor.mm | 10 ++++++- run-test.sh | 35 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 run-test.sh diff --git a/Sources/EMGFaultOrdering/Constructor.mm b/Sources/EMGFaultOrdering/Constructor.mm index 9f4b5cc..7fb891e 100644 --- a/Sources/EMGFaultOrdering/Constructor.mm +++ b/Sources/EMGFaultOrdering/Constructor.mm @@ -12,6 +12,7 @@ #import #import #import +#import #import #import #import @@ -61,6 +62,13 @@ return [NSJSONSerialization dataWithJSONObject:result options:0 error:nil]; } +bool isSimulator(void) { + struct utsname systemInfo; + uname(&systemInfo); + NSString *machine = [NSString stringWithUTF8String:systemInfo.machine]; + return [machine containsString:@"x86_64"] || [machine containsString:@"arm64"]; +} + bool isDebuggerAttached() { const pid_t self = getpid(); int mib[5] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, self, 0}; @@ -237,7 +245,7 @@ bool parseFunctionStarts(const struct mach_header_64 *header, intptr_t slide, vm return getAddresses(); }]; - if (!isDebuggerAttached()) { + if (!isSimulator() && !isDebuggerAttached()) { printf("The debugger is not attached\n"); abort(); } diff --git a/run-test.sh b/run-test.sh new file mode 100755 index 0000000..10215cd --- /dev/null +++ b/run-test.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -euo pipefail + +# Configurable variables +PROJECT_PATH="Demos/DemoApp/DemoApp.xcodeproj" +SCHEME="DemoApp" +DESTINATION="name=iPhone 16 Pro" +XCRESULT_PATH="TestResults.xcresult" +OUTPUT_FILE="order-file.txt" + +# 1. Run the test +echo "Running xcodebuild test..." +xcodebuild test \ + -project "$PROJECT_PATH" \ + -scheme "$SCHEME" \ + -destination "$DESTINATION" \ + -resultBundlePath "$XCRESULT_PATH" + +echo "Test finished. Searching for attachment..." + +# Run xcparse to extract plain text attachments +xcparse attachments "$XCRESULT_PATH" ./out/ --uti public.plain-text + +# Find the output file matching the order-file pattern +ORDER_FILE=$(find ./out -type f -name "order-file_*.txt" | head -n 1) + +if [[ -z "$ORDER_FILE" ]]; then + echo "❌ No 'order-file_*.txt' found in ./out" + exit 1 +fi + +# Move and rename it +mv "$ORDER_FILE" ./order-file.txt +echo "✅ Done"