#!/usr/bin/env python3 """Compile the actual network_console.c with deterministic boundary fakes; no networking.""" import argparse import pathlib import subprocess import tempfile parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--sanitize", action="store_true", help="enable ASan and UBSan if installed") options = parser.parse_args() HERE = pathlib.Path(__file__).resolve().parent ROOT = HERE.parents[1] headers = [ "esp_console.h", "esp_err.h", "esp_heap_caps.h", "esp_netif.h", "esp_idf_version.h", "esp_timer.h", "freertos/FreeRTOS.h", "freertos/queue.h", "freertos/task.h", "lwip/inet.h", "lwip/inet_chksum.h", "lwip/ip_addr.h", "lwip/netdb.h", "lwip/netif.h", "lwip/prot/icmp.h", "lwip/prot/ip4.h", "lwip/sockets.h", "ping/ping_sock.h", ] with tempfile.TemporaryDirectory(prefix="network-diagnostics-") as directory: tmp = pathlib.Path(directory) for header in headers: path = tmp / header path.parent.mkdir(parents=True, exist_ok=True) path.write_text('#include "fakes.h"\n') subprocess.run([ "cc", "-std=c11", "-D_DEFAULT_SOURCE", "-Wall", "-Wextra", "-Werror", "-g", "-O1", *(["-fsanitize=address,undefined", "-fno-omit-frame-pointer"] if options.sanitize else []), "-I", str(tmp), "-I", str(HERE), str(HERE / "test.c"), "-o", str(tmp / "test"), ], cwd=ROOT, check=True) subprocess.run([str(tmp / "test")], cwd=ROOT, check=True)