Skip to content

drivers: video: emul_rx: hotfix: force use of constant value #88890

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

Merged

Conversation

josuah
Copy link
Contributor

@josuah josuah commented Apr 22, 2025

In some compilation attempts, the compiler did not accept a static const variable as initializer. This caused build errors in only some contexts. Always use the devicetree macros to access it.

Note: this has not yet been tested: PR open to check if it fixes it in the actual Zephyr CI

@josuah josuah added the DNM This PR should not be merged (Do Not Merge) label Apr 22, 2025
@josuah josuah requested a review from kartben April 22, 2025 09:44
@github-actions github-actions bot added the area: Video Video subsystem label Apr 22, 2025
@JarmouniA JarmouniA added the Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. label Apr 22, 2025
@josuah
Copy link
Contributor Author

josuah commented Apr 22, 2025

Trying on latest main the error could not be reproduced with the same LLVM major version as the CI uses

$ export ZEPHYR_TOOLCHAIN_VARIANT=llvm-16
$ west build -b native_sim/native tests/drivers/build_all/video -T drivers.video.build

The hotfix is still expected to address the error as uses the value from devicetree rather than the previously declared static const struct emul_rx_cfg_##n.

@josuah josuah removed the DNM This PR should not be merged (Do Not Merge) label Apr 22, 2025
@JarmouniA
Copy link
Contributor

Trying on latest main the error could not be reproduced with the same LLVM major version as the CI uses

$ export ZEPHYR_TOOLCHAIN_VARIANT=llvm-16
$ west build -b native_sim/native tests/drivers/build_all/video -T drivers.video.build

I think you need to enable some specific compiler flag for it to appear.

@ngphibang
Copy link
Contributor

Can you add more details ? I couldn't reproduce the error on my side.

@josuah
Copy link
Contributor Author

josuah commented Apr 22, 2025

@JarmouniA good point, different flags for west build and west twister it seems.
@ngphibang I could reproduce with twister:

$ git fetch origin
$ git checkout bc571d55a2a3859657c07064b2d973e93680f1bc
$ export ZEPHYR_TOOLCHAIN_VARIANT=llvm
$ west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id

@josuah
Copy link
Contributor Author

josuah commented Apr 22, 2025

It looks like the hotfix works:

Before:

~/zephyrproject/zephyr main $ west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id
INFO    - Using Ninja..
INFO    - Zephyr version: v4.1.0-2729-g785d0bbfb3fc
INFO    - Using 'llvm' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/testplan.json
INFO    - JOBS: 1
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
ERROR   - native_sim/native         drivers.video.build                                ERROR: Build failure
ERROR   - see: /home/tinyvision/zephyrproject/zephyr/twister-out/native_sim_native/llvm/tests/drivers/build_all/video/drivers.video.build/build.log
INFO    - Total complete:    1/   1  100%  built (not run):    0, filtered:    0, failed:    0, error:    1
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 0 of 1 executed test configurations passed (0.00%), 0 built (not run), 0 failed, 1 errored, with no warnings in 50.83 seconds.
INFO    - 0 of 1 executed test cases passed (0.00%), 1 blocked on 1 out of total 1019 platforms (0.10%).
INFO    - 0 test configurations executed on platforms, 1 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
INFO    - The following issues were found (showing the top 10 items):
INFO    - 1) drivers.video.build on native_sim/native error (Build failure - error: initializer element is not a compile-time constant)
INFO    -
INFO    - To rerun the tests, call twister using the following commandline:
INFO    - west twister -p <PLATFORM> -s <TEST ID> --no-detailed-test-id, for example:
INFO    -
INFO    - west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id
INFO    - or with west:
INFO    - west build -p -b native_sim/native tests/drivers/build_all/video -T drivers.video.build
INFO    - -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
INFO    - Run completed

After:

~/zephyrproject/zephyr pr-hotfix-video-emul-imager $ west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id
Renaming output directory to /home/tinyvision/zephyrproject/zephyr/twister-out.4
INFO    - Using Ninja..
INFO    - Zephyr version: v4.1.0-2730-gbc571d55a2a3
INFO    - Using 'llvm' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/testplan.json
INFO    - JOBS: 1
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - Total complete:    1/   1  100%  built (not run):    1, filtered:    0, failed:    0, error:    0
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 0 of 1 executed test configurations passed (0.00%), 1 built (not run), 0 failed, 0 errored, with no warnings in 39.89 seconds.
INFO    - 0 of 0 executed test cases passed (0.00%) on 0 out of total 1019 platforms (0.00%).
INFO    - 1 selected test cases not executed: 1 not run (built only).
INFO    - 0 test configurations executed on platforms, 1 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - Run completed

@ngphibang
Copy link
Contributor

ngphibang commented Apr 22, 2025

I think this is a clang issue and is fixed with newer LLVM version, from LLVM-17 and later, cc @tejlmand @dleach02

#54826

@ngphibang ngphibang requested a review from tejlmand April 22, 2025 10:25
kartben
kartben previously approved these changes Apr 22, 2025
Copy link
Contributor

@ngphibang ngphibang left a comment

Choose a reason for hiding this comment

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

Marked as request-changes for now as we needs to do the same for other drivers even if it's a needed fix. But I believe this is a clang issue and already fixed in LLVM newer versions as stated in #54826 unless someone proves that this is not.

In Clang 16 run with some flags, the compiler does not accept a static
const variables as struct initializer. This caused build errors in only
some contexts. Always use the devicetree macros to access the source
device node as a workaround.

Signed-off-by: Josuah Demangeon <[email protected]>
@josuah josuah force-pushed the pr-hotfix-video-emul-imager branch from e6dfdfe to f2e8156 Compare April 22, 2025 11:50
@josuah josuah requested a review from ngphibang April 22, 2025 11:50
@github-actions github-actions bot added platform: ESP32 Espressif ESP32 platform: NXP Drivers NXP Semiconductors, drivers platform: STM32 ST Micro STM32 labels Apr 22, 2025
@ngphibang
Copy link
Contributor

ngphibang commented Apr 22, 2025

@josuah: Thanks for adding other drivers into the PR. But do you see it is fixed in newer LLVM versions (I don't have problem using Zephyr SDK) and think it is a clang issue ?

@josuah
Copy link
Contributor Author

josuah commented Apr 22, 2025

do you see it is fixed in newer LLVM versions and think it is a clang issue ?

I confirm, it works with clang-18 but not with clang-16

Testing on current main:

Fails:

$ ln -sf $(which clang-16) ~/.local/bin/clang
$ west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id

Works:

$ ln -sf $(which clang-18) ~/.local/bin/clang
$ west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id
full logs

* 1201 ~/zephyrproject/zephyr main $ ln -sf $(which clang-18) ~/.local/bin/clang
* 1201 ~/zephyrproject/zephyr main $ west twister -p native_sim/native -s drivers.video.build --no-detailst-id
Renaming output directory to /home/tinyvision/zephyrproject/zephyr/twister-out.6
INFO    - Using Ninja..
INFO    - Zephyr version: v4.1.0-2729-g785d0bbfb3fc
INFO    - Using 'llvm' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/testplan.json
INFO    - JOBS: 1
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - Total complete:    1/   1  100%  built (not run):    1, filtered:    0, failed:    0, error:    0
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 0 of 1 executed test configurations passed (0.00%), 1 built (not run), 0 failed, 0 errored, with no warnings in 66.47 seconds.
INFO    - 0 of 0 executed test cases passed (0.00%) on 0 out of total 1019 platforms (0.00%).
INFO    - 1 selected test cases not executed: 1 not run (built only).
INFO    - 0 test configurations executed on platforms, 1 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - Run completed
* 1202 ~/zephyrproject/zephyr main $ ln -sf $(which clang-16) ~/.local/bin/clang
* 1202 ~/zephyrproject/zephyr main $ west twister -p native_sim/native -s drivers.video.build --no-detailid
Renaming output directory to /home/tinyvision/zephyrproject/zephyr/twister-out.7
INFO    - Using Ninja..
INFO    - Zephyr version: v4.1.0-2729-g785d0bbfb3fc
INFO    - Using 'llvm' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/testplan.json
INFO    - JOBS: 1
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
ERROR   - native_sim/native         drivers.video.build                                ERROR: Build failure
ERROR   - see: /home/tinyvision/zephyrproject/zephyr/twister-out/native_sim_native/llvm/tests/drivers/build_all/video/drivers.video.build/build.log
INFO    - Total complete:    1/   1  100%  built (not run):    0, filtered:    0, failed:    0, error:    1
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 0 of 1 executed test configurations passed (0.00%), 0 built (not run), 0 failed, 1 errored, with no warnings in 36.12 seconds.
INFO    - 0 of 1 executed test cases passed (0.00%), 1 blocked on 1 out of total 1019 platforms (0.10%).
INFO    - 0 test configurations executed on platforms, 1 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.json
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/tinyvision/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
INFO    - The following issues were found (showing the top 10 items):
INFO    - 1) drivers.video.build on native_sim/native error (Build failure - error: initializer element is not a compile-time constant)
INFO    -
INFO    - To rerun the tests, call twister using the following commandline:
INFO    - west twister -p  -s  --no-detailed-test-id, for example:
INFO    -
INFO    - west twister -p native_sim/native -s drivers.video.build --no-detailed-test-id
INFO    - or with west:
INFO    - west build -p -b native_sim/native tests/drivers/build_all/video -T drivers.video.build
INFO    - -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
INFO    - Run completed
* 1203 ~/zephyrproject/zephyr main $

@josuah josuah requested a review from kartben April 22, 2025 12:04
@ngphibang
Copy link
Contributor

ngphibang commented Apr 22, 2025

So, do we need to fix ? if yes, it's ok for me.

@sylvioalves
Copy link
Contributor

sylvioalves commented Apr 22, 2025

So this fixes for clang-18 but keeps clang-16 failing, right?
@josuah, sorry, just read you confirmed it.

@@ -282,6 +283,6 @@ int emul_rx_init(const struct device *dev)
DEVICE_DT_INST_DEFINE(n, &emul_rx_init, NULL, &emul_rx_data_##n, &emul_rx_cfg_##n, \
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &emul_rx_driver_api); \
\
VIDEO_DEVICE_DEFINE(emul_rx_##n, DEVICE_DT_INST_GET(n), emul_rx_cfg_##n.source_dev);
VIDEO_DEVICE_DEFINE(emul_rx_##n, DEVICE_DT_INST_GET(n), SOURCE_DEV(n));
Copy link
Contributor

Choose a reason for hiding this comment

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

Regardless of this being an LLVM issue or not, to me it makes perfect sense to use the DT value here directly, instead of passing it with a struct field.

Copy link
Contributor Author

@josuah josuah Apr 22, 2025

Choose a reason for hiding this comment

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

No clean-up commit needed after it gets merged, then. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

@josuah
Copy link
Contributor Author

josuah commented Apr 22, 2025

<@sylvioalves> So this fixes for clang-18 but keeps clang-16 failing, right?

Glad you asked, that was unclear.

clang-18 always worked, but clang-16 (that the CI uses) fails. This PR fixes it for clang-16.

@kartben kartben merged commit 0b2d455 into zephyrproject-rtos:main Apr 22, 2025
24 checks passed
@josuah josuah deleted the pr-hotfix-video-emul-imager branch April 22, 2025 13:25
#define NXP_VIDEO_SDMA_INIT(inst) \
PINCTRL_DT_INST_DEFINE(inst); \
const struct nxp_video_sdma_config sdma_config_##inst = { \
.dma_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \
.sensor_dev = DEVICE_DT_GET(DT_INST_PHANDLE(inst, sensor)), \
.sensor_dev = SOURCE_DEV(n), \
Copy link
Contributor

@ngphibang ngphibang Apr 23, 2025

Choose a reason for hiding this comment

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

This should be .sensor_dev = SOURCE_DEV(inst). CI didn't detect this failure because smartdma driver does not have a built-in test. I will fix this in #88323.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked not thoroughly enough. Thank you for the vigilance.
Checking again, the others drivers not have this mismatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Video Video subsystem Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. platform: ESP32 Espressif ESP32 platform: NXP Drivers NXP Semiconductors, drivers platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants