@@ -46,30 +46,36 @@ void Test_Berry_ChannelSet() {
46
46
SELFTEST_ASSERT_CHANNEL (1 , 0 );
47
47
SELFTEST_ASSERT_CHANNEL (2 , 0 );
48
48
49
+ int startStackSize = Berry_GetStackSize ();
49
50
// Run Berry code that sets channels
50
51
CMD_ExecuteCommand ("berry setChannel(1, 42)" , 0 );
51
52
CMD_ExecuteCommand ("berry setChannel(2, 123)" , 0 );
53
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
52
54
53
55
// Verify the channels were set correctly
54
56
SELFTEST_ASSERT_CHANNEL (1 , 42 );
55
57
SELFTEST_ASSERT_CHANNEL (2 , 123 );
56
58
57
59
// Test setting multiple channels in one script
58
60
CMD_ExecuteCommand ("berry setChannel(1, 99); setChannel(2, 88)" , 0 );
61
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
59
62
60
63
// Verify the updated values
61
64
SELFTEST_ASSERT_CHANNEL (1 , 99 );
62
65
SELFTEST_ASSERT_CHANNEL (2 , 88 );
63
66
64
67
CMD_ExecuteCommand ("berry def give() return 7 end; setChannel(1, give() * 3)" , 0 );
65
68
SELFTEST_ASSERT_CHANNEL (1 , 21 );
69
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
66
70
67
71
CMD_ExecuteCommand ("berry i = 5; def test() i = 10 end; test(); setChannel(1, i)" , 0 );
68
72
SELFTEST_ASSERT_CHANNEL (1 , 10 ); // or 5 depending on scoping rules
73
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
69
74
70
75
71
76
CMD_ExecuteCommand ("berry setChannel(5, int(\"213\")); " , 0 );
72
77
SELFTEST_ASSERT_CHANNEL (5 , 213 );
78
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
73
79
}
74
80
75
81
void Test_Berry_CancelThread () {
@@ -78,6 +84,7 @@ void Test_Berry_CancelThread() {
78
84
// reset whole device
79
85
SIM_ClearOBK (0 );
80
86
87
+ int startStackSize = Berry_GetStackSize ();
81
88
// Make sure channels start at 0
82
89
CMD_ExecuteCommand ("setChannel 1 0" , 0 );
83
90
CMD_ExecuteCommand ("setChannel 2 0" , 0 );
@@ -88,6 +95,7 @@ void Test_Berry_CancelThread() {
88
95
// Run Berry code that creates a delayed thread that would set channels
89
96
// and stores the thread ID in a global variable
90
97
CMD_ExecuteCommand ("berry thread_id = setTimeout(def() setChannel(1, 42); setChannel(2, 123); end, 100); print(thread_id)" , 0 );
98
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
91
99
92
100
// Now cancel the thread using the thread_id
93
101
CMD_ExecuteCommand ("berry cancel(thread_id)" , 0 );
@@ -103,6 +111,7 @@ void Test_Berry_CancelThread() {
103
111
104
112
// Now let's test the positive case - create a thread and let it complete
105
113
CMD_ExecuteCommand ("berry setTimeout(def() setChannel(1, 99); setChannel(2, 88); end, 50)" , 0 );
114
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
106
115
107
116
// Run scheduler to let the thread complete
108
117
for (i = 0 ; i < 20 ; i ++ ) {
@@ -131,6 +140,7 @@ void Test_Berry_CancelThread() {
131
140
}
132
141
SELFTEST_ASSERT_CHANNEL (1 , 102 );
133
142
SELFTEST_ASSERT_CHANNEL (2 , 94 );
143
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
134
144
135
145
}
136
146
@@ -382,8 +392,9 @@ void Test_Berry_ThreadCleanup() {
382
392
void Test_Berry_AutoloadModule () {
383
393
// reset whole device
384
394
SIM_ClearOBK (0 );
385
- CMD_ExecuteCommand ("lfs_format" , 0 );
395
+ CMD_ExecuteCommand ("lfs_format" , 0 );
386
396
397
+ int startStackSize = Berry_GetStackSize ();
387
398
// Create a Berry module file
388
399
Test_FakeHTTPClientPacket_POST ("api/lfs/autoexec.be" ,
389
400
"autoexec = module('autoexec')\n"
@@ -406,6 +417,7 @@ void Test_Berry_AutoloadModule() {
406
417
407
418
// Simulate a device restart by running the autoexec.txt script
408
419
CMD_ExecuteCommand ("startScript autoexec.txt" , 0 );
420
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
409
421
410
422
// Run scheduler to let any scripts complete
411
423
for (int i = 0 ; i < 5 ; i ++ ) {
@@ -419,6 +431,7 @@ void Test_Berry_AutoloadModule() {
419
431
// Test that we can now use the module functions directly
420
432
CMD_ExecuteCommand ("berry import autoexec; autoexec.init(); setChannel(6, 99)" , 0 );
421
433
SELFTEST_ASSERT_CHANNEL (6 , 99 );
434
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
422
435
}
423
436
424
437
void Test_Berry_StartScriptShortcut () {
@@ -476,6 +489,7 @@ void Test_Berry_PassArg() {
476
489
SIM_ClearOBK (0 );
477
490
CMD_ExecuteCommand ("lfs_format" , 0 );
478
491
492
+ int startStackSize = Berry_GetStackSize ();
479
493
// Create a Berry module file
480
494
Test_FakeHTTPClientPacket_POST ("api/lfs/test.be" ,
481
495
"def mySample(x)\n"
@@ -499,6 +513,7 @@ void Test_Berry_PassArg() {
499
513
500
514
// Verify that the Berry module was loaded and initialized (it should have set channel 5 to 15)
501
515
SELFTEST_ASSERT_CHANNEL (5 , 15 );
516
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
502
517
}
503
518
504
519
@@ -508,6 +523,7 @@ void Test_Berry_PassArgFromCommand() {
508
523
SIM_ClearOBK (0 );
509
524
CMD_ExecuteCommand ("lfs_format" , 0 );
510
525
526
+ int startStackSize = Berry_GetStackSize ();
511
527
// Make sure channel starts at 0
512
528
CMD_ExecuteCommand ("setChannel 5 0" , 0 );
513
529
SELFTEST_ASSERT_CHANNEL (5 , 0 );
@@ -522,6 +538,7 @@ void Test_Berry_PassArgFromCommand() {
522
538
SELFTEST_ASSERT_CHANNEL (5 , 32 );
523
539
CMD_ExecuteCommand ("berry mySample(-5)" , 0 );
524
540
SELFTEST_ASSERT_CHANNEL (5 , 27 );
541
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
525
542
}
526
543
527
544
@@ -558,6 +575,8 @@ void Test_Berry_PassArgFromCommandWithModule() {
558
575
SIM_ClearOBK (0 );
559
576
CMD_ExecuteCommand ("lfs_format" , 0 );
560
577
578
+ int startStackSize = Berry_GetStackSize ();
579
+
561
580
// Create a Berry module file
562
581
Test_FakeHTTPClientPacket_POST ("api/lfs/test.be" ,
563
582
"test = module('test')\n"
@@ -582,6 +601,7 @@ void Test_Berry_PassArgFromCommandWithModule() {
582
601
SELFTEST_ASSERT_CHANNEL (5 , 6 );
583
602
CMD_ExecuteCommand ("berry test.mySample(2)" , 0 );
584
603
SELFTEST_ASSERT_CHANNEL (5 , 8 );
604
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
585
605
}
586
606
587
607
void Test_Berry_FileSystem () {
@@ -590,6 +610,8 @@ void Test_Berry_FileSystem() {
590
610
591
611
CMD_ExecuteCommand ("lfs_format" , 0 );
592
612
613
+ int startStackSize = Berry_GetStackSize ();
614
+
593
615
// Create a Berry module file
594
616
Test_FakeHTTPClientPacket_POST ("api/lfs/test.be" ,
595
617
"test = module('test')\n"
@@ -625,6 +647,7 @@ void Test_Berry_FileSystem() {
625
647
CMD_ExecuteCommand ("berry import test2; test2.mySample()" , 0 );
626
648
Test_FakeHTTPClientPacket_GET ("api/run/test.txt" );
627
649
SELFTEST_ASSERT_HTML_REPLY ("foo bar hey" );
650
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
628
651
}
629
652
630
653
//
@@ -634,6 +657,7 @@ void Test_Berry_AddChangeHandler() {
634
657
// reset whole device
635
658
SIM_ClearOBK (0 );
636
659
660
+ int startStackSize = Berry_GetStackSize ();
637
661
// Make sure channels start at 0
638
662
CMD_ExecuteCommand ("setChannel 1 0" , 0 );
639
663
@@ -698,6 +722,7 @@ void Test_Berry_AddChangeHandler() {
698
722
SELFTEST_ASSERT_CHANNEL (2 , 1 );
699
723
CMD_ExecuteCommand ("setChannel 5 7" , 0 );
700
724
Berry_RunThreads (1 );
725
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
701
726
// TODO - it's triggered now, not as I expected....
702
727
/*
703
728
SELFTEST_ASSERT_CHANNEL(2, 1);
@@ -722,6 +747,7 @@ void Test_Berry_AddChangeHandler() {
722
747
Berry_RunThreads(1);
723
748
SELFTEST_ASSERT_CHANNEL(2, 2);
724
749
*/
750
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
725
751
}
726
752
void Test_Berry_CommandRunner () {
727
753
int i ;
@@ -757,7 +783,7 @@ void Test_Berry_TuyaMCU() {
757
783
SIM_ClearOBK (0 );
758
784
759
785
SIM_UART_InitReceiveRingBuffer (2048 );
760
-
786
+ int startStackSize = Berry_GetStackSize ();
761
787
CMD_ExecuteCommand ("startDriver TuyaMCU" , 0 );
762
788
763
789
// per-dpID handler
@@ -766,9 +792,11 @@ void Test_Berry_TuyaMCU() {
766
792
"setChannel(1, value) \n"
767
793
"end)" , 0 );
768
794
795
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
769
796
SELFTEST_ASSERT_CHANNEL (1 , 0 );
770
797
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 2 , 123 );
771
798
SELFTEST_ASSERT_CHANNEL (1 , 123 );
799
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
772
800
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 2 , 564 );
773
801
SELFTEST_ASSERT_CHANNEL (1 , 564 );
774
802
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 1 , 333 );
@@ -779,42 +807,56 @@ void Test_Berry_TuyaMCU() {
779
807
SELFTEST_ASSERT_CHANNEL (1 , 564 );
780
808
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 2 , 123 );
781
809
SELFTEST_ASSERT_CHANNEL (1 , 123 );
810
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
782
811
783
812
// global handler
784
813
CMD_ExecuteCommand ("setChannel 1 0" , 0 );
785
814
CMD_ExecuteCommand ("berry addEventHandler(\"OnDP\", def(id, value)\n"
786
815
"setChannel(5, id*10000+value) \n"
787
816
"end)" , 0 );
788
817
CMD_ExecuteCommand ("setChannel 5 0" , 0 );
818
+ Sim_RunFrames (100 , false);
789
819
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 2 , 123 );
820
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
790
821
SELFTEST_ASSERT_CHANNEL (5 , 2 * 10000 + 123 );
791
822
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 15 , 123 );
792
823
SELFTEST_ASSERT_CHANNEL (5 , 15 * 10000 + 123 );
793
824
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 15 , 555 );
794
825
SELFTEST_ASSERT_CHANNEL (5 , 15 * 10000 + 555 );
795
826
CMD_Berry_RunEventHandlers_IntInt (CMD_EVENT_ON_DP , 1 , 555 );
796
827
SELFTEST_ASSERT_CHANNEL (5 , 1 * 10000 + 555 );
797
-
828
+ SELFTEST_ASSERT ( Berry_GetStackSize () == startStackSize );
798
829
799
830
800
831
// This packet sets dpID 2 of type Value to 100
801
832
CMD_ExecuteCommand ("uartFakeHex 55AA0307000802020004000000647D" , 0 );
802
833
Sim_RunFrames (100 , false);
803
834
SELFTEST_ASSERT_CHANNEL (1 , 100 );
804
835
SELFTEST_ASSERT_CHANNEL (5 , 2 * 10000 + 100 );
805
-
806
- // This packet sets dpID 2 of type Value to 90
807
- CMD_ExecuteCommand ("uartFakeHex 55AA03070008020200040000005A73" , 0 );
808
- Sim_RunFrames (100 , false);
809
- SELFTEST_ASSERT_CHANNEL (1 , 90 );
810
- SELFTEST_ASSERT_CHANNEL (5 , 2 * 10000 + 90 );
811
- // This packet sets dpID 2 of type Value to 110
812
- CMD_ExecuteCommand ("uartFakeHex 55AA03070008020200040000006E87" , 0 );
813
- Sim_RunFrames (100 , false);
814
- SELFTEST_ASSERT_CHANNEL (1 , 110 );
815
- SELFTEST_ASSERT_CHANNEL (5 , 2 * 10000 + 110 );
816
-
817
- }
836
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
837
+
838
+ for (int tr = 0 ; tr < 20 ; tr ++ ) {
839
+ printf ("Berry stack size: %i\n" ,Berry_GetStackSize ());
840
+ // This packet sets dpID 2 of type Value to 90
841
+ CMD_ExecuteCommand ("uartFakeHex 55AA03070008020200040000005A73" , 0 );
842
+ Sim_RunFrames (100 , false);
843
+ SELFTEST_ASSERT_CHANNEL (1 , 90 );
844
+ SELFTEST_ASSERT_CHANNEL (5 , 2 * 10000 + 90 );
845
+ // TODO: ASSERT! - why?
846
+ //SELFTEST_ASSERT(Berry_GetStackSize() == startStackSize);
847
+
848
+ // This packet sets dpID 2 of type Value to 110
849
+ CMD_ExecuteCommand ("uartFakeHex 55AA03070008020200040000006E87" , 0 );
850
+ Sim_RunFrames (100 , false);
851
+ SELFTEST_ASSERT_CHANNEL (1 , 110 );
852
+ SELFTEST_ASSERT_CHANNEL (5 , 2 * 10000 + 110 );
853
+
854
+ // TODO: ASSERT! - why?
855
+ //SELFTEST_ASSERT(Berry_GetStackSize() == startStackSize);
856
+ }
857
+ int delta = Berry_GetStackSize () - startStackSize ;
858
+ printf ("Stack grew %i\n" , delta );
859
+ }
818
860
819
861
820
862
void Test_Berry_TuyaMCU_Bytes2 () {
@@ -973,6 +1015,7 @@ void Test_Berry_HTTP() {
973
1015
SIM_ClearOBK (0 );
974
1016
CMD_ExecuteCommand ("lfs_format" , 0 );
975
1017
1018
+ int startStackSize = Berry_GetStackSize ();
976
1019
// inject html to state page
977
1020
CMD_ExecuteCommand ("berry addEventHandler(\"OnHTTP\", \"state\", def(request)\n"
978
1021
" poststr(request,\"MySpecialTestString23432411\") \n"
@@ -990,6 +1033,7 @@ void Test_Berry_HTTP() {
990
1033
"end)" , 0 );
991
1034
Test_FakeHTTPClientPacket_GET ("mypage123" );
992
1035
SELFTEST_ASSERT_HTML_REPLY ("Anything" );
1036
+ SELFTEST_ASSERT (Berry_GetStackSize () == startStackSize );
993
1037
994
1038
995
1039
0 commit comments