blob: 352c0c680af9d67b22325989fdcbd41c808ea998 [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file defines GIDL tests used for GIDL golden generation.
// The output of the golden test can be used to understand the differences
// due to a change in GIDL and track regressions.
// While these tests are compiled and run just like the other *.gidl files,
// the primary purpose of this file is NOT testing binding correctness.
// Simple primitive types.
success("GoldenBoolStruct") {
value = GoldenBoolStruct{
v: true,
},
bytes = {
v2 = [
num(1):1, padding:7,
],
},
}
success("GoldenIntStruct") {
value = GoldenIntStruct{
v: 1,
},
bytes = {
v2 = [
num(1):2, padding:6,
],
},
}
success("GoldenUintStruct") {
value = GoldenUintStruct{
v: 1,
},
bytes = {
v2 = [
num(1):2, padding:6,
],
},
}
success("GoldenFloatStruct") {
value = GoldenFloatStruct{
v: 0.0,
},
bytes = {
v2 = [
num(0):4, padding:4,
],
},
}
success("GoldenDoubleStruct") {
value = GoldenDoubleStruct{
v: 0.0,
},
bytes = {
v2 = [
num(0):8,
],
},
}
success("GoldenStringStruct") {
value = GoldenStringStruct{
v: "abcd",
},
bytes = {
v2 = [
num(4):8,
repeat(0xff):8,
0x61, 0x62, 0x63, 0x64, padding:4,
],
},
}
success("GoldenNullableStringStructNonNull") {
value = GoldenNullableStringStruct{
v: "abcd",
},
bytes = {
v2 = [
num(4):8,
repeat(0xff):8,
0x61, 0x62, 0x63, 0x64, padding:4,
],
},
}
success("GoldenNullableStringStructNull") {
value = GoldenNullableStringStruct{
v: null,
},
bytes = {
v2 = [
num(0):8,
repeat(0x00):8,
],
},
}
success("GoldenEnumStruct") {
value = GoldenEnumStruct{
v: 1,
},
bytes = {
v2 = [
num(1):2, padding:6,
],
},
}
success("GoldenBitsStruct") {
value = GoldenBitsStruct{
v: 1,
},
bytes = {
v2 = [
num(1):2, padding:6,
],
},
}
success("GoldenTableStruct") {
value = GoldenTableStruct{
v: GoldenTable{
v: 1,
},
},
bytes = {
v2 = [
num(1):8, // len
repeat(0xff):8, // presence
num(1):4, num(0):2, num(1):2, // envelope
],
},
}
success("GoldenUnionStruct") {
value = GoldenUnionStruct{
v: GoldenUnion{
v: 1,
},
},
bytes = {
v2 = [
num(1):8,
num(1):4, num(0):2, num(1):2,
],
},
}
success("GoldenNullableUnionStructNonNull") {
value = GoldenNullableUnionStruct{
v: GoldenUnion{
v: 1,
},
},
bytes = {
v2 = [
num(1):8,
num(1):4, num(0):2, num(1):2,
],
},
}
success("GoldenNullableUnionStructNull") {
value = GoldenNullableUnionStruct{
v: null,
},
bytes = {
v2 = [
num(0):8,
num(0):4, num(0):2, num(0):2,
],
},
}
success("GoldenByteArrayStruct") {
value = GoldenByteArrayStruct{
v: [1, 2, 3, 4],
},
bytes = {
v2 = [
0x01, 0x02, 0x03, 0x04, padding:4,
],
},
}
// Sometimes GIDL generators might have different behavior for non-byte
// or primitive arrays.
success("GoldenStructArrayStruct") {
value = GoldenStructArrayStruct{
v: [
GoldenIntStruct{v: 1},
GoldenIntStruct{v: 2},
],
},
bytes = {
v2 = [
0x01, 0x00, 0x02, 0x00, padding:4,
],
},
}
success("GoldenByteVectorStruct") {
value = GoldenByteVectorStruct{
v: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],
},
bytes = {
v2 = [
num(12):8,
repeat(0xff):8,
0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04,
0x01, 0x02, 0x03, 0x04, padding:4,
],
},
}
success("GoldenByteNullableVectorStructNonNull") {
value = GoldenNullableByteVectorStruct{
v: [1, 2, 3, 4],
},
bytes = {
v2 = [
num(4):8,
repeat(0xff):8,
0x01, 0x02, 0x03, 0x04, padding:4,
],
},
}
success("GoldenNullableByteVectorStructNull") {
value = GoldenNullableByteVectorStruct{
v: null,
},
bytes = {
v2 = [
num(0):8,
repeat(0x00):8,
],
},
}
// Sometimes GIDL generators might have different behavior for non-byte
// or primitive vectors.
success("GoldenStructVectorStruct") {
value = GoldenStructVectorStruct{
v: [
GoldenIntStruct{v: 1},
GoldenIntStruct{v: 2},
],
},
bytes = {
v2 = [
num(2):8,
repeat(0xff):8,
0x01, 0x00, 0x02, 0x00, padding:4,
],
},
}
success("GoldenNullableStructNonNull") {
value = GoldenNullableStruct{
v: GoldenBoolStruct{
v: true,
},
},
bytes = {
v2 = [
repeat(0xff):8,
num(1):1, padding:7,
],
},
}
success("GoldenNullableStructNull") {
value = GoldenNullableStruct{
v: null,
},
bytes = {
v2 = [
repeat(0x00):8,
],
},
}
encode_success("GoldenHandleBasicRightsStruct") {
handle_defs = {
#0 = channel(rights: channel_default),
},
value = GoldenHandleBasicRightsStruct{
v: #0,
},
bytes = {
v2 = [
repeat(0xff):4, padding:4,
],
},
handle_dispositions = {
v2 = [
{#0, type: event, rights: basic},
],
},
}
decode_success("GoldenHandleBasicRightsStruct") {
bindings_denylist = [dart],
handle_defs = {
#0 = event(rights: event_default),
},
bytes = {
v2 = [
repeat(0xff):4, padding:4,
],
},
handles = {
v2 = [
#0,
],
},
value = GoldenHandleBasicRightsStruct{
v: restrict(#0, type: event, rights: basic),
},
}
success("GoldenNullableHandleStructNonNull") {
handle_defs = {
#0 = event(),
},
value = GoldenNullableHandleStruct{
v: #0,
},
bytes = {
v2 = [
repeat(0xff):4, padding:4,
],
},
handles = {
v2 = [
#0,
],
},
}
success("GoldenNullableHandleStructNull") {
value = GoldenNullableHandleStruct{
v: null,
},
bytes = {
v2 = [
repeat(0x00):4, padding:4,
],
},
}
// Golden test for an encode_failure case.
encode_failure("GoldenStringWithMaxSize2") {
value = GoldenStringWithMaxSize2{
s: "abc", // exceeds the string length
},
err = STRING_TOO_LONG,
}
// Golden test for a decode_failure case.
decode_failure("GoldenStringStructNullBody") {
type = GoldenStringStruct,
bytes = {
v2 = [
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // length of string data
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // invalid null pointer to content
],
},
err = NON_EMPTY_STRING_WITH_NULL_BODY,
}
// Golden test for the decode() function.
encode_success("GoldenHandleBasicRightsStructReEncode") {
// TODO(https://fxbug.dev/42067496): Implement the decode function in all backends.
bindings_allowlist = [rust],
handle_defs = {
// TODO(https://fxbug.dev/42069438): This has to have basic rights. If we use
// event_default, the rights will get reduced in the decode() function,
// and the assertion on the handle_dispositions raw handle will fail.
#0 = event(rights: basic),
},
value = decode({
type = GoldenHandleBasicRightsStruct,
bytes = {
v2 = [
repeat(0xff):4, padding:4,
],
},
handles = {
v2 = [
#0,
],
},
}),
bytes = {
v2 = [
repeat(0xff):4, padding:4,
],
},
handle_dispositions = {
v2 = [
{#0, type: event, rights: basic},
],
},
}
// Example where a handle occurs in the input but not in the decoded output.
// Backends should assert that the handle gets closed.
decode_success("GoldenTableUnknownDropped") {
// TODO(https://fxbug.dev/42166276): Drop unknown data in all bindings.
bindings_denylist = [dart, go],
handle_defs = {
#0 = event(),
},
bytes = {
v2 = [
num(2):8, repeat(0xff):8, // table with 2 fields
repeat(0x00):8, // empty envelope
repeat(0xff):4, num(1):2, num(1):2, // unknown inlined envelope with handle
],
},
handles = {
v2 = [
#0,
],
},
value = GoldenTableStruct{
v: GoldenTable{},
},
}