|
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'} |
| 1 | +#!/bin/bash |
| 2 | +#=============================================================================== |
| 3 | +# |
| 4 | +# FILE: distribute_tests.sh |
| 5 | +# |
| 6 | +# USAGE: ./distribute_tests.sh |
| 7 | +# |
| 8 | +# DESCRIPTION: This script slices tests files across multiple agents for faster execution. |
| 9 | +# We search for specific type of file structure (in this example test*), and slice them according to agent number |
| 10 | +# If we encounter multiple files [file1..file10] and if we have 2 agents, agent1 executes tests odd number of files while agent2 executes even number of files |
| 11 | +# |
| 12 | +#=============================================================================== |
5 | 13 |
|
6 | | -# Find all test files (*.m) under ./tests |
7 | | -# mapfile -t tests < <(find ./tests -type f -name "*.m" | sort) mapfile doesnt work on macOS bash 3.2 |
8 | 14 | tests=() |
9 | 15 | while IFS= read -r file; do |
10 | 16 | tests+=("$file") |
11 | 17 | done < <(find ./tests -type f -name "*.m" | sort) |
12 | 18 |
|
13 | | -# Use Azure DevOps variables if available, else default to 1 |
14 | | -totalAgents=${SYSTEM_TOTALJOBSINPHASE:-1} |
15 | | -agentNumber=${SYSTEM_JOBPOSITIONINPHASE:-1} |
| 19 | +# Use Azure DevOps variables |
| 20 | +totalAgents=${SYSTEM_TOTALJOBSINPHASE} |
| 21 | +agentNumber=${SYSTEM_JOBPOSITIONINPHASE} |
16 | 22 | testCount=${#tests[@]} |
17 | 23 |
|
18 | | -# If not set or zero, default to 1 |
19 | | -if [[ -z "$totalAgents" || "$totalAgents" -eq 0 ]]; then |
| 24 | +if [ $totalAgents -eq 0 ]; then |
20 | 25 | totalAgents=1 |
21 | 26 | fi |
22 | | -if [[ -z "$agentNumber" || "$agentNumber" -eq 0 ]]; then |
| 27 | +# below conditions are used if parallel pipeline is not used. i.e. pipeline is running with single agent (no parallel configuration) |
| 28 | +if [ -z $agentNumber ]; then |
23 | 29 | agentNumber=1 |
24 | 30 | fi |
25 | 31 |
|
|
0 commit comments