Skip to content

Four assertion failures in tests/fl/channels/channel.cpp, once its two crashes are fixed #4240

Closed

Description

@zackees

Follow-up to #4201. The two crashes it reported are fixed in #4239
(PixelIteratorAny's self-referential copy, and XYMap::fromXMap memcpying
from nullptr). With those fixed, tests/fl/channels/channel.cpp runs — 10
cases, 6 pass and 4 fail — so it stays dormant in KNOWN_DORMANT until
these are settled.

To reproduce: on top of #4239, change that file's include from
fl/test/fltest.h to test.h, wrap the body in FL_TEST_FILE(FL_FILEPATH),
and run bash test channel --cpp.

1 & 2: APA102 byte order, two addressing paths

Serpentine 2x2 with APA102 encodes pixels in expected byte order and
XMap reverse addressing with APA102 encodes pixels in reverse order.

Every pixel comes out R/B swapped against what the tests expect. Both
channels are created with RGB order and SpiEncoder::apa102(). The tests
expect the APA102 wire order [brightness][B][G][R]; the encoder emits
[brightness][R][G][B].

The swap is consistent and it is visible only on colours that are not
symmetric under it — LED1 (pure green) passes in the serpentine case while
LED0 (red → blue), LED2 (yellow → cyan) and LED3 (blue → red) all fail, which
is what makes the diagnosis unambiguous:

channel.cpp:141: 255 == 0     # LED0 blue byte, expected 0
channel.cpp:143: 0 == 255     # LED0 red byte, expected 255

I have not determined whether the tests encode the right convention or the
encoder does. That needs someone with context on APA102 colour-order handling
in the SPI encoder path — in particular whether Channel's EOrder is
supposed to be pre-applied before writeAPA102 or consumed by it.

3 & 4: #2517 driver-latch counts

[#2517] Normal flush path does NOT trigger the silent-drop FL_ERROR fails
with 0 == 3 on the enqueue count, and [#2517] Re-enabling the driver resumes enqueue and re-arms the latch fails four assertions with counts
consistently one lower than expected (0 == 1, 1 == 2).

These read like the tests were written against a different enqueue cadence
than the current one — but since they have never run, it is equally possible
the latch logic regressed at some point with nothing to catch it. Unassessed.

Why this is filed rather than fixed

Each of the four is a behaviour question, not a crash, and each needs its own
judgement about whether the test or the code is right. Bundling them into the
crash fix would have made that PR unreviewable, and waking the file before
they are settled would turn CI red.

Related: #4201, #4232 (which woke the other two dormant files), #4239.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Activity

  1. zackees commented on Sep 9, 2026

    @zackees
    MemberAuthor

    The APA102 pair is settled: the tests are wrong, not the encoder

    encodeAPA102 writes the three bytes its input iterator yields, in order, and
    names them in its own comments:

    *out++ = 0xE0 | global_brightness;
    *out++ = pixel[0];  // Index 0 (BGR order: Blue)
    *out++ = pixel[1];  // Index 1 (BGR order: Green)
    *out++ = pixel[2];  // Index 2 (BGR order: Red)

    It performs no reordering. The bytes come from loadAndScaleRGB, which
    yields them in the channel's EOrder. So for APA102 the channel's colour order
    is the wire order — which is what FastLED's own examples tell users:

    // FastLED.addLeds<APA102, PIN_DATA, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical

    Both dormant tests construct the channel with RGB and then assert [br][B][G][R]
    wire bytes — a reordering nothing performs. Hence every pixel appearing red/blue
    swapped; green passed only because it is symmetric under the swap.

    Fix: construct with BGR. I verified it — both cases pass, taking the file
    from 6/10 to 8/10. That keeps the assertions testing something real (that the
    reordering path produces the documented APA102 wire order) rather than rewriting
    expectations to match observed output.

    The #2517 pair is not what it looks like, and I have not solved it

    fakeDriver->enqueueCount is 0, not off-by-one — the channel never enqueues
    at all. Ruled out by experiment:

    hypothesis result
    showLeds(0) short-circuits on zero brightness no — showLeds(255) also gives 0
    wrong entry point (showLeds vs FastLED.show) no — FastLED.add + FastLED.show() also gives 0
    driver advertises no capabilities no — CountingFakeDriver::getCapabilities() returns Capabilities(true, true), same as the mocks in passing tests
    channel starts disabled no — mStateFlags = kEnabled by default, and only strict-mode profile rejection clears it

    So ChannelManager::selectDriverForChannel(mChannelData, busKey) is returning
    nothing for a channel whose only registered driver answers canHandle() == true.
    The next thing to check is mChannelData at that point, and what
    freshBusTestManager() leaves behind versus the ChannelManager::instance() the
    passing tests use.

    I stopped rather than guess. Whoever picks this up starts from "the driver is
    never selected", not "the counts are off by one", which is what the original
    report suggested.

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Solved: clearAllDrivers() leaves the exclusive-driver filter behind

    Picking up from "the driver is never selected" — that was the right thread to pull.

    ChannelManager::clearAllDrivers() empties mDrivers but never touches mExclusiveDriver. And addDriver() consults it:

    // Respect exclusive driver mode: auto-disable if name doesn't match exclusive driver
    bool enabled = true;
    if (!mExclusiveDriver.empty()) {
        enabled = (engineName == mExclusiveDriver);
    }

    So after a clear, the filter still names a driver that no longer exists, and every driver registered afterwards arrives disabled — silently, with nothing short of another setExclusiveDriver*() call able to clear it.

    The leak path across the three #2517 cases is exact:

    1. Disabled driver: enqueue is suppressed ends with setExclusiveDriverByName("DOES_NOT_EXIST").
    2. Its scope_exit calls clearAllDrivers() — which drops the registry but keeps "DOES_NOT_EXIST".
    3. Normal flush path registers HAPPY_DRIVER → disabled → enqueueCount == 0 vs 3.
    4. Re-enabling registers RECOVERY_DRIVER → disabled → 0 == 1, 1 == 2.

    That also explains why the first case passed while the other two failed: it is the one that sets the filter, so it runs before the poison exists.

    This is not a test-isolation problem, which is why the fix is in the library rather than in freshBusTestManager(). FastLED.clear(CHANNEL_ENGINES) is the production caller of clearAllDrivers() (FastLED.cpp.hpp:229), and it has the same defect: clear your drivers after ever setting an exclusive driver, and re-registration silently no-ops.

    Fix is one line — the clear drops the filter along with the registry it refers to.

    And confirming your APA102 call

    Your diagnosis was right and I kept it as written: constructing with BGR rather than rewriting the expected bytes. Both cases pass.

    Result

    All four settled, so channel.cpp is woken and KNOWN_DORMANT is now empty — which also closes #4201.

    $ ./.build/meson-quick/tests/runner .build/meson-quick/tests/fl_channels_channel.so
    [doctest] test cases: 10 | 10 passed | 0 failed
    

    Mutation-tested both fixes: reverting mExclusiveDriver.clear() fails exactly the two #2517 cases; reverting BGR→RGB fails exactly the two APA102 cases. Neither pair is passing by accident.

    PR: #4249

  3. moved this from Triage to Done in FastLED Trackeron Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions