fuzz: Fix tests with fuzz tags (#10619)

* some fixes to fuzz building

* use len

* remove comments

* fix test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Preston Van Loon
2022-05-04 01:15:09 -05:00
committed by GitHub
parent e5e4dee629
commit d2dbc13427
8 changed files with 180 additions and 213 deletions

View File

@@ -1,3 +1,6 @@
//go:build !fuzz
// +build !fuzz
package cache
import (

View File

@@ -1,3 +1,6 @@
//go:build !fuzz
// +build !fuzz
package cache
import (

View File

@@ -1,3 +1,6 @@
//go:build !fuzz
// +build !fuzz
package cache
import (

View File

@@ -31,7 +31,7 @@ var (
// ProposerIndicesCache is a struct with 1 queue for looking up proposer indices by root.
type ProposerIndicesCache struct {
ProposerIndicesCache *cache.FIFO
proposerIndicesCache *cache.FIFO
lock sync.RWMutex
}
@@ -48,7 +48,7 @@ func proposerIndicesKeyFn(obj interface{}) (string, error) {
// NewProposerIndicesCache creates a new proposer indices cache for storing/accessing proposer index assignments of an epoch.
func NewProposerIndicesCache() *ProposerIndicesCache {
return &ProposerIndicesCache{
ProposerIndicesCache: cache.NewFIFO(proposerIndicesKeyFn),
proposerIndicesCache: cache.NewFIFO(proposerIndicesKeyFn),
}
}
@@ -58,10 +58,10 @@ func (c *ProposerIndicesCache) AddProposerIndices(p *ProposerIndices) error {
c.lock.Lock()
defer c.lock.Unlock()
if err := c.ProposerIndicesCache.AddIfNotPresent(p); err != nil {
if err := c.proposerIndicesCache.AddIfNotPresent(p); err != nil {
return err
}
trim(c.ProposerIndicesCache, maxProposerIndicesCacheSize)
trim(c.proposerIndicesCache, maxProposerIndicesCacheSize)
return nil
}
@@ -69,7 +69,7 @@ func (c *ProposerIndicesCache) AddProposerIndices(p *ProposerIndices) error {
func (c *ProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) {
c.lock.RLock()
defer c.lock.RUnlock()
_, exists, err := c.ProposerIndicesCache.GetByKey(key(r))
_, exists, err := c.proposerIndicesCache.GetByKey(key(r))
if err != nil {
return false, err
}
@@ -80,7 +80,7 @@ func (c *ProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) {
func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorIndex, error) {
c.lock.RLock()
defer c.lock.RUnlock()
obj, exists, err := c.ProposerIndicesCache.GetByKey(key(r))
obj, exists, err := c.proposerIndicesCache.GetByKey(key(r))
if err != nil {
return nil, err
}
@@ -99,3 +99,8 @@ func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorInd
return item.ProposerIndices, nil
}
// Len returns the number of keys in the underlying cache.
func (c *ProposerIndicesCache) Len() int {
return len(c.proposerIndicesCache.ListKeys())
}

View File

@@ -30,3 +30,7 @@ func (c *FakeProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.Validato
func (c *FakeProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) {
return false, nil
}
func (c *FakeProposerIndicesCache) Len() int {
return 0
}

View File

@@ -1,3 +1,6 @@
//go:build !fuzz
// +build !fuzz
package cache
import (
@@ -68,7 +71,5 @@ func TestProposerCache_CanRotate(t *testing.T) {
item := &ProposerIndices{BlockRoot: bytesutil.ToBytes32(s)}
require.NoError(t, cache.AddProposerIndices(item))
}
k := cache.ProposerIndicesCache.ListKeys()
assert.Equal(t, maxProposerIndicesCacheSize, uint64(len(k)))
assert.Equal(t, int(maxProposerIndicesCacheSize), cache.Len())
}

View File

@@ -233,7 +233,7 @@ func TestBeaconProposerIndex_BadState(t *testing.T) {
require.NoError(t, state.SetSlot(100))
_, err = BeaconProposerIndex(context.Background(), state)
require.NoError(t, err)
assert.Equal(t, 0, len(proposerIndicesCache.ProposerIndicesCache.ListKeys()))
assert.Equal(t, 0, proposerIndicesCache.Len())
}
func TestComputeProposerIndex_Compatibility(t *testing.T) {

View File

@@ -1,205 +1,177 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@prysm//tools/go:def.bzl", "go_library")
# Build with --define=blst_disabled=true to exclude blst library.
config_setting(
name = "linux_amd64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
values = {
"define": "blst_disabled=false",
},
)
config_setting(
name = "darwin_amd64",
constraint_values = [
"@platforms//os:osx",
"@platforms//cpu:x86_64",
],
values = {
"define": "blst_disabled=false",
},
)
config_setting(
name = "darwin_arm64",
constraint_values = [
"@platforms//os:osx",
"@platforms//cpu:arm64",
],
values = {
"define": "blst_disabled=false",
},
)
config_setting(
name = "windows_amd64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
values = {
"define": "blst_disabled=false",
},
)
config_setting(
name = "linux_arm64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
values = {
"define": "blst_disabled=false",
},
)
config_setting(
name = "android_amd64",
constraint_values = [
"@platforms//os:android",
"@platforms//cpu:x86_64",
],
values = {
"define": "blst_disabled=false",
},
)
config_setting(
name = "android_arm64",
constraint_values = [
"@platforms//os:android",
"@platforms//cpu:aarch64",
],
values = {
"define": "blst_disabled=false",
},
)
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
# gazelle:resolve go github.com/supranational/blst/bindings/go @com_github_supranational_blst//:go_default_library
go_library(
name = "go_default_library",
srcs =
selects.with_or({
(
":linux_amd64",
":linux_arm64",
":darwin_amd64",
":darwin_arm64",
":windows_amd64",
":android_amd64",
":android_arm64",
): [
"aliases.go",
"doc.go",
"init.go",
"public_key.go",
"secret_key.go",
"signature.go",
],
"//conditions:default": [
"stub.go",
],
}),
srcs = [
"aliases.go",
"doc.go",
"init.go",
"public_key.go",
"secret_key.go",
"signature.go",
"stub.go", # keep
],
importpath = "github.com/prysmaticlabs/prysm/crypto/bls/blst",
visibility = [
"//crypto/bls:__pkg__",
],
deps = selects.with_or({
(
":linux_amd64",
":linux_arm64",
":darwin_amd64",
":darwin_arm64",
":windows_amd64",
":android_amd64",
":android_arm64",
): [
"//crypto/bls/common:go_default_library",
deps = select({
"@io_bazel_rules_go//go/platform:android_amd64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"//cache/lru:go_default_library",
"@com_github_dgraph_io_ristretto//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"//conditions:default": ["//crypto/bls/common:go_default_library"],
"@io_bazel_rules_go//go/platform:android_arm64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin_amd64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin_arm64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:ios_amd64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:ios_arm64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux_amd64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux_arm64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"@io_bazel_rules_go//go/platform:windows_amd64": [
"//cache/lru:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/rand:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_supranational_blst//:go_default_library",
],
"//conditions:default": [],
}),
)
# gazelle:ignore
go_test(
name = "go_default_test",
srcs = selects.with_or({
(
":linux_amd64",
":linux_arm64",
":darwin_amd64",
":darwin_arm64",
":windows_amd64",
":android_amd64",
":android_arm64",
): [
"public_key_test.go",
"secret_key_test.go",
],
"//conditions:default": [],
}),
deps = selects.with_or({
(
":linux_amd64",
":linux_arm64",
":darwin_amd64",
":darwin_arm64",
":windows_amd64",
":android_amd64",
":android_arm64",
): [
"//crypto/bls/blst:go_default_library",
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"//conditions:default": [],
}),
)
# gazelle:ignore
go_test(
name = "go_signature_test",
srcs = selects.with_or({
(
":linux_amd64",
":linux_arm64",
":darwin_amd64",
":darwin_arm64",
":windows_amd64",
":android_amd64",
":android_arm64",
): [
"signature_test.go",
],
"//conditions:default": [],
}),
srcs = [
"bls_benchmark_test.go",
"public_key_test.go",
"secret_key_test.go",
"signature_test.go",
],
embed = [":go_default_library"],
deps = selects.with_or({
(
":linux_amd64",
":linux_arm64",
":darwin_amd64",
":darwin_arm64",
":windows_amd64",
":android_amd64",
":android_arm64",
): [
deps = select({
"@io_bazel_rules_go//go/platform:android_amd64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:android_arm64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin_amd64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:darwin_arm64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:ios_amd64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:ios_arm64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux_amd64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux_arm64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
"@io_bazel_rules_go//go/platform:windows_amd64": [
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//testing/assert:go_default_library",
@@ -208,27 +180,3 @@ go_test(
"//conditions:default": [],
}),
)
# gazelle:exclude bls_benchmark_test.go
go_test(
name = "go_benchmark_test",
size = "small",
srcs = ["bls_benchmark_test.go"],
args = [
"-test.bench=.",
"-test.benchmem",
"-test.v",
],
local = True,
tags = [
"benchmark",
"manual",
"no-cache",
],
deps = [
":go_default_library",
"//crypto/bls/common:go_default_library",
"//crypto/hash:go_default_library",
"//encoding/bytesutil:go_default_library",
],
)