Skip to content

Commit

Permalink
fix gosec G404 & update behavior of test target in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ianchen0119 committed Mar 16, 2024
1 parent 13790f0 commit cb200d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ run:
timeout: 10m
skip-files:
- ".*\\.pb\\.go"
- ".*\\_test.go"
skip-dirs-use-default: true

linters:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ golint:
mkdir -p $(CURDIR)/.coverage

test: .coverage
go test -race -coverprofile=.coverage/coverage-unit.txt -covermode=atomic -run=^Test.*$ -v ./...
go test -race -coverprofile=.coverage/coverage-unit2.txt -covermode=atomic -run=^Test -v ./...

reuse-lint:
docker run --rm -v $(CURDIR):/pfcpsim -w /pfcpsim omecproject/reuse-verify:latest reuse lint
Expand Down
17 changes: 12 additions & 5 deletions fuzz/ie_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
package fuzz

import (
"math/rand"
"crypto/rand"
"math/big"
"testing"
"time"

Expand All @@ -16,6 +17,11 @@ import (
const MaxUint = ^uint(0)
const MaxInt = int(MaxUint >> 1)

func getRand(n int) int {
res, _ := rand.Int(rand.Reader, big.NewInt(int64(n)))
return int(res.Int64())
}

// Example of a basic function test
// func TestBasicFunction(t *testing.T) {
// sim := export.NewPfcpSimCfg("eth0", "192.168.0.5", "127.0.0.8")
Expand Down Expand Up @@ -45,12 +51,13 @@ const MaxInt = int(MaxUint >> 1)
func Fuzz(f *testing.F) {
var testcases []uint
for i := 0; i < 100; i++ {
testcases = append(testcases, uint(rand.Intn(MaxInt)))
testcases = append(testcases, uint(getRand(MaxInt)))
}

for _, tc := range testcases {
f.Add(tc)
}

session.SetCheck(false)

f.Fuzz(func(t *testing.T, input uint) {
Expand All @@ -68,7 +75,7 @@ func Fuzz(f *testing.F) {
err = sim.TerminatePFCPSim()
require.NoError(t, err)
}()
err = sim.CreateSession(2, rand.Intn(session.PdrMax),
err = sim.CreateSession(2, getRand(session.PdrMax),
int(input)%session.QerMax,
int(input)%session.FarMax,
int(input)%session.UrrMax,
Expand All @@ -77,8 +84,8 @@ func Fuzz(f *testing.F) {
require.NoError(t, err, "CreateSession failed")
}
err = sim.ModifySession(2,
rand.Intn(session.FarMax),
rand.Intn(session.UrrMax),
getRand(session.FarMax),
getRand(session.UrrMax),
input)
if err != nil {
require.NoError(t, err, "ModifySession failed")
Expand Down

0 comments on commit cb200d8

Please sign in to comment.