Skip to content

Commit

Permalink
fuzz-marshal-float-64ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Jun 7, 2024
1 parent 34fdeeb commit 0d583fb
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
54 changes: 50 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,30 @@ jobs:
go-version: ${{ matrix.go }}
- run: go vet
- name: Run unit tests
run: go test -v -tags unit -race
run: |
# Get the list of all packages
#packages=$(go list ./...)
# for pkg in $packages; do
# Run tests in the package, excluding fuzz tests
go test -v -tags unit -race '${{ matrix.tags }}gocql_debug' -timeout=5m -race ${{ env.args }}
#$pkg | grep -v 'Fuzz'
#done
Fuzzing:
name: Fuzz tests
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.19', '1.20' ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- run: go vet
- name: Run unit tests
run: go test -race -v -fuzz Fuzz -fuzztime 30s -parallel=1 -tags fuzz
integration-cassandra:
timeout-minutes: 15
needs:
Expand Down Expand Up @@ -107,8 +130,17 @@ jobs:
echo "JVM_EXTRA_OPTS=$JVM_EXTRA_OPTS" >> $GITHUB_ENV
- name: Integration tests
run: |
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }}
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
# Get the list of all packages
#packages=$(go list ./...)
#for pkg in $packages; do
# Run tests in the package, excluding fuzz tests
# go test -v -tags '${{ matrix.tags }}gocql_debug' -timeout=5m -race ${{ env.args }} $pkg | grep -v 'Fuzz'
#done
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }}
- name: 'Save ccm logs'
if: 'failure()'
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -198,4 +230,18 @@ jobs:
- name: Integration tests
run: |
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }}
# Get the list of all packages
#packages=$(go list ./...)
#for pkg in $packages; do
# Run tests in the package, excluding fuzz tests
# go test -v -run=TestAuthentication -tags '${{ matrix.tags }}gocql_debug' -timeout=15s -runauth ${{ env.args }} $pkg | grep -v 'Fuzz'
#done
#for pkg in $(go list ./...); do
# go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }} $(find . -name "*_test.go" ! -name "*Fuzz*") -run=TestAuthentication $pkg
#done

go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }}
30 changes: 30 additions & 0 deletions fuzz_cassandra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build fuzz
// +build fuzz

package gocql

import (
"testing"
)

// FuzzMarshalFloat64Ptr aimed to repeatedly test float64 marshaling with generated inputs based on seed corpus.
func FuzzMarshalFloat64Ptr(f *testing.F) {
f.Add(float64(7500), float64(7500.00))

f.Fuzz(func(t *testing.T, num, numWithPoints float64) {
session := createSession(t)
defer session.Close()

if err := createTable(session, "CREATE TABLE IF NOT EXISTS gocql_test.float_test (id double, test double, primary key (id))"); err != nil {
t.Fatal("create table:", err)
}

if err := session.Query(`TRUNCATE TABLE gocql_test.float_test`).Exec(); err != nil {
t.Fatal("truncate table:", err)
}

if err := session.Query(`INSERT INTO float_test (id,test) VALUES (?,?)`, numWithPoints, &num).Exec(); err != nil {
t.Fatal("insert float64:", err)
}
})
}

0 comments on commit 0d583fb

Please sign in to comment.