zircon/kernel/lib/debuglog/debuglog_tests.cc
// Test that write fails with an error once the |DLog| has been shutdown.
Test that write fails with an error once the |DLog| has been shutdown.
Test that write fails with an error once the |DLog| has been shutdown .
bool shutdown() {
  BEGIN_TEST;
  fbl::AllocChecker ac;
  ktl::unique_ptr<DLog> log = ktl::make_unique<DLog>(&ac);
  ASSERT_TRUE(ac.check());
  char msg[] = "Message!";
  ASSERT_EQ(ZX_OK, log->write(DEBUGLOG_WARNING, 0, {msg, sizeof(msg)}));
  log->shutdown();
  ASSERT_EQ(ZX_ERR_BAD_STATE, log->write(DEBUGLOG_WARNING, 0, msg));
  DlogReader reader;
  reader.InitializeForTest(log.get());
  size_t got;
  uint8_t read_buf[DLOG_MAX_RECORD];
  ASSERT_EQ(ZX_OK, reader.Read(0, read_buf, sizeof(read_buf), &got));
  ASSERT_EQ(sizeof(dlog_header) + sizeof(msg), got);
  ASSERT_EQ(ZX_ERR_SHOULD_WAIT, reader.Read(0, read_buf, sizeof(read_buf), &got));
  reader.Disconnect();
  END_TEST;
}
bool shutdown ( ) { BEGIN_TEST ; fbl :: AllocChecker ac ; ktl :: unique_ptr < DLog > log = ktl :: make_unique < DLog > ( & ac ) ; ASSERT_TRUE ( ac . check ( ) ) ; char msg [ ] = " " ; ASSERT_EQ ( ZX_OK , log -> write ( DEBUGLOG_WARNING , 0 , { msg , sizeof ( msg ) } ) ) ; log -> shutdown ( ) ; ASSERT_EQ ( ZX_ERR_BAD_STATE , log -> write ( DEBUGLOG_WARNING , 0 , msg ) ) ; DlogReader reader ; reader . InitializeForTest ( log . get ( ) ) ; size_t got ; uint8_t read_buf [ DLOG_MAX_RECORD ] ; ASSERT_EQ ( ZX_OK , reader . Read ( 0 , read_buf , sizeof ( read_buf ) , & got ) ) ; ASSERT_EQ ( sizeof ( dlog_header ) + sizeof ( msg ) , got ) ; ASSERT_EQ ( ZX_ERR_SHOULD_WAIT , reader . Read ( 0 , read_buf , sizeof ( read_buf ) , & got ) ) ; reader . Disconnect ( ) ; END_TEST ; }
Test that write fails with an error once the |DLog| has been shutdown.
Test that write fails with an error once the |DLog| has been shutdown .
// Write one message and see that it succeeds. // Now ask the DLog to shutdown, write another, see that it fails. // See that there is only one message in the DLog.