forked from arendst/Tasmota
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbug4_http_taskloop_diag.tc
More file actions
108 lines (98 loc) · 2.97 KB
/
Copy pathbug4_http_taskloop_diag.tc
File metadata and controls
108 lines (98 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Bug #4 diagnostic: is httpGet() TaskLoop crash HTTPClientLight-specific
// or does the plain WiFiClient+HTTPClient path crash too?
//
// Test matrix:
// A) main-loop + plain http:// → baseline, must work
// B) main-loop + https:// → baseline, must work
// C) TaskLoop + plain http:// → key datapoint
// D) TaskLoop + https:// → known to crash per gemu2015
//
// NOTE: Inline variant — string literals passed to user functions with char[]
// params trigger a compiler bug (LOAD_CONST vs const-pool ref mismatch).
// Working around it by inlining the http calls.
persist int stage_done; // bitmask: 1=A 2=B 4=C 8=D
persist int a_ok;
persist int b_ok;
persist int c_ok;
persist int d_ok;
persist int a_code;
persist int b_code;
persist int c_code;
persist int d_code;
persist int summary_printed;
char log_buf[96];
char resp[512];
char url_http[64];
char url_https[64];
void EverySecond() {
int code;
if ((stage_done & 1) == 0) {
addLog("[DIAG] A: main-loop + http://");
resp[0] = 0;
code = httpGet(url_http, resp);
a_code = code;
a_ok = (code > 0);
sprintf(log_buf, "[DIAG] A code=%d len=%d", code, strlen(resp));
addLog(log_buf);
stage_done = stage_done | 1;
return;
}
if ((stage_done & 2) == 0) {
addLog("[DIAG] B: main-loop + https://");
resp[0] = 0;
code = httpGet(url_https, resp);
b_code = code;
b_ok = (code > 0);
sprintf(log_buf, "[DIAG] B code=%d len=%d", code, strlen(resp));
addLog(log_buf);
stage_done = stage_done | 2;
return;
}
if (!summary_printed && (stage_done & 15) == 15) {
sprintf(log_buf, "[DIAG] SUMMARY A=%d(%d) B=%d(%d) C=%d(%d) D=%d(%d)",
a_ok, a_code, b_ok, b_code, c_ok, c_code, d_ok, d_code);
addLog(log_buf);
summary_printed = 1;
}
}
void TaskLoop() {
int code;
while ((stage_done & 3) != 3) {
delay(1000);
}
delay(2000);
addLog("[DIAG] C: task-loop + http:// (crash here = WiFi stack itself not task-safe)");
resp[0] = 0;
code = httpGet(url_http, resp);
c_code = code;
c_ok = (code > 0);
sprintf(log_buf, "[DIAG] C code=%d len=%d", code, strlen(resp));
addLog(log_buf);
stage_done = stage_done | 4;
delay(2000);
addLog("[DIAG] D: task-loop + https:// (expected crash per gemu2015)");
resp[0] = 0;
code = httpGet(url_https, resp);
d_code = code;
d_ok = (code > 0);
sprintf(log_buf, "[DIAG] D code=%d len=%d", code, strlen(resp));
addLog(log_buf);
stage_done = stage_done | 8;
while (1) delay(60000);
}
int main() {
addLog("[DIAG] Bug #4 httpGet TaskLoop diagnostic start");
strcpy(url_http, "http://example.com/");
strcpy(url_https, "https://example.com/");
stage_done = 0;
summary_printed = 0;
a_ok = 0;
b_ok = 0;
c_ok = 0;
d_ok = 0;
a_code = 0;
b_code = 0;
c_code = 0;
d_code = 0;
return 0;
}