logo elektroda
logo elektroda
X
logo elektroda

Verification Needed for 64-bit Flags Command on Multiple Platforms

XJ_ 804 38
ADVERTISEMENT
  • Helpful post
    #1 21456883
    XJ_
    Level 11  
    I modified the Flags command to support 64bit. The display on WEBui is also fixed. Checked on the simulator and on BK7238. Is there anyone who can verify this on other platforms?

    test:

    flags 18446744073709551615


    Screenshot of the OpenBK7238 user interface displaying a list of flag settings.

    Added after 38 [seconds]:

    PR: https://github.com/openshwprojects/OpenBK7231T_App/pull/1548
  • ADVERTISEMENT
  • #2 21456900
    insmod
    Level 24  
    Wouldn't it break config on platforms where long is 8 bytes?

    Btw, what was the original reason to make flags into 2 integers, instead of an uint64_t?
  • ADVERTISEMENT
  • #3 21456907
    XJ_
    Level 11  
    insmod wrote:
    Btw, what was the original reason to make flags into 2 integers, instead of an uint64_t?

    I don´t know. Maybe, first version have 32 flags only.

    Added after 11 [minutes]:

    insmod wrote:
    Wouldn't it break config on platforms where long is 8 bytes?

    You're right, changed to uint32.

    Added after 3 [minutes]:

    BTW, on which platform for OBK is a long actually 8 bytes long? Are they all 32 bit mcu's, or not?
    It's my fault, I'm a developer mainly for Win and on 64bit Win (LLP64) long is 32bit
  • #4 21456953
    insmod
    Level 24  
    >>21456907 Currently all are 32bit, but who knows in the future. And while long on 32bit is usually 4 bytes, who knows what some compilers would do. I know that i've seen 4 bytes long on 64 bit windows.
  • #5 21456954
    XJ_
    Level 11  
    >>21456953
    OK, thanks to uint32, the flags are ready for the 64-bit future ;-)
  • #6 21457325
    p.kaczmarek2
    Moderator Smart Home
    I don't remember well, but I think I've started with a single 32-bit integer. Then I added another 32 bits it has turned out that there is a long-standing bug with flag set (or read?). It has been tacked several times but we didn't get any definitive fix, unless PR 1548 works well on all platforms?
    Helpful post? Buy me a coffee.
  • #7 21457353
    divadiow
    Level 34  
    Ok will test. Is the latest build looking final for testing?

    Are there platforms I shouldn't bother with at all because it'll definitely not work? And should all the ESPs be treated as one test or one from each series required - like one ESP32-C#, one ESP32-S# etc
  • #8 21457359
    p.kaczmarek2
    Moderator Smart Home
    One thing I remember is that my initial flags code was working well on Windows. That's why the bug was not found for so long...
    Helpful post? Buy me a coffee.
  • #9 21457366
    XJ_
    Level 11  
    >>21457353
    It is final. There is no need to test all devices, all of them are 32bit.
    The thing to test is if funcion strtoull() works ok on the main SDKs (ESP, BL, LN). Beken is ok.

    u.newValue = (uint64_t)strtoull(args, NULL, 10); 
  • #10 21457368
    p.kaczmarek2
    Moderator Smart Home
    Hey, I've just got an idea!

    Maybe we could do a selftest system like the one on Windows, but designed to run on Device?

    For example, put it into the cmd_selfTest.c and make there a long list of commands with result assertions.

    Then we could run it on physical devices to make sure that everything is okay.

    This could be very useful, especially considering platform differences and such....

    We already had issues related to those, for example:
    - time_t size (32 bit vs 64 bit)
    - missing realloc on BL602
    - strange sprintf behaviour (remember static IP page?)
    Helpful post? Buy me a coffee.
  • #11 21457373
    XJ_
    Level 11  
    >>21457368
    p.kaczmarek2 wrote:
    Maybe we could do a selftest system like the one on Windows, but designed to run on Device?

    I think this is not necessary. The main problems are revealed on win, and the "special" unexpected ones would be detected by the test with very little probability anyway.
  • #12 21457377
    p.kaczmarek2
    Moderator Smart Home
    Are you sure? I suspect that even at this moment realloc is still broken on BL602... @miegapele may know more about it.
    Helpful post? Buy me a coffee.
  • #13 21457380
    XJ_
    Level 11  
    p.kaczmarek2 wrote:
    moment realloc

    I don't know what the problem is with realloc, but if the same problem will be on windows, would selftest find it?
  • #14 21457385
    p.kaczmarek2
    Moderator Smart Home
    No, realloc implementation is per platform. That's why it's (as I suspect) broken on BL602, but works on other platforms.

    Related issue:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1529

    That's why I think we may benefit from making a simple self-test that runs on any platform, with #define entry in obk_config.h , so it takes 0 space in Release builds.
    It could test for basic stuff, like JSON parsing, commands execution, etc.
    Helpful post? Buy me a coffee.
  • #15 21457388
    XJ_
    Level 11  
    I mean, if we didn't know about it and the problem wasn't programmed to be checked

    Added after 4 [minutes]:

    p.kaczmarek2 wrote:
    It could test for basic stuff, like JSON parsing, commands execution, etc.

    but ok, the fact is that this would save a lot of work testing new things on platforms other than where they were debugged.
  • ADVERTISEMENT
  • Helpful post
    #16 21457513
    divadiow
    Level 34  
    1548_merge_66c6fb20c815
    OpenW600 settings screen with selected flags
    Screenshot of the OpenW800_CDD5556C settings panel with enabled MQTT and LED flags.
    Configuration panel of OpenLN882H with active MQTT flags.
    View of user interface with OpenBL602 flag settings, most of which are checked.
    OpenESP32S3 interface with active flags for MQTT and LED configuration.
    OpenRTL87X0C application interface with a list of set MQTT flags.
    Screenshot of flag settings for OpenRTL8710B_601D473E.

    All set flags without error apart from RTL-B which had a hard fault. It came back up with all but 1 set though

    Code: Text
    Log in, to see the code


    List of configuration flags with flag 13 highlighted.

    Added after 3 [minutes]:

    setting flag 13 and saving thereafter does not cause a hard fault though

    Added after 3 [minutes]:

    interesting. with all flags cleared and only flag 13 set it'll hard fault if you move to the home page.

    Added after 2 [minutes]:

    I guess that's this it doesn't like
    Screenshot showing pin states with various settings, where only P28 is set to '1'.

    Added after 16 [minutes]:

    but unrelated to the flags fix. The same happens with general release 1.18.47 and only flag 13
    Code: Text
    Log in, to see the code
  • #17 21457587
    XJ_
    Level 11  
    @divadiow Thanks for the great test. So just to be sure, the RTL error is not related to PR, or should I do something?

    Added after 1 [minutes]:

    divadiow wrote:
    but unrelated to the flags fix. T

    OK, I see.
  • #18 21457592
    p.kaczmarek2
    Moderator Smart Home
    I am adding self test system to build device.
    https://github.com/openshwprojects/OpenBK7231...mmit/a00d88b2a112c260985661cd079b7a5deba9a014

    Usage:
    1. enable ENABLE_TEST_COMMANDS in obk_config.h
    2. add your command to cmd_test.c
    Code: C / C++
    Log in, to see the code

    Code: C / C++
    Log in, to see the code

    3. add it to drv_test.c:

    Screenshot showing source code in Microsoft Visual Studio.
    4. do build

    5. in build run:
    
     backlog startDriver Test; StartTest 100;
    

    100 means 100ms interval between steps.
    It runs in such a way, that it first prints command it will run, it waits 100ms for log to come through, then runs command, then checks run result, then waits 100 ms, and pritns again....

    Sample run:
    Screenshot of a software test log with messages about test results.
    Test interface with toggle buttons and test results.

    The most important thing to note here is that if some command crashes, you can also run it from console without test driver.

    Please give me initial feedback, but also wait 1 day before running it. I will improve it a bit soon.
    Helpful post? Buy me a coffee.
  • #19 21457611
    XJ_
    Level 11  
    p.kaczmarek2 wrote:
    Please give me initial feedback

    Yeah, that looks good. I'll definitely check it out later.
  • #20 21457612
    p.kaczmarek2
    Moderator Smart Home
    See this commit for test of math expression with setChannel:
    https://github.com/openshwprojects/OpenBK7231...mmit/0d18dd0a229b6de6dfd1abd2a396c8de076e40c7
    And this commit for some LLM-generated basic tests:
    https://github.com/openshwprojects/OpenBK7231...mmit/1b455ef82ec026f914eccb7bea1f2a0ecbc5dcb5

    Added after 1 [minutes]:

    One of practical uses of this could be this cursed IP parse bug:
    View of Visual Studio editor with C code.
    Helpful post? Buy me a coffee.
  • #22 21457658
    p.kaczmarek2
    Moderator Smart Home
    Yes and this will be finally meaningful, and not pointless like testing on Windows, because those functions are outside our SDK and testing them on Windows won't tell us if they will work on Beken on BL602.

    Added after 1 [hours] 18 [minutes]:

    IP parse test:
    https://github.com/openshwprojects/OpenBK7231...mmit/23e67076c3bf9b0b035ed2bb77066238277f76c9
    Helpful post? Buy me a coffee.
  • #23 21458333
    divadiow
    Level 34  
    this all sounds quite good. How exactly do self-tests work and help? I'm not very codey, but it seems like a sensible thing to have in place. If, for example, a contributor proposes code changes in a new PR and they cause a problem somewhere, how does the self-test manifest? What and where fails? Somewhere in the build workflow log?
  • #24 21458365
    p.kaczmarek2
    Moderator Smart Home
    I am thinking about creating a separate guide for that, but I can already start here.

    So, there are two types of self tests.
    1. Windows-only self tests - they are run in Windows simulator, they reside here:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/src/selftest
    They are run on Github on each build:
    Screenshot showing results of a software build simulation.

    Those self tests are basically simulating a use case scenario, for example, setting up a LED, and then they check externally is the use case result as expected.
    For example, if we set two PWM pins, we expect CW control to show up and we expect Dimmer command to work. We expect certain things to be published when light state changse, we can test it as well. So, we simulate setting of two PWM pins, then we run some commands, and check is result as expected (for example, are output PWM values as expected for correct CW control).

    Example 1 - if we set channel 1 to 123, is $CH1 constant working in script and expands to 123?
    Code: C / C++
    Log in, to see the code

    If "buffer" is not "123", then SELFTEST_ASSERT_STRING will show error on Github build (red cross instead of green checkmark).

    Example 2 - if we set two PWM pins, are they correctly detected as CW light? Is light responding to commands and settings PWMs correctly?
    Code: C / C++
    Log in, to see the code

    Let's look deeper at one fragment:
    Code: C / C++
    Log in, to see the code

    This basically says:
    - if you have CW light set up, and OBK receives a POWER OFF Tasmota command, the led_enableAll variable should be 0 (false) and both PWMs should be 0
    - if you later receive POWER ON Tasmota command, led_enableAll is expected to be 1 (true) and for current configuration (set earlier in code) first PWM should be 100%, second 0% (because we earlier set up temperature 100% cold)

    Thanks to this mechanism, as soon as somebody breaks the expected behaviour (for example, adds a change that makes CW lights not working), we will know at compile time, because self test will catch it.

    2. Per-platform tests, introduced yesterday.
    The test runner is here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_test.c
    The test commands are here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/cmnds/cmd_test.c

    Per-platform can be only run on true platform devices, like BK7231, not in simulator.
    They were introduced because not everything can be tested in Windows simulator.
    Some things are per-platform, for example sscanf command, or realloc, etc.
    So we have "different" sscanf or sprintf on each platform - different on BK7231, W800, W600...

    That's why I added test commands like this one:
    Code: C / C++
    Log in, to see the code

    This checks IP parsing, and this is required, because it has proven problematic, see implementation:
    Code: C / C++
    Log in, to see the code

    This is not just a theoretical sample - we really had this issue:
    Screenshot of a comment discussing software update issues.
    As you can see above, we had a sscanf problem that requires special handling on W600/LN882H/Realtek, and we didn't catch it early.
    If we had per-platform device tests back then that cover str to ip, we would have caught it earlier.

    It is impossible to catch this problem on WIndows self tests, because it is present only on some platforms with their specific implementation.

    Thanks to the per-platform tests, it's now possible to catch it.
    If you compile OBK with test commands enabled, and if your platform has str_to_ip broken, then this code:
    Code: C / C++
    Log in, to see the code

    will attempt to parse "192.168.0.123", but it will fail,, then "if" will detect it, so it will return CMD_RES_ERROR.
    So, later, the drv_test.c will catch it, and it will show error here:
    Test panel displaying switch states and test results.

    Self tests are very useful, because they can quickly check if all tested features can work as expected. You don't need to setup a CW light to check if PWMs are set correctly - this is done by Windows selftests in SImulator on each Github build. You also don't need now to manually check each page like local ip config on every platform, because per-platform tests will cover it as well....

    How to run self tests?
    - to run Windows simulator self tests, just trigger online github build, they are ran automatically
    - to run per-platform tests, compile OBK with ENABLE_TEST_COMMANDS , flash it to your device, and run "backlog startDriver Test; StartTest 100;"

    I didn't have time to run per-platform tests myself, but I strongly suspect that at least realloc test will just crash BL602 device - realloc is known to be a problem on BL602.
    Helpful post? Buy me a coffee.
  • #25 21458377
    divadiow
    Level 34  
    thank you. that is very interesting and makes things clearer. fascinating!
  • ADVERTISEMENT
  • #26 21458386
    p.kaczmarek2
    Moderator Smart Home
    So now let's make a demonstration. We'll consider a hypothetical scenario where someone breaks some function by accident, for example, the channel set.
    I modified CHANNEL_Set_Ex to always set value to 0:
    Screenshot shows a GitHub pull request for merging a branch in the openshwprojects project.
    Then I commited changes to Github.
    Let's see what happens.
    It's building, so we wait a moment...
    Task list in progress on a version control platform with status information.
    And then we get:
    Dashboard showing the status of task checks in a build system.
    AS you can see, many self tests have failed. They expect channels to work, so they recognized that something is wrong:


    Computer screen from a CI/CD panel showing various build and test job statuses, with one error.
    Helpful post? Buy me a coffee.
  • #27 21458705
    XJ_
    Level 11  
    >>21458386
    great work, as usual!

    Added after 1 [minutes]:

    so this build simulator test will automatically run on every PR/update?

    Added after 55 [seconds]:

    Or does it have to be started manually?
  • #28 21458712
    p.kaczmarek2
    Moderator Smart Home
    Build Simulator and the tests ran on Windows are nothing new, they are already in our Github for a month or more. They run with each commit.

    The only new thing that I introduced yesterday is the per-platform testing that can be started only manually on physical device.
    Helpful post? Buy me a coffee.
  • #29 21458729
    XJ_
    Level 11  
    p.kaczmarek2 wrote:
    The only new thing that I introduced yesterday is the per-platform testing that can be started only manually on physical device.

    I see. It seemed strange to me how a test for a specific MCU HW could run on github ;-)
  • Helpful post
    #30 21459645
    divadiow
    Level 34  
    1548_merge_82ad074ae93b
    Screenshot of OpenRTL8720D settings interface with selected flag options.
    no hard fault but flag 13 is deselected on reboot, otherwise seems OK on RTL8720D

    Screen displaying PIN states.

Topic summary

The discussion revolves around the modification of the Flags command to support 64-bit integers, with a focus on verifying its functionality across multiple platforms. The original implementation used two 32-bit integers due to historical limitations, but the transition to a single uint64_t is seen as a step towards future-proofing. Participants discuss potential issues with platform compatibility, particularly regarding the size of data types like 'long' on different architectures. Testing is emphasized, with suggestions for a self-test system to ensure consistent behavior across devices. Initial tests indicate successful flag setting, although some issues, such as a hard fault on the RTL-B platform, were noted. The conversation also touches on the importance of testing functions like strtoull() across various SDKs and the implementation of per-platform testing to catch platform-specific bugs.
Summary generated by the language model.
ADVERTISEMENT