Skip to content

fix TEST_CASE("esp_littlefs_info returns used_bytes > total_bytes", "[littlefs]")#257

Merged
BrianPugh merged 2 commits into
masterfrom
test-fix
Apr 7, 2026
Merged

fix TEST_CASE("esp_littlefs_info returns used_bytes > total_bytes", "[littlefs]")#257
BrianPugh merged 2 commits into
masterfrom
test-fix

Conversation

@BrianPugh

Copy link
Copy Markdown
Member

Fix infinite loop in "used_bytes > total_bytes" test

When the filesystem is nearly full, littlefs internally recovers from NOSPC during metadata directory splits by falling back to in-place compaction (lfs_dir_splittingcompact). This means fwrite/fclose never return errors even though the allocator logs "No more free space" — the operation actually succeeds.

The test relied on I/O errors to exit its fill loop. This has broken before (ESP-IDF v5.0 changed stdio buffering so fwrite stopped failing; fixed by also checking fclose). Now neither fails.

Fix: detect disk-full by stopping once used_bytes from esp_littlefs_info stops growing for 10 consecutive iterations. The used <= total invariant is still checked every iteration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the LittleFS test esp_littlefs_info returns used_bytes > total_bytes to avoid an infinite loop when the filesystem recovers internally from NOSPC and stdio calls don’t return errors, by adding a secondary “disk full” detection based on used_bytes no longer increasing.

Changes:

  • Add tracking (prev_used/stall_count) to break out of the fill loop when used_bytes stops growing for 10 iterations.
  • Hoist total/used declarations outside the loop and reset them each iteration before calling esp_littlefs_info.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_littlefs.c Outdated
Comment thread test/test_littlefs.c Outdated
@BrianPugh BrianPugh merged commit 55a0fa2 into master Apr 7, 2026
12 checks passed
@BrianPugh BrianPugh deleted the test-fix branch April 7, 2026 12:50
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.

2 participants