Route all loader messages to log collector (#10528)

This commit is contained in:
Jack May
2020-06-13 13:20:08 -07:00
committed by GitHub
parent e5a2c75fab
commit b6a9573748
11 changed files with 240 additions and 230 deletions

View File

@ -1337,10 +1337,8 @@ dependencies = [
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-logger 1.3.0",
"solana-runtime 1.3.0",
"solana-sdk 1.3.0",
"solana_rbpf 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -6,7 +6,7 @@ use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use solana_rbpf::EbpfVm;
use solana_sdk::{
account::Account,
entrypoint_native::{InvokeContext, ProcessInstruction},
entrypoint_native::{InvokeContext, Logger, ProcessInstruction},
instruction::{CompiledInstruction, InstructionError},
message::Message,
pubkey::Pubkey,
@ -135,6 +135,7 @@ fn bench_program_alu(bencher: &mut Bencher) {
#[derive(Debug, Default)]
pub struct MockInvokeContext {
key: Pubkey,
mock_logger: MockLogger,
}
impl InvokeContext for MockInvokeContext {
fn push(&mut self, _key: &Pubkey) -> Result<(), InstructionError> {
@ -155,8 +156,19 @@ impl InvokeContext for MockInvokeContext {
fn get_programs(&self) -> &[(Pubkey, ProcessInstruction)] {
&[]
}
fn log_enabled(&self) -> bool {
false
fn get_logger(&self) -> Rc<RefCell<dyn Logger>> {
Rc::new(RefCell::new(self.mock_logger.clone()))
}
}
#[derive(Debug, Default, Clone)]
pub struct MockLogger {
pub log: Rc<RefCell<Vec<String>>>,
}
impl Logger for MockLogger {
fn log_enabled(&self) -> bool {
true
}
fn log(&mut self, message: &str) {
self.log.borrow_mut().push(message.to_string());
}
fn log(&mut self, _message: &str) {}
}