Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/platforms/esp32/test/main/test_erl_sources/test_wifi_scan.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ wifi_scan_test() ->
io:format("network:wifi_scan found ~p networks.\n", [Num]),
lists:foreach(
fun(
_Network = #{
#{
authmode := Mode,
bssid := BSSID,
channel := Number,
Expand All @@ -61,10 +61,22 @@ wifi_scan_test() ->
ssid := SSID
}
) ->
io:format(
"Network: ~p, BSSID: ~p, signal ~p dBm, Security: ~p, channel ~p, hidden: ~p\n",
[SSID, BSSID, DBm, Mode, Number, Hidden]
)
io:put_chars([
"Network: ",
SSID,
", BSSID: ",
bssid_hex(BSSID),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test. Are we asserting against the BSSID hex?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No asserts, suppose this an indirect test, and the entire thing is also indirectly an example.

Do you want to get rid of bssid_hex helpers? and just remove BSSID logging?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I the values are know in advance we should at least match them against some know values, so we can detect bugs in the network driver.
Anyway this suggestion is not about C61 flappiness, so it can be discuted/postponed to another PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I was just suggesting we are modifying dead code. No one reads this log I guess. But we can keep this homemade bin to hex.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think the BSSID of the mock access point can be reliably be known ahead of time. I only added the logging to make the test more useful if someone wanted to smoke test on local hardware. For the sake of the CI it probably makes more sense to remove all logging rather that add unnecessary code that will make the CI take longer to run.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with some logging, in case of any problem it makes our life easier.

", signal ",
integer_to_list(DBm),
" dBm",
", Security: ",
atom_to_list(Mode),
", channel ",
integer_to_list(Number),
", hidden: ",
atom_to_list(Hidden),
"\n"
])
end,
Networks
),
Expand All @@ -82,6 +94,29 @@ wifi_scan_test() ->
erlang:error({network_start_failed, Reason})
end.

%% Inline hex formatter — Important on
%% tiny-RAM targets (esp32c61) where it can OOM.
bssid_hex(<<A, B, C, D, E, F>>) ->
[
byte_hex(A),
$:,
byte_hex(B),
$:,
byte_hex(C),
$:,
byte_hex(D),
$:,
byte_hex(E),
$:,
byte_hex(F)
].

byte_hex(B) ->
[hex_char(B bsr 4), hex_char(B band 16#0F)].

hex_char(N) when N < 10 -> $0 + N;
hex_char(N) -> $a + N - 10.

deny_concurrent_scan_test() ->
case network:start([{sta, [managed, {scan_dwell_ms, 400}]}]) of
{ok, _Pid} ->
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/esp32/test/main/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,13 @@ TEST_CASE("test_wifi_example", "[test_run]")
}
#endif

#if !CONFIG_IDF_TARGET_ESP32C61
TEST_CASE("test_wifi_managed", "[test_run]")
{
term ret_value = avm_test_case("test_wifi_managed.beam");
TEST_ASSERT(ret_value == OK_ATOM);
}
#endif

TEST_CASE("test_wifi_scan", "[test_run]")
{
Expand Down
Loading