dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.26k stars 4.73k forks source link

[wasi] Failures in wit-bindgen runtime tests on mono #107212

Open lewing opened 2 months ago

lewing commented 2 months ago

Using https://github.com/bytecodealliance/wit-bindgen/pull/958 to run cargo test -p wit-bindgen-cli --no-default-features -F csharp-mono we see the following errors on mono

running 27 tests
test flavorful::run ... ok
test other_dependencies::run ... ok
test ownership::run ... ok
test lists::run has been running for over 60 seconds
test many_arguments::run has been running for over 60 seconds
test numbers::run has been running for over 60 seconds
test options::run has been running for over 60 seconds
test records::run has been running for over 60 seconds
test resource_aggregates::run has been running for over 60 seconds
test resource_alias::run has been running for over 60 seconds
test resource_alias_redux::run has been running for over 60 seconds
test resource_borrow_export::run has been running for over 60 seconds
test resource_borrow_import::run has been running for over 60 seconds
test resource_borrow_in_record::run has been running for over 60 seconds
test resource_borrow_simple::run has been running for over 60 seconds
test resource_floats::run has been running for over 60 seconds
test resource_import_and_export::run has been running for over 60 seconds
test resource_into_inner::run has been running for over 60 seconds
test resource_with_lists::run has been running for over 60 seconds
test resource_borrow_simple::run ... ok
TODO: cabi_post_test:resource-borrow-in-record/test#[constructor]thing
TODO: cabi_post_test:resource-borrow-in-record/test#[constructor]thing
TODO: cabi_post_test:resource-with-lists/test#[constructor]thing
TODO: cabi_post_test:resource-with-lists/test#[method]thing.foo
TODO: cabi_post_test:resource-borrow-in-record/test#test
TODO: cabi_post_test:resource-with-lists/test#[method]thing.foo
TODO: cabi_post_test:resource-borrow-in-record/test#[method]thing.get
TODO: cabi_post_test:resource-with-lists/test#[static]thing.baz
TODO: cabi_post_test:resource-borrow-in-record/test#[method]thing.get
test resource_borrow_in_record::run ... ok
test resource_with_lists::run ... ok
TODO: cabi_post_test:records/test#multiple-results
TODO: cabi_post_test:records/test#swap-tuple
TODO: cabi_post_test:records/test#roundtrip-flags1
TODO: cabi_post_test:records/test#roundtrip-flags1
TODO: cabi_post_test:records/test#roundtrip-flags1
TODO: cabi_post_test:records/test#roundtrip-flags1
TODO: cabi_post_test:records/test#roundtrip-flags2
TODO: cabi_post_test:records/test#roundtrip-flags2
TODO: cabi_post_test:records/test#roundtrip-flags2
TODO: cabi_post_test:records/test#roundtrip-flags2
TODO: cabi_post_test:records/test#roundtrip-record1
TODO: cabi_post_test:resource-alias/e1#[constructor]x
TODO: cabi_post_test:records/test#roundtrip-record1
TODO: cabi_post_test:records/test#tuple1
TODO: cabi_post_test:resource-alias/e1#a
TODO: cabi_post_test:resource-alias/e1#[constructor]x
TODO: cabi_post_test:resource-alias/e1#[constructor]x
TODO: cabi_post_test:resource-alias/e1#[constructor]x
TODO: cabi_post_test:resource-alias/e2#a
test records::run ... ok
test resource_alias::run ... ok
test rust_xcrate::run ... ok
test type_section_suffix::run ... ok
TODO: cabi_post_test:resource-import-and-export/test#[constructor]thing
TODO: cabi_post_test:resource-import-and-export/test#[method]thing.foo
TODO: cabi_post_test:resource-import-and-export/test#[method]thing.foo
TODO: cabi_post_test:resource-import-and-export/test#[constructor]thing
TODO: cabi_post_test:resource-import-and-export/test#[static]thing.baz
TODO: cabi_post_test:resource-import-and-export/test#[method]thing.foo
test resource_import_and_export::run ... ok
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
TODO: cabi_post_test:resource-aggregates/test#[constructor]thing
test many_arguments::run ... FAILED
TODO: deallocate buffer for indirect parameters
TODO: cabi_post_test:resource-aggregates/test#foo
test resource_into_inner::run ... ok
test resource_aggregates::run ... ok
TODO: cabi_post_allocated-bytes
hello!
hello,
world!
0
65535
-32768
32767
TODO: cabi_post_test:lists/test#empty-list-result
TODO: cabi_post_test:lists/test#empty-string-result
TODO: cabi_post_test:lists/test#list-result
TODO: cabi_post_test:lists/test#list-result2
TODO: cabi_post_test:lists/test#list-result3
TODO: cabi_post_test:lists/test#string-roundtrip
TODO: cabi_post_test:lists/test#string-roundtrip
TODO: cabi_post_test:lists/test#string-roundtrip
TODO: cabi_post_allocated-bytes
test lists::run ... ok
TODO: cabi_post_exports#[constructor]float
TODO: cabi_post_exports#[method]float.get
TODO: cabi_post_test
TODO: cabi_post_exports#[static]float.add
TODO: cabi_post_exports#[method]float.get
TODO: cabi_post_test:resource-alias-redux/resource-alias1#[constructor]thing
TODO: cabi_post_test:resource-alias-redux/resource-alias1#a
TODO: cabi_post_test:resource-alias-redux/resource-alias1#[method]thing.get
TODO: cabi_post_test:resource-alias-redux/resource-alias1#[constructor]thing
TODO: cabi_post_test:resource-alias-redux/resource-alias1#[constructor]thing
test resource_floats::run ... okTODO: cabi_post_test:resource-alias-redux/resource-alias2#b

TODO: cabi_post_test:resource-alias-redux/resource-alias1#[method]thing.get
TODO: cabi_post_test:resource-alias-redux/resource-alias1#[method]thing.get
test resource_alias_redux::run ... ok
TODO: cabi_post_test:numbers/test#roundtrip-u8
TODO: cabi_post_test:numbers/test#roundtrip-u8
TODO: cabi_post_test:numbers/test#roundtrip-u8
TODO: cabi_post_test:numbers/test#roundtrip-s8
TODO: cabi_post_test:numbers/test#roundtrip-s8
TODO: cabi_post_test:numbers/test#roundtrip-s8
TODO: cabi_post_test:numbers/test#roundtrip-u16
TODO: cabi_post_test:numbers/test#roundtrip-u16
TODO: cabi_post_test:numbers/test#roundtrip-u16
TODO: cabi_post_test:numbers/test#roundtrip-s16
TODO: cabi_post_test:numbers/test#roundtrip-s16
TODO: cabi_post_test
TODO: cabi_post_test:numbers/test#roundtrip-s16
TODO: cabi_post_test:numbers/test#roundtrip-u32
TODO: cabi_post_test:numbers/test#roundtrip-u32
TODO: cabi_post_test:numbers/test#roundtrip-u32
TODO: cabi_post_test:options/test#option-none-result
TODO: cabi_post_test:numbers/test#roundtrip-s32
TODO: cabi_post_test:numbers/test#roundtrip-s32
TODO: cabi_post_test:numbers/test#roundtrip-s32
TODO: cabi_post_test:options/test#option-some-result
TODO: cabi_post_test:numbers/test#roundtrip-u64
TODO: cabi_post_test:numbers/test#roundtrip-u64
TODO: cabi_post_test:numbers/test#roundtrip-u64
TODO: cabi_post_test:numbers/test#roundtrip-s64
TODO: cabi_post_test:numbers/test#roundtrip-s64
TODO: cabi_post_test:options/test#option-roundtrip
TODO: cabi_post_test:numbers/test#roundtrip-s64
TODO: cabi_post_test:numbers/test#roundtrip-f32
TODO: cabi_post_test:numbers/test#roundtrip-f32
TODO: cabi_post_test:options/test#double-option-roundtrip
TODO: cabi_post_test:numbers/test#roundtrip-f32
TODO: cabi_post_test:options/test#double-option-roundtrip
TODO: cabi_post_test:numbers/test#roundtrip-f32
TODO: cabi_post_test:options/test#double-option-roundtrip
TODO: cabi_post_test:numbers/test#roundtrip-f64
TODO: cabi_post_test:numbers/test#roundtrip-f64
TODO: cabi_post_test:numbers/test#roundtrip-f64
TODO: cabi_post_test:numbers/test#roundtrip-f64
TODO: cabi_post_test:numbers/test#roundtrip-char
TODO: cabi_post_test:numbers/test#roundtrip-char
TODO: cabi_post_test:numbers/test#roundtrip-char
TODO: cabi_post_test:numbers/test#get-scalar
TODO: cabi_post_test:numbers/test#get-scalar
test resource_borrow_import::run ... ok
TODO: cabi_post_test:resource-borrow-export/test#[constructor]thing
TODO: cabi_post_test:resource-borrow-export/test#foo
test options::run ... ok
test numbers::run ... ok
test resource_borrow_export::run ... ok
test resources::run has been running for over 60 seconds
test results::run has been running for over 60 seconds
test smoke::run has been running for over 60 seconds
test strings::run has been running for over 60 seconds
test variants::run has been running for over 60 seconds
test versions::run has been running for over 60 seconds
test versions::run ... FAILED
TODO: cabi_post_test:results/test#string-error
TODO: cabi_post_test:results/test#string-error
TODO: cabi_post_test:results/test#enum-error
TODO: cabi_post_test:results/test#enum-error
TODO: cabi_post_test:results/test#record-error
TODO: cabi_post_test:results/test#record-error
TODO: cabi_post_test:results/test#record-error
TODO: cabi_post_test:results/test#variant-error
TODO: cabi_post_test:results/test#variant-error
TODO: cabi_post_test:results/test#variant-error
TODO: cabi_post_test:results/test#empty-error
TODO: cabi_post_test:results/test#empty-error
TODO: cabi_post_test:results/test#empty-error
TODO: cabi_post_test:results/test#double-error
TODO: cabi_post_test:results/test#double-error
TODO: cabi_post_test:results/test#double-error
test smoke::run ... ok
test results::run ... ok
TODO: cabi_post_return-empty
TODO: cabi_post_roundtrip
TODO: cabi_post_exports#test-imports
TODO: cabi_post_roundtrip
TODO: cabi_post_exports#[constructor]x
TODO: cabi_post_exports#[method]x.get-a
TODO: cabi_post_exports#[method]x.get-a
TODO: cabi_post_exports#[constructor]z
TODO: cabi_post_exports#[method]z.get-a
TODO: cabi_post_exports#[constructor]z
TODO: cabi_post_exports#[method]z.get-a
TODO: cabi_post_exports#[static]x.add
TODO: cabi_post_exports#[method]x.get-a
TODO: cabi_post_exports#add
TODO: cabi_post_exports#[method]z.get-a
TODO: cabi_post_exports#[static]z.num-dropped
TODO: cabi_post_exports#[static]z.num-dropped
test strings::run ... ok
test resources::run ... ok
test variants::run ... FAILED

failures:

---- many_arguments::run stdout ----
building MONO
testing "D:\\bytcodealliance\\wit-bindgen\\target\\runtime-tests\\many_arguments\\csharp-mono-many-arguments\\bin\\Debug\\net9.0\\AppBundle\\csharp-wasm.wasm"
Error: error while executing at wasm backtrace:
    0: 0x742d - many_arguments
                    at D:\bytcodealliance\wit-bindgen\target\runtime-tests\many_arguments\csharp-mono-many-arguments\D:/bytcodealliance/wit-bindgen/target/runtime-tests/many_arguments/csharp-mono-many-arguments/obj/Debug/net9.0/wasm/for-publish\pinvoke-table.h:241:3

Caused by:
    wasm trap: indirect call type mismatch

---- versions::run stdout ----
building MONO
testing "D:\\bytcodealliance\\wit-bindgen\\target\\runtime-tests\\versions\\csharp-mono-foo\\bin\\Debug\\net9.0\\AppBundle\\csharp-wasm.wasm"
Error: error while executing at wasm backtrace:
    0: 0x7b17 - test_3A_dep_2F_test_40_0_1_0_23_x
                    at D:\bytcodealliance\wit-bindgen\target\runtime-tests\versions\csharp-mono-foo\D:/bytcodealliance/wit-bindgen/target/runtime-tests/versions/csharp-mono-foo/obj/Debug/net9.0/wasm/for-publish\pinvoke-table.h:301:3

Caused by:
    wasm trap: uninitialized element

---- variants::run stdout ----
building MONO
testing "D:\\bytcodealliance\\wit-bindgen\\target\\runtime-tests\\variants\\csharp-mono-variants\\bin\\Debug\\net9.0\\AppBundle\\csharp-wasm.wasm"
Error: error while executing at wasm backtrace:
    0: 0xda7f5b - wit-component:adapter:wasi_snapshot_preview1!wasi_snapshot_preview1::bindings::wasi::cli::exit::exit::h75b515544c429a0a
    1: 0xda7ed0 - wit-component:adapter:wasi_snapshot_preview1!proc_exit
    2: 0xdab769 - wit-component:shim!adapt-wasi_snapshot_preview1-proc_exit
    3: 0x251d0a - __wasi_proc_exit
                    at C:\wasi-sdk\sysroot\wasi-libc-wasm32-wasip2\libc-bottom-half/sources\__wasilibc_real.c:574:5
    4: 0x250f82 - _Exit
                    at C:\wasi-sdk\sysroot\wasi-libc-wasm32-wasip2\libc-bottom-half/cloudlibc/src/libc/stdlib\_Exit.c:11:3
    5: 0x253cfc - exit
                    at C:\wasi-sdk\sysroot\wasi-libc-wasm32-wasip2\libc-top-half/musl/src/exit\exit.c:50:2
    6: 0x9825 - wasi_trace_logger
                    at C:\Users\lewing\AppData\Local\Microsoft\dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.wasi-wasm\9.0.0-rc.2.24429.19\runtimes\wasi-wasm\native\src\driver.c:84:3
    7: 0x48bc0 - eglib_log_adapter
                    at /__w/1/s/src/mono/mono/utils/mono-logger.c:394:2
    8: 0x45e57 - monoeg_g_logstr
                    at /__w/1/s/src/mono/mono/eglib/goutput.c:151:2              - monoeg_g_logv_nofree
                    at /__w/1/s/src/mono/mono/eglib/goutput.c:166:2
    9: 0x45f64 - monoeg_g_logv
                    at /__w/1/s/src/mono/mono/eglib/goutput.c:173:10              - monoeg_g_log
                    at /__w/1/s/src/mono/mono/eglib/goutput.c:182:2
   10: 0x45fb2 - monoeg_g_log_disabled
                    at /__w/1/s/src/mono/mono/eglib/goutput.c:189:2
   11: 0x20ad4 - get_build_args_from_sig_info
                    at /__w/1/s/src/mono/mono/mini/interp/interp.c:1458:3
   12: 0x1f424 - ves_pinvoke_method
                    at /__w/1/s/src/mono/mono/mini/interp/interp.c:1756:27
   13: 0xf004 - mono_interp_exec_method
                    at /__w/1/s/src/mono/mono/mini/interp/interp.c:4259:4
   14: 0x1e794 - interp_entry
                    at /__w/1/s/src/mono/mono/mini/interp/interp.c:2320:2
   15: 0x21678 - interp_entry_static_0
                    at /__w/1/s/src/mono/mono/mini/interp/interp.c:3090:46
   16: 0x8c59 - test_imports
                    at D:\bytcodealliance\wit-bindgen\target\runtime-tests\variants\csharp-mono-variants\D:/bytcodealliance/wit-bindgen/target/runtime-tests/variants/csharp-mono-variants/obj/Debug/net9.0/wasm/for-publish\pinvoke-table.h:429:3

Caused by:
    Exited with i32 exit status 1

failures:
    many_arguments::run
    variants::run
    versions::run

test result: FAILED. 24 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 391.68s
dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @directhex, @matouskozak See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

lewing commented 2 months ago

cc @kg

kg commented 2 months ago

I don't really know what to make of this since i know nothing about WIT and very little about WASI. But if someone wants help investigating it they can feel free to tag me in to help them. To me it looks like unsupported p/invoke scenarios?

lewing commented 2 months ago

The first two are UCO issues, for example:

typedef void (*WasmInterpEntrySig_4) (int*, int*);
__attribute__((export_name("test:dep/test@0.1.0#x")))
float test_3A_dep_2F_test_40_0_1_0_23_x () { 
  float res;
  initialize_runtime(); 
  if (!(WasmInterpEntrySig_4)wasm_native_to_interp_ftndescs [4].func) {
   mono_wasm_marshal_get_managed_wrapper ("csharp-wasm","FooWorld.wit.exports.test.dep.v0_1_0", "TestInterop", "wasmExportX", 0);
  }
  ((WasmInterpEntrySig_4)wasm_native_to_interp_ftndescs [4].func) ((int*)&res, wasm_native_to_interp_ftndescs [4].arg);
  return res;
}
        [UnmanagedCallersOnly(EntryPoint = "test:dep/test@0.1.0#x")]
        public static unsafe float wasmExportX() {

            float ret;
            ret = TestImpl.X();
            return ret;

        }

looks like it isn't finding the wrapper in mono_wasm_marshal_get_managed_wrapper

lewing commented 2 months ago

yeah the lookup logic is still too simple and there are collisions in the function lookup

lewing commented 1 month ago

I think #107113 handles (will retest once it lands) the method resolution in every important case, there are some corner cases around trimmed assemblies with overloaded methods that it doesn't address (but could do slightly better with when EntryPoint is defined). And #107194 will allow us to use LinkerArg in wit-bindgen.