Skip to content

Commit 1229e22

Browse files
committed
fix: tests relating to MW init
1 parent a7674eb commit 1229e22

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/comm/comm_megawifi.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,15 @@ static enum mw_err associate_ap(void)
4545
return MW_ERR_NONE;
4646
}
4747

48-
static enum mw_err display_local_ip(void)
48+
static enum mw_err get_local_ip(u32* ip)
4949
{
5050
struct mw_ip_cfg* ip_cfg;
5151
enum mw_err err = mw_ip_current(&ip_cfg);
5252
if (err != MW_ERR_NONE) {
5353
return err;
5454
}
55-
char ip_str[16] = {};
56-
uint32_to_ip_str(ip_cfg->addr.addr, ip_str);
57-
#if DEBUG_MEGAWIFI_INIT
58-
log_info("MW: IP: %s", ip_str);
59-
scheduler_yield();
60-
#endif
61-
return err;
55+
*ip = ip_cfg->addr.addr;
56+
return MW_ERR_NONE;
6257
}
6358

6459
static bool detect_mw(void)
@@ -113,10 +108,14 @@ static void init_mega_wifi(void)
113108
return;
114109
}
115110
scheduler_yield();
116-
117111
associate_ap();
118-
display_local_ip();
119112

113+
u32 ip;
114+
err = get_local_ip(&ip);
115+
if (err != MW_ERR_NONE) {
116+
log_warn("MW: Cannot get IP");
117+
return;
118+
}
120119
err = listen_on_udp_port(CH_CONTROL_PORT, UDP_CONTROL_PORT);
121120
if (err != MW_ERR_NONE) {
122121
return;
@@ -125,7 +124,10 @@ static void init_mega_wifi(void)
125124
if (err != MW_ERR_NONE) {
126125
return;
127126
}
128-
log_info("MW: Ctrl UDP %u", UDP_CONTROL_PORT);
127+
128+
char ip_str[16];
129+
uint32_to_ip_str(ip, ip_str);
130+
log_info("MW: Ctrl UDP %s:%u", ip_str, UDP_CONTROL_PORT);
129131
scheduler_yield();
130132
}
131133

tests/unit/test_comm_megawifi.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,30 @@ static void expect_ap_connection(void)
5555
will_return(__wrap_mw_ap_assoc_wait, MW_ERR_NONE);
5656
}
5757

58-
static void expect_ip_log(void)
58+
static void expect_ip_cfg(void)
5959
{
6060
mock_ip_cfg(IP(127, 1, 2, 3));
6161
will_return(__wrap_mw_ip_current, MW_ERR_NONE);
62-
if (settings_debug_megawifi_init()) {
63-
expect_log_info("MW: IP: %s");
64-
}
6562
}
6663

6764
static void megawifi_init(void)
6865
{
6966
expect_any(__wrap_scheduler_addTickHandler, onTick);
7067
expect_any(__wrap_scheduler_addFrameHandler, onFrame);
7168
will_return(__wrap_mw_uart_is_present, true);
69+
expect_log_info("MW: Detecting...");
70+
expect_scheduler_yield();
7271
expect_mw_init();
72+
expect_log_info("MW: Found v%d.%d");
73+
expect_scheduler_yield();
7374
expect_mw_detect();
75+
expect_log_info("MW: Ctrl UDP %s:%u");
7476
expect_scheduler_yield();
75-
expect_ap_connection();
76-
expect_ip_log();
7777
expect_scheduler_yield();
78+
expect_ap_connection();
79+
expect_ip_cfg();
7880
expect_udp_port_open(CH_CONTROL_PORT, "5006");
7981
expect_udp_port_open(CH_MIDI_PORT, "5007");
80-
if (settings_debug_megawifi_init()) {
81-
expect_log_info("MW: Listening on UDP %d");
82-
}
8382
__real_comm_megawifi_init();
8483
}
8584

0 commit comments

Comments
 (0)