diff --git a/.github/workflows/posix.yml b/.github/workflows/posix.yml index 0c64cd932..5f91bc3d1 100644 --- a/.github/workflows/posix.yml +++ b/.github/workflows/posix.yml @@ -245,18 +245,22 @@ jobs: name: cov-posix-ncp-rcp-migrate path: tmp/coverage.info - posix-pty: + pty-linux: + name: pty-linux OT_DAEMON=${{ matrix.OT_DAEMON }} runs-on: ubuntu-20.04 + strategy: + matrix: + OT_DAEMON: ['off', 'on'] env: COVERAGE: 1 + OT_DAEMON: ${{ matrix.OT_DAEMON }} + OT_READLINE: 'readline' steps: - uses: actions/checkout@v2 - with: - submodules: true - name: Bootstrap run: | sudo rm /etc/apt/sources.list.d/* && sudo apt-get update - sudo apt-get --no-install-recommends install -y socat expect lcov net-tools + sudo apt-get --no-install-recommends install -y socat expect lcov net-tools ninja-build cd /tmp wget https://github.com/obgm/libcoap/archive/bsd-licensed.tar.gz tar xvf bsd-licensed.tar.gz @@ -267,7 +271,6 @@ jobs: sudo make install - name: Build run: | - ./bootstrap script/check-posix-pty build - name: Run run: | @@ -277,44 +280,29 @@ jobs: ./script/test generate_coverage gcc - uses: actions/upload-artifact@v2 with: - name: cov-posix-pty + name: cov-pty-linux-${{ matrix.DAEMON }} path: tmp/coverage.info - posix-pty-daemon: - runs-on: ubuntu-20.04 + pty-macos: + name: pty-macos OT_DAEMON=${{ matrix.OT_DAEMON }} + runs-on: macos-10.15 + strategy: + matrix: + OT_DAEMON: ['off', 'on'] env: - COVERAGE: 1 - DAEMON: 1 + OT_DAEMON: ${{ matrix.OT_DAEMON }} + OT_READLINE: 'off' steps: - uses: actions/checkout@v2 - with: - submodules: true - name: Bootstrap run: | - sudo rm /etc/apt/sources.list.d/* && sudo apt-get update - sudo apt-get --no-install-recommends install -y socat expect lcov net-tools - cd /tmp - wget https://github.com/obgm/libcoap/archive/bsd-licensed.tar.gz - tar xvf bsd-licensed.tar.gz - cd libcoap-bsd-licensed - ./autogen.sh - ./configure --prefix= --exec-prefix=/usr --with-boost=internal --disable-tests --disable-documentation - make -j2 - sudo make install + brew install ninja socat - name: Build run: | - ./bootstrap script/check-posix-pty build - name: Run run: | script/check-posix-pty check - - name: Generate Coverage - run: | - ./script/test generate_coverage gcc - - uses: actions/upload-artifact@v2 - with: - name: cov-posix-pty-daemon - path: tmp/coverage.info upload-coverage: needs: @@ -322,8 +310,7 @@ jobs: - posix-cli - posix-ncp - posix-ncp-rcp-migrate - - posix-pty - - posix-pty-daemon + - pty-linux runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/simulation-1.1.yml b/.github/workflows/simulation-1.1.yml index 08958c3fd..24c679368 100644 --- a/.github/workflows/simulation-1.1.yml +++ b/.github/workflows/simulation-1.1.yml @@ -202,6 +202,7 @@ jobs: path: tmp/coverage.info cli-mtd: + name: cli-mtd MESSAGE_USE_HEAP=${{ matrix.message_use_heap }} runs-on: ubuntu-20.04 strategy: matrix: diff --git a/script/check-posix-pty b/script/check-posix-pty index f468a1d54..9b2ff73c0 100755 --- a/script/check-posix-pty +++ b/script/check-posix-pty @@ -50,32 +50,63 @@ at_exit() exit $EXIT_CODE } -build() +wait_for_socat() { - make -f examples/Makefile-simulation - make -f src/posix/Makefile-posix PLATFORM_NETIF=1 PLATFORM_UDP=1 UDP_FORWARD=0 MAX_POWER_TABLE=1 + if [[ "$(head -n2 "$SOCAT_OUTPUT" | wc -l | tr -d ' ')" == 2 ]]; then + RADIO_PTY=$(head -n1 "$SOCAT_OUTPUT" | grep -o '/dev/.\+') + CORE_PTY=$(head -n2 "$SOCAT_OUTPUT" | tail -n1 | grep -o '/dev/.\+') + return 0 + else + echo 'Still waiting for socat' + fi + return 1 } -check() +wait_for_leader() +{ + if grep -q leader "$OT_OUTPUT"; then + return 0 + else + echo 'Still waiting for leader' + fi + return 1 +} + +timeout_run() +{ + local count="$1" + local exit_code + shift 1 + + while [[ $count != 0 && $exit_code != 0 ]]; do + count=$((count - 1)) + "$@" && return 0 || exit_code=$? + sleep 1 + done + + return $exit_code +} + +do_build() +{ + ./script/cmake-build simulation + ./script/cmake-build posix -DOT_PLATFORM_NETIF=1 -DOT_PLATFORM_UDP=1 -DOT_UDP_FORWARD=0 -DOT_POSIX_MAX_POWER_TABLE=1 -DOT_DAEMON="${OT_DAEMON}" -DOT_READLINE="${OT_READLINE}" +} + +do_check() { trap at_exit INT TERM EXIT + sudo rm -rf tmp + SOCAT_OUTPUT=/tmp/ot-socat OT_OUTPUT=/tmp/ot-output socat -d -d pty,raw,echo=0 pty,raw,echo=0 >/dev/null 2>$SOCAT_OUTPUT & - while true; do - if test "$(head -n2 $SOCAT_OUTPUT | wc -l)" = 2; then - RADIO_PTY=$(head -n1 $SOCAT_OUTPUT | grep -o '/dev/.\+') - CORE_PTY=$(head -n2 $SOCAT_OUTPUT | tail -n1 | grep -o '/dev/.\+') - break - fi - echo 'Waiting for socat ready...' - sleep 1 - done + timeout_run 10 wait_for_socat echo 'RADIO_PTY' "$RADIO_PTY" echo 'CORE_PTY' "$CORE_PTY" - RADIO_NCP_PATH="$PWD/output/simulation/bin/ot-rcp" + RADIO_NCP_PATH="$PWD/build/simulation/examples/apps/ncp/ot-rcp" # shellcheck disable=SC2094 $RADIO_NCP_PATH 1 >"$RADIO_PTY" <"$RADIO_PTY" & @@ -85,10 +116,10 @@ check() RADIO_URL="spinel+hdlc+uart://${CORE_PTY}?region=US&max-power-table=11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26" - if [[ ${DAEMON} == 1 ]]; then - sudo "$PWD/output/posix/bin/ot-daemon" -I "${VALID_NETIF_NAME}" "${RADIO_URL}" & + if [[ ${OT_DAEMON} == 'on' ]]; then + sudo "$PWD/build/posix/src/posix/ot-daemon" -I "${VALID_NETIF_NAME}" "${RADIO_URL}" & sleep 1 - OT_CLI_CMD="$PWD/output/posix/bin/ot-ctl" + OT_CLI_CMD="$PWD/build/posix/src/posix/ot-ctl" sudo "${OT_CLI_CMD}" panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl' # verify this reset and factoryreset end immediately @@ -97,7 +128,7 @@ check() sleep 2 sudo "${OT_CLI_CMD}" factoryreset else - OT_CLI="$PWD/output/posix/bin/ot-cli" + OT_CLI="$PWD/build/posix/src/posix/ot-cli" sudo "${OT_CLI}" -I "${VALID_NETIF_NAME}" -n "${RADIO_URL}" # Cover setting a too long(max is 15 characters) network interface name. @@ -105,11 +136,14 @@ check() readonly INVALID_NETIF_NAME="wan0123456789123" sudo "${OT_CLI}" -I "${INVALID_NETIF_NAME}" -n "${RADIO_URL}" || test $? = 2 - OT_CLI_CMD="$PWD/output/posix/bin/ot-cli ${RADIO_URL}" + OT_CLI_CMD="$PWD/build/posix/src/posix/ot-cli ${RADIO_URL}" fi sudo expect <(rval), MSG_NOSIGNAL); #else - rval = write(sSessionSocket, buf, static_cast(rval)); + rval = static_cast(write(sSessionSocket, buf, static_cast(rval))); #endif if (rval < 0) diff --git a/src/posix/platform/udp.cpp b/src/posix/platform/udp.cpp index 96b3b978a..80483b8ef 100644 --- a/src/posix/platform/udp.cpp +++ b/src/posix/platform/udp.cpp @@ -312,7 +312,7 @@ otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifId VerifyOrExit(setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, nullptr, 0) == 0, error = OT_ERROR_FAILED); #else // __NetBSD__ || __FreeBSD__ || __APPLE__ unsigned int netifIndex = 0; - VerifyOrExit(setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &netifIndex, sizeof(netifIndex)) == 0, + VerifyOrExit(setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF, &netifIndex, sizeof(netifIndex)) == 0, error = OT_ERROR_FAILED); #endif // __linux__ break;