Skip to content
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

Add first party C tests #764

Merged
merged 1 commit into from
Mar 7, 2025
Merged

Conversation

Timmmm
Copy link
Collaborator

@Timmmm Timmmm commented Feb 28, 2025

Add first party C tests that can be used for tests specific to this model. This uses Clang as the cross-compiler.

This includes a copy of nanoprinf for printing to the UART.

@jordancarlin
Copy link
Collaborator

I definitely prefer this to the Zig implementation, even if the CMake file is a bit messier. Ideally it would work with both gcc and clang, especially because a lot of other riscv projects point users very strongly towards gcc (like the riscv-arch-test documentation).

@pmundkur pmundkur added the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Mar 1, 2025
@Timmmm Timmmm force-pushed the user/timh/clang_tests branch from 5195089 to f127eb0 Compare March 4, 2025 14:20
Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

Thanks for adding GCC. A few more comments.

DEPENDS ${common_deps} "src/${test_source}"
COMMAND ${CROSS_COMPILER_COMMAND_RV${xlen}}
# The ISA string to compile for.
-march=rv${xlen}gc
Copy link
Collaborator

Choose a reason for hiding this comment

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

As our tests evolve we'll need a more comprehensive march string. We use rv64gcv_zcb_zfa_zba_zbb_zbc_zbs_zfh_zicboz_zicbop_zicbom_zicond_zbkb_zbkx_zknd_zkne_zknh for our tests. We really want to enable every extension so that any instruction can be used in a test file for the model.

Copy link
Contributor

Choose a reason for hiding this comment

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

But some extensions are incompatible, such as Zcf and Zclsd, each test should be able to specify its own match string

One example is gcc's test framework, you can specify it in the comments (for reference)

gcc/testsuite/gcc.target/riscv/cmo-zicbom-1.c

/* { dg-do compile } */
/* { dg-options "-march=rv64gc_zicbom -mabi=lp64" } */
...

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is a very good point. Not sure that we need that level of complexity yet in the first version of this PR (would rather get some testing in instead of waiting for it to be perfect and continue with almost no tests), but definitely something we will need to address eventually.

Copy link
Contributor

Choose a reason for hiding this comment

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

completely agree, would be great to see this merged soon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah my plan was to embed a list of march and model configs inside the source files and then we would run each test for all of those. Probably worth waiting until after the new config system is done though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems reasonable. We should probably open an issue to track this after this PR is merged.

@Timmmm Timmmm force-pushed the user/timh/clang_tests branch from 6986639 to 831e9aa Compare March 5, 2025 14:09
@arichardson
Copy link
Collaborator

I like this, just a few minor comments (and haven't managed to review all the asm code)

@Timmmm
Copy link
Collaborator Author

Timmmm commented Mar 6, 2025

I figured out the lga thing - in the code I copied it from it was fine with just la but for some reason I was getting a relocation out of range error.

It was because I forgot to set __global_pointer$ in the linker script, and I guess it defaults to 0 or something, but the code starts at like 0x8000000000 so it was out of the 2GB range limit on la. Setting __global_pointer$ to be near .text means we can just use la.

I'll fix the other issues mentioned in a bit.

@Timmmm Timmmm force-pushed the user/timh/clang_tests branch from ca5efd5 to 43442e3 Compare March 6, 2025 09:43
Copy link

github-actions bot commented Mar 6, 2025

Test Results

396 tests  +4   396 ✅ +4   1m 19s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 16a2f97. ± Comparison against base commit 91b55d3.

♻️ This comment has been updated with latest results.

Add first party C tests that can be used for tests specific to this model. This uses Clang or RISCV GCC as the cross-compiler.

This includes a copy of `nanoprinf` for printing to the UART.
@Timmmm Timmmm force-pushed the user/timh/clang_tests branch from d971e16 to 16a2f97 Compare March 6, 2025 10:15
@Timmmm Timmmm marked this pull request as ready for review March 6, 2025 10:17
@Timmmm
Copy link
Collaborator Author

Timmmm commented Mar 6, 2025

I removed the max_pmp test. I'll add it with my PR that fixes the PMP code.

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

LGTM at this point. There are still improvements to be made (especially with ISA strings), but those can be part of a follow up PR. This will be great to get in so new tests can easily be added for the model.

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

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

LGTM, this is great and any improvements can be made in follow-up changes

@Timmmm Timmmm added the will be merged Scheduled to be merged in a few days if nobody objects label Mar 6, 2025
@jordancarlin jordancarlin removed the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Mar 7, 2025
@Timmmm Timmmm merged commit 40d26b5 into riscv:master Mar 7, 2025
2 checks passed
@Timmmm Timmmm deleted the user/timh/clang_tests branch March 7, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
will be merged Scheduled to be merged in a few days if nobody objects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants