This commit is contained in:
Alexander Meißner
2021-11-17 10:31:07 +01:00
committed by GitHub
parent c53174dc56
commit 318d26f0ff
13 changed files with 371 additions and 114 deletions

View File

@@ -2764,6 +2764,13 @@ mod tests {
};
use std::str::FromStr;
const DEFAULT_CONFIG: Config = Config {
max_call_depth: 20,
stack_frame_size: 4_096,
enable_instruction_meter: true,
enable_instruction_tracing: false,
};
macro_rules! assert_access_violation {
($result:expr, $va:expr, $len:expr) => {
match $result {
@@ -2785,10 +2792,9 @@ mod tests {
const LENGTH: u64 = 1000;
let data = vec![0u8; LENGTH as usize];
let addr = data.as_ptr() as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion::new_from_slice(&data, START, 0, false)],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -2825,7 +2831,6 @@ mod tests {
// Pubkey
let pubkey = solana_sdk::pubkey::new_rand();
let addr = &pubkey as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
@@ -2834,7 +2839,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let translated_pubkey =
@@ -2856,7 +2861,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let translated_instruction =
@@ -2875,7 +2880,6 @@ mod tests {
let data: Vec<u8> = vec![];
assert_eq!(0x1 as *const u8, data.as_ptr());
let addr = good_data.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
@@ -2884,7 +2888,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let translated_data = translate_slice::<u8>(
@@ -2909,7 +2913,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let translated_data = translate_slice::<u8>(
@@ -2952,7 +2956,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let translated_data = translate_slice::<u64>(
@@ -2982,7 +2986,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let translated_data = translate_slice::<Pubkey>(
@@ -3002,7 +3006,6 @@ mod tests {
fn test_translate_string_and_do() {
let string = "Gaggablaghblagh!";
let addr = string.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
@@ -3011,7 +3014,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
assert_eq!(
@@ -3034,9 +3037,9 @@ mod tests {
#[test]
#[should_panic(expected = "UserError(SyscallError(Abort))")]
fn test_syscall_abort() {
let config = Config::default();
let memory_mapping =
MemoryMapping::new::<UserError>(vec![MemoryRegion::default()], &config).unwrap();
MemoryMapping::new::<UserError>(vec![MemoryRegion::default()], &DEFAULT_CONFIG)
.unwrap();
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
SyscallAbort::call(
&mut SyscallAbort {},
@@ -3056,7 +3059,6 @@ mod tests {
fn test_syscall_sol_panic() {
let string = "Gaggablaghblagh!";
let addr = string.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
@@ -3065,7 +3067,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -3133,7 +3135,6 @@ mod tests {
loader_id: &bpf_loader::id(),
enforce_aligned_host_addrs: true,
};
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
@@ -3142,7 +3143,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -3247,8 +3248,7 @@ mod tests {
compute_meter,
logger,
};
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(vec![], &config).unwrap();
let memory_mapping = MemoryMapping::new::<UserError>(vec![], &DEFAULT_CONFIG).unwrap();
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log_u64.call(1, 2, 3, 4, 5, &memory_mapping, &mut result);
@@ -3275,7 +3275,6 @@ mod tests {
loader_id: &bpf_loader::id(),
enforce_aligned_host_addrs: true,
};
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
@@ -3284,7 +3283,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: false,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -3319,7 +3318,6 @@ mod tests {
#[test]
fn test_syscall_sol_alloc_free() {
let config = Config::default();
// large alloc
{
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
@@ -3330,7 +3328,7 @@ mod tests {
0,
true,
)],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let mut syscall = SyscallAllocFree {
@@ -3357,7 +3355,7 @@ mod tests {
0,
true,
)],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let mut syscall = SyscallAllocFree {
@@ -3383,7 +3381,7 @@ mod tests {
0,
true,
)],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let mut syscall = SyscallAllocFree {
@@ -3403,7 +3401,6 @@ mod tests {
fn check_alignment<T>() {
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion::new_from_slice(
heap.as_slice(),
@@ -3411,7 +3408,7 @@ mod tests {
0,
true,
)],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let mut syscall = SyscallAllocFree {
@@ -3457,7 +3454,6 @@ mod tests {
let ro_len = bytes_to_hash.len() as u64;
let ro_va = 96;
let rw_va = 192;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![
MemoryRegion {
@@ -3489,7 +3485,7 @@ mod tests {
is_writable: true,
},
],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
let compute_meter: Rc<RefCell<dyn ComputeMeter>> =
@@ -3555,7 +3551,6 @@ mod tests {
#[test]
fn test_syscall_get_sysvar() {
let config = Config::default();
// Test clock sysvar
{
let got_clock = Clock::default();
@@ -3569,7 +3564,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: true,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -3611,7 +3606,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: true,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -3661,7 +3656,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: true,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();
@@ -3701,7 +3696,7 @@ mod tests {
vm_gap_shift: 63,
is_writable: true,
}],
&config,
&DEFAULT_CONFIG,
)
.unwrap();