fix: support JD host native QEMU validation
This commit is contained in:
parent
856a6c9ffb
commit
95385e812a
5 changed files with 101 additions and 9 deletions
|
|
@ -183,10 +183,13 @@ def main() -> None:
|
|||
parser.add_argument("--login-only", action="store_true")
|
||||
parser.add_argument("--anchor-http", action="store_true")
|
||||
parser.add_argument("--service-equivalence", action="store_true")
|
||||
parser.add_argument("--timeout-seconds", type=float)
|
||||
parser.add_argument("--guest-ip", default="172.16.0.6")
|
||||
parser.add_argument("--peer-ip", default="172.16.0.1")
|
||||
parser.add_argument("--relay-ip", default="43.153.193.169")
|
||||
args = parser.parse_args()
|
||||
if args.timeout_seconds is not None and args.timeout_seconds <= 0:
|
||||
raise SystemExit("--timeout-seconds must be greater than zero")
|
||||
if sum((args.resident, args.final_resident, args.login_only)) > 1:
|
||||
raise SystemExit("--resident, --final-resident and --login-only are mutually exclusive")
|
||||
if args.final_resident and not args.recovery_token_file:
|
||||
|
|
@ -202,10 +205,15 @@ def main() -> None:
|
|||
RELAY_IP = socket.inet_aton(args.relay_ip)
|
||||
|
||||
peer = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
peer.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4 * 1024 * 1024)
|
||||
peer.bind(("127.0.0.1", args.listen_port))
|
||||
peer.settimeout(0.2)
|
||||
qemu = ("127.0.0.1", args.qemu_port)
|
||||
deadline = time.monotonic() + (30 if args.service_equivalence else 15)
|
||||
deadline = time.monotonic() + (
|
||||
args.timeout_seconds
|
||||
if args.timeout_seconds is not None
|
||||
else (30 if args.service_equivalence else 15)
|
||||
)
|
||||
arp_verified = False
|
||||
login_count = 0
|
||||
resident_login_count = 0
|
||||
|
|
@ -323,6 +331,11 @@ def main() -> None:
|
|||
)
|
||||
code_syn_sent = True
|
||||
continue
|
||||
if args.service_equivalence and anchor_syn_sent and not code_http_verified:
|
||||
# The final-resident fixture keeps emitting ordinary ICMP heartbeats while
|
||||
# the two HTTP probes run. Older QEMU socket backends can otherwise let
|
||||
# that traffic starve the second TCP response in the UDP receive queue.
|
||||
continue
|
||||
sequence = int.from_bytes(frame[40:42], "big")
|
||||
if sequence <= 3:
|
||||
magic = LOGIN_MAGIC
|
||||
|
|
@ -346,7 +359,8 @@ def main() -> None:
|
|||
raise AssertionError(f"unexpected native sequence {sequence}")
|
||||
verified_request(frame, sequence, magic)
|
||||
peer.sendto(ordinary_reply(frame), qemu)
|
||||
time.sleep(0.005 if args.service_equivalence else 0.05)
|
||||
if not args.service_equivalence:
|
||||
time.sleep(0.05)
|
||||
response_capability = NATIVE_ACK_MAGIC
|
||||
if (
|
||||
args.final_resident
|
||||
|
|
@ -359,8 +373,8 @@ def main() -> None:
|
|||
reply = authenticated_reply(frame, response_capability)
|
||||
for repetition in range(4):
|
||||
peer.sendto(reply, qemu)
|
||||
if repetition < 3:
|
||||
time.sleep(0.001 if args.service_equivalence else 0.01)
|
||||
if repetition < 3 and not args.service_equivalence:
|
||||
time.sleep(0.01)
|
||||
if (
|
||||
(args.anchor_http or args.service_equivalence)
|
||||
and args.final_resident
|
||||
|
|
|
|||
|
|
@ -13,6 +13,18 @@ source_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|||
native_root=${source_root}/native/x86_64-bios
|
||||
test_root=$(mktemp -d)
|
||||
peer_pid=
|
||||
qemu_netdev_backend() {
|
||||
local id=$1
|
||||
local local_port=$2
|
||||
local remote_port=$3
|
||||
if qemu-system-x86_64 -netdev help 2>&1 | grep -qx 'dgram'; then
|
||||
printf 'dgram,id=%s,local.type=inet,local.host=127.0.0.1,local.port=%s,remote.type=inet,remote.host=127.0.0.1,remote.port=%s' \
|
||||
"${id}" "${local_port}" "${remote_port}"
|
||||
else
|
||||
printf 'socket,id=%s,udp=127.0.0.1:%s,localaddr=127.0.0.1:%s' \
|
||||
"${id}" "${remote_port}" "${local_port}"
|
||||
fi
|
||||
}
|
||||
cleanup() {
|
||||
if [[ -n ${peer_pid} ]]; then
|
||||
kill "${peer_pid}" 2>/dev/null || true
|
||||
|
|
@ -45,12 +57,14 @@ dd if="${candidate}" of="${test_root}/disk.img" \
|
|||
|
||||
peer_port=$((33000 + ${BASHPID:-$$} % 1000))
|
||||
qemu_port=$((peer_port + 1))
|
||||
qemu_netdev=$(qemu_netdev_backend ghnet "${qemu_port}" "${peer_port}")
|
||||
python3 "${source_root}/scripts/qemu-native-net-peer.py" \
|
||||
--listen-port "${peer_port}" \
|
||||
--qemu-port "${qemu_port}" \
|
||||
--receipt "${test_root}/peer.hldp" \
|
||||
--final-resident \
|
||||
--service-equivalence \
|
||||
--timeout-seconds "${GHOS_PEER_TIMEOUT_SECONDS:-30}" \
|
||||
--recovery-token-file "${token_file}" >"${test_root}/peer.log" 2>&1 &
|
||||
peer_pid=$!
|
||||
set +e
|
||||
|
|
@ -59,7 +73,7 @@ timeout "${GHOS_QEMU_TIMEOUT_SECONDS:-40}" qemu-system-x86_64 \
|
|||
-m 64M \
|
||||
-drive "if=none,id=ghboot,format=raw,file=${test_root}/disk.img" \
|
||||
-device virtio-blk-pci,drive=ghboot,disable-modern=on,bootindex=0 \
|
||||
-netdev "dgram,id=ghnet,local.type=inet,local.host=127.0.0.1,local.port=${qemu_port},remote.type=inet,remote.host=127.0.0.1,remote.port=${peer_port}" \
|
||||
-netdev "${qemu_netdev}" \
|
||||
-device virtio-net-pci,netdev=ghnet,disable-modern=on,mac=52:54:00:26:71:98 \
|
||||
-display none \
|
||||
-monitor none \
|
||||
|
|
@ -111,6 +125,7 @@ dd if="${candidate}" of="${test_root}/wrong-capability-disk.img" \
|
|||
bs=512 seek=105 conv=notrunc status=none
|
||||
wrong_peer_port=$((peer_port + 2))
|
||||
wrong_qemu_port=$((qemu_port + 2))
|
||||
wrong_qemu_netdev=$(qemu_netdev_backend ghnet "${wrong_qemu_port}" "${wrong_peer_port}")
|
||||
python3 "${source_root}/scripts/qemu-native-net-peer.py" \
|
||||
--listen-port "${wrong_peer_port}" \
|
||||
--qemu-port "${wrong_qemu_port}" \
|
||||
|
|
@ -125,7 +140,7 @@ timeout 5 qemu-system-x86_64 \
|
|||
-m 64M \
|
||||
-drive "if=none,id=ghboot,format=raw,file=${test_root}/wrong-capability-disk.img" \
|
||||
-device virtio-blk-pci,drive=ghboot,disable-modern=on,bootindex=0 \
|
||||
-netdev "dgram,id=ghnet,local.type=inet,local.host=127.0.0.1,local.port=${wrong_qemu_port},remote.type=inet,remote.host=127.0.0.1,remote.port=${wrong_peer_port}" \
|
||||
-netdev "${wrong_qemu_netdev}" \
|
||||
-device virtio-net-pci,netdev=ghnet,disable-modern=on,mac=52:54:00:26:71:98 \
|
||||
-display none \
|
||||
-monitor none \
|
||||
|
|
@ -161,6 +176,7 @@ candidate:
|
|||
lba_start: 105
|
||||
sector_count: 29
|
||||
sha256: ${image_sha}
|
||||
qemu_network_backend: ${qemu_netdev%%,*}
|
||||
resident_runtime:
|
||||
initial_login_replies: 3
|
||||
code_commit_reply_verified: true
|
||||
|
|
|
|||
Loading…
Reference in a new issue