Skip to content

Commit 327d949

Browse files
authored
[PM-26160] Test workflows - Split Build / Test steps and pre-boot simulator (#2015)
1 parent cb17d21 commit 327d949

File tree

3 files changed

+104
-46
lines changed

3 files changed

+104
-46
lines changed

.github/workflows/test-bwa.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ env:
4949
MINT_LINK_PATH: .mint/bin # used by mint in bootstrap.sh
5050
MINT_PATH: .mint/lib # used by mint in bootstrap.sh
5151
_COVERAGE_PATH: build/coverage.xml
52-
_RESULT_BUNDLE_PATH: build/AuthenticatorTests.xcresult
52+
_BUILD_RESULT_BUNDLE_PATH: build/bwa-build.xcresult
53+
_TESTS_RESULT_BUNDLE_PATH: build/bwa-tests.xcresult
5354
_SIMULATOR_NAME: ${{ inputs.simulator-name }}
5455
_SIMULATOR_VERSION: ${{ inputs.simulator-version }}
5556
_XCODE_VERSION: ${{ inputs.xcode-version }}
@@ -124,15 +125,39 @@ jobs:
124125
brew bundle
125126
./Scripts/bootstrap.sh
126127
127-
- name: Build and test
128+
- name: Boot Simulator
129+
run: |
130+
echo "Listing simulator devices:"
131+
SIMULATORS=$(xcrun simctl list devices "iOS $_SIMULATOR_VERSION" available)
132+
echo "$DEVICES_LIST"
133+
DEVICE_ID=$(echo "$SIMULATORS" | grep "$_SIMULATOR_NAME" | head -1 | sed -E 's/.*\(([A-F0-9-]+)\).*/\1/')
134+
echo "--------------------------------"
135+
echo "Booting simulator: $_SIMULATOR_NAME ($_SIMULATOR_VERSION) with ID: $DEVICE_ID"
136+
xcrun simctl boot "$DEVICE_ID"
137+
xcrun simctl bootstatus "$DEVICE_ID"
138+
139+
- name: Build
140+
run: |
141+
python Scripts/pyeetd/main.py & PYEETD_PID=$!
142+
xcrun xcodebuild build-for-testing \
143+
-workspace Bitwarden.xcworkspace \
144+
-scheme Authenticator \
145+
-configuration Debug \
146+
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
147+
-derivedDataPath build/DerivedData \
148+
-resultBundlePath $_BUILD_RESULT_BUNDLE_PATH \
149+
-quiet
150+
kill $PYEETD_PID
151+
152+
- name: Test
128153
run: |
129154
python Scripts/pyeetd/main.py & PYEETD_PID=$!
130-
xcrun xcodebuild test \
155+
xcrun xcodebuild test-without-building \
131156
-workspace Bitwarden.xcworkspace \
132157
-scheme Authenticator \
133158
-configuration Debug \
134159
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
135-
-resultBundlePath $_RESULT_BUNDLE_PATH \
160+
-resultBundlePath $_TESTS_RESULT_BUNDLE_PATH \
136161
-derivedDataPath build/DerivedData \
137162
-test-timeouts-enabled yes \
138163
-maximum-test-execution-time-allowance 1 \
@@ -144,15 +169,15 @@ jobs:
144169
- name: Print Logs Summary
145170
if: always()
146171
run: |
147-
xcresultparser -o cli "$_RESULT_BUNDLE_PATH"
172+
xcresultparser -o cli "$_TESTS_RESULT_BUNDLE_PATH"
148173
echo "# Test Summary" >> $GITHUB_STEP_SUMMARY
149-
xcresultparser -f -o txt "$_RESULT_BUNDLE_PATH" | grep "Number of" >> $GITHUB_STEP_SUMMARY
174+
xcresultparser -f -o txt "$_TESTS_RESULT_BUNDLE_PATH" | grep "Number of" >> $GITHUB_STEP_SUMMARY
150175
151176
- name: Convert coverage to Cobertura
152177
run: |
153178
set -o pipefail && \
154179
xcresultparser --output-format cobertura \
155-
"$_RESULT_BUNDLE_PATH" > "$_COVERAGE_PATH"
180+
"$_TESTS_RESULT_BUNDLE_PATH" > "$_COVERAGE_PATH"
156181
157182
- name: Upload test reports
158183
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
@@ -162,7 +187,8 @@ jobs:
162187
compression-level: 9
163188
path: |
164189
${{ env._COVERAGE_PATH }}
165-
${{ env._RESULT_BUNDLE_PATH }}
190+
${{ env._TESTS_RESULT_BUNDLE_PATH }}
191+
${{ env._BUILD_RESULT_BUNDLE_PATH }}
166192
167193
report:
168194
name: Process Test Reports

.github/workflows/test.yml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ env:
4444
MINT_LINK_PATH: .mint/bin # used by mint in bootstrap.sh
4545
MINT_PATH: .mint/lib # used by mint in bootstrap.sh
4646
_COVERAGE_PATH: build/coverage.xml
47-
_RESULT_BUNDLE_PATH: build/BitwardenTests.xcresult
47+
_BUILD_RESULT_BUNDLE_PATH: build/bwpm-build.xcresult
48+
_TESTS_RESULT_BUNDLE_PATH: build/bwpm-tests.xcresult
4849
_SIMULATOR_NAME: ${{ inputs.simulator-name }}
4950
_SIMULATOR_VERSION: ${{ inputs.simulator-version }}
5051
_XCODE_VERSION: ${{ inputs.xcode-version }}
@@ -119,43 +120,59 @@ jobs:
119120
brew bundle
120121
./Scripts/bootstrap.sh
121122
122-
- name: Build and test
123+
- name: Boot Simulator
124+
run: |
125+
echo "Listing simulator devices:"
126+
SIMULATORS=$(xcrun simctl list devices "iOS $_SIMULATOR_VERSION" available)
127+
echo "$SIMULATORS"
128+
DEVICE_ID=$(echo "$SIMULATORS" | grep "$_SIMULATOR_NAME" | head -1 | sed -E 's/.*\(([A-F0-9-]+)\).*/\1/')
129+
echo "--------------------------------"
130+
echo "Booting simulator: $_SIMULATOR_NAME ($_SIMULATOR_VERSION) with ID: $DEVICE_ID"
131+
xcrun simctl boot "$DEVICE_ID"
132+
xcrun simctl bootstatus "$DEVICE_ID"
133+
134+
- name: Build
123135
run: |
124136
python Scripts/pyeetd/main.py & PYEETD_PID=$!
125-
xcrun xcodebuild test \
126-
-workspace Bitwarden.xcworkspace \
127-
-scheme Bitwarden \
128-
-configuration Debug \
129-
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
130-
-resultBundlePath $_RESULT_BUNDLE_PATH \
131-
-derivedDataPath build/DerivedData \
132-
-test-timeouts-enabled yes \
133-
-maximum-test-execution-time-allowance 1 \
134-
-retry-tests-on-failure \
135-
-test-repetition-relaunch-enabled YES \
136-
-quiet
137+
xcrun xcodebuild build-for-testing \
138+
-workspace Bitwarden.xcworkspace \
139+
-scheme Bitwarden \
140+
-configuration Debug \
141+
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
142+
-derivedDataPath build/DerivedData \
143+
-resultBundlePath $_BUILD_RESULT_BUNDLE_PATH \
144+
-quiet
137145
kill $PYEETD_PID
138146
139-
- name: Output processes
147+
- name: Test
140148
run: |
141-
echo "Sorted by memory usage"
142-
ps -em -o pid,pcpu,pmem,comm | head -n40
143-
echo "--------------------------------"
144-
echo "Sorted by CPU usage"
145-
ps -er -o pid,pcpu,pmem,comm | head -n40
149+
python Scripts/pyeetd/main.py & PYEETD_PID=$!
150+
xcrun xcodebuild test-without-building \
151+
-workspace Bitwarden.xcworkspace \
152+
-scheme Bitwarden \
153+
-configuration Debug \
154+
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
155+
-resultBundlePath $_TESTS_RESULT_BUNDLE_PATH \
156+
-derivedDataPath build/DerivedData \
157+
-test-timeouts-enabled yes \
158+
-maximum-test-execution-time-allowance 1 \
159+
-retry-tests-on-failure \
160+
-test-repetition-relaunch-enabled YES \
161+
-quiet
162+
kill $PYEETD_PID
146163
147164
- name: Print Logs Summary
148165
if: always()
149166
run: |
150-
xcresultparser -o cli "$_RESULT_BUNDLE_PATH"
167+
xcresultparser -o cli "$_TESTS_RESULT_BUNDLE_PATH"
151168
echo "# Test Summary" >> $GITHUB_STEP_SUMMARY
152-
xcresultparser -f -o txt "$_RESULT_BUNDLE_PATH" | grep "Number of" >> $GITHUB_STEP_SUMMARY
169+
xcresultparser -f -o txt "$_TESTS_RESULT_BUNDLE_PATH" | grep "Number of" >> $GITHUB_STEP_SUMMARY
153170
154171
- name: Convert coverage to Cobertura
155172
run: |
156173
set -o pipefail && \
157174
xcresultparser --output-format cobertura \
158-
"$_RESULT_BUNDLE_PATH" > "$_COVERAGE_PATH"
175+
"$_TESTS_RESULT_BUNDLE_PATH" > "$_COVERAGE_PATH"
159176
160177
- name: Upload test reports
161178
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
@@ -165,7 +182,8 @@ jobs:
165182
compression-level: 9
166183
path: |
167184
${{ env._COVERAGE_PATH }}
168-
${{ env._RESULT_BUNDLE_PATH }}
185+
${{ env._TESTS_RESULT_BUNDLE_PATH }}
186+
${{ env._BUILD_RESULT_BUNDLE_PATH }}
169187
170188
report:
171189
name: Process Test Reports

Scripts/pyeetd/main.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from enum import Enum
1818

1919
OS_PROCESSES = {
20-
"Spotlight",
21-
"ReportCrash",
2220
"ecosystemanalyticsd"
2321
"com.apple.ecosystemd",
2422
"com.apple.metadata.mds",
@@ -35,7 +33,13 @@
3533
"PhotosPosterProvider",
3634
"AvatarPosterExtension",
3735
"GradientPosterExtension",
38-
"MonogramPosterExtension"
36+
"MonogramPosterExtension",
37+
# "System/Library/PrivateFrameworks/SessionCore.framework/Support/liveactivitiesd",
38+
# "Applications/News.app",
39+
# "usr/libexec/icloudmailagent",
40+
# "Applications/Family.app",
41+
# "Applications/PosterBoard.app",
42+
# "Applications/PassbookStub.app",
3943
}
4044

4145
SIMULATOR_PATH_SEARCH_KEY = "simruntime/Contents/Resources/RuntimeRoot"
@@ -116,23 +120,33 @@ def find_unwanted(processes):
116120
def yeet(processes):
117121
output = []
118122
for p in processes:
119-
output.append(f"🤠 pyeetd: Stopping - {p.output_string}")
120-
os.killpg(p.pid, signal.SIGKILL)
123+
try:
124+
output.append(f"🤠 pyeetd: Stopping - {p.output_string}")
125+
try:
126+
os.killpg(p.pid, signal.SIGKILL)
127+
except PermissionError:
128+
subprocess.run(['sudo', 'kill', '-SIGKILL', str(p.pid)], capture_output=True, check=False)
129+
output.append(f"🔐 pyeetd with sudo - {p.pid}")
130+
except (OSError, ProcessLookupError) as e:
131+
output.append(f"😪 pyeetd: Failed to stop {p.pid} - {e}")
121132
return output
122133

123134
def main():
124135
print_cycles = PRINT_PROCESSES_INTERVAL // SLEEP_DELAY
125136
i = 0
126137
while True:
127-
output = []
128-
processes = get_processes(ProcessSort.CPU)
129-
processes_to_yeet = find_unwanted(processes)
130-
output.extend(yeet(processes_to_yeet))
131-
output.append(f"🤠 {time.strftime('%Y-%m-%d %H:%M:%S')} - pyeetd {len(processes_to_yeet)} processes.")
132-
print("\n".join(output))
133-
if i % print_cycles == 0:
134-
print_processes(processes, 10)
135-
i += 1
138+
try:
139+
output = []
140+
processes = get_processes(ProcessSort.CPU)
141+
processes_to_yeet = find_unwanted(processes)
142+
output.extend(yeet(processes_to_yeet))
143+
output.append(f"🤠 {time.strftime('%Y-%m-%d %H:%M:%S')} - pyeetd {len(processes_to_yeet)} processes.")
144+
print("\n".join(output))
145+
if i % print_cycles == 0:
146+
print_processes(processes, 10)
147+
i += 1
148+
except Exception as e:
149+
print(f"🤠 pyeetd: Error in main loop - {e}")
136150
time.sleep(SLEEP_DELAY)
137151

138152
if __name__ == '__main__':

0 commit comments

Comments
 (0)