4
0

build-generics.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. use rustsbi::RustSBI;
  2. use sbi_spec::binary::SbiRet;
  3. // These structs should pass Rust build.
  4. #[derive(RustSBI)]
  5. struct WithGenerics<T: rustsbi::Timer> {
  6. reset: DummyReset,
  7. timer: T,
  8. info: DummyEnvInfo,
  9. }
  10. #[derive(RustSBI)]
  11. struct WithWhereClause<T>
  12. where
  13. T: rustsbi::Timer,
  14. {
  15. reset: DummyReset,
  16. timer: T,
  17. info: DummyEnvInfo,
  18. }
  19. #[derive(RustSBI)]
  20. struct WithConstantGenerics<const N: usize> {
  21. info: DummyEnvInfo,
  22. _dummy: [u8; N],
  23. }
  24. #[derive(RustSBI)]
  25. struct WithLifetime<'a> {
  26. info: &'a DummyEnvInfo,
  27. }
  28. #[derive(RustSBI)]
  29. struct WithEverythingCombined<'a, T: rustsbi::Timer, U, const N: usize>
  30. where
  31. U: rustsbi::Reset,
  32. {
  33. timer: T,
  34. reset: U,
  35. info: &'a DummyEnvInfo,
  36. _dummy: [u8; N],
  37. }
  38. #[test]
  39. fn test_impl_id() {
  40. let sbi = WithGenerics {
  41. reset: DummyReset,
  42. timer: DummyTimer,
  43. info: DummyEnvInfo,
  44. };
  45. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  46. let sbi = WithWhereClause {
  47. reset: DummyReset,
  48. timer: DummyTimer,
  49. info: DummyEnvInfo,
  50. };
  51. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  52. let sbi = WithConstantGenerics {
  53. info: DummyEnvInfo,
  54. _dummy: [0; 100],
  55. };
  56. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  57. let dummy_info = DummyEnvInfo;
  58. let sbi = WithLifetime { info: &dummy_info };
  59. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  60. let sbi = WithEverythingCombined {
  61. timer: DummyTimer,
  62. reset: DummyReset,
  63. info: &dummy_info,
  64. _dummy: [0; 10],
  65. };
  66. assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
  67. }
  68. struct DummyReset;
  69. impl rustsbi::Reset for DummyReset {
  70. fn system_reset(&self, _: u32, _: u32) -> SbiRet {
  71. unimplemented!()
  72. }
  73. }
  74. struct DummyTimer;
  75. impl rustsbi::Timer for DummyTimer {
  76. fn set_timer(&self, _: u64) {
  77. unimplemented!()
  78. }
  79. }
  80. struct DummyEnvInfo;
  81. impl rustsbi::EnvInfo for DummyEnvInfo {
  82. fn mvendorid(&self) -> usize {
  83. unimplemented!()
  84. }
  85. fn marchid(&self) -> usize {
  86. unimplemented!()
  87. }
  88. fn mimpid(&self) -> usize {
  89. unimplemented!()
  90. }
  91. }