diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2021-03-08 15:49:27 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-08 15:51:47 -0800 |
commit | 333e489763cf741035cae7d0b425f22622fea3de (patch) | |
tree | 47ad6be0ac137b2590f2564d2493d2e27e6ac400 | |
parent | 1b9d45dbe8755914d07937ad348211f60ffcfc01 (diff) |
[lisa] Do not generate any tests for dynamic types.
The dynamic type user defines the marshalling logic, so we don't need to test
for things like alignment, absence of slices, etc.
For dynamic types, the go_marshal generator just generates the missing methods
required to implement marshal.Marshallable.
PiperOrigin-RevId: 361676311
-rw-r--r-- | tools/go_marshal/gomarshal/generator.go | 8 | ||||
-rw-r--r-- | tools/go_marshal/gomarshal/generator_tests.go | 12 |
2 files changed, 10 insertions, 10 deletions
diff --git a/tools/go_marshal/gomarshal/generator.go b/tools/go_marshal/gomarshal/generator.go index abd6f69ea..634abd1af 100644 --- a/tools/go_marshal/gomarshal/generator.go +++ b/tools/go_marshal/gomarshal/generator.go @@ -427,7 +427,7 @@ func (g *Generator) generateOne(t *marshallableType, fset *token.FileSet) *inter // implementations type t. func (g *Generator) generateOneTestSuite(t *marshallableType) *testGenerator { i := newTestGenerator(t.spec, t.recv) - i.emitTests(t.slice, t.dynamic) + i.emitTests(t.slice) return i } @@ -488,7 +488,11 @@ func (g *Generator) Run() error { panic(fmt.Sprintf("Generated code for '%s' referenced a non-existent import with local name '%s'. Either go-marshal needs to add an import to the generated file, or a package in an input source file has a package name differ from the final component of its path, which go-marshal doesn't know how to detect; use an import alias to work around this limitation.", impl.typeName(), name)) } } - ts = append(ts, g.generateOneTestSuite(t)) + // Do not generate tests for dynamic types because they inherently + // violate some go_marshal requirements. + if !t.dynamic { + ts = append(ts, g.generateOneTestSuite(t)) + } } } diff --git a/tools/go_marshal/gomarshal/generator_tests.go b/tools/go_marshal/gomarshal/generator_tests.go index ca3e15c16..6cf00843f 100644 --- a/tools/go_marshal/gomarshal/generator_tests.go +++ b/tools/go_marshal/gomarshal/generator_tests.go @@ -216,16 +216,12 @@ func (g *testGenerator) emitTestSizeBytesOnTypedNilPtr() { }) } -func (g *testGenerator) emitTests(slice *sliceAPI, isDynamic bool) { +func (g *testGenerator) emitTests(slice *sliceAPI) { g.emitTestNonZeroSize() g.emitTestSuspectAlignment() - if !isDynamic { - // Do not test these for dynamic structs because they violate some - // assumptions that these tests make. - g.emitTestMarshalUnmarshalPreservesData() - g.emitTestWriteToUnmarshalPreservesData() - g.emitTestSizeBytesOnTypedNilPtr() - } + g.emitTestMarshalUnmarshalPreservesData() + g.emitTestWriteToUnmarshalPreservesData() + g.emitTestSizeBytesOnTypedNilPtr() if slice != nil { g.emitTestMarshalUnmarshalSlicePreservesData(slice) |