[kvm-unit-tests PATCH v7] riscv: sbi: Add SBI Debug Triggers Extension tests

Andrew Jones andrew.jones at linux.dev
Tue Jul 1 01:45:23 PDT 2025


On Mon, Jun 30, 2025 at 03:32:23PM -0700, Jesse Taube wrote:
...
> +static unsigned long gen_tdata1(enum McontrolType type, enum Tdata1Value value, enum Tdata1Mode mode)
> +{
> +	switch (type) {
> +	case SBI_DBTR_TDATA1_TYPE_MCONTROL:
> +		return gen_tdata1_mcontrol(mode, value);
> +	case SBI_DBTR_TDATA1_TYPE_MCONTROL6:
> +		return gen_tdata1_mcontrol6(mode, value);
> +	default:
> +		assert_msg(false, "Invalid mcontrol type: %lu", type);
> +	}
> +}

Please don't forget to also test with rv32. Enums have ambiguous sizes. It
appears rv64 uses a long and rv32 uses an int so this assert doesn't
compile on rv32 due to the use of the %lu format. There's not much we can
do here other than specify the enum type with the

'enum <name> : <type> {...}'

syntax, but that's a C23 feature, so I think it's better to just cast.
I've done

  assert_msg(false, "Invalid mcontrol type: %u", (int)type);

to resolve that.

But, the tests also hang when running with rv32. I haven't tried to debug
yet.

Thanks,
drew



More information about the kvm-riscv mailing list