Fixed tests failing because of a too small memory
This commit is contained in:
parent
86113da9d3
commit
15a04fb9da
@ -36,14 +36,22 @@ pub struct Section{
|
||||
}
|
||||
|
||||
impl Section {
|
||||
|
||||
/// Creates a memory section from a SectionFormat
|
||||
fn from(section: &SectionFormat) -> Section {
|
||||
fn from(section: &mut SectionFormat) -> Section {
|
||||
let addr = usize::from_str_radix(§ion.addr, 16).unwrap_or_default();
|
||||
let len = usize::from_str_radix(§ion.len, 16).unwrap_or_default();
|
||||
let content: Vec<u8> = section.content.as_bytes().chunks(2).map(|x| {
|
||||
u8::from_str_radix(std::str::from_utf8(x).unwrap_or_default(), 16).unwrap_or_default()
|
||||
}).collect();
|
||||
let content: Vec<u8>;
|
||||
unsafe {
|
||||
content = section.content.as_bytes_mut()
|
||||
.chunks_mut(4).map(
|
||||
|x| {
|
||||
x.reverse();
|
||||
u8::from_str_radix(
|
||||
std::str::from_utf8(x).unwrap_or_default(), 16
|
||||
).unwrap_or_default()
|
||||
}
|
||||
).collect();
|
||||
}
|
||||
Section { addr, len, content }
|
||||
}
|
||||
|
||||
@ -126,12 +134,12 @@ impl MemChecker{
|
||||
}
|
||||
else {
|
||||
//lecture ligne CONTENT
|
||||
let section_f = SectionFormat{
|
||||
let mut section_f = SectionFormat {
|
||||
addr: tmp_addr_str.clone(),
|
||||
len: tmp_len_str.clone(),
|
||||
content: current_line.clone().replace(' ', ""),
|
||||
};
|
||||
sections.push(Section::from(§ion_f));
|
||||
sections.push(Section::from(&mut section_f));
|
||||
}
|
||||
|
||||
}
|
||||
@ -235,12 +243,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_section_content(){
|
||||
let section_format = SectionFormat{
|
||||
let mut section_format = SectionFormat{
|
||||
addr: "0".to_string(),
|
||||
len: "0".to_string(),
|
||||
content: "00FF0AA0A5".to_string(),
|
||||
};
|
||||
let section = Section::from(§ion_format);
|
||||
let section = Section::from(&mut section_format);
|
||||
let expected_vec: Vec<u8> = vec![0u8, 255u8, 10u8, 160u8, 165u8];
|
||||
assert_eq!(section.content, expected_vec);
|
||||
}
|
||||
|
@ -93,25 +93,29 @@ pub fn read_settings() -> Result<Settings, Error> {
|
||||
}
|
||||
|
||||
/// Returns a mock configuration for Machine unit testing
|
||||
///
|
||||
/// FIXME: Does not cover the whole configuration yet
|
||||
pub fn get_debug_configuration() -> Settings {
|
||||
let mut settings_map = Settings::new();
|
||||
settings_map.insert(MachineSettingKey::PageSize, 128);
|
||||
settings_map.insert(MachineSettingKey::NumPhysPages, 400);
|
||||
settings_map.insert(MachineSettingKey::PageSize, 2048);
|
||||
settings_map.insert(MachineSettingKey::NumPhysPages, 8192);
|
||||
settings_map.insert(MachineSettingKey::UserStackSize, 4096);
|
||||
settings_map
|
||||
}
|
||||
|
||||
/// Removes comments and empty lines
|
||||
fn filter_garbage<R: std::io::Read>(reader: BufReader<R>) -> Vec<String> {
|
||||
reader.lines()
|
||||
.map(|l| l.unwrap())
|
||||
.filter(|l| !l.is_empty() && !l.starts_with("#"))
|
||||
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
/// Inserts user settings into setting map
|
||||
fn update_settings_map(mut settings_map: Settings, key: &str, setting: &str) -> Settings {
|
||||
let key = MachineSettingKey::from(key);
|
||||
let setting = u64::from_str_radix(setting, 10).unwrap_or(0);
|
||||
let setting = setting.parse::<u64>().unwrap_or(0);
|
||||
settings_map.insert(key, setting);
|
||||
settings_map
|
||||
}
|
Loading…
Reference in New Issue
Block a user