#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT"

fuser -k 9000/tcp 4840/tcp 2>/dev/null || true
sleep 1

./build/bin/softbus_daemon \
  --config config/daemon_profile.json \
  --point-table config/point_table.json \
  --self-test > /tmp/valve_loop_daemon.log 2>&1 &
DAEMON_PID=$!
sleep 1
./build/bin/softbus_edge --config config/edge.json > /tmp/valve_loop_edge.log 2>&1 &
EDGE_PID=$!
sleep 8

kill "$DAEMON_PID" "$EDGE_PID" 2>/dev/null || true
fuser -k 9000/tcp 4840/tcp 2>/dev/null || true

grep -q "state=Succeeded" /tmp/valve_loop_daemon.log
grep -q "executedValue=60" /tmp/valve_loop_daemon.log
grep -q "ValveOpening value=60" /tmp/valve_loop_edge.log

echo "valve_control_loop: PASS"
