Fixed tests failing because of a too small memory
This commit is contained in:
parent
86113da9d3
commit
15a04fb9da
@ -14,7 +14,7 @@ use std::{fs, io::{BufRead, BufReader, Lines, Error}};
|
|||||||
use crate::Machine;
|
use crate::Machine;
|
||||||
|
|
||||||
/// File section
|
/// File section
|
||||||
pub struct SectionFormat{
|
pub struct SectionFormat {
|
||||||
/// Memory address of the section
|
/// Memory address of the section
|
||||||
addr: String,
|
addr: String,
|
||||||
/// The size of data in bytes
|
/// The size of data in bytes
|
||||||
@ -26,7 +26,7 @@ pub struct SectionFormat{
|
|||||||
/// # Memory section
|
/// # Memory section
|
||||||
///
|
///
|
||||||
/// Representation of a section of memory from BurritOS or NachOS
|
/// Representation of a section of memory from BurritOS or NachOS
|
||||||
pub struct Section{
|
pub struct Section {
|
||||||
/// Memory address of the section
|
/// Memory address of the section
|
||||||
addr: usize,
|
addr: usize,
|
||||||
/// The size of data in bytes
|
/// The size of data in bytes
|
||||||
@ -36,15 +36,23 @@ pub struct Section{
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Section {
|
impl Section {
|
||||||
|
|
||||||
/// Creates a memory section from a SectionFormat
|
/// 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 addr = usize::from_str_radix(§ion.addr, 16).unwrap_or_default();
|
||||||
let len = usize::from_str_radix(§ion.len, 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| {
|
let content: Vec<u8>;
|
||||||
u8::from_str_radix(std::str::from_utf8(x).unwrap_or_default(), 16).unwrap_or_default()
|
unsafe {
|
||||||
}).collect();
|
content = section.content.as_bytes_mut()
|
||||||
Section{addr, len, content}
|
.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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pretty prints a memory section
|
/// Pretty prints a memory section
|
||||||
@ -68,7 +76,7 @@ pub struct MemChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl MemChecker{
|
impl MemChecker {
|
||||||
|
|
||||||
///Translate lines of a file in e Vector of String
|
///Translate lines of a file in e Vector of String
|
||||||
///We need this method to parse the memory we received
|
///We need this method to parse the memory we received
|
||||||
@ -126,12 +134,12 @@ impl MemChecker{
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//lecture ligne CONTENT
|
//lecture ligne CONTENT
|
||||||
let section_f = SectionFormat{
|
let mut section_f = SectionFormat {
|
||||||
addr: tmp_addr_str.clone(),
|
addr: tmp_addr_str.clone(),
|
||||||
len: tmp_len_str.clone(),
|
len: tmp_len_str.clone(),
|
||||||
content: current_line.clone().replace(' ', ""),
|
content: current_line.clone().replace(' ', ""),
|
||||||
};
|
};
|
||||||
sections.push(Section::from(§ion_f));
|
sections.push(Section::from(&mut section_f));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -169,7 +177,7 @@ impl MemChecker{
|
|||||||
machine.pc = m_c.pc as u64;
|
machine.pc = m_c.pc as u64;
|
||||||
|
|
||||||
for section in m_c.sections.iter() {
|
for section in m_c.sections.iter() {
|
||||||
for (i,b) in section.content.iter().enumerate() {
|
for (i, b) in section.content.iter().enumerate() {
|
||||||
machine.main_memory[section.addr + i] = *b;
|
machine.main_memory[section.addr + i] = *b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,12 +243,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_section_content(){
|
fn test_create_section_content(){
|
||||||
let section_format = SectionFormat{
|
let mut section_format = SectionFormat{
|
||||||
addr: "0".to_string(),
|
addr: "0".to_string(),
|
||||||
len: "0".to_string(),
|
len: "0".to_string(),
|
||||||
content: "00FF0AA0A5".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];
|
let expected_vec: Vec<u8> = vec![0u8, 255u8, 10u8, 160u8, 165u8];
|
||||||
assert_eq!(section.content, expected_vec);
|
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
|
/// Returns a mock configuration for Machine unit testing
|
||||||
|
///
|
||||||
/// FIXME: Does not cover the whole configuration yet
|
/// FIXME: Does not cover the whole configuration yet
|
||||||
pub fn get_debug_configuration() -> Settings {
|
pub fn get_debug_configuration() -> Settings {
|
||||||
let mut settings_map = Settings::new();
|
let mut settings_map = Settings::new();
|
||||||
settings_map.insert(MachineSettingKey::PageSize, 128);
|
settings_map.insert(MachineSettingKey::PageSize, 2048);
|
||||||
settings_map.insert(MachineSettingKey::NumPhysPages, 400);
|
settings_map.insert(MachineSettingKey::NumPhysPages, 8192);
|
||||||
settings_map.insert(MachineSettingKey::UserStackSize, 4096);
|
settings_map.insert(MachineSettingKey::UserStackSize, 4096);
|
||||||
settings_map
|
settings_map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Removes comments and empty lines
|
||||||
fn filter_garbage<R: std::io::Read>(reader: BufReader<R>) -> Vec<String> {
|
fn filter_garbage<R: std::io::Read>(reader: BufReader<R>) -> Vec<String> {
|
||||||
reader.lines()
|
reader.lines()
|
||||||
.map(|l| l.unwrap())
|
.map(|l| l.unwrap())
|
||||||
.filter(|l| !l.is_empty() && !l.starts_with("#"))
|
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Inserts user settings into setting map
|
||||||
fn update_settings_map(mut settings_map: Settings, key: &str, setting: &str) -> Settings {
|
fn update_settings_map(mut settings_map: Settings, key: &str, setting: &str) -> Settings {
|
||||||
let key = MachineSettingKey::from(key);
|
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.insert(key, setting);
|
||||||
settings_map
|
settings_map
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user