-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc/spectre: add spectre index test
Test for CL 222660. Change-Id: I1dae41a9746dfc4144a0d29c02201de8ecd216fd Reviewed-on: https://go-review.googlesource.com/c/go/+/222978 Reviewed-by: Keith Randall <[email protected]>
- Loading branch information
Showing
5 changed files
with
422 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
#include "textflag.h" | ||
|
||
TEXT ·clflush(SB),NOSPLIT,$0-8 | ||
MOVQ arg+0(FP), AX | ||
CLFLUSH 0(AX) | ||
RET | ||
|
||
TEXT ·rdtscp(SB),NOSPLIT,$0-8 | ||
RDTSCP | ||
SHLQ $32, DX | ||
ORQ DX, AX | ||
MOVQ AX, ret+0(FP) | ||
RET | ||
|
||
TEXT ·nop(SB),NOSPLIT,$0-0 | ||
RET | ||
|
||
TEXT ·cpuid(SB),NOSPLIT,$0-0 | ||
CPUID | ||
RET | ||
|
||
TEXT ·features(SB),NOSPLIT,$0-2 | ||
MOVL $0, AX | ||
MOVL $0, CX | ||
CPUID | ||
CMPL AX, $1 | ||
JLT none | ||
|
||
MOVL $1, AX | ||
MOVL $0, CX | ||
CPUID | ||
SHRL $19, DX | ||
ANDL $1, DX | ||
MOVB DX, hasCLFLUSH+0(FP) | ||
|
||
MOVL $0x80000001, AX | ||
MOVL $0, CX | ||
CPUID | ||
SHRL $27, DX | ||
ANDL $1, DX | ||
MOVB DX, hasRDTSCP+0(FP) | ||
RET | ||
|
||
none: | ||
MOVB $0, hasCLFLUSH+0(FP) | ||
MOVB $0, hasRDTSCP+1(FP) | ||
RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package spectre contains a Spectre test. | ||
// It only runs on certain architectures. | ||
package spectre |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package spectre | ||
|
||
import "testing" | ||
|
||
func shouldPanic(f func()) { | ||
defer func() { | ||
if recover() == nil { | ||
panic("index did not panic") | ||
} | ||
}() | ||
f() | ||
} | ||
|
||
var ( | ||
Zero = 0 | ||
One = 1 | ||
Two = 2 | ||
Three = 3 | ||
Four = 4 | ||
Five = 5 | ||
) | ||
|
||
func TestIndex(t *testing.T) { | ||
xs := "hello" | ||
xi := []int{10, 20, 30, 40, 50} | ||
xf := []float64{10, 20, 30, 40, 50} | ||
|
||
xs = xs[Zero:Five] | ||
xi = xi[Zero:Five] | ||
xf = xf[Zero:Five] | ||
|
||
if xs[Four] != 'o' { | ||
t.Errorf("xs[4] = %q, want %q", xs[Four], 'o') | ||
} | ||
if xi[Four] != 50 { | ||
t.Errorf("xi[4] = %d, want 50", xi[Four]) | ||
} | ||
if xf[Four] != 50 { | ||
t.Errorf("xf[4] = %v, want 50", xf[Four]) | ||
} | ||
|
||
xs1 := xs[One:] | ||
xi1 := xi[One:] | ||
xf1 := xf[One:] | ||
|
||
if xs1[Three] != 'o' { | ||
t.Errorf("xs1[3] = %q, want %q", xs1[Three], 'o') | ||
} | ||
if xi1[Three] != 50 { | ||
t.Errorf("xi1[3] = %d, want 50", xi1[Three]) | ||
} | ||
if xf1[Three] != 50 { | ||
t.Errorf("xf1[3] = %v, want 50", xf1[Three]) | ||
} | ||
} |
Oops, something went wrong.