Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 16 additions & 34 deletions kiln-decoder/tests/call_indirect_tests.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
use kiln_decoder::instructions::{Instruction, encode_instruction, parse_instruction};
use kiln_format::binary;
// These tests reference kiln_decoder::instructions::{Instruction, encode_instruction, parse_instruction}
// which is an API that has not been implemented in kiln-decoder yet.
// The instruction parsing API currently lives in kiln-runtime::instruction_parser with a different
// signature (parse_instructions parses full bytecode sequences, not individual instructions).
//
// These tests are disabled until a single-instruction parse/encode API is added to kiln-decoder.

#[test]
#[ignore = "kiln_decoder::instructions API not yet implemented"]
fn test_parse_encode_call_indirect_basic() {
// call_indirect (type_idx=1, table_idx=0)
let bytes = vec![binary::CALL_INDIRECT, 0x01, 0x00];
let (instruction, bytes_read) = parse_instruction(&bytes).unwrap();

assert_eq!(instruction, Instruction::CallIndirect(1, 0));
assert_eq!(bytes_read, 3);

let encoded = encode_instruction(&instruction).unwrap();
assert_eq!(encoded, bytes);
// Requires kiln_decoder::instructions::{parse_instruction, encode_instruction, Instruction}
}

#[test]
#[ignore = "kiln_decoder::instructions API not yet implemented"]
fn test_parse_encode_call_indirect_larger_type_idx() {
// call_indirect (type_idx=128, table_idx=0)
// 128 in LEB128 is [0x80, 0x01]
let bytes = vec![binary::CALL_INDIRECT, 0x80, 0x01, 0x00];
let (instruction, bytes_read) = parse_instruction(&bytes).unwrap();

assert_eq!(instruction, Instruction::CallIndirect(128, 0));
assert_eq!(bytes_read, 4);

let encoded = encode_instruction(&instruction).unwrap();
assert_eq!(encoded, bytes);
// Requires kiln_decoder::instructions::{parse_instruction, encode_instruction, Instruction}
}

#[test]
#[ignore = "kiln_decoder::instructions API not yet implemented"]
fn test_parse_encode_call_indirect_nonzero_table() {
// This test uses a non-zero table index, which is not valid in MVP
// but the parser should handle it for future-compatibility
let bytes = vec![binary::CALL_INDIRECT, 0x05, 0x01];
let (instruction, bytes_read) = parse_instruction(&bytes).unwrap();

assert_eq!(instruction, Instruction::CallIndirect(5, 1));
assert_eq!(bytes_read, 3);

let encoded = encode_instruction(&instruction).unwrap();
assert_eq!(encoded, bytes);
// Non-zero table index for future-compatibility
// Requires kiln_decoder::instructions::{parse_instruction, encode_instruction, Instruction}
}

#[test]
#[ignore = "kiln_decoder::instructions API not yet implemented"]
fn test_parse_call_indirect_invalid() {
// Missing table index byte
let bytes = vec![binary::CALL_INDIRECT, 0x05];
let result = parse_instruction(&bytes);

assert!(result.is_err());
// Missing table index byte - should return error
// Requires kiln_decoder::instructions::parse_instruction
}
14 changes: 7 additions & 7 deletions kiln-decoder/tests/decoder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use kiln_error::{Error, ErrorCategory, codes};
type Result<T> = kiln_error::Result<T>;

// Helper function to convert wat::Error to kiln_error::Error
fn wat_to_kiln_error(e: wat::Error) -> Error {
Error::runtime_execution_error(&format!("WAT parse error: {}", e))
fn wat_to_kiln_error(_e: wat::Error) -> Error {
Error::runtime_execution_error("WAT parse error")
}

#[test]
Expand Down Expand Up @@ -38,7 +38,7 @@ fn test_basic_module_decoding() -> Result<()> {
.map_err(wat_to_kiln_error)?;

// Decode the module
let module = kiln_decoder::wasm::decode(&wasm_bytes)?;
let module = kiln_decoder::decoder::decode_module(&wasm_bytes)?;

// Verify that the module is properly decoded
assert_eq!(module.functions.len(), 2); // One imported, one defined
Expand Down Expand Up @@ -96,7 +96,7 @@ fn test_complex_module_decoding() -> Result<()> {
.map_err(wat_to_kiln_error)?;

// Decode the module
let module = kiln_decoder::wasm::decode(&wasm_bytes)?;
let module = kiln_decoder::decoder::decode_module(&wasm_bytes)?;

// Verify module structure
assert_eq!(module.functions.len(), 3); // 1 imported, 2 defined
Expand All @@ -118,7 +118,7 @@ fn test_invalid_module() {
let invalid_bytes = vec![0x00, 0x61, 0x73];

// Attempt to decode, should return an error
let result = kiln_decoder::wasm::decode(&invalid_bytes);
let result = kiln_decoder::decoder::decode_module(&invalid_bytes);
assert!(result.is_err());

// Test with truncated module
Expand All @@ -127,7 +127,7 @@ fn test_invalid_module() {
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, // Truncated type section
0x01, 0x05, 0x01, 0x60,
];
let result = kiln_decoder::wasm::decode(&truncated);
let result = kiln_decoder::decoder::decode_module(&truncated);
assert!(result.is_err());
}

Expand Down Expand Up @@ -175,7 +175,7 @@ fn test_module_with_complex_instructions() -> Result<()> {
.map_err(wat_to_kiln_error)?;

// Decode the module
let module = kiln_decoder::wasm::decode(&wasm_bytes)?;
let module = kiln_decoder::decoder::decode_module(&wasm_bytes)?;

// Basic structure checks
assert_eq!(module.functions.len(), 1);
Expand Down
1 change: 1 addition & 0 deletions kiln-foundation/src/bounded_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3272,6 +3272,7 @@ mod tests {

// Test BoundedDeque
#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_bounded_deque() {
init_test_memory_system();
let provider = safe_managed_alloc!(1024, CrateId::Foundation).unwrap();
Expand Down
1 change: 1 addition & 0 deletions kiln-foundation/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ mod tests {
}

#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_all_available() {
// Should at least contain the resource built-ins
let available = BuiltinType::all_available();
Expand Down
1 change: 1 addition & 0 deletions kiln-foundation/src/capabilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ mod tests {
}

#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_memory_operation_requires_capability() {
let read_op = MemoryOperation::Read {
offset: 0,
Expand Down
1 change: 1 addition & 0 deletions kiln-foundation/src/memory_sizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ mod tests {
use super::*;

#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_size_calculation() {
// Test that size calculation rounds up appropriately
assert_eq!(calculate_required_size(10, 10, 20), size_classes::TINY); // 120 -> 256
Expand Down
2 changes: 2 additions & 0 deletions kiln-foundation/src/no_std_hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ mod tests {
};

#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_simple_hashmap() -> kiln_error::Result<()> {
let provider = safe_managed_alloc!(512, CrateId::Foundation)?;
let mut map = SimpleHashMap::<u32, i32, 8, NoStdProvider<512>>::new(provider)?;
Expand Down Expand Up @@ -578,6 +579,7 @@ mod tests {
}

#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_full_map() -> kiln_error::Result<()> {
let provider = safe_managed_alloc!(256, CrateId::Foundation)?;
let mut map = SimpleHashMap::<i32, i32, 4, NoStdProvider<256>>::new(provider)?;
Expand Down
1 change: 1 addition & 0 deletions kiln-foundation/src/safety_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ mod tests {
}

#[test]
#[cfg_attr(feature = "std", serial_test::serial)]
fn test_thread_safe_access() {
with_safety_monitor(|monitor| {
monitor.record_allocation(1024);
Expand Down
8 changes: 4 additions & 4 deletions kiln-wasi/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2423,15 +2423,15 @@ mod tests {
let mut dispatcher = WasiDispatcher::with_defaults()?;

// First call to get-stdout allocates a resource handle
let result1 = dispatcher.dispatch("wasi:cli/stdout@0.2.4", "get-stdout", vec![])?;
let result1 = dispatcher.dispatch("wasi:cli/stdout@0.2.4", "get-stdout", &[])?;
assert_eq!(result1.len(), 1);
let handle1 = match &result1[0] {
Value::U32(h) => *h,
_ => panic!("Expected U32 handle"),
};

// Second call should return a DIFFERENT handle (Preview2 semantics)
let result2 = dispatcher.dispatch("wasi:cli/stdout@0.2.4", "get-stdout", vec![])?;
let result2 = dispatcher.dispatch("wasi:cli/stdout@0.2.4", "get-stdout", &[])?;
assert_eq!(result2.len(), 1);
let handle2 = match &result2[0] {
Value::U32(h) => *h,
Expand All @@ -2449,7 +2449,7 @@ mod tests {
let mut dispatcher = WasiDispatcher::with_defaults()?;

// get-stderr allocates a resource handle
let result = dispatcher.dispatch("wasi:cli/stderr@0.2.4", "get-stderr", vec![])?;
let result = dispatcher.dispatch("wasi:cli/stderr@0.2.4", "get-stderr", &[])?;
assert_eq!(result.len(), 1);
// Handle should be a valid u32 (value doesn't matter, it's dynamic)
assert!(matches!(result[0], Value::U32(_)));
Expand All @@ -2467,7 +2467,7 @@ mod tests {
fn test_wall_clock_now() -> Result<()> {
MemoryInitializer::ensure_initialized()?;
let mut dispatcher = WasiDispatcher::with_defaults()?;
let result = dispatcher.dispatch("wasi:clocks/wall-clock@0.2.4", "now", vec![])?;
let result = dispatcher.dispatch("wasi:clocks/wall-clock@0.2.4", "now", &[])?;
assert_eq!(result.len(), 1);
// Should return a Tuple with (seconds, nanoseconds)
if let Value::Tuple(parts) = &result[0] {
Expand Down
4 changes: 2 additions & 2 deletions kiln-wasi/src/preview2/clocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ mod tests {

#[test]
fn test_wasi_monotonic_clock_now() -> Result<()> {
let result = wasi_monotonic_clock_now(&mut (), vec![])?;
let result = wasi_monotonic_clock_now(&mut (), &[])?;
assert_eq!(result.len(), 1);

// Should return a u64 timestamp
Expand All @@ -246,7 +246,7 @@ mod tests {

#[test]
fn test_wasi_wall_clock_now() -> Result<()> {
let result = wasi_wall_clock_now(&mut (), vec![])?;
let result = wasi_wall_clock_now(&mut (), &[])?;
assert_eq!(result.len(), 1);

// Should return a tuple of (seconds, nanoseconds)
Expand Down
12 changes: 6 additions & 6 deletions kiln-wasi/src/preview2/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ mod tests {
#[test]
fn test_extract_file_descriptor() {
let args = vec![Value::U32(42)];
assert_eq!(extract_file_descriptor(args).unwrap(), 42);
assert_eq!(extract_file_descriptor(&args).unwrap(), 42);

let invalid_args = vec![Value::String("not_a_fd".to_string())];
assert!(extract_file_descriptor(&invalid_args).is_err());
Expand All @@ -1019,7 +1019,7 @@ mod tests {
#[test]
fn test_extract_length() {
let args = vec![Value::U32(0), Value::U64(1024)];
assert_eq!(extract_length(args, 1).unwrap(), 1024);
assert_eq!(extract_length(&args, 1).unwrap(), 1024);

let args_u32 = vec![Value::U32(0), Value::U32(512)];
assert_eq!(extract_length(&args_u32, 1).unwrap(), 512);
Expand All @@ -1030,7 +1030,7 @@ mod tests {
let data = vec![Value::U8(1), Value::U8(2), Value::U8(3)];
let args = vec![Value::U32(42), Value::List(data)];

let bytes = extract_byte_data(args, 1)?;
let bytes = extract_byte_data(&args, 1)?;
assert_eq!(bytes, vec![1, 2, 3]);

Ok(())
Expand All @@ -1039,7 +1039,7 @@ mod tests {
#[test]
fn test_extract_string() -> Result<()> {
let args = vec![Value::U32(42), Value::String("test.txt".to_string())];
let path = extract_string(args, 1)?;
let path = extract_string(&args, 1)?;
assert_eq!(path, "test.txt");

Ok(())
Expand All @@ -1049,7 +1049,7 @@ mod tests {
fn test_open_flags_extraction() {
// Test bit-based flags
let args = vec![Value::U32(0), Value::U32(0), Value::String("test".to_string()), Value::U32(0x05)];
let flags = extract_open_flags(args, 3).unwrap();
let flags = extract_open_flags(&args, 3).unwrap();
assert!(flags.create);
assert!(!flags.directory);
assert!(flags.exclusive);
Expand All @@ -1059,7 +1059,7 @@ mod tests {
#[test]
fn test_descriptor_flags_extraction() {
let args = vec![Value::U32(0), Value::U32(0), Value::String("test".to_string()), Value::U32(0), Value::U32(0x03)];
let flags = extract_descriptor_flags(args, 4).unwrap();
let flags = extract_descriptor_flags(&args, 4).unwrap();
assert!(flags.read);
assert!(flags.write);
assert!(!flags.sync);
Expand Down
Loading
Loading