Skip to content

Commit 6aea1e0

Browse files
authoredAug 24, 2023
fix round2_32, split round2 tests because they depend on sizeof int at compile time (#1607)
1 parent 4b0e6c7 commit 6aea1e0

File tree

4 files changed

+67
-30
lines changed

4 files changed

+67
-30
lines changed
 

‎http_test.go

-30
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"math"
1110
"mime/multipart"
1211
"net/http"
1312
"net/http/httptest"
@@ -16,7 +15,6 @@ import (
1615
"strings"
1716
"testing"
1817
"time"
19-
"unsafe"
2018

2119
"github.com/valyala/bytebufferpool"
2220
)
@@ -1968,34 +1966,6 @@ func testSetResponseBodyStreamChunked(t *testing.T, body string, trailer map[str
19681966
}
19691967
}
19701968

1971-
func TestRound2ForSliceCap(t *testing.T) {
1972-
t.Parallel()
1973-
1974-
testRound2ForSliceCap(t, 0, 0)
1975-
testRound2ForSliceCap(t, 1, 1)
1976-
testRound2ForSliceCap(t, 2, 2)
1977-
testRound2ForSliceCap(t, 3, 4)
1978-
testRound2ForSliceCap(t, 4, 4)
1979-
testRound2ForSliceCap(t, 5, 8)
1980-
testRound2ForSliceCap(t, 7, 8)
1981-
testRound2ForSliceCap(t, 8, 8)
1982-
testRound2ForSliceCap(t, 9, 16)
1983-
testRound2ForSliceCap(t, 0x10001, 0x20000)
1984-
1985-
if unsafe.Sizeof(int(0)) == 4 {
1986-
testRound2ForSliceCap(t, math.MaxInt32-1, math.MaxInt32)
1987-
} else {
1988-
testRound2ForSliceCap(t, math.MaxInt32, math.MaxInt32)
1989-
testRound2ForSliceCap(t, math.MaxInt64-1, math.MaxInt64-1)
1990-
}
1991-
}
1992-
1993-
func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) {
1994-
if roundUpForSliceCap(n) != expectedRound2 {
1995-
t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2)
1996-
}
1997-
}
1998-
19991969
func TestRequestReadChunked(t *testing.T) {
20001970
t.Parallel()
20011971

‎round2_32.go

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package fasthttp
55

6+
import "math"
7+
68
func roundUpForSliceCap(n int) int {
79
if n <= 0 {
810
return 0

‎round2_32_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//go:build !amd64 && !arm64 && !ppc64 && !ppc64le && !s390x
2+
// +build !amd64,!arm64,!ppc64,!ppc64le,!s390x
3+
4+
package fasthttp
5+
6+
import (
7+
"math"
8+
"testing"
9+
)
10+
11+
func TestRound2ForSliceCap(t *testing.T) {
12+
t.Parallel()
13+
14+
testRound2ForSliceCap(t, 0, 0)
15+
testRound2ForSliceCap(t, 1, 1)
16+
testRound2ForSliceCap(t, 2, 2)
17+
testRound2ForSliceCap(t, 3, 4)
18+
testRound2ForSliceCap(t, 4, 4)
19+
testRound2ForSliceCap(t, 5, 8)
20+
testRound2ForSliceCap(t, 7, 8)
21+
testRound2ForSliceCap(t, 8, 8)
22+
testRound2ForSliceCap(t, 9, 16)
23+
testRound2ForSliceCap(t, 0x10001, 0x20000)
24+
25+
testRound2ForSliceCap(t, math.MaxInt32-1, math.MaxInt32-1)
26+
}
27+
28+
func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) {
29+
if roundUpForSliceCap(n) != expectedRound2 {
30+
t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2)
31+
}
32+
}

‎round2_64_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//go:build amd64 || arm64 || ppc64 || ppc64le || s390x
2+
// +build amd64 arm64 ppc64 ppc64le s390x
3+
4+
package fasthttp
5+
6+
import (
7+
"math"
8+
"testing"
9+
)
10+
11+
func TestRound2ForSliceCap(t *testing.T) {
12+
t.Parallel()
13+
14+
testRound2ForSliceCap(t, 0, 0)
15+
testRound2ForSliceCap(t, 1, 1)
16+
testRound2ForSliceCap(t, 2, 2)
17+
testRound2ForSliceCap(t, 3, 4)
18+
testRound2ForSliceCap(t, 4, 4)
19+
testRound2ForSliceCap(t, 5, 8)
20+
testRound2ForSliceCap(t, 7, 8)
21+
testRound2ForSliceCap(t, 8, 8)
22+
testRound2ForSliceCap(t, 9, 16)
23+
testRound2ForSliceCap(t, 0x10001, 0x20000)
24+
25+
testRound2ForSliceCap(t, math.MaxInt32, math.MaxInt32)
26+
testRound2ForSliceCap(t, math.MaxInt64-1, math.MaxInt64-1)
27+
}
28+
29+
func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) {
30+
if roundUpForSliceCap(n) != expectedRound2 {
31+
t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2)
32+
}
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.