Skip to content

Commit 96b217a

Browse files
committed
Add azure parallel startegy example
1 parent 7d386ae commit 96b217a

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

AzureDevOps/DistributeTests.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# Distribute tests across multiple agents for parallel execution (Bash version)
3+
# Produces MATLAB cell array like:
4+
# {'/path/to/file1.m','/path/to/file2.m'}
5+
6+
# Find all test files (*.m) under ./tests
7+
mapfile -t tests < <(find ./tests -type f -name "*.m" | sort)
8+
9+
totalAgents=${CI_TOTAL:-1}
10+
agentNumber=${CI_INDEX:-1}
11+
testCount=${#tests[@]}
12+
13+
echo "Total agents: $totalAgents"
14+
echo "Agent number: $agentNumber"
15+
echo "Total tests: $testCount"
16+
17+
testsToRun=()
18+
19+
# Slice test files so each agent gets unique tests
20+
for (( i=agentNumber; i<=testCount; i+=totalAgents )); do
21+
file="${tests[i-1]}"
22+
testsToRun+=("$file")
23+
echo "Added $file"
24+
done
25+
26+
# Format as MATLAB cell array: {'file1','file2'}
27+
joined="{"
28+
for idx in "${!testsToRun[@]}"; do
29+
if [[ $idx -gt 0 ]]; then
30+
joined+=","
31+
fi
32+
joined+="'${testsToRun[$idx]}'"
33+
done
34+
joined+="}"
35+
36+
echo "Final test file list (MATLAB cell array): $joined"
37+
38+
# Set as Azure Pipelines variable
39+
echo "##vso[task.setvariable variable=MATLABTestFiles;]$joined"

AzureDevOps/DistributeTests.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# Distribute tests across multiple agents for parallel execution (Bash version)
3+
# Produces MATLAB cell array like:
4+
# {'/path/to/file1.m','/path/to/file2.m'}
5+
6+
# Find all test files (*.m) under ./tests
7+
mapfile -t tests < <(find ./tests -type f -name "*.m" | sort)
8+
9+
totalAgents=${CI_TOTAL:-1}
10+
agentNumber=${CI_INDEX:-1}
11+
testCount=${#tests[@]}
12+
13+
testsToRun=()
14+
15+
# Slice test files so each agent gets unique tests
16+
for (( i=agentNumber; i<=testCount; i+=totalAgents )); do
17+
file="${tests[i-1]}"
18+
testsToRun+=("$file")
19+
echo "Added $file"
20+
done
21+
22+
# Format as MATLAB cell array: {'file1','file2'}
23+
joined="{"
24+
for idx in "${!testsToRun[@]}"; do
25+
if [[ $idx -gt 0 ]]; then
26+
joined+=","
27+
fi
28+
joined+="'${testsToRun[$idx]}'"
29+
done
30+
joined+="}"
31+
32+
echo "Final test file list (MATLAB cell array): $joined"
33+
34+
# Set as Azure Pipelines variable
35+
echo "##vso[task.setvariable variable=MATLABTestFiles;]$joined"

AzureDevOps/ParallelStrategy.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
jobs:
2+
- job: ParallelWindows
3+
# Parallel strategy to run tests in parallel
4+
strategy:
5+
parallel: 2
6+
pool:
7+
vmImage: windows-latest
8+
steps:
9+
# Install MATLAB and required products
10+
- task: InstallMATLAB@1
11+
inputs:
12+
release: R2025a
13+
products: MATLAB_Test Simulink_Test
14+
15+
- powershell: .\AzureDevOps\DistributeTests.ps1
16+
displayName: 'PowerShell Script to distribute tests'
17+
18+
- task: RunMATLABTests@1
19+
inputs:
20+
selectByName: $(MATLABTestFiles)
21+
sourceFolder:
22+
env:
23+
MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN)
24+
25+
- job: ParallelLinux
26+
# Parallel strategy to run tests in parallel
27+
strategy:
28+
parallel: 2
29+
pool:
30+
vmImage: ubuntu-latest
31+
steps:
32+
# Install MATLAB and required products
33+
- task: InstallMATLAB@1
34+
inputs:
35+
release: R2025a
36+
products: MATLAB_Test Simulink_Test
37+
38+
- bash: chmod +x ./AzureDevOps/DistributeTests.sh && ./AzureDevOps/DistributeTests.sh
39+
displayName: 'Bash Script to distribute tests'
40+
41+
- task: RunMATLABTests@1
42+
inputs:
43+
selectByName: $(MATLABTestFiles)
44+
sourceFolder:
45+
env:
46+
MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN)
47+
48+
- job: ParallelMac
49+
# Parallel strategy to run tests in parallel
50+
strategy:
51+
parallel: 2
52+
pool:
53+
vmImage: macOS-latest
54+
steps:
55+
# Install MATLAB and required products
56+
- task: InstallMATLAB@1
57+
inputs:
58+
release: R2025a
59+
products: MATLAB_Test Simulink_Test
60+
61+
- bash: chmod +x ./AzureDevOps/DistributeTests.sh && ./AzureDevOps/DistributeTests.sh
62+
displayName: 'Bash Script to distribute tests'
63+
64+
- task: RunMATLABTests@1
65+
inputs:
66+
selectByName: $(MATLABTestFiles)
67+
sourceFolder:
68+
env:
69+
MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN)

0 commit comments

Comments
 (0)