|
6 | 6 | These scripts contain "#! test <command>" comments. |
7 | 7 | They are expanded, executed and then diffed against the output in |
8 | 8 | "tests/integrations/references". |
| 9 | +
|
| 10 | +Platform-specific tests: |
| 11 | + Scripts suffixed with _linux, _darwin, or _windows (e.g., docker-alpine_linux.sh) |
| 12 | + only run on that platform. Scripts without a suffix run on all platforms. |
| 13 | +
|
| 14 | +Build tags (p4): |
| 15 | + Some nodes require Go build tags to be compiled in. P4 nodes (core/p4-run@v1, |
| 16 | + core/p4-sync@v1, etc.) are guarded by `//go:build p4` and require the P4 API SDK. |
| 17 | + The test runner auto-detects the P4 API SDK in `p4api/` and builds with `-tags=p4` |
| 18 | + when available. Run `bash setup.sh` to download the SDK if not present. |
| 19 | +
|
| 20 | + To add a new P4 e2e test: |
| 21 | + 1. Run `bash setup.sh` to download the P4 API SDK (if not already done) |
| 22 | + 2. Create a .sh script in tests_e2e/scripts/ (no platform suffix = runs everywhere) |
| 23 | + 3. Set P4 env vars (P4PORT, P4USER, P4PASSWD) and use `#! test actrun <graph_file>` |
| 24 | + 4. Run `python tests_e2e/tests_e2e.py p4_connect.sh` to generate the reference file |
| 25 | + 5. Commit the reference file — it must match output for the tagged build in CI |
| 26 | + 6. See tests_e2e/scripts/p4_connect.sh for an example |
9 | 27 | """ |
10 | 28 |
|
11 | 29 | import os |
@@ -297,21 +315,95 @@ def process_and_run_test(root_dir: str, source_script: str, ref_dir: str, cov_di |
297 | 315 | normalize_stack_trace_lines(ref_dir, script_name) |
298 | 316 | return output.getvalue(), result.returncode == 0 |
299 | 317 |
|
| 318 | +def get_p4_build_config() -> dict | None: |
| 319 | + """Detect P4 API SDK and return CGO flags for building with p4 tag. |
| 320 | + Returns None if P4 SDK is not available.""" |
| 321 | + p4api_dir = Path(os.getcwd()) / "p4api" |
| 322 | + if not p4api_dir.exists(): |
| 323 | + return None |
| 324 | + |
| 325 | + p4_include = str(p4api_dir / "include") |
| 326 | + arch = platform.machine().lower() |
| 327 | + if arch in ("aarch64", "arm64"): |
| 328 | + arch = "arm64" |
| 329 | + else: |
| 330 | + arch = "x64" |
| 331 | + |
| 332 | + if sys.platform == "linux": |
| 333 | + lib_name = "linux-aarch64" if arch == "arm64" else "linux-x86_64" |
| 334 | + p4_lib = str(p4api_dir / lib_name / "lib") |
| 335 | + ssl_lib = str(p4api_dir / f"ssl-linux-{arch}" / "lib") |
| 336 | + if not Path(p4_lib).exists(): |
| 337 | + return None |
| 338 | + cgo_cppflags = f"-I{p4_include}" |
| 339 | + if Path(ssl_lib).exists(): |
| 340 | + cgo_ldflags = f"-L{p4_lib} -lp4api {ssl_lib}/libssl.a {ssl_lib}/libcrypto.a" |
| 341 | + else: |
| 342 | + cgo_ldflags = f"-L{p4_lib} -lp4api -lssl -lcrypto" |
| 343 | + elif sys.platform == "darwin": |
| 344 | + p4_lib = str(p4api_dir / "macos" / "lib") |
| 345 | + ssl_lib = str(p4api_dir / f"ssl-macos-{arch}" / "lib") |
| 346 | + if not Path(p4_lib).exists(): |
| 347 | + return None |
| 348 | + cgo_cppflags = f"-I{p4_include}" |
| 349 | + cgo_ldflags = f"-L{p4_lib} -lp4api {ssl_lib}/libssl.a {ssl_lib}/libcrypto.a -framework ApplicationServices -framework Foundation -framework Security -framework CoreFoundation" |
| 350 | + elif sys.platform == "win32": |
| 351 | + if arch == "arm64": |
| 352 | + return None # P4 not supported on Windows ARM64 |
| 353 | + p4_lib = str(p4api_dir / "windows-x86_64" / "lib") |
| 354 | + if not Path(p4_lib).exists(): |
| 355 | + return None |
| 356 | + cgo_cppflags = f"-I{p4_include} -DOS_NT" |
| 357 | + # Try static OpenSSL from MSYS2 MinGW |
| 358 | + msys2_root = os.environ.get("MSYS2_ROOT", r"D:\a\_temp\msys64") |
| 359 | + msys2_ssl = Path(msys2_root) / "mingw64" / "lib" |
| 360 | + ssl_lib = str(p4api_dir / "ssl-windows-x64" / "lib") |
| 361 | + if Path(ssl_lib).exists() and (Path(ssl_lib) / "libssl.a").exists(): |
| 362 | + cgo_ldflags = f"-L{p4_lib} -lp4api {ssl_lib}/libssl.a {ssl_lib}/libcrypto.a -lcrypt32 -lws2_32 -lole32 -lshell32 -luser32 -ladvapi32" |
| 363 | + elif (msys2_ssl / "libssl.a").exists(): |
| 364 | + cgo_ldflags = f"-L{p4_lib} -lp4api {msys2_ssl}/libssl.a {msys2_ssl}/libcrypto.a -lcrypt32 -lws2_32 -lole32 -lshell32 -luser32 -ladvapi32" |
| 365 | + else: |
| 366 | + cgo_ldflags = f"-L{p4_lib} -lp4api -lssl -lcrypto -lcrypt32 -lws2_32 -lole32 -lshell32 -luser32 -ladvapi32" |
| 367 | + else: |
| 368 | + return None |
| 369 | + |
| 370 | + return { |
| 371 | + "CGO_ENABLED": "1", |
| 372 | + "CGO_CPPFLAGS": cgo_cppflags, |
| 373 | + "CGO_LDFLAGS": cgo_ldflags, |
| 374 | + } |
| 375 | + |
| 376 | + |
300 | 377 | def compile_binaries(is_github_runner: bool): |
301 | 378 | if is_github_runner: |
302 | 379 | return |
303 | 380 |
|
304 | 381 | # build CLI |
305 | 382 | cli_out = 'dist/actrun' + ('.exe' if IS_WINDOWS else '') |
306 | | - |
| 383 | + |
307 | 384 | env = GLOBAL_ENVS.copy() |
308 | 385 | env["GCFLAGS"] = "-N -l" |
309 | | - |
310 | | - build_cmd = ['go', 'build', '-o', cli_out, '.'] |
| 386 | + |
| 387 | + # Detect P4 API SDK and add build tag + CGO flags if available |
| 388 | + tags = [] |
| 389 | + p4_config = get_p4_build_config() |
| 390 | + if p4_config: |
| 391 | + tags.append("p4") |
| 392 | + env.update(p4_config) |
| 393 | + print(f"P4 API SDK detected, building with -tags=p4") |
| 394 | + else: |
| 395 | + print(f"P4 API SDK not found, building without p4 support") |
| 396 | + |
| 397 | + build_cmd = ['go', 'build'] |
| 398 | + if tags: |
| 399 | + build_cmd.append(f'-tags={",".join(tags)}') |
| 400 | + build_cmd.extend(['-o', cli_out, '.']) |
| 401 | + |
311 | 402 | if COVERAGE: |
312 | 403 | # TODO: (Seb) coverage build takes ages |
313 | | - build_cmd = ['go', 'test', '.', '-buildvcs=true', '-cover', '-coverprofile', '-tags=main_test', '-c', '-o', cli_out] |
314 | | - |
| 404 | + coverage_tags = ['main_test'] + tags |
| 405 | + build_cmd = ['go', 'test', '.', '-buildvcs=true', '-cover', '-coverprofile', f'-tags={",".join(coverage_tags)}', '-c', '-o', cli_out] |
| 406 | + |
315 | 407 | print(f"Building {cli_out}") |
316 | 408 | subprocess.run(build_cmd, stdout=sys.stdout, stderr=subprocess.STDOUT, check=True, env=env) |
317 | 409 |
|
|
0 commit comments