Skip to content

Commit 75d2817

Browse files
committed
Add a large string array test
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 49030f9 commit 75d2817

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

tests/runtime/lists.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ impl test::lists::test::Host for MyImports {
5151
assert_eq!(ptr, [(1, 2, 3), (4, 5, 6)]);
5252
}
5353

54+
fn list_param_large(&mut self, ptr: Vec<String>) {
55+
assert_eq!(ptr.len(), 1000);
56+
}
57+
5458
fn list_result(&mut self) -> Vec<u8> {
5559
vec![1, 2, 3, 4, 5]
5660
}
@@ -133,6 +137,8 @@ fn run_test(lists: Lists, store: &mut Store<crate::Wasi<MyImports>>) -> Result<(
133137
vec!["baz".to_owned()],
134138
],
135139
)?;
140+
let arg0: Vec<String> = (0..1000).map(|_| "string".to_string()).collect();
141+
exports.call_list_param_large(&mut *store, &arg0)?;
136142
assert_eq!(exports.call_list_result(&mut *store)?, [1, 2, 3, 4, 5]);
137143
assert_eq!(exports.call_list_result2(&mut *store)?, "hello!");
138144
assert_eq!(

tests/runtime/lists/wasm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ void exports_test_lists_test_list_param4(lists_list_list_string_t *a) {
315315
lists_list_list_string_free(a);
316316
}
317317

318+
void exports_test_lists_test_list_param_large(lists_list_list_string_t *a) {
319+
assert(a->len == 1000);
320+
lists_list_string_free(a);
321+
}
322+
318323
void exports_test_lists_test_list_param5(lists_list_tuple3_u8_u32_u8_t *a) {
319324
assert(a->len == 2);
320325
assert(a->ptr[0].f0 == 1);

tests/runtime/lists/wasm.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public static void TestImports()
4949
}
5050
});
5151

52+
List<string> randomStrings = new List<string>();
53+
for (int i = 0; i < 1000; i++)
54+
{
55+
randomStrings.Add(Guid.NewGuid().ToString());
56+
}
57+
TestInterop.ListParamLarge(randomStrings);
58+
5259
{
5360
byte[] result = TestInterop.ListResult();
5461
Debug.Assert(result.Length == 5);
@@ -233,6 +240,11 @@ public static void ListParam5(List<(byte, uint, byte)> a)
233240
Debug.Assert(a[1].Item3 == 6);
234241
}
235242

243+
public static void ListParamLarge(List<String> a)
244+
{
245+
Debug.Assert(a.Count() == 1000);
246+
}
247+
236248
public static byte[] ListResult()
237249
{
238250
return new byte[] { (byte)1, (byte)2, (byte)3, (byte)4, (byte)5 };

tests/runtime/lists/wasm.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"math"
5+
"math/rand"
6+
"strconv"
57
. "wit_lists_go/gen"
68
)
79

@@ -29,6 +31,12 @@ func (i ListImpl) TestImports() {
2931
TestListsTestListParam2("foo")
3032
TestListsTestListParam3([]string{"foo", "bar", "baz"})
3133
TestListsTestListParam4([][]string{{"foo", "bar"}, {"baz"}})
34+
35+
randomStrings := make([]string, 1000)
36+
for i := 0; i < 1000; i++ {
37+
randomStrings[i] = "str" + strconv.Itoa(rand.Intn(1000))
38+
}
39+
TestListsTestListParamLarge(randomStrings)
3240
res3 := TestListsTestListResult()
3341
if len(res3) != 5 {
3442
panic("TestListsTestListResult")
@@ -212,6 +220,12 @@ func (i ListImpl) ListParam5(a []ExportsTestListsTestTuple3U8U32U8T) {
212220
}
213221
}
214222

223+
fun (i ListImpl) ListParamLarge(a []string) {
224+
if len(a) != 1000 {
225+
panic("ListParamLarge")
226+
}
227+
}
228+
215229
func (i ListImpl) ListResult() []uint8 {
216230
return []uint8{1, 2, 3, 4, 5}
217231
}

tests/runtime/lists/wasm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ impl Guest for Component {
2929
vec!["baz".to_owned()],
3030
]);
3131
list_param5(&[(1, 2, 3), (4, 5, 6)]);
32+
let large_list: Vec<String> = (0..1000).map(|_| "string".to_string()).collect();
33+
list_param_large(large_list);
3234
assert_eq!(list_result(), [1, 2, 3, 4, 5]);
3335
assert_eq!(list_result2(), "hello!");
3436
assert_eq!(list_result3(), ["hello,", "world!"]);
@@ -114,6 +116,10 @@ impl exports::test::lists::test::Guest for Component {
114116
assert_eq!(ptr, [(1, 2, 3), (4, 5, 6)]);
115117
}
116118

119+
fn list_param_large(ptr: Vec<String>) {
120+
assert_eq!(ptr.len(), 1000);
121+
}
122+
117123
fn list_result() -> Vec<u8> {
118124
vec![1, 2, 3, 4, 5]
119125
}

tests/runtime/lists/world.wit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface test {
1111
list-param3: func(a: list<string>);
1212
list-param4: func(a: list<list<string>>);
1313
list-param5: func(a: list<tuple<u8, u32, u8>>);
14+
list-param-large: func(a: list<string>);
1415
list-result: func() -> list<u8>;
1516
list-result2: func() -> string;
1617
list-result3: func() -> list<string>;

0 commit comments

Comments
 (0)