Skip to content

Commit

Permalink
Add graphical shell module with integration tests and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Dec 15, 2024
1 parent 0e896b4 commit 692b151
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"Modules/Executables/Shell/Command_line",
"Modules/Executable",
"Modules/Executables/WASM",
"Modules/Executables/Shell/Graphical",
]
exclude = [
"Modules/Virtual_machine/Tests/WASM_test",
Expand Down Expand Up @@ -81,4 +82,4 @@ WASM = ["dep:WASM_bindings"]
[[example]]
name = "Native"
path = "Examples/Native.rs"
required-features = ["Host"]
required-features = ["Host"]
21 changes: 21 additions & 0 deletions Modules/Executables/Shell/Graphical/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "Graphical_shell"
version = "0.1.0"
edition = "2021"

[dependencies]
Graphics = { path = "../../../Graphics" }
File_system = { path = "../../../File_system" }
Virtual_file_system = { path = "../../../Virtual_file_system" }
Executable = { path = "../../../Executable" }
Task = { path = "../../../Task" }
Users = { path = "../../../Users" }

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

[[test]]
name = "Integration_test"
path = "Tests/Integration_test.rs"
94 changes: 94 additions & 0 deletions Modules/Executables/Shell/Graphical/Tests/Integration_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]

use Executable::Standard_type;
use File_system::{Create_device, Create_file_system, Memory_device_type, Mode_type};
use Graphical_shell::Shell_executable_type;

#[cfg(target_os = "linux")]
#[ignore]
#[test]
fn main() {
use Drivers::Native::Window_screen;
use Graphics::{Get_recommended_buffer_size, Point_type};

// - Initialize the task manager.
let Task_instance = Task::Initialize().unwrap();

// - Initialize the user manager.
let _ = Users::Initialize();

// - Initialize the time manager.
let _ = Time::Initialize(Create_device!(Drivers::Native::Time_driver_type::New()));

// - Initialize the graphics manager.

const Resolution: Point_type = Point_type::New(800, 480);

let (Screen_device, Pointer_device) = Window_screen::New(Resolution).unwrap();

const Buffer_size: usize = Get_recommended_buffer_size(&Resolution);

Graphics::Initialize(Screen_device, Pointer_device, Buffer_size, true);

// - Initialize the virtual file system.
let Memory_device = Create_device!(Memory_device_type::<512>::New(1024 * 512));

LittleFS::File_system_type::Format(Memory_device.clone(), 256).unwrap();

let File_system = LittleFS::File_system_type::New(Memory_device, 256).unwrap();

Virtual_file_system::Initialize(Create_file_system!(File_system)).unwrap();

let Task = Task_instance.Get_current_task_identifier().unwrap();

Virtual_file_system::Get_instance()
.Mount_static_device(Task, &"/Shell", Create_device!(Shell_executable_type))
.unwrap();

Virtual_file_system::Get_instance()
.Create_directory(&"/Devices", Task)
.unwrap();

Drivers::Native::Console::Mount_devices(Task, Virtual_file_system::Get_instance()).unwrap();

let Standard_in = Virtual_file_system::Get_instance()
.Open(&"/Devices/Standard_in", Mode_type::Read_only.into(), Task)
.unwrap();

let Standard_out = Virtual_file_system::Get_instance()
.Open(&"/Devices/Standard_out", Mode_type::Write_only.into(), Task)
.unwrap();

let Standard_error = Virtual_file_system::Get_instance()
.Open(
&"/Devices/Standard_error",
Mode_type::Write_only.into(),
Task,
)
.unwrap();

let Standard = Standard_type::New(
Standard_in,
Standard_out,
Standard_error,
Task,
Virtual_file_system::Get_instance(),
);

Task_instance
.Set_environment_variable(Task, "Paths", "/")
.unwrap();

Task_instance
.Set_environment_variable(Task, "Host", "xila")
.unwrap();

let Result = Executable::Execute("/Shell", "".to_string(), Standard)
.unwrap()
.Join()
.unwrap();

assert!(Result == 0);
}
1 change: 1 addition & 0 deletions Modules/Executables/Shell/Graphical/src/Desk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

37 changes: 37 additions & 0 deletions Modules/Executables/Shell/Graphical/src/Device.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use Executable::Read_data_type;
use File_system::Device_trait;

use crate::Main::Main;

pub struct Shell_executable_type;

impl Device_trait for Shell_executable_type {
fn Read(&self, Buffer: &mut [u8]) -> File_system::Result_type<File_system::Size_type> {
let Read_data: &mut Read_data_type = Buffer
.try_into()
.map_err(|_| File_system::Error_type::Invalid_parameter)?;

*Read_data = Read_data_type::New(Main, 1024 * 32);

Ok(size_of::<Read_data_type>().into())
}

fn Write(&self, _: &[u8]) -> File_system::Result_type<File_system::Size_type> {
Err(File_system::Error_type::Unsupported_operation)
}

fn Get_size(&self) -> File_system::Result_type<File_system::Size_type> {
Err(File_system::Error_type::Unsupported_operation)
}

fn Set_position(
&self,
_: &File_system::Position_type,
) -> File_system::Result_type<File_system::Size_type> {
Err(File_system::Error_type::Unsupported_operation)
}

fn Flush(&self) -> File_system::Result_type<()> {
Err(File_system::Error_type::Unsupported_operation)
}
}
29 changes: 29 additions & 0 deletions Modules/Executables/Shell/Graphical/src/Main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use core::num::NonZeroUsize;

use Executable::Standard_type;

use crate::Shell_type;

pub fn Main(Standard: Standard_type, Arguments: String) -> Result<(), NonZeroUsize> {
Shell_type::New(Standard).Main(Arguments)
}

impl Shell_type {
pub fn New(Standard: Standard_type) -> Self {
let User: String = "".to_string();

Self {
Standard,
User,
Running: true,
}
}

pub fn Main(&mut self, Arguments: String) -> Result<(), NonZeroUsize> {
self.Standard.Print_line("Hello, World!");

let Window = Graphics::Get_instance().Create_window();

Ok(())
}
}
17 changes: 17 additions & 0 deletions Modules/Executables/Shell/Graphical/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]

use Executable::Standard_type;

mod Desk;
mod Device;
mod Main;

pub use Device::*;

pub struct Shell_type {
Standard: Standard_type,
User: String,
Running: bool,
}

0 comments on commit 692b151

Please sign in to comment.