Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz-marshal-float-64ptr #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,90 @@ jobs:
- run: go vet
- name: Run unit tests
run: go test -v -tags unit -race
Fuzz:
timeout-minutes: 15
needs:
- build
name: Fuzz tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: [ '1.19', '1.20' ]
cassandra_version: [ '4.0.8', '4.1.1' ]
auth: [ "false" ]
compressor: [ "snappy" ]
tags: [ "cassandra", "integration", "ccm", "fuzz" ]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- uses: actions/cache@v2
id: gomod-cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install CCM
run: pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}"
- name: Start cassandra nodes
run: |
VERSION=${{ matrix.cassandra_version }}
keypath="$(pwd)/testdata/pki"
conf=(
"client_encryption_options.enabled: true"
"client_encryption_options.keystore: $keypath/.keystore"
"client_encryption_options.keystore_password: cassandra"
"client_encryption_options.require_client_auth: true"
"client_encryption_options.truststore: $keypath/.truststore"
"client_encryption_options.truststore_password: cassandra"
"concurrent_reads: 2"
"concurrent_writes: 2"
"write_request_timeout_in_ms: 5000"
"read_request_timeout_in_ms: 5000"
)

if [[ $VERSION == 3.*.* ]]; then
conf+=(
"rpc_server_type: sync"
"rpc_min_threads: 2"
"rpc_max_threads: 2"
"enable_user_defined_functions: true"
"enable_materialized_views: true"
)
elif [[ $VERSION == 4.0.* ]]; then
conf+=(
"enable_user_defined_functions: true"
"enable_materialized_views: true"
)
else
conf+=(
"user_defined_functions_enabled: true"
"materialized_views_enabled: true"
)
fi

ccm remove test || true

ccm create test -v $VERSION -n 3 -d --vnodes --jvm_arg="-Xmx256m -XX:NewSize=100m"
ccm updateconf "${conf[@]}"

export JVM_EXTRA_OPTS=" -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"

ccm start --wait-for-binary-proto --verbose
ccm status
ccm node1 nodetool status

args="-gocql.timeout=60s -runssl -proto=4 -rf=3 -clusterSize=3 -autowait=2000ms -compressor=${{ matrix.compressor }} -gocql.cversion=$VERSION -cluster=$(ccm liveset) ./..."

echo "args=$args" >> $GITHUB_ENV
echo "JVM_EXTRA_OPTS=$JVM_EXTRA_OPTS" >> $GITHUB_ENV
- name: Run Fuzz tests
run: |
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
go test -v -tags "${{ matrix.tags }} gocql_debug" -fuzz Fuzz -fuzztime 30s -parallel=1 -timeout=5m -race ${{ env.args }}
integration-cassandra:
timeout-minutes: 15
needs:
Expand Down Expand Up @@ -198,4 +282,4 @@ 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 }}
go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }}
34 changes: 0 additions & 34 deletions fuzz.go

This file was deleted.

118 changes: 118 additions & 0 deletions fuzz_cassandra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//go:build fuzz
// +build fuzz

package gocql

import (
"bytes"
"fmt"
"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)
}
})
}

func FuzzTracing(f *testing.F) {
f.Add(42)

f.Fuzz(func(t *testing.T, id int) {
session := createSession(t)
defer session.Close()

if err := createTable(session, `CREATE TABLE gocql_test.trace (id int primary key)`); err != nil {
t.Fatal("create:", err)
}

buf := &bytes.Buffer{}
trace := &traceWriter{session: session, w: buf}
if err := session.Query(`INSERT INTO trace (id) VALUES (?)`, id).Trace(trace).Exec(); err != nil {
t.Fatal("insert:", err)
} else if buf.Len() == 0 {
t.Fatal("insert: failed to obtain any tracing")
}
trace.mu.Lock()
buf.Reset()
trace.mu.Unlock()

var value int
if err := session.Query(`SELECT id FROM trace WHERE id = ?`, id).Trace(trace).Scan(&value); err != nil {
t.Fatal("select:", err)
} else if value != id {
t.Fatalf("value: expected %d, got %d", id, value)
} else if buf.Len() == 0 {
t.Fatal("select: failed to obtain any tracing")
}

// also works from session tracer
session.SetTrace(trace)
trace.mu.Lock()
buf.Reset()
trace.mu.Unlock()
if err := session.Query(`SELECT id FROM trace WHERE id = ?`, id).Scan(&value); err != nil {
t.Fatal("select:", err)
}
if buf.Len() == 0 {
t.Fatal("select: failed to obtain any tracing")
}
})
}
func FuzzDurationType(f *testing.F) {
f.Add(int32(1), int32(500), int32(0x7FFFFFFF), int64(0x7FFFFFFFFFFFFFFF))

f.Fuzz(func(t *testing.T, id, month, day int32, nanoseconds int64) {

session := createSession(t)
defer session.Close()

fmt.Println("\nLOL")
fmt.Printf("\nid:%v.\nmonth:%v.\nday:%v.\nnanoseconds:%v\n", id, month, day, nanoseconds)
if session.cfg.ProtoVersion < 4 {
t.Skip("Duration type is not supported. Please use protocol version >= 4 and cassandra version >= 3.11")
}

if err := createTable(session, `CREATE TABLE gocql_test.duration_table (
k int primary key, v duration
)`); err != nil {
t.Fatal("create:", err)
}

duration := Duration{
Months: month,
Days: day,
Nanoseconds: nanoseconds,
}

if err := session.Query(`INSERT INTO gocql_test.duration_table (k, v) VALUES (?, ?)`, id, duration).Exec(); err != nil {
t.Fatal(err)
}

var scanedID int
var selectedDuration Duration
if err := session.Query(`SELECT k, v FROM gocql_test.duration_table`).Scan(&scanedID, &selectedDuration); err != nil {
t.Fatal(err)
}
if selectedDuration.Months != duration.Months || selectedDuration.Days != duration.Days || selectedDuration.Nanoseconds != duration.Nanoseconds {
t.Fatalf("Unexpeted value returned, expected=%v, received=%v", duration, selectedDuration)
}
})
}
Loading