MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / maps_alignment

Function maps_alignment

tests/all/component_model/dynamic.rs:379–440  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

377
378#[test]
379fn maps_alignment() -> Result<()> {
380 let engine = super::map_engine();
381 let mut store = Store::new(&engine, ());
382
383 // Test map<u8, u64> - key_size=1, value_align=8
384 // This would fail with the alignment bug because value would be at offset 1 instead of 8
385 let component = Component::new(&engine, make_echo_component("(map u8 u64)", 8))?;
386 let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
387 let func = instance.get_func(&mut store, "echo").unwrap();
388
389 let input_map = vec![
390 (Val::U8(1), Val::U64(100)),
391 (Val::U8(2), Val::U64(200)),
392 (Val::U8(3), Val::U64(300)),
393 ];
394 let input = Val::Map(input_map);
395
396 let mut output = [Val::Bool(false)];
397 func.call(&mut store, &[input.clone()], &mut output)?;
398 assert_eq!(input, output[0]);
399
400 // Test map<u32, u64> - key_size=4, value_align=8
401 // This would fail with the alignment bug because value would be at offset 4 instead of 8
402 let component = Component::new(&engine, make_echo_component("(map u32 u64)", 8))?;
403 let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
404 let func = instance.get_func(&mut store, "echo").unwrap();
405
406 let input_map = vec![(Val::U32(1), Val::U64(1000)), (Val::U32(2), Val::U64(2000))];
407 let input = Val::Map(input_map);
408
409 func.call(&mut store, &[input.clone()], &mut output)?;
410 assert_eq!(input, output[0]);
411
412 // Test map<u8, u32> - key_size=1, value_align=4
413 // This would fail with the alignment bug because value would be at offset 1 instead of 4
414 let component = Component::new(&engine, make_echo_component("(map u8 u32)", 8))?;
415 let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
416 let func = instance.get_func(&mut store, "echo").unwrap();
417
418 let input_map = vec![(Val::U8(10), Val::U32(100)), (Val::U8(20), Val::U32(200))];
419 let input = Val::Map(input_map);
420
421 func.call(&mut store, &[input.clone()], &mut output)?;
422 assert_eq!(input, output[0]);
423
424 // Test map<u16, u64> - key_size=2, value_align=8
425 // This would fail with the alignment bug because value would be at offset 2 instead of 8
426 let component = Component::new(&engine, make_echo_component("(map u16 u64)", 8))?;
427 let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
428 let func = instance.get_func(&mut store, "echo").unwrap();
429
430 let input_map = vec![
431 (Val::U16(1), Val::U64(10000)),
432 (Val::U16(2), Val::U64(20000)),
433 ];
434 let input = Val::Map(input_map);
435
436 func.call(&mut store, &[input.clone()], &mut output)?;

Callers

nothing calls this directly

Calls 10

map_engineFunction · 0.85
make_echo_componentFunction · 0.85
OkFunction · 0.85
newFunction · 0.50
MapClass · 0.50
instantiateMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45
callMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected