riscv-ovpsim / imperas-riscv-tests

160 stars 37 forks source link

Semihosting and Unit testing #19

Open fpedd opened 3 years ago

fpedd commented 3 years ago

I am using CTest to run some unit tests on OVPsimPlus. Every unit test consists of an independent .elf and its main returns 0 on success, and 1 on failure. Is there a way, using semihosting, to forward this return value to the OVPsimPlus executable, so that OVPsimPlus itself returns 0 on success and 1 on failure of the unit test? Currently, OVPsimPlus returns 0 regardless.

duncangraham-Imperas commented 3 years ago

The riscvOVPsimPlus executable is a fixed virtual platform containing specific functionality. Part of this functionality is support for various test infrastructures and semihosting capabilities. What you are looking for is simple to realize using the OVP APIs (used to create riscvOVPsimPlus) but as it is a specifc custom feature is not included by the fixed virtual platform (riscvOVPsimPlus). The return code from riscvOVPsimPlus is the return state of the execution of the virtual platform and will return 0 on sucessfuly runing the application to exit()

PhilippvK commented 2 years ago

@duncangraham-Imperas I have a very similar issue. If my target software terminates with a exit(1) statement the exit code of the OVPsimPlus executable would still be zero.


I found out about the option

--override riscvOVPsim/cpu/pk/reportExitErrors=F (Boolean) (default=F) (default) Report non-zero exit() return codes as simulator errors

which seems to be related with what we are trying to achieve.

However adding --override riscvOVPsim/cpu/pk/reportExitErrors=T to the cmdline did not result in the expected behavior.

Could you please provide some details on this option and how is is intended to be used?

duncangraham-Imperas commented 2 years ago

Looking at the implementation there appears to be some confusion on how this is implemented. I do not see that this is used in the PK semihosting. Instead if tracing is enabled, using strace argument, then the code provided to the call to exit is output.

I will ask our engineering group to look into this to see if an update is required

duncangraham-Imperas commented 2 years ago

We see that although the parameter is available the code to display the exit code was not added to the PK semihost library. This has now been fixed and will be available in the next version of riscvOVPsim.

fpedd commented 2 years ago

@duncangraham-Imperas Thank you very much for getting this fixed! This makes running unit tests on OVPsim a lot easier.