blob: 71375698d376d8832727fab413d1a76a37794f5f [file] [log] [blame]
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07001// Copyright 2012 The Go Authors. All rights reserved.
Shenghou Ma551d8b92012-08-17 03:42:34 +08002// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package 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>
12int vabs(int x) {
13 puts("testLibgcc is disabled on ARM because 5l cannot handle thumb library.");
14 return (x < 0) ? -x : x;
15}
Shenghou Ma110fa222015-04-11 05:57:15 -040016#elif defined(__arm64__) && defined(__clang__)
17#include <stdio.h>
18int vabs(int x) {
19 puts("testLibgcc is disabled on ARM64 with clang due to lack of libgcc.");
20 return (x < 0) ? -x : x;
21}
Shenghou Ma551d8b92012-08-17 03:42:34 +080022#else
23int __absvsi2(int); // dummy prototype for libgcc function
24// we shouldn't name the function abs, as gcc might use
25// the builtin one.
26int vabs(int x) { return __absvsi2(x); }
27#endif
28*/
29import "C"
30
31import "testing"
32
33func 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}