Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async control & api update #3

Merged
merged 23 commits into from
Jan 7, 2024
Merged

Async control & api update #3

merged 23 commits into from
Jan 7, 2024

Conversation

GreenWizard2015
Copy link
Collaborator

I don't think there's any point in describing the code :)

The main issue is with compiling the unit tests. I've set up a native environment and separated the platform-dependent code, but for some reason, all files are being compiled during the build, which is causing problems.

@psmgeelen
Copy link
Owner

Awesome!

@psmgeelen
Copy link
Owner

@psmgeelen
Copy link
Owner

@psmgeelen
Copy link
Owner

@omonrise has debugged most issues, but we might have an issue with the testing suite itself: https://docs.platformio.org/en/latest/advanced/unit-testing/frameworks/index.html It seems that not every platform is supported by each testing suite

@psmgeelen
Copy link
Owner

@psmgeelen
Copy link
Owner

And there something for local development called Arduino Mock?!? https://github.com/platformio/platformio-examples/tree/develop/unit-testing/arduino-mock

@omonrise
Copy link
Collaborator

tried to switch to unity testing framework aaand

In file included from .pio\libdeps\uno_r4_wifi\Unity\src\unity.h:21:0,
from .pio\libdeps\uno_r4_wifi\Unity\src\unity.c:7:
.pio\libdeps\uno_r4_wifi\Unity\src\unity_internals.h:11:10: fatal error: unity_config.h: No such file or directory



#include "unity_config.h"
^~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\uno_r4_wifi\lib062\Unity\unity.c.o] Error 1

Hi @GreenWizard2015 :)

@psmgeelen
Copy link
Owner

@GreenWizard2015 , so we put in some effort to make this work. Its not 100% functional yet. Could you review all the links that we have shared. Our learning from our session were:

  • There were some issues with references that were called on as if they were pointers (arrows versus dots)
  • gtest doesnt work for Arduino, so we migrated to unity
  • we removed the local environment as we are not sure whether we need this right now
  • We need to look into the platformio examples more to understand how this is all connected. A great resource is https://github.com/platformio/platformio-examples/tree/develop/unit-testing/arduino-mock

Would this be enough for you to look into it again and see whether you can solve it?

@GreenWizard2015
Copy link
Collaborator Author

@omonrise yeah, hi)

Well, everything didn't go quite as I wanted, so I redid everything) Now the project assembles properly, the tests work, and even their status is visible in VSCode.

I really don't like the idea of testing with a fake Android. To be more precise, I don't want to test absolutely everything this way. I believe it's better to abstract as much as possible from the hardware/platform. And only in extreme cases, test with hardware emulation.

@psmgeelen
Copy link
Owner

So I am fine with skipping the emulator stuff, :) I still have a few notes:

  • Am I understanding correctly that we test the code on the native and build for Arduino? If so, this is something that I would strongly favour too, and would consider a good solution for our use-case.
  • A noticed a typo and made a comment
  • Because we test only on native, we dont have to care for compatability of the framework, and therefore can use gtest. Is that a correct statement?

@GreenWizard2015
Copy link
Collaborator Author

Yes, everything is as you described.

I'm not sure if there would be issues due to FakeArduino, but my experience suggests that it's better to avoid such things. This way, the tests are more reliable, and the code is more thoughtful because there are strict limitations and you can't just lump everything together in a way that somehow works.

@psmgeelen
Copy link
Owner

I was cheeky and split out the CI, to have a clearer feedback of the CI-checks.

@psmgeelen
Copy link
Owner

psmgeelen commented Dec 29, 2023

Ow, and what would a test protocol look like with all the code changes for real life testing? Specifically a question for @GreenWizard2015

@GreenWizard2015
Copy link
Collaborator Author

In general, its ready and I'm waiting for the feedback :-)

@psmgeelen
Copy link
Owner

As discussed,

test protocol:

  1. trigger the pump and let it run
  2. trigger the pump and test status
  3. trigger the pump and interrupt

I will be testing it in real life today or tomorrow

@psmgeelen
Copy link
Owner

I can confirm that everything works:

  1. Build works locally:
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  27.9% (used 9128 bytes from 32768 bytes)
Flash: [========  ]  77.1% (used 202032 bytes from 262144 bytes)
Building .pio/build/uno_r4_wifi/firmware.bin
============================================================================ [SUCCESS] Took 0.99 seconds ============================================================================

Environment    Status    Duration
-------------  --------  ------------
uno_r4_wifi    SUCCESS   00:00:00.986
============================================================================ 1 succeeded in 00:00:00.986 ============================================================================
 *  Terminal will be reused by tasks, press any key to close it. 

Note that we are almost out of memory, so lets stop adding features ;)

  1. Test pass locally:
Processing test_native in native environment
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Library Manager: Installing google/googletest @ ^1.12.1
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Testing...
WaterPumpScheduler.test_pump_stops_after_given_time     [PASSED]
WaterPumpScheduler.test_pump_is_periodically_forced_to_stop_after_given_time    [PASSED]
CommandProcessor.pour_tea_invalid_milliseconds  [PASSED]
CommandProcessor.pour_tea       [PASSED]
CommandProcessor.stop   [PASSED]
CommandProcessor.status [PASSED]
CommandProcessor.status_running [PASSED]
------------------------------------------------------------------- native:test_native [PASSED] Took 5.11 seconds -------------------------------------------------------------------

====================================================================================== SUMMARY ======================================================================================
Environment    Test         Status    Duration
-------------  -----------  --------  ------------
native         test_native  PASSED    00:00:05.112
===================================================================== 7 test cases: 7 succeeded in 00:00:05.112 =====================================================================
 *  Terminal will be reused by tasks, press any key to close it. 
  1. The uploading/monitoring and connecting to WiFi works
Done in 0.001 seconds
Write 202032 bytes to flash (50 pages)

[                              ] 0% (0/50 pages)
[=                             ] 4% (2/50 pages)
[=                             ] 6% (3/50 pages)
[==                            ] 8% (4/50 pages)
[===                           ] 10% (5/50 pages)
[===                           ] 12% (6/50 pages)
[====                          ] 14% (7/50 pages)
[====                          ] 16% (8/50 pages)
[=====                         ] 18% (9/50 pages)
[======                        ] 20% (10/50 pages)
[======                        ] 22% (11/50 pages)
[=======                       ] 24% (12/50 pages)
[=======                       ] 26% (13/50 pages)
[========                      ] 28% (14/50 pages)
[=========                     ] 30% (15/50 pages)
[=========                     ] 32% (16/50 pages)
[==========                    ] 34% (17/50 pages)
[==========                    ] 36% (18/50 pages)
[===========                   ] 38% (19/50 pages)
[============                  ] 40% (20/50 pages)
[============                  ] 42% (21/50 pages)
[=============                 ] 44% (22/50 pages)
[=============                 ] 46% (23/50 pages)
[==============                ] 48% (24/50 pages)
[===============               ] 50% (25/50 pages)
[===============               ] 52% (26/50 pages)
[================              ] 54% (27/50 pages)
[================              ] 56% (28/50 pages)
[=================             ] 58% (29/50 pages)
[==================            ] 60% (30/50 pages)
[==================            ] 62% (31/50 pages)
[===================           ] 64% (32/50 pages)
[===================           ] 66% (33/50 pages)
[====================          ] 68% (34/50 pages)
[=====================         ] 70% (35/50 pages)
[=====================         ] 72% (36/50 pages)
[======================        ] 74% (37/50 pages)
[======================        ] 76% (38/50 pages)
[=======================       ] 78% (39/50 pages)
[========================      ] 80% (40/50 pages)
[========================      ] 82% (41/50 pages)
[=========================     ] 84% (42/50 pages)
[=========================     ] 86% (43/50 pages)
[==========================    ] 88% (44/50 pages)
[===========================   ] 90% (45/50 pages)
[===========================   ] 92% (46/50 pages)
[============================  ] 94% (47/50 pages)
[============================  ] 96% (48/50 pages)
[============================= ] 98% (49/50 pages)
[==============================] 100% (50/50 pages)
Done in 12.519 seconds
--- Terminal on /dev/ttyACM0 | 9600 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
Latest available version: 0.3.0
Please upgrade your firmware.
Connecting to FamGeelen2.4Ghz
Atempt to connect: 1
.
Connection status: 3

Connected. IP: 192.168.178.60
SSID: FamGeelen2.4Ghz
BSSID: DC:39:6F:B8:B8:E3
signal strength (RSSI): -59
Encryption Type: 2
----------------------------------------------
  1. And the API itself works, too. I will be releasing a Video to showcase how to test in practise. @GreenWizard2015 , feel free to merge!

@GreenWizard2015
Copy link
Collaborator Author

just in case, don't merge till we done full testing of this and UI branch.

@psmgeelen
Copy link
Owner

All testing done

  • Build successful
  • API tests successful

@psmgeelen
Copy link
Owner

Lets merge :)

@GreenWizard2015 GreenWizard2015 merged commit 86b2ede into main Jan 7, 2024
2 checks passed
@GreenWizard2015 GreenWizard2015 deleted the feature/async_control branch January 7, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants