Skip to content

Commit a49f061

Browse files
committed
refactor(test): implement cross-platform CPU detection in run_test.sh
1 parent 9f1e234 commit a49f061

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

tests/run_test.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#!/usr/bin/env bash
2-
# cleanup function to ensure background cloudSQL process is terminated
1+
#!/bin/bash
2+
3+
# cloudSQL E2E and Logic Test Runner
4+
# This script builds the engine and runs both Python E2E tests and SLT logic tests.
5+
36
cleanup() {
4-
if [ -n "$SQL_PID" ]; then
5-
kill $SQL_PID 2>/dev/null || true
6-
wait $SQL_PID 2>/dev/null || true
7+
echo "Shutting down..."
8+
if [ ! -z "$SQL_PID" ]; then
9+
kill $SQL_PID 2>/dev/null
710
fi
811
}
912

@@ -18,8 +21,21 @@ TEST_DATA_DIR="$ROOT_DIR/test_data"
1821
rm -rf "$TEST_DATA_DIR" || true
1922
mkdir -p "$TEST_DATA_DIR"
2023

24+
# Detect CPU count for parallel make
25+
if command -v nproc >/dev/null 2>&1; then
26+
CPU_COUNT=$(nproc)
27+
elif command -v sysctl >/dev/null 2>&1; then
28+
CPU_COUNT=$(sysctl -n hw.ncpu)
29+
elif command -v getconf >/dev/null 2>&1; then
30+
CPU_COUNT=$(getconf _NPROCESSORS_ONLN)
31+
else
32+
CPU_COUNT=1
33+
fi
34+
35+
echo "Detected $CPU_COUNT CPUs, building with -j$CPU_COUNT"
36+
2137
cd "$BUILD_DIR" || exit 1
22-
make -j$(sysctl -n hw.ncpu)
38+
make -j"$CPU_COUNT"
2339
./cloudSQL -p 5438 -d "$TEST_DATA_DIR" &
2440
SQL_PID=$!
2541
sleep 2

0 commit comments

Comments
 (0)