From ea7c76cc4b4540504cd60d1167fd861939bbaea0 Mon Sep 17 00:00:00 2001 From: Moandor Date: Thu, 4 Jun 2020 13:11:14 +0800 Subject: [PATCH] [test] add expect tests for pcap receiving (#5043) This adds expect tests for testing the pcap receiving function of promiscuous mode. Also makes otLinkSetPromiscuous be called before otLinkSetPcapCallback so that the callback won't be set when promiscuous mode fails to start. --- src/cli/cli.cpp | 2 +- tests/scripts/expect/cli-2-nodes.exp | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index ccec36f2b..144f366d6 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2433,8 +2433,8 @@ void Interpreter::ProcessPromiscuous(uint8_t aArgsLength, char *aArgs[]) { if (strcmp(aArgs[0], "enable") == 0) { - otLinkSetPcapCallback(mInstance, &HandleLinkPcapReceive, this); SuccessOrExit(error = otLinkSetPromiscuous(mInstance, true)); + otLinkSetPcapCallback(mInstance, &HandleLinkPcapReceive, this); } else if (strcmp(aArgs[0], "disable") == 0) { diff --git a/tests/scripts/expect/cli-2-nodes.exp b/tests/scripts/expect/cli-2-nodes.exp index 3ec38ccd8..94a2ae222 100755 --- a/tests/scripts/expect/cli-2-nodes.exp +++ b/tests/scripts/expect/cli-2-nodes.exp @@ -53,11 +53,10 @@ proc wait_for {command expected} { set timeout 1 spawn $env(OT_COMMAND) 1 set spawn_1 $spawn_id -expect_after { - timeout { exit 1 } -} spawn $env(OT_COMMAND) 2 set spawn_2 $spawn_id +spawn $env(OT_COMMAND) 3 +set spawn_3 $spawn_id expect_after { timeout { exit 1 } } @@ -84,6 +83,10 @@ expect "Done" expect "Commissioner: active" send "commissioner joiner add $eui64 $psk\n" expect "Done" +send "channel\n" +expect -re {(\d+)} +set channel $expect_out(1,string) +expect "Done" set spawn_id $spawn_2 send "mode rs\n" @@ -97,6 +100,12 @@ send "thread start\n" expect "Done" wait_for "state" "child" +set spawn_id $spawn_3 +send "channel $channel\n" +expect "Done" +send "promiscuous enable\n" +expect "Done" + # ping set spawn_id $spawn_2 @@ -107,12 +116,19 @@ set addr $expect_out(1,string) set spawn_id $spawn_1 send "ping $addr\n" expect "16 bytes from $addr: icmp_seq=1" -send "ping $addr 20 10 0.123456 255\n" +send "ping $addr 20 10 0.00123456 255\n" for {set i 2} {$i <= 11} {incr i} { expect "28 bytes from $addr: icmp_seq=$i" } +# pcap receive +set spawn_id $spawn_3 +expect -re {={44}\[len =\s+\d+]={28}} +expect -re {\|( ([0-9A-Z]{2}|\.\.)){16}\|( .){16}\|} +expect -re {-{83}} + + # child set spawn_id $spawn_2 send "extaddr\n"