Browse Source

tests: add build-full test.

Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
Zhouqi Jiang 1 year ago
parent
commit
d88469db97
6 changed files with 257 additions and 6 deletions
  1. 3 0
      examples/derive/commons.rs
  2. 2 2
      examples/derive/main.rs
  3. 2 2
      macros/src/lib.rs
  4. 1 1
      src/lib.rs
  5. 1 1
      src/nacl.rs
  6. 248 0
      tests/build-full.rs

+ 3 - 0
examples/derive/commons.rs

@@ -1,3 +1,6 @@
+// Mock implementaion module. Actual SBI implementaion should implement
+// those SBI extensions with machine environment specific hardware features.
+
 use rustsbi::{HartMask, MachineInfo};
 use sbi_spec::binary::SbiRet;
 

+ 2 - 2
examples/derive/main.rs

@@ -49,7 +49,7 @@ fn main() {
     // Finally, fill SBI return value into exception environment and return.
     // In bare metal: fill `a0` and `a1` register in trap context with `SbiRet` value;
     // In hypervisor: fill guest supervisor `a0` and `a1` with `SbiRet` value.
-    let _  = ret; // It should be filled into context on real programs.
+    let _ = ret; // It should be filled into context on real programs.
 
     // Congratulations! You have learned how to use RustSBI to create your SBI implementaion.
     // You may consider using the RustSBI Prototyping System, build a standalone
@@ -57,7 +57,7 @@ fn main() {
     // development.
 
     // Additionally, we present another mock function suggesting this instance is running
-    // RustSBI by showing that SBI implementation ID equals 4. 
+    // RustSBI by showing that SBI implementation ID equals 4.
     let ret = sbi.handle_ecall(0x10, 0x1, [0; 6]);
     println!("SBI implementation ID: {:x?}", ret.value);
 }

+ 2 - 2
macros/src/lib.rs

@@ -49,7 +49,7 @@ pub fn derive_rustsbi(input: TokenStream) -> TokenStream {
                 "hsm" => imp.hsm = Some(name),
                 "spi" | "ipi" => imp.ipi = Some(name),
                 "srst" | "reset" => imp.reset = Some(name),
-                "timer" => imp.timer = Some(name),
+                "time" | "timer" => imp.timer = Some(name),
                 "pmu" => imp.pmu = Some(name),
                 "dbcn" | "console" => imp.console = Some(name),
                 "susp" => imp.susp = Some(name),
@@ -145,7 +145,7 @@ fn impl_derive_rustsbi(name: &Ident, imp: RustSBIImp) -> TokenStream {
     };
     let timer_procedure = if let Some(timer) = &imp.timer {
         quote! {
-            ::rustsbi::spec::timer::EID_TIMER => ::rustsbi::_rustsbi_timer(&self.#timer, param, function),
+            ::rustsbi::spec::time::EID_TIME => ::rustsbi::_rustsbi_timer(&self.#timer, param, function),
         }
     } else {
         quote! {}

+ 1 - 1
src/lib.rs

@@ -176,7 +176,7 @@
 //! struct Executor {
 //!     ctx: SupervisorContext,
 //!     /* other environment variables ... */
-//!     sbi: RustSBI<Clint, Clint, MyPlatRfnc, MyPlatHsm, MyBoardPower, MyPlatPmu, MyPlatDbcn, MyPlatSusp, MyPlatCppc>,
+//!     // sbi: RustSBI<Clint, Clint, MyPlatRfnc, MyPlatHsm, MyBoardPower, MyPlatPmu, MyPlatDbcn, MyPlatSusp, MyPlatCppc>,
 //!     /* custom_1: CustomSBI<...> */
 //! }
 //!

+ 1 - 1
src/nacl.rs

@@ -143,7 +143,7 @@ pub trait Nacl: Send + Sync {
     fn sync_sret(&self) -> SbiRet;
 }
 
-impl<T: Nacl> Nacl for T {
+impl<T: Nacl> Nacl for &T {
     #[inline]
     fn probe_feature(&self, feature_id: u32) -> SbiRet {
         T::probe_feature(self, feature_id)

+ 248 - 0
tests/build-full.rs

@@ -0,0 +1,248 @@
+use rustsbi::RustSBI;
+use sbi_spec::{
+    binary::{Physical, SbiRet, SharedPtr},
+    nacl::shmem_size::NATIVE,
+};
+
+// This struct should pass Rust build.
+
+#[derive(RustSBI)]
+struct FullyImplemented {
+    console: DummyConsole,
+    cppc: DummyCppc,
+    hsm: DummyHsm,
+    ipi: DummyIpi,
+    nacl: DummyNacl,
+    pmu: DummyPmu,
+    reset: DummyReset,
+    fence: DummyFence,
+    sta: DummySta,
+    susp: DummySusp,
+    timer: DummyTimer,
+    info: DummyMachineInfo,
+}
+
+#[derive(RustSBI)]
+struct AlternateName {
+    dbcn: DummyConsole,
+    cppc: DummyCppc,
+    hsm: DummyHsm,
+    ipi: DummyIpi,
+    nacl: DummyNacl,
+    pmu: DummyPmu,
+    srst: DummyReset,
+    rfnc: DummyFence,
+    sta: DummySta,
+    susp: DummySusp,
+    time: DummyTimer,
+    info: DummyMachineInfo,
+}
+
+struct DummyConsole;
+
+impl rustsbi::Console for DummyConsole {
+    fn write(&self, _: Physical<&[u8]>) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn read(&self, _: Physical<&mut [u8]>) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn write_byte(&self, _: u8) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyCppc;
+
+impl rustsbi::Cppc for DummyCppc {
+    fn probe(&self, _: u32) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn read(&self, _: u32) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn read_hi(&self, _: u32) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn write(&self, _: u32, _: u64) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyHsm;
+
+impl rustsbi::Hsm for DummyHsm {
+    fn hart_start(&self, _: usize, _: usize, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn hart_stop(&self) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn hart_get_status(&self, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyIpi;
+
+impl rustsbi::Ipi for DummyIpi {
+    fn send_ipi(&self, _: rustsbi::HartMask) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyNacl;
+
+impl rustsbi::Nacl for DummyNacl {
+    fn probe_feature(&self, _: u32) -> SbiRet {
+        unimplemented!()
+    }
+    fn set_shmem(&self, _: SharedPtr<[u8; NATIVE]>, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn sync_csr(&self, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn sync_hfence(&self, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn sync_sret(&self) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyPmu;
+
+impl rustsbi::Pmu for DummyPmu {
+    fn num_counters(&self) -> usize {
+        unimplemented!()
+    }
+
+    fn counter_get_info(&self, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn counter_config_matching(&self, _: usize, _: usize, _: usize, _: usize, _: u64) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn counter_start(&self, _: usize, _: usize, _: usize, _: u64) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn counter_stop(&self, _: usize, _: usize, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn counter_fw_read(&self, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyReset;
+
+impl rustsbi::Reset for DummyReset {
+    fn system_reset(&self, _: u32, _: u32) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyFence;
+
+impl rustsbi::Fence for DummyFence {
+    fn remote_fence_i(&self, _: rustsbi::HartMask) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn remote_sfence_vma(&self, _: rustsbi::HartMask, _: usize, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+
+    fn remote_sfence_vma_asid(&self, _: rustsbi::HartMask, _: usize, _: usize, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummySta;
+
+impl rustsbi::Sta for DummySta {
+    fn set_shmem(&self, _: SharedPtr<[u8; 64]>, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummySusp;
+
+impl rustsbi::Susp for DummySusp {
+    fn system_suspend(&self, _: u32, _: usize, _: usize) -> SbiRet {
+        unimplemented!()
+    }
+}
+
+struct DummyTimer;
+
+impl rustsbi::Timer for DummyTimer {
+    fn set_timer(&self, _: u64) {
+        unimplemented!()
+    }
+}
+
+struct DummyMachineInfo;
+
+impl rustsbi::MachineInfo for DummyMachineInfo {
+    fn mvendorid(&self) -> usize {
+        unimplemented!()
+    }
+
+    fn marchid(&self) -> usize {
+        unimplemented!()
+    }
+
+    fn mimpid(&self) -> usize {
+        unimplemented!()
+    }
+}
+
+#[test]
+fn rustsbi_impl_id() {
+    let sbi = FullyImplemented {
+        console: DummyConsole,
+        cppc: DummyCppc,
+        hsm: DummyHsm,
+        ipi: DummyIpi,
+        nacl: DummyNacl,
+        pmu: DummyPmu,
+        reset: DummyReset,
+        fence: DummyFence,
+        sta: DummySta,
+        susp: DummySusp,
+        timer: DummyTimer,
+        info: DummyMachineInfo,
+    };
+    assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
+    let sbi = AlternateName {
+        dbcn: DummyConsole,
+        cppc: DummyCppc,
+        hsm: DummyHsm,
+        ipi: DummyIpi,
+        nacl: DummyNacl,
+        pmu: DummyPmu,
+        srst: DummyReset,
+        rfnc: DummyFence,
+        sta: DummySta,
+        susp: DummySusp,
+        time: DummyTimer,
+        info: DummyMachineInfo,
+    };
+    assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
+}