elks-enhanced
public
Read
Owner: themaster
Branch: master
Commits: 6893
Updated: 2026-04-19 00:15
Git CLI clone URL
git clone https://www.xt-emporium.com/git/elks-enhanced.git
Fullscreen desktop URL
Code
Commits
History
Branches
Bug Reports
Discussions
Compare
Settings
elks-enhanced
/
qemu-uip-dhcp-test.sh
File editor
#!/bin/sh set -eu SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) MFS=${MFS:-"$SCRIPT_DIR/elks/tools/bin/mfs"} IMAGE=${IMAGE:-"$SCRIPT_DIR/image/fd1440.img"} WORKDIR=${WORKDIR:-$(mktemp -d /tmp/elks-uip-dhcp.XXXXXX)} QUERY_HOST=${QUERY_HOST:-example.com} QEMU_PID= QEMU_LOG= HTTP_PID= HTTP_PORT= HTTP_ROOT= usage() { echo "Usage: $0" exit 1 } find_qemu() { if [ -n "${QEMU:-}" ]; then printf '%s\n' "$QEMU" return fi for bin in qemu-system-i386 qemu-system-x86_64; do if command -v "$bin" >/dev/null 2>&1; then command -v "$bin" return fi done echo "QEMU system emulator not found" >&2 exit 1 } QEMU_BIN=$(find_qemu) cleanup() { if [ -n "${HTTP_PID:-}" ]; then kill "$HTTP_PID" >/dev/null 2>&1 || true wait "$HTTP_PID" 2>/dev/null || true HTTP_PID= fi if [ -n "${QEMU_PID:-}" ]; then kill "$QEMU_PID" >/dev/null 2>&1 || true wait "$QEMU_PID" 2>/dev/null || true QEMU_PID= fi } trap cleanup EXIT INT TERM require_host_tools() { if ! command -v python3 >/dev/null 2>&1; then echo "python3 not found" >&2 exit 1 fi if [ ! -x "$MFS" ]; then echo "mfs tool not found at $MFS" >&2 exit 1 fi if [ ! -f "$IMAGE" ]; then echo "image not found at $IMAGE" >&2 exit 1 fi } pick_http_port() { HTTP_PORT=$(python3 - <<'PY' import socket with socket.socket() as sock: sock.bind(("127.0.0.1", 0)) print(sock.getsockname()[1]) PY ) } start_http() { HTTP_ROOT=$WORKDIR/http-root mkdir -p "$HTTP_ROOT" printf '%s\n' "uip dhcp outbound test" >"$HTTP_ROOT/index.html" pick_http_port python3 -m http.server "$HTTP_PORT" --bind 127.0.0.1 -d "$HTTP_ROOT" \ >"$WORKDIR/http.log" 2>&1 & HTTP_PID=$! } render_rc() { rcfile=$1 cat >"$rcfile" <<EOF exec > /boot.log 2>&1 umask 022 export PATH=/bin export UIP_TRACE=/tmp/uip.trace clock -s -u uip -b -p ne0 -D -q $QUERY_HOST > /uip.start 2>&1 || { echo \$? > /uip.start.status sync exit 1 } echo 0 > /uip.start.status i=0 configured=0 while test "\$i" -lt 30 do if test -f /tmp/uip-network.cfg; then source /tmp/uip-network.cfg if test "\$configured" = "1"; then break fi fi sync sleep 1 i=\`expr "\$i" + 1\` done if test "\$configured" != "1"; then echo timeout > /dhcp.ready sync sleep 20 exit 1 fi echo ok > /dhcp.ready urlget http://10.0.2.2:$HTTP_PORT/ > /url.out 2>&1 echo \$? > /url.status i=0 while test "\$i" -lt 20 do if test -f /tmp/uip-network.cfg; then source /tmp/uip-network.cfg if test "\$resolv_status" = "found"; then break fi fi sync sleep 1 i=\`expr "\$i" + 1\` done nslookup $QUERY_HOST > /nslookup.out 2>&1 echo \$? > /nslookup.status if test -f /tmp/uip-network.cfg; then cat /tmp/uip-network.cfg > /uip-network.cfg fi sync sleep 20 EOF } prepare_image() { base_image=$1 out_image=$2 rcfile=$WORKDIR/rc.sys cp "$base_image" "$out_image" render_rc "$rcfile" "$MFS" "$out_image" rm /etc/rc.sys >/dev/null 2>&1 || true "$MFS" "$out_image" cp "$rcfile" /etc/rc.sys } start_qemu() { image_file=$1 log_file=$2 QEMU_LOG=$log_file "$QEMU_BIN" \ -nodefaults \ -machine isapc \ -cpu 486,tsc \ -m 8M \ -rtc base=utc \ -display none \ -monitor none \ -serial none \ -drive file="$image_file",if=floppy,format=raw \ -boot a \ -netdev user,id=mynet \ -device ne2k_isa,irq=12,netdev=mynet >"$QEMU_LOG" 2>&1 & QEMU_PID=$! } extract_guest_file() { image_file=$1 guest_path=$2 host_path=$3 if "$MFS" -f "$image_file" cat "$guest_path" >"$host_path" 2>/dev/null; then return 0 fi : >"$host_path" return 1 } validate_results() { outdir=$1 if ! grep -q '^ok$' "$outdir/dhcp.ready"; then echo "DHCP did not complete" >&2 return 1 fi if ! grep -q '^mode=dhcp$' "$outdir/uip-network.cfg"; then echo "runtime state did not enter dhcp mode" >&2 return 1 fi if ! grep -q '^configured=1$' "$outdir/uip-network.cfg"; then echo "runtime state was not configured" >&2 return 1 fi if grep -q '^dns=0.0.0.0$' "$outdir/uip-network.cfg"; then echo "DHCP did not provide or apply a DNS server" >&2 return 1 fi if ! grep -q '^resolv_status=found$' "$outdir/uip-network.cfg"; then echo "uIP resolver did not resolve the test host" >&2 return 1 fi if grep -q '^resolv_result=0.0.0.0$' "$outdir/uip-network.cfg"; then echo "uIP resolver result was empty" >&2 return 1 fi if ! grep -q '^0$' "$outdir/url.status"; then echo "outbound HTTP failed" >&2 return 1 fi if ! grep -q 'uip dhcp outbound test' "$outdir/url.out"; then echo "outbound HTTP body mismatch" >&2 return 1 fi if ! grep -q '^0$' "$outdir/nslookup.status"; then echo "ELKS nslookup failed" >&2 return 1 fi if ! grep -q "$QUERY_HOST is " "$outdir/nslookup.out"; then echo "ELKS nslookup output missing result" >&2 return 1 fi return 0 } main() { image_file=$WORKDIR/test.img log_file=$WORKDIR/qemu.log if [ "$#" -ne 0 ]; then usage fi require_host_tools start_http prepare_image "$IMAGE" "$image_file" start_qemu "$image_file" "$log_file" sleep 45 cleanup extract_guest_file "$image_file" /boot.log "$WORKDIR/boot.log" || true extract_guest_file "$image_file" /tmp/uip.trace "$WORKDIR/uip.trace" || true extract_guest_file "$image_file" /uip-network.cfg "$WORKDIR/uip-network.cfg" || true extract_guest_file "$image_file" /dhcp.ready "$WORKDIR/dhcp.ready" || true extract_guest_file "$image_file" /url.out "$WORKDIR/url.out" || true extract_guest_file "$image_file" /url.status "$WORKDIR/url.status" || true extract_guest_file "$image_file" /nslookup.out "$WORKDIR/nslookup.out" || true extract_guest_file "$image_file" /nslookup.status "$WORKDIR/nslookup.status" || true extract_guest_file "$image_file" /uip.start "$WORKDIR/uip.start" || true extract_guest_file "$image_file" /uip.start.status "$WORKDIR/uip.start.status" || true validate_results "$WORKDIR" printf 'artifacts: %s\n' "$WORKDIR" } main "$@"
Commit message
This repository is read-only for this account.
Repository snapshot
Current branch
master
Visibility
public
Your access
Read
Remote
Configured
File activity
View file history