| 1 |
// Copyright 2016 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 sys_test |
| 6 |
|
| 7 |
import ( |
| 8 |
"internal/runtime/sys" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
func TestTrailingZeros64(t *testing.T) { |
| 13 |
for i := 0; i <= 64; i++ { |
| 14 |
x := uint64(5) << uint(i) |
| 15 |
if got := sys.TrailingZeros64(x); got != i { |
| 16 |
t.Errorf("TrailingZeros64(%d)=%d, want %d", x, got, i) |
| 17 |
} |
| 18 |
} |
| 19 |
} |
| 20 |
func TestTrailingZeros32(t *testing.T) { |
| 21 |
for i := 0; i <= 32; i++ { |
| 22 |
x := uint32(5) << uint(i) |
| 23 |
if got := sys.TrailingZeros32(x); got != i { |
| 24 |
t.Errorf("TrailingZeros32(%d)=%d, want %d", x, got, i) |
| 25 |
} |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
func TestBswap64(t *testing.T) { |
| 30 |
x := uint64(0x1122334455667788) |
| 31 |
y := sys.Bswap64(x) |
| 32 |
if y != 0x8877665544332211 { |
| 33 |
t.Errorf("Bswap(%x)=%x, want 0x8877665544332211", x, y) |
| 34 |
} |
| 35 |
} |
| 36 |
func TestBswap32(t *testing.T) { |
| 37 |
x := uint32(0x11223344) |
| 38 |
y := sys.Bswap32(x) |
| 39 |
if y != 0x44332211 { |
| 40 |
t.Errorf("Bswap(%x)=%x, want 0x44332211", x, y) |
| 41 |
} |
| 42 |
} |