Skip to content

Commit

Permalink
Show hint example
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens committed Dec 13, 2024
1 parent bc3dba4 commit ea77dbd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ceno_emul/tests/test_elf.rs → ceno_host/tests/test_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use ceno_emul::{
CENO_PLATFORM, EmuContext, InsnKind, Platform, StepRecord, VMState,
host_utils::read_all_messages,
};
use ceno_host::CenoStdin;
use itertools::enumerate;

#[test]
fn test_ceno_rt_mini() -> Result<()> {
Expand Down Expand Up @@ -75,6 +77,20 @@ fn test_ceno_rt_io() -> Result<()> {
Ok(())
}

#[test]
fn test_hints() {
let mut hints = CenoStdin::default();
hints.write(&"This is my hint string.".to_string()).unwrap();
hints.write(&1997_u32).unwrap();
hints.write(&1999_u32).unwrap();

let all_messages = ceno_host::run(CENO_PLATFORM, ceno_examples::hints, &hints);
for (i, msg) in enumerate(&all_messages) {
println!("{i}: {msg}");
}
assert_eq!(all_messages[0], "3992003");
}

fn run(state: &mut VMState) -> Result<Vec<StepRecord>> {
let steps = state.iter_until_halt().collect::<Result<Vec<_>>>()?;
eprintln!("Emulator ran for {} steps.", steps.len());
Expand Down
20 changes: 20 additions & 0 deletions guest/examples/examples/hints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![no_main]
#![no_std]

extern crate ceno_rt;
use ceno_rt::println;
use core::fmt::Write;
use rkyv::{Archived, string::ArchivedString};

ceno_rt::entry!(main);
fn main() {
let msg: &ArchivedString = ceno_rt::read();

let a: &Archived<u32> = ceno_rt::read();
let b: &Archived<u32> = ceno_rt::read();
let product: u32 = a * b;

assert_eq!(product, 3992003);
println!("{product}");
println!("This message is a hint: {msg}");
}

0 comments on commit ea77dbd

Please sign in to comment.