From 750c96b3113e383ed7dec6f00cdea5a9c1a65e69 Mon Sep 17 00:00:00 2001 From: Alix ANNERAUD Date: Tue, 8 Oct 2024 20:27:31 +0200 Subject: [PATCH] Add integration test for environment variable in virtual machine --- Modules/Virtual_machine/Tests/Test.rs | 12 +++++++++++- Modules/Virtual_machine/Tests/WASM_test/src/main.rs | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Modules/Virtual_machine/Tests/Test.rs b/Modules/Virtual_machine/Tests/Test.rs index d9b7517..94edaca 100644 --- a/Modules/Virtual_machine/Tests/Test.rs +++ b/Modules/Virtual_machine/Tests/Test.rs @@ -82,7 +82,7 @@ extern "C" fn Test_string( #[test] fn Integration_test() { - Task::Initialize().expect("Failed to initialize task manager"); + let Task_instance = Task::Initialize().expect("Failed to initialize task manager"); Users::Initialize().expect("Failed to initialize users manager"); @@ -96,9 +96,18 @@ fn Integration_test() { File_system::Initialize(File_system).unwrap(); + // Set environment variables + let Task = Task_instance.Get_current_task_identifier().unwrap(); + + Task_instance + .Set_environment_variable(Task, "Path", "/:/bin:/usr/bin") + .unwrap(); + + // Load the WASM binary let Binary_buffer = include_bytes!("./WASM_test/target/wasm32-wasip1/release/Virtual_machine_WASM_test.wasm"); + // Register the functions pub struct Registrable {} impl Registrable_trait for Registrable { @@ -116,6 +125,7 @@ fn Integration_test() { let User_data = Data_type::New(); + // Instantiate the environment let (_Runtime, _Module, Instance) = Instantiate_test_environment( Binary_buffer, Registrable {}, diff --git a/Modules/Virtual_machine/Tests/WASM_test/src/main.rs b/Modules/Virtual_machine/Tests/WASM_test/src/main.rs index c7df419..71d44e2 100644 --- a/Modules/Virtual_machine/Tests/WASM_test/src/main.rs +++ b/Modules/Virtual_machine/Tests/WASM_test/src/main.rs @@ -134,6 +134,16 @@ fn Test_file() { } } +fn Test_environment_variables() { + println!("Environment variables:"); + + let Environment = std::env::vars(); + + for (Key, Value) in Environment { + println!("{}: {}", Key, Value); + } +} + fn Test_directory() { create_dir("/test_dir").unwrap(); @@ -171,5 +181,7 @@ fn main() -> Result<(), ()> { Test_directory(); + Test_environment_variables(); + Ok(()) }