fix(test): make the native-windows test suite build and run - #11482
Conversation
pio test -e native-windows failed every suite at the build stage. Five independent causes, all Windows-only: - TestUtil.cpp called lstat(), which MinGW-w64 does not provide. The state-checkpoint walk added in #11322 is fenced with ARCH_PORTDUINO, which native-windows also satisfies, so all 53 suites failed to compile. Route it through a stat() shim on _WIN32. - test_default, test_http_content_handler, test_meshpacket_serializer and test_serial define no setUp/tearDown and relied on the weak defaults PlatformIO emits in unity_config.c. GCC lowers a weak definition on PE-COFF to a weak external, leaving the symbol undefined, so it does not satisfy unity.c's reference and the link fails. Define them explicitly, as the other 49 suites already do. - test_mqtt included <arpa/inet.h>, absent on MinGW, for htonl(). Use winsock2.h there. - test_gps_update_scheduling uses TEST_ASSERT_DOUBLE_WITHIN. Unity omits double support unless UNITY_INCLUDE_DOUBLE is defined, so the assertion compiled to an unconditional failure. Define it for the env. - test_getfiles_rejects_overlong_path is excluded on _WIN32. Overrunning the 228-byte file_name needs at least 229 bytes below the portduino root, and that root is already ~34 bytes, so every qualifying path passes the 260-byte MAX_PATH: the nested mkdir() fails, the file is never created, and getFiles() has nothing to drop. No component layout satisfies both limits. Each of the seven suites that failed on Windows was verified individually after the change. test_fscommon_getfiles still fails in a full run, for a cause outside this change: rmDir() does not remove directories on Windows, so empty dirs left by an earlier run survive setUp() and make getFiles() report a depth truncation. That is a pre-existing FSCommon bug, reported separately. No Linux or macOS behaviour changes: every guard is _WIN32-only except UNITY_INCLUDE_DOUBLE, which is scoped to env:native-windows.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe changes improve native test compatibility across Windows, non-Windows platforms, and MinGW. They add platform-specific filesystem and networking handling, Unity lifecycle hooks, Windows-specific test guards, and Unity double-precision support. ChangesNative test compatibility
Estimated code review effort: 2 (Simple) | ~10 minutes Mergeability Score: ⚪ Minimal · up to This change is limited to making the native-Windows test suite build and run, with no actionable merge-blocking risk remaining after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
⚡ Try this PR in the Web FlasherNote Building this pull request… the flash button, badges and supported-board |
|
The Once that lands and the platform pin picks it up, the suite goes green on Windows with no further change here. |
The flag was scoped to env:native-windows, but the gap is not Windows-specific. Verified on Debian with gcc against the Linux env's own Unity 2.6.1 and PlatformIO's generated native unity_config: UNITY_INCLUDE_DOUBLE : NOT defined UNITY_EXCLUDE_DOUBLE : defined test_double_within:FAIL: Unity Double Precision Disabled UNITY_INCLUDE_DOUBLE appears nowhere in the repo, the ini files, the workflow, or PlatformIO's unity runner, which adds only UNITY_INCLUDE_CONFIG_H. So TEST_ASSERT_DOUBLE_* is an always-failing stub on Linux and macOS too, not only on Windows. Moved to portduino_base.build_flags_common, which every native env resolves: native, native-tft, native-fb, native-tft-debug, coverage, coverage-event-policy, native-macos, native-windows and native-wasm. This does change Linux and macOS: TEST_ASSERT_DOUBLE_* becomes a real comparison instead of a stub. test_gps_update_scheduling is the only suite using those macros and its arithmetic is integer-based and bit-identical across platforms, so it should pass wherever it runs. Note it currently reports PASSED on CI in 0.03s while emitting no Unity output at all, so those assertions appear never to execute there; that is tracked separately and is not addressed here.
pio test -e native-windowsfailed all 53 suites at the build stage. Five independent causes, all Windows-only, plus one Unity configuration gap that turned out not to be Windows-specific at all.Causes
lstat()intest/TestUtil.cpp. MinGW-w64 does not provide it. The state-checkpoint walk added in #11322 is fenced withARCH_PORTDUINO, whichnative-windowsalso satisfies, so the file failed to compile and took every suite with it. This is the regression that broke the Windows runner; the others were masked behind it. Routed through astat()shim on_WIN32.Missing
setUp/tearDownin four suites.test_default,test_http_content_handler,test_meshpacket_serializerandtest_serialdefine neither and relied on the weak defaults PlatformIO emits in its generatedunity_config.c. Those defaults are enabled on MinGW, but GCC lowers a weak definition on PE-COFF to a weak external:setUpstays undefined (w) with a renamed alternate, rather than ELF's weak definition (W), so it does not satisfyunity.c's strong reference and the link fails. Defined explicitly, as the other 49 suites already do.<arpa/inet.h>intest_mqtt. Absent on MinGW; included only forhtonl(). Useswinsock2.hthere.UNITY_INCLUDE_DOUBLEwas never defined anywhere. Unity omits double support unless asked, soTEST_ASSERT_DOUBLE_*compiles into an unconditional "Unity Double Precision Disabled" failure. This is not Windows-specific. Verified on Debian with gcc, against the Linux env's own Unity 2.6.1 and PlatformIO's generatednativeunity_config:The macro appears nowhere in the repo, the ini files,
test_native.yml, or PlatformIO's Unity runner, which adds onlyUNITY_INCLUDE_CONFIG_H. It is therefore defined inportduino_base.build_flags_common, which every native env resolves:native,native-tft,native-fb,native-tft-debug,coverage,coverage-event-policy,native-macos,native-windows,native-wasm.test_getfiles_rejects_overlong_path. Excluded on_WIN32. Overrunning the 228-bytefile_nameneeds at least 229 bytes below the portduino root, and that root is already about 34 bytes, so every qualifying path passes the 260-byteMAX_PATH. The nestedmkdir()fails, the file is never created, andgetFiles()has nothing to drop. No component layout satisfies both limits.Verification
Full
pio test -e native-windowson Windows 11 / UCRT64 gcc 16.1.0, before and after:Scope
Every guard is
_WIN32-only exceptUNITY_INCLUDE_DOUBLE, which now applies to all native envs and does change Linux and macOS:TEST_ASSERT_DOUBLE_*becomes a real comparison instead of a stub that always fails.test_gps_update_schedulingis the only suite in the repo using those macros, and its arithmetic is integer-based and bit-identical across platforms, so it should pass wherever it runs.Worth flagging for review: that suite currently reports PASSED on CI in 0.03 seconds while emitting no Unity output at all, so its assertions appear never to execute there. That is a separate issue and is not addressed here.
No CI job currently compiles the test tree for
native-windows:test_native.ymlruns on Ubuntu against-e coverage, andbuild_windows_bin.ymlrunspio run, neverpio test. That is why thelstatregression stood for a week.Known limitation
test_fscommon_getfilesstill fails in a full run, for a cause outside this change:VFSImpl::rmdir()in framework-portduino callsunlink(), which cannot remove a directory, so the tree its depth-limit case creates survivessetUp()'srmDir()and makesgetFiles()report a spurious depth truncation. Fixed by meshtastic/framework-portduino#77; once that lands and the platform pin picks it up, the suite goes green on Windows with no further change here.Summary by CodeRabbit
Bug Fixes
Tests