// expect_message_in_debuglog will read the last 10000 messages in zircon's debuglog, looking
// for a message that equals `sent_msg`. If found, the function returns. If the first 10,000
// messages doesn't contain `sent_msg`, it will panic.
expect_message_in_debuglog will read the last 10000 messages in zircon's debuglog, looking
for a message that equals `sent_msg`. If found, the function returns. If the first 10,000
messages doesn't contain `sent_msg`, it will panic.
expect_message_in_debuglog will read the last 10000 messages in zircon ' s debuglog looking for a message that equals ` sent_msg ` . If found the function returns . If the first 10 000 messages doesn ' t contain ` sent_msg ` it will panic .
fn expect_message_in_debuglog(sent_msg: String) {
        let resource = Resource::from(Handle::invalid());
        let debuglog = DebugLog::create(&resource, DebugLogOpts::READABLE).unwrap();
        let mut record = Vec::with_capacity(sys::ZX_LOG_RECORD_MAX);
        for _ in 0..10000 {
            match debuglog.read(&mut record) {
                Ok(()) => {
                    // TODO(fxbug.dev/32998): Manually unpack log record until DebugLog::read returns
                    // an wrapper type.
                    let mut len_bytes = [0; 2];
                    len_bytes.copy_from_slice(&record[4..6]);
                    let data_len = u16::from_le_bytes(len_bytes) as usize;
                    let log = &record[32..(32 + data_len)];
                    if log == sent_msg.as_bytes() {
                        // We found our log!
                        return;
                    }
                }
                Err(status) if status == Status::SHOULD_WAIT => {
                    debuglog
                        .wait_handle(Signals::LOG_READABLE, Time::INFINITE)
                        .expect("Failed to wait for log readable");
                    continue;
                }
                Err(status) => {
                    panic!("Unexpected error from zx_debuglog_read: {}", status);
                }
            }
        }
        panic!("first 10000 log messages didn't include the one we sent!");
    }
fn expect_message_in_debuglog ( sent_msg : String ) { let resource = Resource :: from ( Handle :: invalid ( ) ) ; let debuglog = DebugLog :: create ( & resource , DebugLogOpts :: READABLE ) . unwrap ( ) ; let mut record = Vec :: with_capacity ( sys :: ZX_LOG_RECORD_MAX ) ; for _ in 0 .. 10000 { match debuglog . read ( & mut record ) { Ok ( ( ) ) => { // TODO(fxbug.dev/32998): Manually unpack log record until DebugLog::read returns // an wrapper type. let mut len_bytes = [ 0 ; 2 ] ; len_bytes . copy_from_slice ( & record [ 4 .. 6 ] ) ; let data_len = u16 :: from_le_bytes ( len_bytes ) as usize ; let log = & record [ 32 .. ( 32 + data_len ) ] ; if log == sent_msg . as_bytes ( ) { // We found our log! return ; } } Err ( status ) if status == Status :: SHOULD_WAIT => { debuglog . wait_handle ( Signals :: LOG_READABLE , Time :: INFINITE ) . expect ( " " ) ; continue ; } Err ( status ) => { panic ! ( " " status ) ; } } } panic ! ( " " ) ; }
expect_message_in_debuglog will read the last 10000 messages in zircon's debuglog, looking
for a message that equals `sent_msg`.
expect_message_in_debuglog will read the last 10000 messages in zircon ' s debuglog looking for a message that equals ` sent_msg ` .
sent_msg
String