Skip to content

Commit 67136b8

Browse files
hugueskambaevedon
authored andcommitted
Make compatible with Minimal-printf (#42)
Remove flags and width format sub-specifiers on `printf()` calls as Minimal-printf does not support them. This commit ensures that the output when built with Minimal-printf is legible and similar to the output when using the standard library.
1 parent 89dab83 commit 67136b8

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

main.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,39 @@ void print_stats()
3333
int count;
3434

3535
memset(&stats[0], 0, sizeof(mbed_stats_socket_t) * MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
36-
printf("%-15s%-15s%-15s%-15s%-15s%-15s%-15s\n", "Num", "ID", "State", "Proto", "Sent", "Recv", "Time");
3736
while (COMPLETED_FLAG != threadFlag.get()) {
3837
count = SocketStats::mbed_stats_socket_get_each(&stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
3938
for (int i = 0; i < count; i++) {
4039
stdio_mutex.lock();
41-
printf("\n%-15d", num);
42-
printf("%-15p", stats[i].reference_id);
40+
printf("Num: %d", num);
41+
printf(" ID: %p", stats[i].reference_id);
4342

4443
switch (stats[i].state) {
4544
case SOCK_CLOSED:
46-
printf("%-15s", "Closed");
45+
printf(" State: Closed");
4746
break;
4847
case SOCK_OPEN:
49-
printf("%-15s", "Open");
48+
printf(" State: Open");
5049
break;
5150
case SOCK_CONNECTED:
52-
printf("%-15s", "Connected");
51+
printf(" State: Connected");
5352
break;
5453
case SOCK_LISTEN:
55-
printf("%-15s", "Listen");
54+
printf(" State: Listen");
5655
break;
5756
default:
58-
printf("%-15s", "Error");
57+
printf(" State: Error");
5958
break;
6059
}
6160

6261
if (NSAPI_TCP == stats[i].proto) {
63-
printf("%-15s", "TCP");
62+
printf(" Proto: TCP");
6463
} else {
65-
printf("%-15s", "UDP");
64+
printf(" Proto: UDP");
6665
}
67-
printf("%-15d", stats[i].sent_bytes);
68-
printf("%-15d", stats[i].recv_bytes);
69-
printf("%-15lld\n", stats[i].last_change_tick);
66+
printf(" Sent: %d", stats[i].sent_bytes);
67+
printf(" Recv: %d", stats[i].recv_bytes);
68+
printf(" Time: %lld\n", stats[i].last_change_tick);
7069
stdio_mutex.unlock();
7170
}
7271
num++;

tests/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
Examples are tested using tool [htrun](https://github.com/ARMmbed/mbed-os-tools/tree/master/packages/mbed-host-tests) and templated print log.
44

55
To run the test, use following command after you build the example:
6+
```bash
7+
$ mbedhtrun -d <MOUNT_POINT> -p <SERIAL_PORT> -m <TARGET> -f ./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-socket-stats.bin --compare-log tests/socket-stats.log
68
```
7-
mbedhtrun -d D: -p COM4 -m K64F -f .\BUILD\K64F\GCC_ARM\socket-stats.bin --compare-log tests\socket-stats.log
9+
For example:
10+
```bash
11+
$ mbedhtrun -d /media/user01/DAPLINK -p /dev/ttyACM0 -m K64F -f ./BUILD/K64F/GCC_ARM/mbed-os-example-socket-stats.bin --compare-log tests/socket-stats.log
812
```
913

1014

tests/socket-stats.log

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ Mbed OS version:
44
IP address: (?:[0-9]{1,3}\.){3}[0-9]{1,3}
55
Netmask: (?:[0-9]{1,3}\.){3}[0-9]{1,3}
66
Gateway: (?:[0-9]{1,3}\.){3}[0-9]{1,3}
7-
Num\s+ID\s+State\s+Proto\s+Sent\s+Recv\s+Time
87

9-
\d+\s+(0x)?[0-9a-fA-F]+\s+Open\s+TCP\s+\d+\s+\d+\s+\d+
10-
\d+\s+(0x)?[0-9a-fA-F]+\s+Closed\s+UDP\s+\d+\s+\d+\s+\d+
8+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Open Proto: TCP Sent: \d+ Recv: \d+ Time: \d+
9+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Closed Proto: UDP Sent: \d+ Recv: \d+ Time: \d+
1110
sent \d+ \[GET \/ HTTP\/\d.\d\]
1211

13-
\d+\s+(0x)?[0-9a-fA-F]+\s+Connected\s+TCP\s+\d+\s+\d+\s+\d+
14-
\d+\s+(0x)?[0-9a-fA-F]+\s+Closed\s+UDP\s+\d+\s+\d+\s+\d+
12+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Connected Proto: TCP Sent: \d+ Recv: \d+ Time: \d+
13+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Closed Proto: UDP Sent: \d+ Recv: \d+ Time: \d+
1514
recv \d+ \[HTTP\/\d.\d \d+ OK\]
1615

17-
\d+\s+(0x)?[0-9a-fA-F]+\s+Connected\s+TCP\s+\d+\s+\d+\s+\d+
18-
\d+\s+(0x)?[0-9a-fA-F]+\s+Closed\s+UDP\s+\d+\s+\d+\s+\d+
16+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Connected Proto: TCP Sent: \d+ Recv: \d+ Time: \d+
17+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Closed Proto: UDP Sent: \d+ Recv: \d+ Time: \d+
1918
External IP address: (?:[0-9]{1,3}\.){3}[0-9]{1,3}
2019

21-
\d+\s+(0x)?[0-9a-fA-F]+\s+Connected\s+TCP\s+\d+\s+\d+\s+\d+
22-
\d+\s+(0x)?[0-9a-fA-F]+\s+Closed\s+UDP\s+\d+\s+\d+\s+\d+
20+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Connected Proto: TCP Sent: \d+ Recv: \d+ Time: \d+
21+
Num: \d+ ID: (0x)?[0-9a-fA-F]+ State: Closed Proto: UDP Sent: \d+ Recv: \d+ Time: \d+
2322
Done

0 commit comments

Comments
 (0)