Skip to content

Commit 9ee42c8

Browse files
committed
apd: add ARM 32-bit and 64-bit testing to CI
1 parent 4df06f4 commit 9ee42c8

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed

.github/workflows/go.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414

1515
strategy:
1616
matrix:
17+
arch:
18+
- x64
19+
- armv7
20+
- aarch64
1721
go:
1822
- '1.13'
1923
- '1.14'
@@ -30,27 +34,58 @@ jobs:
3034
go-version: '${{ matrix.go }}'
3135

3236
- name: 'Build'
37+
if: ${{ matrix.arch == 'x64' }}
3338
run: go build -v ./...
3439

3540
- name: 'Test'
41+
if: ${{ matrix.arch == 'x64' }}
3642
run: go test -v ./...
3743

3844
- name: 'TestRace'
45+
if: ${{ matrix.arch == 'x64' }}
3946
run: go test -race -v ./...
4047

4148
- name: 'Bench'
49+
if: ${{ matrix.arch == 'x64' }}
4250
run: go test -run=- -bench=. -benchtime=1x -v ./...
4351

4452
- name: 'BenchRace'
53+
if: ${{ matrix.arch == 'x64' }}
4554
run: go test -run=- -bench=. -benchtime=1x -race -v ./...
4655

4756
- name: 'Vet'
57+
if: ${{ matrix.arch == 'x64' }}
4858
# -unsafeptr=false is needed because of the noescape function in bigint.go.
4959
run: go vet -unsafeptr=false ./...
5060

5161
- name: 'Staticcheck'
5262
# staticcheck requires go1.14.
53-
if: ${{ matrix.go != '1.13' }}
63+
if: ${{ matrix.arch == 'x64' && matrix.go != '1.13' }}
5464
run: |
5565
go get honnef.co/go/tools/cmd/staticcheck
5666
staticcheck ./...
67+
68+
- name: 'BuildTest for armv7'
69+
if: ${{ matrix.arch == 'armv7' }}
70+
env:
71+
GOARCH: arm
72+
GOARM: 7
73+
run: go test -c ./...
74+
75+
- name: 'BuildTest for aarch64'
76+
if: ${{ matrix.arch == 'aarch64' }}
77+
env:
78+
GOARCH: arm64
79+
run: go test -c ./...
80+
81+
- name: 'Test and Bench on ${{ matrix.arch }}'
82+
# arch != 'x64': we already tested on x86 above.
83+
# go != '1.13': go1.13 + arm is significantly slower, so don't run test suite.
84+
if: ${{ matrix.arch != 'x64' && matrix.go != '1.13' }}
85+
uses: uraimo/[email protected]
86+
with:
87+
arch: ${{ matrix.arch }}
88+
distro: ubuntu20.04
89+
dockerRunArgs: --mount type=bind,source="$(pwd)",target=/checkout,readonly
90+
run: |
91+
find /checkout -name '*.test' -type f -executable -print0 | xargs -0 -I '{}' sh -c '{} -test.run=. -test.bench=. -test.benchtime=1x -test.v'

decimal_test.go

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"encoding/json"
1919
"fmt"
2020
"math"
21+
"math/bits"
2122
"testing"
2223
"unsafe"
2324
)
@@ -787,16 +788,30 @@ func TestReduce(t *testing.T) {
787788
// TestSizeof is meant to catch changes that unexpectedly increase
788789
// the size of the BigInt, Decimal, and Context structs.
789790
func TestSizeof(t *testing.T) {
791+
// map[uint_size][type]sizeof
792+
exp := map[int]map[string]uintptr{
793+
32: {
794+
"BigInt": 20,
795+
"Decimal": 28,
796+
"Context": 24,
797+
},
798+
64: {
799+
"BigInt": 24,
800+
"Decimal": 32,
801+
"Context": 32,
802+
},
803+
}[bits.UintSize]
804+
790805
var b BigInt
791-
if s := unsafe.Sizeof(b); s != 24 {
806+
if s := unsafe.Sizeof(b); s != exp["BigInt"] {
792807
t.Errorf("sizeof(BigInt) changed: %d", s)
793808
}
794809
var d Decimal
795-
if s := unsafe.Sizeof(d); s != 32 {
810+
if s := unsafe.Sizeof(d); s != exp["Decimal"] {
796811
t.Errorf("sizeof(Decimal) changed: %d", s)
797812
}
798813
var c Context
799-
if s := unsafe.Sizeof(c); s != 32 {
814+
if s := unsafe.Sizeof(c); s != exp["Context"] {
800815
t.Errorf("sizeof(Context) changed: %d", s)
801816
}
802817
}
@@ -805,19 +820,43 @@ func TestSizeof(t *testing.T) {
805820
// returns the shallow size of the structs, the Size method reports the total
806821
// memory footprint of each struct and all referenced objects.
807822
func TestSize(t *testing.T) {
823+
// map[uint_size][is_inline][type]size
824+
exp := map[int]map[bool]map[string]uintptr{
825+
32: {
826+
true: {
827+
"BigInt": 20,
828+
"Decimal": 28,
829+
},
830+
false: {
831+
"BigInt": 72,
832+
"Decimal": 80,
833+
},
834+
},
835+
64: {
836+
true: {
837+
"BigInt": 24,
838+
"Decimal": 32,
839+
},
840+
false: {
841+
"BigInt": 112,
842+
"Decimal": 120,
843+
},
844+
},
845+
}[bits.UintSize]
846+
808847
var d Decimal
809-
if e, s := uintptr(32), d.Size(); e != s {
848+
if e, s := exp[true]["Decimal"], d.Size(); e != s {
810849
t.Errorf("(*Decimal).Size() != %d: %d", e, s)
811850
}
812-
if e, s := uintptr(24), d.Coeff.Size(); e != s {
851+
if e, s := exp[true]["BigInt"], d.Coeff.Size(); e != s {
813852
t.Errorf("(*BigInt).Size() != %d: %d", e, s)
814853
}
815854
// Set to an inlinable value.
816855
d.SetInt64(1234)
817-
if e, s := uintptr(32), d.Size(); e != s {
856+
if e, s := exp[true]["Decimal"], d.Size(); e != s {
818857
t.Errorf("(*Decimal).Size() != %d: %d", e, s)
819858
}
820-
if e, s := uintptr(24), d.Coeff.Size(); e != s {
859+
if e, s := exp[true]["BigInt"], d.Coeff.Size(); e != s {
821860
t.Errorf("(*BigInt).Size() != %d: %d", e, s)
822861
}
823862
// Set to a non-inlinable value.
@@ -828,10 +867,10 @@ func TestSize(t *testing.T) {
828867
// Sanity-check, in case inlineWords changes.
829868
t.Fatal("BigInt inlined large value. Did inlineWords change?")
830869
}
831-
if e, s := uintptr(120), d.Size(); e != s {
870+
if e, s := exp[false]["Decimal"], d.Size(); e != s {
832871
t.Errorf("(*Decimal).Size() != %d: %d", e, s)
833872
}
834-
if e, s := uintptr(112), d.Coeff.Size(); e != s {
873+
if e, s := exp[false]["BigInt"], d.Coeff.Size(); e != s {
835874
t.Errorf("(*BigInt).Size() != %d: %d", e, s)
836875
}
837876
}

gda_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func gdaTest(t *testing.T, path string, tcs []TestCase) {
532532
if err != nil {
533533
t.Fatal(err)
534534
}
535-
case <-time.After(time.Second * 5):
535+
case <-time.After(time.Second * 20):
536536
t.Fatalf("timeout")
537537
}
538538
if d.Coeff.Sign() < 0 {

0 commit comments

Comments
 (0)