CompiledModule: export Custom Sections (#1048)

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Co-authored-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Edoardo Vacchi
2023-01-19 13:39:43 +01:00
committed by GitHub
parent f484f22e47
commit d07c40f5d6
5 changed files with 153 additions and 1 deletions

View File

@@ -60,6 +60,15 @@ func TestRuntimeConfig(t *testing.T) {
dwarfDisabled: true, // dwarf is a more technical name and ok here.
},
},
{
name: "WithCustomSections",
with: func(c RuntimeConfig) RuntimeConfig {
return c.WithCustomSections(true)
},
expected: &runtimeConfig{
storeCustomSections: true,
},
},
}
for _, tt := range tests {
@@ -597,6 +606,49 @@ func Test_compiledModule_Name(t *testing.T) {
}
}
func Test_compiledModule_CustomSections(t *testing.T) {
tests := []struct {
name string
input *compiledModule
expected []string
}{
{
name: "no custom section",
input: &compiledModule{module: &wasm.Module{}},
expected: []string{},
},
{
name: "name",
input: &compiledModule{module: &wasm.Module{
CustomSections: []*wasm.CustomSection{
{Name: "custom1"},
{Name: "custom2"},
{Name: "customDup"},
{Name: "customDup"},
},
}},
expected: []string{
"custom1",
"custom2",
"customDup",
"customDup",
},
},
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
customSections := tc.input.CustomSections()
require.Equal(t, len(tc.expected), len(customSections))
for i := 0; i < len(tc.expected); i++ {
require.Equal(t, tc.expected[i], customSections[i].Name())
}
})
}
}
func Test_compiledModule_Close(t *testing.T) {
for _, ctx := range []context.Context{nil, testCtx} { // Ensure it doesn't crash on nil!
e := &mockEngine{name: "1", cachedModules: map[*wasm.Module]struct{}{}}