-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Xila-Project/Feature/Tasks
Feature/tasks
- Loading branch information
Showing
64 changed files
with
4,586 additions
and
1,235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#![allow(non_snake_case)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(non_upper_case_globals)] | ||
|
||
use Bindings::{File_system_bindings, Task_bindings}; | ||
use File_system::{ | ||
Drivers::Native::File_system_type, | ||
Prelude::{Path_type, Virtual_file_system_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" | ||
); | ||
|
||
let Task_manager = Task::Manager_type::New(); | ||
|
||
let (_Runtime, _Module, Instance) = Instantiate_test_environment( | ||
Binary_buffer, | ||
Task_bindings::New(Task_manager.clone()), | ||
&Data_type::New(), | ||
); | ||
|
||
assert_eq!( | ||
Instance.Call_export_function("Test_task", &vec![]).unwrap(), | ||
WasmValue::I32(42) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use std::num::NonZeroU32; | ||
|
||
use Binding_tool::Bind_function_WASM; | ||
|
||
#[Bind_function_WASM] | ||
fn Open(Path: &str, Flags: u32, File_identifier: &mut u32) -> Result<(), NonZeroU32> {} | ||
|
||
#[Bind_function_WASM] | ||
fn Read(File_identifier: u32, Buffer: &mut [u8], Read_size: &mut u64) -> Result<(), NonZeroU32> {} | ||
|
||
#[Bind_function_WASM] | ||
fn Create_file(Path: &str) -> Result<(), NonZeroU32> {} | ||
|
||
#[Bind_function_WASM] | ||
fn Write(File_identifier: u32, Buffer: &[u8], Write_size: &mut u64) -> Result<(), NonZeroU32> {} | ||
|
||
#[Bind_function_WASM] | ||
fn Exists(Path: &str, Exists: &mut bool) -> Result<(), NonZeroU32> {} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
#[repr(C)] | ||
#[allow(dead_code)] | ||
pub enum Position_type { | ||
Start(u64), | ||
Current(i64), | ||
End(i64), | ||
} | ||
|
||
#[Bind_function_WASM] | ||
fn Set_position( | ||
File_identifier: u32, | ||
Position: &Position_type, | ||
Result_value: &mut u64, | ||
) -> Result<(), NonZeroU32> { | ||
} | ||
|
||
#[Bind_function_WASM] | ||
fn Delete(Path: &str, Recursive: bool) -> Result<(), NonZeroU32> {} | ||
|
||
#[no_mangle] | ||
fn Test_file_system() -> u32 { | ||
let mut File_identifier = 0; | ||
|
||
let mut File_exists: bool = true; | ||
|
||
Exists("/wasm.txt", &mut File_exists).expect("Failed to check if file exists"); | ||
|
||
if File_exists { | ||
Delete("/wasm.txt", false).expect("Failed to delete file"); | ||
} | ||
|
||
Create_file("/wasm.txt").expect("Failed to create file"); | ||
|
||
Exists("/wasm.txt", &mut File_exists).expect("Failed to check if file exists"); | ||
|
||
if !File_exists { | ||
return 2; | ||
} | ||
|
||
let Flags = 0b11 << 4; | ||
|
||
Open("/wasm.txt", Flags, &mut File_identifier).expect("Failed to open file"); | ||
|
||
let mut Write_size = 0; | ||
|
||
let Message = "Hello world from WASM !"; | ||
|
||
Write(File_identifier, Message.as_bytes(), &mut Write_size).expect("Failed to write file"); | ||
|
||
if Write_size != Message.len() as u64 { | ||
return 4; | ||
} | ||
|
||
let mut Result_position = 0; | ||
|
||
Set_position( | ||
File_identifier, | ||
&Position_type::Start(0), | ||
&mut Result_position, | ||
) | ||
.expect("Failed to set position"); | ||
|
||
let mut Buffer = [0; 64]; | ||
|
||
let mut Read_size = 0; | ||
|
||
Read(File_identifier, &mut Buffer, &mut Read_size).expect("Failed to read file"); | ||
|
||
let String = String::from_utf8_lossy(&Buffer[..Read_size as usize]); | ||
|
||
if String != Message { | ||
return 6; | ||
} | ||
|
||
Delete("/wasm.txt", false).expect("Failed to delete file"); | ||
|
||
0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![allow(non_upper_case_globals)] | ||
|
||
use std::{num::NonZeroU32, sync::RwLock}; | ||
|
||
use Binding_tool::Bind_function_WASM; | ||
|
||
#[Bind_function_WASM] | ||
fn New_task(Name: &str, Stack_size: u32, Function: u32) -> Result<(), NonZeroU32> {} | ||
|
||
#[Bind_function_WASM] | ||
fn Sleep(Duration: u64) {} | ||
|
||
fn Test_function() { | ||
*Test_variable.write().unwrap() = 42; | ||
} | ||
|
||
static Test_variable: RwLock<u32> = RwLock::new(0); | ||
|
||
#[no_mangle] | ||
fn Test_task() -> u32 { | ||
let _ = New_task("Test", 4096, Test_function as usize as u32); | ||
|
||
Sleep(1); | ||
|
||
*Test_variable.read().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,7 @@ | ||
#![allow(non_snake_case)] | ||
#![allow(non_camel_case_types)] | ||
#![no_main] | ||
|
||
use Binding_tool::Bind_function_WASM; | ||
mod File_system; | ||
|
||
#[Bind_function_WASM] | ||
fn Open_file(Path: &str, Mode: u32, File_identifier: &mut u16) -> u32 {} | ||
|
||
#[Bind_function_WASM] | ||
fn Read_file(File_identifier: u16, Buffer: &mut [u8], Read_size: &mut u32) -> u32 {} | ||
|
||
extern crate wee_alloc; | ||
|
||
// Use `wee_alloc` as the global allocator saving kilobytes of code size | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
fn main() -> Result<(), ()> { | ||
let mut File_identifier = 1; | ||
|
||
let Result = Open_file("test.txt", 1, &mut File_identifier); | ||
|
||
if Result != 0 { | ||
return Err(()); | ||
} | ||
|
||
let mut Buffer = [0; 1024]; | ||
|
||
let mut Read_size = 0; | ||
|
||
let Result = Read_file(File_identifier, &mut Buffer, &mut Read_size); | ||
|
||
if Result != 0 { | ||
return Err(()); | ||
} | ||
|
||
let String = String::from_utf8_lossy(&Buffer[..Read_size as usize]); | ||
|
||
if String != "Hello World!" { | ||
return Err(()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
mod Task; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.