]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/test/issue3261.go
all: make copyright headers consistent with one space after period
[gostls13.git] / misc / cgo / test / issue3261.go
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package cgotest
6
7 /*
8 // libgcc on ARM might be compiled as thumb code, but our 5l
9 // can't handle that, so we have to disable this test on arm.
10 #ifdef __ARMEL__
11 #include <stdio.h>
12 int vabs(int x) {
13         puts("testLibgcc is disabled on ARM because 5l cannot handle thumb library.");
14         return (x < 0) ? -x : x;
15 }
16 #elif defined(__arm64__) && defined(__clang__)
17 #include <stdio.h>
18 int vabs(int x) {
19         puts("testLibgcc is disabled on ARM64 with clang due to lack of libgcc.");
20         return (x < 0) ? -x : x;
21 }
22 #else
23 int __absvsi2(int); // dummy prototype for libgcc function
24 // we shouldn't name the function abs, as gcc might use
25 // the builtin one.
26 int vabs(int x) { return __absvsi2(x); }
27 #endif
28 */
29 import "C"
30
31 import "testing"
32
33 func testLibgcc(t *testing.T) {
34         var table = []struct {
35                 in, out C.int
36         }{
37                 {0, 0},
38                 {1, 1},
39                 {-42, 42},
40                 {1000300, 1000300},
41                 {1 - 1<<31, 1<<31 - 1},
42         }
43         for _, v := range table {
44                 if o := C.vabs(v.in); o != v.out {
45                         t.Fatalf("abs(%d) got %d, should be %d", v.in, o, v.out)
46                         return
47                 }
48         }
49 }