]> Cypherpunks repositories - gostls13.git/commitdiff
godefs: rudimentary tests
authorRobert Hencke <robert.hencke@gmail.com>
Mon, 20 Jun 2011 01:54:07 +0000 (11:54 +1000)
committerRob Pike <r@golang.org>
Mon, 20 Jun 2011 01:54:07 +0000 (11:54 +1000)
currently only defined for darwin

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4528123

src/cmd/godefs/Makefile
src/cmd/godefs/test.sh [new file with mode: 0755]
src/cmd/godefs/testdata.c [new file with mode: 0644]
src/cmd/godefs/testdata_darwin_386.golden [new file with mode: 0644]
src/cmd/godefs/testdata_darwin_amd64.golden [new file with mode: 0644]
src/run.bash

index b5c76fb0fe8ea5f7082e19f5e06e31e41bcad1c9..77cd26c04b89d38c2a1ec55f9a205b6c6afae6a4 100644 (file)
@@ -14,3 +14,6 @@ OFILES=\
 HFILES=a.h
 
 include ../../Make.ccmd
+
+test: $(TARG)
+       ./test.sh
diff --git a/src/cmd/godefs/test.sh b/src/cmd/godefs/test.sh
new file mode 100755 (executable)
index 0000000..c035af8
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# Copyright 2011 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.
+
+eval $(gomake --no-print-directory -f ../../Make.inc go-env)
+
+TMP="testdata_tmp.go"
+TEST="testdata.c"
+GOLDEN="testdata_${GOOS}_${GOARCH}.golden"
+
+case ${GOARCH} in
+"amd64") CCARG="-f-m64";;
+"386") CCARG="-f-m32";;
+*) CCARG="";;
+esac
+
+cleanup() {
+       rm ${TMP}
+}
+
+error() {
+       cleanup
+       echo $1
+       exit 1
+}
+
+if [ ! -e ${GOLDEN} ]; then
+       echo "skipping - no golden defined for this platform"
+       exit
+fi
+
+./godefs -g test ${CCARG} ${TEST} > ${TMP}
+if [ $? != 0 ]; then
+       error "Error: Could not run godefs for ${TEST}"
+fi
+
+diff ${TMP} ${GOLDEN}
+if [ $? != 0 ]; then
+       error "FAIL: godefs for ${TEST} did not match ${GOLDEN}"
+fi
+
+cleanup
+
+echo "PASS"
diff --git a/src/cmd/godefs/testdata.c b/src/cmd/godefs/testdata.c
new file mode 100644 (file)
index 0000000..3f459c4
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright 2011 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.
+
+#include <stdint.h>
+
+// Issue 432 - enum fields in struct can cause misaligned struct fields
+typedef enum {
+       a
+} T1;
+
+struct T2 {
+       uint8_t a;
+       T1 b;
+       T1 c;
+       uint16_t d;
+};
+
+typedef struct T2 T2;
+typedef T2 $T2;
+
+// Issue 1162 - structs with fields named Pad[0-9]+ conflict with field
+// names used by godefs for padding
+struct T3 {
+       uint8_t a;
+       int Pad0;
+};
+
+typedef struct T3 $T3;
+
+// Issue 1466 - forward references to types in stabs debug info were
+// always treated as enums
+struct T4 {};
+
+struct T5 {
+       struct T4 *a;
+};
+
+typedef struct T5 T5;
+typedef struct T4 $T4;
+typedef T5 $T5;
\ No newline at end of file
diff --git a/src/cmd/godefs/testdata_darwin_386.golden b/src/cmd/godefs/testdata_darwin_386.golden
new file mode 100644 (file)
index 0000000..d929238
--- /dev/null
@@ -0,0 +1,31 @@
+// ./godefs -g test -f-m32 testdata.c
+
+// MACHINE GENERATED - DO NOT EDIT.
+
+package test
+
+// Constants
+
+// Types
+
+type T2 struct {
+       A uint8;
+       Pad_godefs_0 [3]byte;
+       B uint32;
+       C uint32;
+       D uint16;
+       Pad_godefs_1 [2]byte;
+}
+
+type T3 struct {
+       A uint8;
+       Pad_godefs_0 [3]byte;
+       Pad0 int32;
+}
+
+type T4 struct {
+}
+
+type T5 struct {
+       A *T4;
+}
diff --git a/src/cmd/godefs/testdata_darwin_amd64.golden b/src/cmd/godefs/testdata_darwin_amd64.golden
new file mode 100644 (file)
index 0000000..a694f4a
--- /dev/null
@@ -0,0 +1,31 @@
+// ./godefs -g test -f-m64 testdata.c
+
+// MACHINE GENERATED - DO NOT EDIT.
+
+package test
+
+// Constants
+
+// Types
+
+type T2 struct {
+       A uint8;
+       Pad_godefs_0 [3]byte;
+       B uint32;
+       C uint32;
+       D uint16;
+       Pad_godefs_1 [2]byte;
+}
+
+type T3 struct {
+       A uint8;
+       Pad_godefs_0 [3]byte;
+       Pad0 int32;
+}
+
+type T4 struct {
+}
+
+type T5 struct {
+       A *T4;
+}
index bb3d06c45ca219b4f3e882d092da0fc20291063a..4c9d2ec38b9a6f87776faa0943e78d674f988dd8 100755 (executable)
@@ -49,6 +49,10 @@ GOMAXPROCS=10 gomake testshort
 time gomake test
 ) || exit $?
 
+(xcd cmd/godefs
+gomake test
+) || exit $?
+
 [ "$GOARCH" == arm ] ||
 [ "$GOHOSTOS" == windows ] ||
 (xcd ../misc/cgo/stdio