-
Notifications
You must be signed in to change notification settings - Fork 6
Adding example for running tests in parallel in Azure #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
96b217a
Add azure parallel startegy example
Vahila d2cd614
Update file
Vahila e03c52f
Update file
Vahila 982dd65
Update file
Vahila 91fd679
Update file
Vahila 76eeb0c
Update file
Vahila 92bc54f
Update file
Vahila 1f07238
Update file
Vahila b1c0c8e
Update file
Vahila 02db0b3
Update file
Vahila 12b8bec
Update file
Vahila 956ab1e
Update file
Vahila 2e6d8ca
Update file
Vahila fc5d5a7
Update file
Vahila 9385b68
Update file
Vahila 085e078
Update file
Vahila 3097975
Update file
Vahila 4758771
Update file
Vahila 45ef02b
Update file
Vahila 69d39c2
Update file
Vahila 8258dbc
Update file
Vahila 034ad30
Update file
Vahila ff6eb3a
Update file
Vahila 9bf7953
Address review comments
Vahila 4aeabe0
Address review comments
Vahila 13e8cb1
Address review comments
Vahila 8f89dca
Update buildtool task
Vahila d819763
Update README
Vahila e37a140
Update README
Vahila 66f0350
Update file
Vahila 04de8cf
Update file
Vahila 3cd4074
Address review comments
Vahila 6d6210e
Address review comments
Vahila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Distribute tests across multiple agents in VSTS pipeline | ||
| .DESCRIPTION | ||
mw-hrastega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| This script divides test files across multiple agents for faster execution. It searches for files matching a specific pattern (for example, `test*`) and assigns them based on the agent number. | ||
| For example, if there are multiple files [test1..test10] and 2 agents: | ||
| - Agent 1 runs tests from odd-numbered files. | ||
| - Agent 2 runs tests from even-numbered files. | ||
| For detailed slicing information, see https://learn.microsoft.com/en-us/azure/devops/pipelines/test/parallel-testing-any-test-runner?view=azure-devops | ||
| #> | ||
|
|
||
| $tests = Get-ChildItem .\tests\ -Filter *.m -File # Search for test files matching the specified pattern | ||
| $totalAgents = [int]$Env:SYSTEM_TOTALJOBSINPHASE # Standard VSTS variable containing the number of parallel jobs | ||
| $agentNumber = [int]$Env:SYSTEM_JOBPOSITIONINPHASE # Current job position | ||
| $testCount = $tests.Count | ||
|
|
||
| # Handle cases where the pipeline runs without parallel configuration (single agent) | ||
| if ($totalAgents -eq 0) { | ||
| $totalAgents = 1 | ||
| } | ||
| if (!$agentNumber -or $agentNumber -eq 0) { | ||
| $agentNumber = 1 | ||
| } | ||
|
|
||
| Write-Host "Total agents: $totalAgents" | ||
| Write-Host "Agent number: $agentNumber" | ||
| Write-Host "Total tests: $testCount" | ||
|
|
||
| $testsToRun= @() | ||
| # Slice test files so each agent gets a unique set of files to execute | ||
| For ($i=$agentNumber; $i -le $testCount;) { | ||
| $file = $tests[$i-1] | ||
|
|
||
| $fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name) | ||
| $testsToRun += "$fileName/*" | ||
| $i = $i + $totalAgents | ||
| } | ||
|
|
||
| # Join all test files into a space-separated string | ||
| $testFiles = $testsToRun -Join " " | ||
| Write-Host "Tests to run $testFiles" | ||
| # Write files into a variable for execution in a subsequent task | ||
| Write-Host "##vso[task.setvariable variable=MATLABTestFiles;]$testFiles" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
mw-hrastega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #=============================================================================== | ||
| # | ||
| # FILE: distribute_tests.sh | ||
| # | ||
| # USAGE: ./distribute_tests.sh | ||
| # | ||
| # DESCRIPTION: This script divides test files across multiple agents for faster execution. It searches for files matching a specific pattern (for example, `test*`) and assigns them based on the agent number. | ||
| # For example, if there are multiple files [test1..test10] and 2 agents: | ||
| # - Agent 1 runs tests from odd-numbered files. | ||
| # - Agent 2 runs tests from even-numbered files. | ||
| # For detailed slicing information, see https://learn.microsoft.com/en-us/azure/devops/pipelines/test/parallel-testing-any-test-runner?view=azure-devops | ||
| # | ||
| #=============================================================================== | ||
|
|
||
| tests=() | ||
| # Search for test files matching the specified pattern | ||
| while IFS= read -r file; do | ||
| tests+=("$file") | ||
| done < <(find ./tests -type f -name "*.m" | sort) | ||
|
|
||
| totalAgents=${SYSTEM_TOTALJOBSINPHASE} # Standard VSTS variable containing the number of parallel jobs | ||
| agentNumber=${SYSTEM_JOBPOSITIONINPHASE} # Current job position | ||
| testCount=${#tests[@]} | ||
|
|
||
| # Handle cases where the pipeline runs without parallel configuration (single agent) | ||
| if [ $totalAgents -eq 0 ]; then | ||
| totalAgents=1 | ||
| fi | ||
| if [ -z $agentNumber ]; then | ||
| agentNumber=1 | ||
| fi | ||
|
|
||
| echo "Total agents: $totalAgents" | ||
| echo "Agent number: $agentNumber" | ||
| echo "Total tests: $testCount" | ||
|
|
||
| testsToRun=() | ||
| # Slice test files so each agent gets a unique set of files | ||
| for (( i=agentNumber; i<=testCount; i+=totalAgents )); do | ||
| file="${tests[i-1]}" | ||
|
|
||
| fileName=$(basename "$file" .m) | ||
| testsToRun+=("${fileName}/*") | ||
| done | ||
|
|
||
| # Join all test files into a space-separated string | ||
| testFiles="${testsToRun[*]}" | ||
| echo "Tests to run $testFiles" | ||
|
|
||
| # Write files into a variable for execution in a subsequent task | ||
| echo "##vso[task.setvariable variable=MATLABTestFiles;]$testFiles" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| jobs: | ||
| - job: ParallelWindows | ||
| # Specify 'parallel' strategy to run tests in parallel | ||
| strategy: | ||
| parallel: 2 | ||
| pool: | ||
| vmImage: windows-latest | ||
| steps: | ||
| # Install MATLAB and required products | ||
| - task: InstallMATLAB@1 | ||
| inputs: | ||
| products: MATLAB_Compiler_SDK MATLAB_Test | ||
|
|
||
| - task: RunMATLABBuild@1 | ||
| inputs: | ||
| tasks: mex buildPythonPackage | ||
| env: | ||
| MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN) | ||
|
|
||
| - powershell: .\AzureDevOps\DistributeTests.ps1 | ||
| displayName: 'PowerShell script to distribute tests' | ||
|
|
||
| - task: RunMATLABTests@1 | ||
| inputs: | ||
| selectByName: $(MATLABTestFiles) | ||
| sourceFolder: src | ||
| env: | ||
| MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN) | ||
|
|
||
| - job: ParallelLinux | ||
| # Specify 'parallel' strategy to run tests in parallel | ||
| strategy: | ||
| parallel: 2 | ||
| pool: | ||
| vmImage: ubuntu-latest | ||
| steps: | ||
| # Install MATLAB and required products | ||
| - task: InstallMATLAB@1 | ||
| inputs: | ||
| products: MATLAB_Compiler_SDK MATLAB_Test | ||
|
|
||
| - task: RunMATLABBuild@1 | ||
| inputs: | ||
| tasks: mex buildPythonPackage | ||
| env: | ||
| MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN) | ||
|
|
||
| - bash: chmod +x ./AzureDevOps/DistributeTests.sh && ./AzureDevOps/DistributeTests.sh | ||
| displayName: 'Bash script to distribute tests' | ||
|
|
||
| - task: RunMATLABTests@1 | ||
| inputs: | ||
| selectByName: $(MATLABTestFiles) | ||
| sourceFolder: src | ||
| env: | ||
| MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN) | ||
|
|
||
| - job: ParallelMac | ||
| # Specify 'parallel' strategy to run tests in parallel | ||
| strategy: | ||
| parallel: 2 | ||
| pool: | ||
| vmImage: macOS-latest | ||
| steps: | ||
| # Install MATLAB and required products | ||
| - task: InstallMATLAB@1 | ||
| inputs: | ||
| products: MATLAB_Compiler_SDK MATLAB_Test | ||
|
|
||
| - task: RunMATLABBuild@1 | ||
| inputs: | ||
| tasks: mex buildPythonPackage | ||
| env: | ||
| MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN) | ||
|
|
||
| - bash: chmod +x ./AzureDevOps/DistributeTests.sh && ./AzureDevOps/DistributeTests.sh | ||
| displayName: 'Bash script to distribute tests' | ||
|
|
||
| - task: RunMATLABTests@1 | ||
| inputs: | ||
| selectByName: $(MATLABTestFiles) | ||
| sourceFolder: src | ||
| env: | ||
| MLM_LICENSE_TOKEN: $(MLM_LICENSE_TOKEN) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ For starter workflows, use the [`ci-configuration-examples`](https://github.com/ | |
|
|
||
| # Workflows | ||
|
|
||
| The repository contains examples for packaging and distributing a toolbox, as well as building and uploading Python<sup>®</sup> packages. | ||
| The repository contains examples for packaging and distributing a toolbox, building and uploading Python<sup>®</sup> packages, and running tests across multiple build agents. | ||
|
|
||
| - **Package and Distribute Toolbox**: Using a matrix build across multiple platforms, compile, link, and test your C source files to produce a binary MEX file per operating system. Then, bundle the resulting binaries into a toolbox and distribute it as a GitHub release. | ||
|
|
||
|
|
@@ -36,6 +36,8 @@ The repository contains examples for packaging and distributing a toolbox, as we | |
| | GitHub Actions| [`.github/workflows/CrossPlatformBuilder.yml`](https://github.com/mathworks/advanced-ci-configuration-examples/blob/main/.github/workflows/CrossPlatformBuilder.yml) | | ||
| | Jenkins | [`Jenkins/CrossPlatformBuilder/Jenkinsfile`](https://github.com/mathworks/advanced-ci-configuration-examples/blob/main/Jenkins/CrossPlatformBuilder/Jenkinsfile) | | ||
|
|
||
| - **Run Tests Across Multiple Agents**: Use the [parallel strategy](https://learn.microsoft.com/en-us/azure/devops/pipelines/test/parallel-testing-any-test-runner?view=azure-devops) in Azure DevOps to run tests across multiple agents and speed up the testing process. For configuration details, see the example in [`AzureDevOps/ParallelStrategy.yml`](https://github.com/mathworks/advanced-ci-configuration-examples/blob/main/AzureDevOps/ParallelStrategy.yml) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Vahila, can you terminate this paragraph with a period? |
||
| <br> | ||
|
|
||
| ## Get Started | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.