Skip to content

Commit f174b00

Browse files
committed
Add CGo test results for Go 1.14.
1 parent 175d047 commit f174b00

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed

cgo/cgo_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"go/ast"
8+
"go/build"
89
"go/format"
910
"go/parser"
1011
"go/token"
@@ -19,6 +20,22 @@ import (
1920
// Pass -update to go test to update the output of the test files.
2021
var flagUpdate = flag.Bool("update", false, "Update images based on test output.")
2122

23+
// getExpectedFile looks for the expected data file, which might change depending on Go version.
24+
func getExpectedFile(name string) (string, []byte, error) {
25+
// Must iterate in reverse, to go newest to oldest.
26+
for i := len(build.Default.ReleaseTags) - 1; i >= 0; i-- {
27+
tag := build.Default.ReleaseTags[i]
28+
outfile := filepath.Join("testdata", name+".out."+tag)
29+
expectedBytes, err := ioutil.ReadFile(outfile)
30+
if err == nil {
31+
return outfile, expectedBytes, err
32+
}
33+
}
34+
outfile := filepath.Join("testdata", name+".out.go")
35+
expectedBytes, err := ioutil.ReadFile(outfile)
36+
return outfile, expectedBytes, err
37+
}
38+
2239
func TestCGo(t *testing.T) {
2340
var cflags = []string{"--target=armv6m-none-eabi"}
2441

@@ -77,8 +94,7 @@ func TestCGo(t *testing.T) {
7794
actual := strings.Replace(string(buf.Bytes()), "\r\n", "\n", -1)
7895

7996
// Read the file with the expected output, to compare against.
80-
outfile := filepath.Join("testdata", name+".out.go")
81-
expectedBytes, err := ioutil.ReadFile(outfile)
97+
outfile, expectedBytes, err := getExpectedFile(name)
8298
if err != nil {
8399
t.Fatalf("could not read expected output: %v", err)
84100
}

cgo/testdata/types.out.go1.14

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package main
2+
3+
import "unsafe"
4+
5+
var _ unsafe.Pointer
6+
7+
const C.option2A = 20
8+
const C.optionA = 0
9+
const C.optionB = 1
10+
const C.optionC = -5
11+
const C.optionD = -4
12+
const C.optionE = 10
13+
const C.optionF = 11
14+
const C.optionG = 12
15+
const C.unused1 = 5
16+
17+
type C.int16_t = int16
18+
type C.int32_t = int32
19+
type C.int64_t = int64
20+
type C.int8_t = int8
21+
type C.uint16_t = uint16
22+
type C.uint32_t = uint32
23+
type C.uint64_t = uint64
24+
type C.uint8_t = uint8
25+
type C.uintptr_t = uintptr
26+
type C.char uint8
27+
type C.int int32
28+
type C.long int32
29+
type C.longlong int64
30+
type C.schar int8
31+
type C.short int16
32+
type C.uchar uint8
33+
type C.uint uint32
34+
type C.ulong uint32
35+
type C.ulonglong uint64
36+
type C.ushort uint16
37+
type C.bitfield_t = C.struct_4
38+
type C.myIntArray = [10]C.int
39+
type C.myint = C.int
40+
type C.option2_t = C.uint
41+
type C.option_t = C.enum_option
42+
type C.point2d_t = struct {
43+
x C.int
44+
y C.int
45+
}
46+
type C.point3d_t = C.struct_point3d
47+
type C.struct_nested_t = struct {
48+
begin C.point2d_t
49+
end C.point2d_t
50+
tag C.int
51+
52+
coord C.union_2
53+
}
54+
type C.types_t = struct {
55+
f float32
56+
d float64
57+
ptr *C.int
58+
}
59+
type C.union1_t = struct{ i C.int }
60+
type C.union2d_t = C.union_union2d
61+
type C.union3_t = C.union_1
62+
type C.union_nested_t = C.union_3
63+
type C.unionarray_t = struct{ arr [10]C.uchar }
64+
65+
func (s *C.struct_4) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f }
66+
func (s *C.struct_4) set_bitfield_a(value C.uchar) {
67+
s.__bitfield_1 = s.__bitfield_1&^0x1f | value&0x1f<<0
68+
}
69+
func (s *C.struct_4) bitfield_b() C.uchar {
70+
return s.__bitfield_1 >> 5 & 0x1
71+
}
72+
func (s *C.struct_4) set_bitfield_b(value C.uchar) {
73+
s.__bitfield_1 = s.__bitfield_1&^0x20 | value&0x1<<5
74+
}
75+
func (s *C.struct_4) bitfield_c() C.uchar {
76+
return s.__bitfield_1 >> 6
77+
}
78+
func (s *C.struct_4) set_bitfield_c(value C.uchar,
79+
80+
) { s.__bitfield_1 = s.__bitfield_1&0x3f | value<<6 }
81+
82+
type C.struct_4 struct {
83+
start C.uchar
84+
__bitfield_1 C.uchar
85+
86+
d C.uchar
87+
e C.uchar
88+
}
89+
type C.struct_point3d struct {
90+
x C.int
91+
y C.int
92+
z C.int
93+
}
94+
type C.struct_type1 struct {
95+
_type C.int
96+
__type C.int
97+
___type C.int
98+
}
99+
type C.struct_type2 struct{ _type C.int }
100+
101+
func (union *C.union_1) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) }
102+
func (union *C.union_1) unionfield_d() *float64 { return (*float64)(unsafe.Pointer(&union.$union)) }
103+
func (union *C.union_1) unionfield_s() *C.short { return (*C.short)(unsafe.Pointer(&union.$union)) }
104+
105+
type C.union_1 struct{ $union uint64 }
106+
107+
func (union *C.union_2) unionfield_area() *C.point2d_t {
108+
return (*C.point2d_t)(unsafe.Pointer(&union.$union))
109+
}
110+
func (union *C.union_2) unionfield_solid() *C.point3d_t {
111+
return (*C.point3d_t)(unsafe.Pointer(&union.$union))
112+
}
113+
114+
type C.union_2 struct{ $union [3]uint32 }
115+
116+
func (union *C.union_3) unionfield_point() *C.point3d_t {
117+
return (*C.point3d_t)(unsafe.Pointer(&union.$union))
118+
}
119+
func (union *C.union_3) unionfield_array() *C.unionarray_t {
120+
return (*C.unionarray_t)(unsafe.Pointer(&union.$union))
121+
}
122+
func (union *C.union_3) unionfield_thing() *C.union3_t {
123+
return (*C.union3_t)(unsafe.Pointer(&union.$union))
124+
}
125+
126+
type C.union_3 struct{ $union [2]uint64 }
127+
128+
func (union *C.union_union2d) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) }
129+
func (union *C.union_union2d) unionfield_d() *[2]float64 {
130+
return (*[2]float64)(unsafe.Pointer(&union.$union))
131+
}
132+
133+
type C.union_union2d struct{ $union [2]uint64 }
134+
type C.enum_option C.int
135+
type C.enum_unused C.uint

0 commit comments

Comments
 (0)