Файловый менеджер - Редактировать - /var/www/html/testgodefs.zip
Ðазад
PK ! `T�� � testgodefs_test.gonu �[��� // Copyright 2019 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package testgodefs import ( "bytes" "internal/testenv" "os" "os/exec" "path/filepath" "runtime" "strings" "testing" ) // We are testing cgo -godefs, which translates Go files that use // import "C" into Go files with Go definitions of types defined in the // import "C" block. Add more tests here. var filePrefixes = []string{ "anonunion", "bitfields", "issue8478", "fieldtypedef", "issue37479", "issue37621", "issue38649", "issue39534", "issue48396", } func TestGoDefs(t *testing.T) { testenv.MustHaveGoRun(t) testenv.MustHaveCGO(t) testdata, err := filepath.Abs("testdata") if err != nil { t.Fatal(err) } gopath, err := os.MkdirTemp("", "testgodefs-gopath") if err != nil { t.Fatal(err) } defer os.RemoveAll(gopath) dir := filepath.Join(gopath, "src", "testgodefs") if err := os.MkdirAll(dir, 0755); err != nil { t.Fatal(err) } for _, fp := range filePrefixes { cmd := exec.Command("go", "tool", "cgo", "-godefs", "-srcdir", testdata, "-objdir", dir, fp+".go") cmd.Stderr = new(bytes.Buffer) out, err := cmd.Output() if err != nil { t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr) } fn := fp + "_defs.go" if err := os.WriteFile(filepath.Join(dir, fn), out, 0644); err != nil { t.Fatal(err) } // Verify that command line arguments are not rewritten in the generated comment, // see go.dev/issue/52063 hasGeneratedByComment := false for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") { cgoExe := "cgo" if runtime.GOOS == "windows" { cgoExe = "cgo.exe" } if !strings.HasPrefix(line, "// "+cgoExe+" -godefs") { continue } if want := "// " + cgoExe + " " + strings.Join(cmd.Args[3:], " "); line != want { t.Errorf("%s: got generated comment %q, want %q", fn, line, want) } hasGeneratedByComment = true break } if !hasGeneratedByComment { t.Errorf("%s: comment with generating cgo -godefs command not found", fn) } } main, err := os.ReadFile(filepath.Join("testdata", "main.go")) if err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, "main.go"), main, 0644); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module testgodefs\ngo 1.14\n"), 0644); err != nil { t.Fatal(err) } // Use 'go run' to build and run the resulting binary in a single step, // instead of invoking 'go build' and the resulting binary separately, so that // this test can pass on mobile builders, which do not copy artifacts back // from remote invocations. cmd := exec.Command("go", "run", ".") cmd.Env = append(os.Environ(), "GOPATH="+gopath) cmd.Dir = dir if out, err := cmd.CombinedOutput(); err != nil { t.Fatalf("%s [%s]: %v\n%s", strings.Join(cmd.Args, " "), dir, err, out) } } PK ! ���_ _ testdata/issue8478.gonu �[��� // Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main // Issue 8478. Test that void* is consistently mapped to *byte. /* typedef struct { void *p; void **q; void ***r; } s; */ import "C" type Issue8478 C.s PK ! �U��y y testdata/issue37479.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main /* typedef struct A A; typedef struct { struct A *next; struct A **prev; } N; struct A { N n; }; typedef struct B { A* a; } B; */ import "C" type N C.N type A C.A type B C.B PK ! ��M� testdata/issue39534.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main // enum { ENUMVAL = 0x1 }; import "C" const ENUMVAL = C.ENUMVAL PK ! D��2 2 testdata/main.gonu �[��� // Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "os" "reflect" ) // Test that the struct field in anonunion.go was promoted. var v1 T var v2 = v1.L // Test that P, Q, and R all point to byte. var v3 = Issue8478{P: (*byte)(nil), Q: (**byte)(nil), R: (***byte)(nil)} // Test that N, A and B are fully defined var v4 = N{} var v5 = A{} var v6 = B{} // Test that S is fully defined var v7 = S{} // Test that #define'd type is fully defined var _ = issue38649{X: 0} // Test that prefixes do not cause duplicate field names. var _ = Issue48396{Fd: 1, Bpf_fd: 2} func main() { pass := true // The Go translation of bitfields should not have any of the // bitfield types. The order in which bitfields are laid out // in memory is implementation defined, so we can't easily // know how a bitfield should correspond to a Go type, even if // it appears to be aligned correctly. bitfieldType := reflect.TypeOf(bitfields{}) check := func(name string) { _, ok := bitfieldType.FieldByName(name) if ok { fmt.Fprintf(os.Stderr, "found unexpected bitfields field %s\n", name) pass = false } } check("Short1") check("Short2") check("Short3") if !pass { os.Exit(1) } } PK ! J�F F testdata/issue37621.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main /* struct tt { long long a; long long b; }; struct s { struct tt ts[3]; }; */ import "C" type TT C.struct_tt type S C.struct_s PK ! `h�� testdata/anonunion.gonu �[��� // Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main // This file tests that when cgo -godefs sees a struct with a field // that is an anonymous union, the first field in the union is // promoted to become a field of the struct. See issue 6677 for // background. /* typedef struct { union { long l; int c; }; } t; */ import "C" // Input for cgo -godefs. type T C.t PK ! ���] ] testdata/fieldtypedef.gonu �[��� // Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main /* struct S1 { int f1; }; struct S2 { struct S1 s1; }; typedef struct S1 S1Type; typedef struct S2 S2Type; */ import "C" type S1 C.S1Type type S2 C.S2Type PK ! _��3 3 testdata/issue38649.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main /* struct Issue38649 { int x; }; #define issue38649 struct Issue38649 */ import "C" type issue38649 C.issue38649 PK ! rF F testdata/bitfields.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main // This file tests that we don't generate an incorrect field location // for a bitfield that appears aligned. /* struct bitfields { unsigned int B1 : 5; unsigned int B2 : 1; unsigned int B3 : 1; unsigned int B4 : 1; unsigned int Short1 : 16; // misaligned on 8 bit boundary unsigned int B5 : 1; unsigned int B6 : 1; unsigned int B7 : 1; unsigned int B8 : 1; unsigned int B9 : 1; unsigned int B10 : 3; unsigned int Short2 : 16; // alignment is OK unsigned int Short3 : 16; // alignment is OK }; */ import "C" type bitfields C.struct_bitfields PK ! 1��: : testdata/issue48396.gonu �[��� // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main /* // from <linux/kcm.h> struct issue48396 { int fd; int bpf_fd; }; */ import "C" type Issue48396 C.struct_issue48396 PK ! `T�� � testgodefs_test.gonu �[��� PK ! ���_ _ � testdata/issue8478.gonu �[��� PK ! �U��y y � testdata/issue37479.gonu �[��� PK ! ��M� I testdata/issue39534.gonu �[��� PK ! D��2 2 � testdata/main.gonu �[��� PK ! J�F F testdata/issue37621.gonu �[��� PK ! `h�� � testdata/anonunion.gonu �[��� PK ! ���] ] � testdata/fieldtypedef.gonu �[��� PK ! _��3 3 | testdata/issue38649.gonu �[��� PK ! rF F � testdata/bitfields.gonu �[��� PK ! 1��: : � testdata/issue48396.gonu �[��� PK � "