Skip to content

Commit d6e5bea

Browse files
dhusebyDave Granthamseetadev
authored
first pass at linux+macos+wsl support (#790)
* first pass at linux+macos+wsl support Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org> * fix local cache and get_num_cpu use Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org> * add early exit when no tests Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org> --------- Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org> Co-authored-by: Dave Grantham <dwg@linuxprogrammer.org> Co-authored-by: Manu Sheel Gupta <manusheel.edu@gmail.com>
1 parent 2d2165b commit d6e5bea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+340
-128
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ downloads/
5555

5656
# Rust build artifacts
5757
target/
58+
59+
# the local build cache folder
60+
**/.cache/

docs/bash.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ WORKER_COUNT="${WORKER_COUNT:-1}"
9797
DEBUG="${DEBUG:-false}"
9898
```
9999

100+
Note: The test framework uses `get_cpu_count()` from `lib/lib-host-os.sh` for cross-platform CPU detection (macOS uses `sysctl`, Linux/WSL uses `nproc`).
101+
100102
**snake_case** for:
101103
- Local variables
102104
- Function parameters
@@ -132,7 +134,7 @@ Use parameter expansion for defaults:
132134
IMAGES_YAML="${IMAGES_YAML:-./images.yaml}"
133135

134136
# Command substitution default
135-
WORKER_COUNT="${WORKER_COUNT:-$(nproc 2>/dev/null || echo 4)}"
137+
WORKER_COUNT="${WORKER_COUNT:-$(get_cpu_count)}"
136138

137139
# Empty string default (variable may not be set)
138140
TEST_IGNORE="${TEST_IGNORE:-}"
@@ -918,7 +920,7 @@ done
918920
919921
**Pattern**:
920922
```bash
921-
WORKER_COUNT=$(nproc)
923+
WORKER_COUNT=$(get_cpu_count)
922924
923925
run_test() {
924926
local index="${1}"
@@ -976,7 +978,7 @@ seq 0 $((TEST_COUNT - 1)) | xargs -P "${WORKER_COUNT}" -I {} bash -c 'run_test {
976978
**Alternative pattern** using bash job control:
977979
978980
```bash
979-
WORKER_COUNT=$(nproc)
981+
WORKER_COUNT=$(get_cpu_count)
980982
981983
for ((i=0; i<TEST_COUNT; i++)); do
982984
# Run in background
@@ -1034,7 +1036,7 @@ wait # Wait for all background jobs
10341036
**2. Resource Limits**:
10351037
```bash
10361038
# Respect system resources
1037-
WORKER_COUNT=$(nproc)
1039+
WORKER_COUNT=$(get_cpu_count)
10381040
10391041
# Or limit explicitly
10401042
WORKER_COUNT=4

docs/overall-flow.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ The `inputs.yaml` file must be loaded *before* libraries are sourced because it
178178
179179
4. Set test-specific defaults:
180180
- **Perf**: `ITERATIONS=10`, `UPLOAD_BYTES=1GB`, `DOWNLOAD_BYTES=1GB`
181-
- **Transport**: `WORKER_COUNT=$(nproc)`
182-
- **Hole-Punch**: `WORKER_COUNT=$(nproc)`
181+
- **Transport**: `WORKER_COUNT=$(get_cpu_count)` (from lib-host-os.sh)
182+
- **Hole-Punch**: `WORKER_COUNT=$(get_cpu_count)` (from lib-host-os.sh)
183183
184184
**Code Location**:
185185
- `perf/run.sh:88-207`
@@ -674,6 +674,7 @@ The `inputs.yaml` file must be loaded *before* libraries are sourced because it
674674
675675
b. **Parallel** (transport, hole-punch with WORKER_COUNT>1):
676676
```bash
677+
WORKER_COUNT=$(get_cpu_count) # From lib-host-os.sh
677678
for ((i=0; i<TEST_COUNT; i++)); do
678679
bash "${SCRIPT_DIR}/run-single-test.sh" "$i" "tests" "$RESULTS_FILE" &
679680
@@ -1061,7 +1062,7 @@ The `inputs.yaml` file must be loaded *before* libraries are sourced because it
10611062
### Transport Tests
10621063
10631064
**Unique Characteristics**:
1064-
- Parallel execution (WORKER_COUNT=$(nproc))
1065+
- Parallel execution (WORKER_COUNT=$(get_cpu_count))
10651066
- Browser implementations (dialOnly)
10661067
- GitHub sources with patches
10671068
- Simple pass/fail (no measurements)
@@ -1074,7 +1075,7 @@ The `inputs.yaml` file must be loaded *before* libraries are sourced because it
10741075
### Hole-Punch Tests
10751076
10761077
**Unique Characteristics**:
1077-
- Parallel execution (WORKER_COUNT=$(nproc))
1078+
- Parallel execution (WORKER_COUNT=$(get_cpu_count))
10781079
- 5-container topology per test
10791080
- Unique subnets per test (NAT simulation)
10801081
- DCUtR protocol measurements
@@ -1131,7 +1132,7 @@ These stop the entire run:
11311132
11321133
### Parallel Execution
11331134
1134-
- **Transport/Hole-Punch**: WORKER_COUNT=$(nproc) for fast execution
1135+
- **Transport/Hole-Punch**: WORKER_COUNT=$(get_cpu_count) for fast execution (from lib-host-os.sh)
11351136
- **Perf**: WORKER_COUNT=1 for accurate measurements
11361137
11371138
### Network Isolation

hole-punch/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ Check dependencies:
110110
./run.sh --check-deps
111111
```
112112

113-
Required: bash 4.0+, docker 20.10+, yq 4.0+, wget, unzip
113+
**Required dependencies**:
114+
- bash 4.0+
115+
- docker 20.10+ (with daemon running)
116+
- yq 4.0+
117+
- git 2.0+
118+
- docker compose (plugin or standalone)
119+
- Standard UNIX utilities (see [lib/check-dependencies.sh](../lib/check-dependencies.sh) for complete list)
120+
121+
**Optional dependencies** (for advanced features):
122+
- gnuplot 5.0+ (for performance charts)
123+
- pandoc (for HTML report generation)
114124

115125
### Basic Usage
116126

@@ -134,7 +144,7 @@ Required: bash 4.0+, docker 20.10+, yq 4.0+, wget, unzip
134144
### Parallel Execution
135145

136146
Hole-punch tests run in **parallel** (like transport tests):
137-
- Default workers: `$(nproc)` (number of CPU cores)
147+
- Default workers: `$(get_cpu_count)` from lib-host-os.sh (cross-platform CPU detection)
138148
- Override with `--workers N`
139149
- Tests execute concurrently for faster completion
140150
- Each test creates isolated Docker networks to avoid collisions

hole-punch/images/linux/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Linux NAT Router Configuration Script
33
# Configures iptables-based NAT between LAN and WAN networks
44

hole-punch/images/rust/v0.56/run-peer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -e
33

44
# Set route to relay subnet

hole-punch/images/rust/v0.56/run-relay.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -e
33

44
# Set route to dialer subnet

hole-punch/lib/generate-dashboard.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Generate results.md dashboard from results.yaml
33

44
set -euo pipefail

hole-punch/lib/generate-tests.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Generate test matrix from images.yaml with filtering
33
# Outputs test-matrix.yaml with content-addressed caching
44
# Permutations: dialer × listener × transport × secureChannel × muxer × relay × dialer_router × listener_router
@@ -12,6 +12,7 @@ trap 'echo "ERROR in generate-tests.sh at line $LINENO: Command exited with stat
1212
# Source common libraries
1313
source "${SCRIPT_LIB_DIR}/lib-filter-engine.sh"
1414
source "${SCRIPT_LIB_DIR}/lib-generate-tests.sh"
15+
source "${SCRIPT_LIB_DIR}/lib-host-os.sh"
1516
source "${SCRIPT_LIB_DIR}/lib-image-building.sh"
1617
source "${SCRIPT_LIB_DIR}/lib-image-naming.sh"
1718
source "${SCRIPT_LIB_DIR}/lib-output-formatting.sh"
@@ -422,8 +423,8 @@ echo ""
422423
main_tests=()
423424
ignored_main_tests=()
424425

425-
# Determine worker count (from environment, defaults to nproc)
426-
WORKER_COUNT="${WORKER_COUNT:-$(nproc 2>/dev/null || echo 4)}"
426+
# Determine worker count (from environment, defaults to hardware cpu count)
427+
WORKER_COUNT="${WORKER_COUNT:-$(get_cpu_count)}"
427428

428429
# Worker function to generate tests for a chunk of dialers
429430
# Args: worker_id dialer_id1 dialer_id2 ...

hole-punch/lib/run-single-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Run a single hole punch test using docker compose
33

44
set -euo pipefail

0 commit comments

Comments
 (0)