Skip to content

Commit

Permalink
Merge pull request #23 from Xila-Project/Feature/Drivers
Browse files Browse the repository at this point in the history
Feature/drivers
  • Loading branch information
AlixANNERAUD authored Jul 12, 2024
2 parents a8972d5 + 205c7c6 commit 8083cb2
Show file tree
Hide file tree
Showing 48 changed files with 129 additions and 297 deletions.
18 changes: 5 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ members = [
"Modules/Bindings",
"Modules/Shared",
"Modules/Virtual_machine",
"Modules/Virtual_machine/Tests/WASM_test",
"Modules/Bindings/Tests/WASM_test",
"Modules/Graphics",
"Modules/Screen",
"Modules/Task",
"Modules/Users",
"Modules/Drivers",
]
exclude = ["Build_tool"]
exclude = [
"Build_tool",
"Modules/Virtual_machine/Tests/WASM_test",
"Modules/Bindings/Tests/WASM_test",
]

[package]
name = "Xila"
Expand Down Expand Up @@ -46,16 +48,6 @@ embassy = [
[dependencies]
Virtual_machine = { path = "Modules/Virtual_machine" }

[profile.release.package.File_system_bindings_WASM_test]
# lto = true
opt-level = 's'
strip = true

[profile.release.package.Virtual_machine_WASM_test]
# lto = true
opt-level = 's'
strip = true

[target.'cfg( target_os = "espidf" )'.dependencies]
esp-idf-sys = { version = "0.34.1", features = ["binstart"] }
esp-idf-hal = "0.43.1"
Expand Down
3 changes: 3 additions & 0 deletions Modules/Bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Task = { path = "../Task" }
Graphics = { path = "../Graphics" }
Screen = { path = "../Screen" }

[dev-dependencies]
Drivers = { path = "../Drivers" }

[[test]]
name = "File_system_bindings_tests"
path = "Tests/File_system.rs"
Expand Down
7 changes: 4 additions & 3 deletions Modules/Bindings/Tests/File_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#![allow(non_upper_case_globals)]

use Bindings::File_system_bindings;
use File_system::{Drivers::Native::File_system_type, Prelude::Path_type};
use File_system::Path_type;
use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue};

#[test]
fn Integration_test() {
let Binary_buffer = include_bytes!(
"../../../target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm"
"../Tests/WASM_test/target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm"
);

Users::Initialize().expect("Failed to initialize users manager");
Expand All @@ -18,7 +18,8 @@ fn Integration_test() {

let Virtual_file_system = File_system::Initialize().expect("Failed to initialize file system");

let Native_file_system = File_system_type::New().expect("Failed to create file system");
let Native_file_system =
Drivers::Native::File_system_type::New().expect("Failed to create file system");

let _ = Virtual_file_system.Mount(Box::new(Native_file_system), Path_type::Get_root());

Expand Down
2 changes: 1 addition & 1 deletion Modules/Bindings/Tests/Task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue};
#[test]
fn Integration_test() {
let Binary_buffer = include_bytes!(
"../../../target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm"
"../Tests/WASM_test/target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm"
);

Task::Initialize().expect("Failed to initialize task manager");
Expand Down
1 change: 1 addition & 0 deletions Modules/Bindings/Tests/WASM_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
6 changes: 5 additions & 1 deletion Modules/Bindings/Tests/WASM_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[workspace]

[package]
name = "File_system_bindings_WASM_test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
opt-level = 's'
strip = true

[dependencies]
Binding_tool = { path = "../../../../../Binding_tool", features = ["WASM"] }
5 changes: 4 additions & 1 deletion Modules/Bindings/src/File_system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use Binding_tool::Bind_function_native;
use File_system::Prelude::*;
use File_system::{
Error_type, Flags_type, Path_type, Position_type, Result_type, Size_type,
Unique_file_identifier_type, Virtual_file_system_type,
};
use Virtual_machine::{Function_descriptor_type, Function_descriptors, Registrable_trait};

pub struct File_system_bindings;
Expand Down
8 changes: 7 additions & 1 deletion Modules/Drivers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"

[dependencies]
File_system = { path = "../File_system" }
Task = { version = "0.1.0", path = "../Task" }
Users = { version = "0.1.0", path = "../Users" }
paste = "1.0.15"
quote = "1.0.36"

Expand Down Expand Up @@ -35,9 +37,13 @@ esp-idf-sys = { version = "0.34.1" }
[build-dependencies]
embuild = { version = "0.32", features = ["espidf"] }

[dev-dependencies]
[target.'cfg( target_os = "espidf" )'.dev-dependencies]
anyhow = "1"
esp-idf-sys = { version = "0.34.1", features = ["binstart"] }
mipidsi = "0.5.0"
display-interface-spi = "0.4.1"
embedded-graphics = "0.7.1"

[[test]]
name = "Native"
path = "Tests/Native/Main.rs"
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ const Device_path: &Path_type = unsafe { Path_type::New_unchecked_constant("/Dev

#[cfg(target_os = "linux")]
#[test]
fn Test_virtual_file_system_file() {
fn Test_file_system() {
use std::sync::RwLock;

use File_system::{
Drivers::Native::File_system_type,
Prelude::{Device_trait, File_type, Mode_type, Path_type, Position_type, Status_type},
Device_trait, File_type, Mode_type, Path_type, Position_type, Result_type, Status_type,
};

Task::Initialize().expect("Failed to initialize task manager");

Users::Initialize().expect("Failed to initialize users manager");

let File_system =
Drivers::Native::File_system_type::New().expect("Failed to create file system");

let Virtual_file_system = File_system::Initialize().expect("Failed to initialize file system");

Virtual_file_system
.Mount(
Box::new(File_system_type::New().expect("Failed to create file system")),
Path_type::Get_root(),
)
.Mount(Box::new(File_system), Path_type::Get_root())
.expect("Failed to mount file system");

let File_path = Path_type::New("/test.txt").expect("Failed to create path");
Expand Down Expand Up @@ -132,30 +131,27 @@ fn Test_virtual_file_system_file() {
struct Dummy_device_type(RwLock<u64>);

impl Device_trait for Dummy_device_type {
fn Read(&self, Buffer: &mut [u8]) -> File_system::Prelude::Result_type<usize> {
fn Read(&self, Buffer: &mut [u8]) -> Result_type<usize> {
Buffer.copy_from_slice(&self.0.read()?.to_le_bytes());

Ok(std::mem::size_of::<u64>())
}

fn Write(&self, Buffer: &[u8]) -> File_system::Prelude::Result_type<usize> {
fn Write(&self, Buffer: &[u8]) -> Result_type<usize> {
*self.0.write()? = u64::from_le_bytes(Buffer.try_into().unwrap());

Ok(std::mem::size_of::<u64>())
}

fn Get_size(&self) -> File_system::Prelude::Result_type<usize> {
fn Get_size(&self) -> Result_type<usize> {
Ok(std::mem::size_of::<u64>())
}

fn Set_position(
&self,
_: &File_system::Prelude::Position_type,
) -> File_system::Prelude::Result_type<usize> {
fn Set_position(&self, _: &Position_type) -> Result_type<usize> {
Ok(0)
}

fn Flush(&self) -> File_system::Prelude::Result_type<()> {
fn Flush(&self) -> Result_type<()> {
Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions Modules/Drivers/Tests/Native/Main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod File_system;
Original file line number Diff line number Diff line change
@@ -1,71 +1,30 @@
use crate::Prelude::{
use File_system::{
Error_type, File_identifier_type, File_system_traits, Flags_type, Path_owned_type, Path_type,
Permissions_type, Position_type, Result_type, Size_type, Type_type,
Position_type, Result_type, Size_type, Type_type,
};

use std::collections::BTreeMap;
use std::env::{current_dir, var};
use std::fs::*;
use std::io::{ErrorKind, Read, Seek, Write};

use std::path::PathBuf;
use std::sync::RwLock;

use Task::Task_identifier_type;

impl From<FileType> for Type_type {
fn from(value: FileType) -> Self {
if value.is_dir() {
return Type_type::Directory;
} else if value.is_symlink() {
return Type_type::Symbolic_link;
}
Type_type::File
}
}

impl From<std::io::ErrorKind> for Error_type {
fn from(Error: std::io::ErrorKind) -> Self {
use std::io::ErrorKind;

match Error {
ErrorKind::PermissionDenied => Error_type::Permission_denied,
ErrorKind::NotFound => Error_type::Not_found,
ErrorKind::AlreadyExists => Error_type::Already_exists,
ErrorKind::InvalidInput => Error_type::Invalid_path,
ErrorKind::InvalidData => Error_type::Invalid_file,
_ => Error_type::Unknown,
}
}
}

impl From<std::io::Error> for Error_type {
fn from(Error: std::io::Error) -> Self {
Error.kind().into()
fn From_file_type(value: FileType) -> Type_type {
if value.is_dir() {
return Type_type::Directory;
} else if value.is_symlink() {
return Type_type::Symbolic_link;
}
Type_type::File
}

impl Flags_type {
fn Into_open_options(self, Open_options: &mut OpenOptions) {
Open_options
.read(self.Get_mode().Get_read())
.write(self.Get_mode().Get_write() || self.Get_status().Get_append());
}
}

impl From<&PathBuf> for Path_owned_type {
fn from(item: &PathBuf) -> Self {
Path_owned_type::New(item.to_str().unwrap().to_string()).unwrap()
}
}

#[cfg(target_family = "unix")]
impl From<&Permissions_type> for std::fs::Permissions {
fn from(Permissions: &Permissions_type) -> Self {
use std::os::unix::fs::PermissionsExt;

std::fs::Permissions::from_mode(Permissions.To_unix() as u32)
}
fn Apply_flags_to_open_options(Flags: Flags_type, Open_options: &mut OpenOptions) {
Open_options
.read(Flags.Get_mode().Get_read())
.write(Flags.Get_mode().Get_write() || Flags.Get_status().Get_append());
}

pub struct File_system_type {
Expand Down Expand Up @@ -155,7 +114,7 @@ impl File_system_traits for File_system_type {

let mut Open_options = OpenOptions::new();

Flags.Into_open_options(&mut Open_options);
Apply_flags_to_open_options(Flags, &mut Open_options);

let File = Open_options
.open(Full_path.as_ref() as &Path_type)
Expand Down Expand Up @@ -239,7 +198,7 @@ impl File_system_traits for File_system_type {
fn Get_type(&self, Path: &dyn AsRef<Path_type>) -> Result_type<Type_type> {
let Full_path = self.Get_full_path(&Path)?;
let Metadata = metadata(Full_path.as_ref() as &Path_type)?;
Ok(Metadata.file_type().into())
Ok(From_file_type(Metadata.file_type()))
}

fn Get_size(&self, Path: &dyn AsRef<Path_type>) -> Result_type<Size_type> {
Expand Down
3 changes: 3 additions & 0 deletions Modules/Drivers/src/Native/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod File_system;

pub use File_system::*;
3 changes: 3 additions & 0 deletions Modules/Drivers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

#[cfg(target_vendor = "espressif")]
pub mod Espressif;

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
pub mod Native;
4 changes: 0 additions & 4 deletions Modules/File_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ Shared = { path = "../Shared" }
[features]
std = []
default = ["std"]

[[test]]
name = "Virtual_file_system"
path = "Tests/Virtual_file_system.rs"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Prelude::{Position_type, Result_type};
use crate::{Position_type, Result_type};

pub trait Device_trait: Send + Sync {
fn Read(&self, Buffer: &mut [u8]) -> Result_type<usize>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Users::{
Group_identifier_type, Root_group_identifier, Root_user_identifier, User_identifier_type,
};

use crate::Prelude::{
use crate::{
Error_type, File_identifier_type, File_system_traits, Flags_type, Path_type, Permissions_type,
Position_type, Result_type, Size_type, Type_type,
};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl File_system_traits for File_system_type {
&self,
Task: Task_identifier_type,
Path: &dyn AsRef<Path_type>,
Flags: crate::Prelude::Flags_type,
Flags: crate::Flags_type,
) -> Result_type<File_identifier_type> {
let Opened_device = self
.0
Expand Down
File renamed without changes.
Loading

0 comments on commit 8083cb2

Please sign in to comment.