Skip to content

Commit

Permalink
Add a large string array test
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <[email protected]>
  • Loading branch information
jsturtevant committed Feb 5, 2025
1 parent 49030f9 commit 75d2817
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/runtime/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl test::lists::test::Host for MyImports {
assert_eq!(ptr, [(1, 2, 3), (4, 5, 6)]);
}

fn list_param_large(&mut self, ptr: Vec<String>) {
assert_eq!(ptr.len(), 1000);
}

fn list_result(&mut self) -> Vec<u8> {
vec![1, 2, 3, 4, 5]
}
Expand Down Expand Up @@ -133,6 +137,8 @@ fn run_test(lists: Lists, store: &mut Store<crate::Wasi<MyImports>>) -> Result<(
vec!["baz".to_owned()],
],
)?;
let arg0: Vec<String> = (0..1000).map(|_| "string".to_string()).collect();
exports.call_list_param_large(&mut *store, &arg0)?;
assert_eq!(exports.call_list_result(&mut *store)?, [1, 2, 3, 4, 5]);
assert_eq!(exports.call_list_result2(&mut *store)?, "hello!");
assert_eq!(
Expand Down
5 changes: 5 additions & 0 deletions tests/runtime/lists/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ void exports_test_lists_test_list_param4(lists_list_list_string_t *a) {
lists_list_list_string_free(a);
}

void exports_test_lists_test_list_param_large(lists_list_list_string_t *a) {
assert(a->len == 1000);
lists_list_string_free(a);
}

void exports_test_lists_test_list_param5(lists_list_tuple3_u8_u32_u8_t *a) {
assert(a->len == 2);
assert(a->ptr[0].f0 == 1);
Expand Down
12 changes: 12 additions & 0 deletions tests/runtime/lists/wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public static void TestImports()
}
});

List<string> randomStrings = new List<string>();
for (int i = 0; i < 1000; i++)
{
randomStrings.Add(Guid.NewGuid().ToString());
}
TestInterop.ListParamLarge(randomStrings);

{
byte[] result = TestInterop.ListResult();
Debug.Assert(result.Length == 5);
Expand Down Expand Up @@ -233,6 +240,11 @@ public static void ListParam5(List<(byte, uint, byte)> a)
Debug.Assert(a[1].Item3 == 6);
}

public static void ListParamLarge(List<String> a)
{
Debug.Assert(a.Count() == 1000);
}

public static byte[] ListResult()
{
return new byte[] { (byte)1, (byte)2, (byte)3, (byte)4, (byte)5 };
Expand Down
14 changes: 14 additions & 0 deletions tests/runtime/lists/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"math"
"math/rand"
"strconv"
. "wit_lists_go/gen"
)

Expand Down Expand Up @@ -29,6 +31,12 @@ func (i ListImpl) TestImports() {
TestListsTestListParam2("foo")
TestListsTestListParam3([]string{"foo", "bar", "baz"})
TestListsTestListParam4([][]string{{"foo", "bar"}, {"baz"}})

randomStrings := make([]string, 1000)
for i := 0; i < 1000; i++ {
randomStrings[i] = "str" + strconv.Itoa(rand.Intn(1000))
}
TestListsTestListParamLarge(randomStrings)
res3 := TestListsTestListResult()
if len(res3) != 5 {
panic("TestListsTestListResult")
Expand Down Expand Up @@ -212,6 +220,12 @@ func (i ListImpl) ListParam5(a []ExportsTestListsTestTuple3U8U32U8T) {
}
}

fun (i ListImpl) ListParamLarge(a []string) {
if len(a) != 1000 {
panic("ListParamLarge")
}
}

func (i ListImpl) ListResult() []uint8 {
return []uint8{1, 2, 3, 4, 5}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/runtime/lists/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl Guest for Component {
vec!["baz".to_owned()],
]);
list_param5(&[(1, 2, 3), (4, 5, 6)]);
let large_list: Vec<String> = (0..1000).map(|_| "string".to_string()).collect();
list_param_large(large_list);
assert_eq!(list_result(), [1, 2, 3, 4, 5]);
assert_eq!(list_result2(), "hello!");
assert_eq!(list_result3(), ["hello,", "world!"]);
Expand Down Expand Up @@ -114,6 +116,10 @@ impl exports::test::lists::test::Guest for Component {
assert_eq!(ptr, [(1, 2, 3), (4, 5, 6)]);
}

fn list_param_large(ptr: Vec<String>) {
assert_eq!(ptr.len(), 1000);
}

fn list_result() -> Vec<u8> {
vec![1, 2, 3, 4, 5]
}
Expand Down
1 change: 1 addition & 0 deletions tests/runtime/lists/world.wit
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface test {
list-param3: func(a: list<string>);
list-param4: func(a: list<list<string>>);
list-param5: func(a: list<tuple<u8, u32, u8>>);
list-param-large: func(a: list<string>);
list-result: func() -> list<u8>;
list-result2: func() -> string;
list-result3: func() -> list<string>;
Expand Down

0 comments on commit 75d2817

Please sign in to comment.