Skip to content

Commit

Permalink
fix: fixed some annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaau committed Feb 18, 2025
1 parent b02cd42 commit 415eecc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
26 changes: 14 additions & 12 deletions gnovm/stdlibs/testing/fuzzing/fuzz_hasher.gno
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ type (
}
)

// ----------------------------------------
// FuzzHasher: main struct
// ----------------------------------------
// FuzzHasher is the main struct for managing hash mappings.
//
// It maintains mappings between hash numbers, internal hashes, and coverage data.
// The struct includes a counter for assigning unique hash numbers.
type FuzzHasher struct {
HashNumber2Internal *[MaxCapacity]InternalHash // Table: hashNumber -> internalHash
internal2Cov map[InternalHash]Coverage // Table: internalHash -> Coverage
Expand All @@ -42,14 +43,15 @@ type FuzzHasher struct {
// coverageCache map[string]hashNumber // coverage -> hashNumber
}

// ----------------------------------------
// registerCoverage2HashNumber
// ----------------------------------------
// 1) computes internalHash from coverage
// 2) inserts coverage into internal2Cov
// 3) obtains hashNumber (unique ID)
// 4) updates hashNumber2Internal
// 5) returns the assigned hashNumber
// RegisterCoverage2HashNumber computes an internal hash from the given coverage,
// stores the mapping, assigns a unique hash number, and updates the internal tables.
//
// It performs the following steps:
// 1. Computes the internal hash from the coverage.
// 2. Inserts the coverage into internal2Cov.
// 3. Obtains a unique hash number.
// 4. Updates HashNumber2Internal.
// 5. Returns the assigned hash number.
func (fh *FuzzHasher) RegisterCoverage2HashNumber(coverage Coverage) HashNumber {
ih := GetInternalHash(coverage) // compute internalHash
fh.internal2Cov[ih] = coverage
Expand Down Expand Up @@ -111,7 +113,7 @@ func (fh *FuzzHasher) countHashNumber(ih InternalHash) HashNumber {
return current
}

// IsExistingCoverage는 주어진 coverage가 이미 등록되어 있는지 확인하여, 등록되어 있으면 true, 아니면 false를 반환합니다.
// IsExistingCoverage checks whether the given coverage is already registered.
func (fh *FuzzHasher) IsExistingCoverage(cv Coverage) bool {
ih := GetInternalHash(cv)
_, exists := fh.internal2Cov[ih]
Expand Down
5 changes: 2 additions & 3 deletions gnovm/stdlibs/testing/fuzzing/fuzz_logger.gno
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ func TokenizeXXX(s interface{}) []Token {
var tokens []Token
var b []byte

// 입력 타입 체크
switch v := s.(type) {
case string:
b = []byte(v) // string을 []byte로 변환
b = []byte(v)
case []byte:
b = v // []byte 그대로 사용
b = v
default:
panic("unsupported type: must be string or []byte")
}
Expand Down
4 changes: 2 additions & 2 deletions gnovm/stdlibs/testing/fuzzing/mutator.gno
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ func NewMutSample(seed Seed) *MutSample {
Seed: seed,
ArgPowerSetScores: scores,
SamplePopularity: 1,
RootEntsDict: formattedRootEntsDict, // arg idx와 Ent매핑
RootEntsDict: formattedRootEntsDict,
NotSbEntsDict: formattedNotSbEntsDict,
CachedPowerSetCumSum: nil, // Cache starts empty
NeedsUpdateCache: true,
Expand Down Expand Up @@ -890,7 +890,7 @@ var entMutators = map[MutationCode]MutateFunc{
CHP: changePattern,
IR: insertRandomly,
IG: insertGradual,
II: insertInteresting, // 수정된 이름
II: insertInteresting,
IP: insertPattern,
SW: swap,
PKL: preserveKindLight,
Expand Down
2 changes: 0 additions & 2 deletions gnovm/stdlibs/testing/fuzzing/parser_for_not_sb.gno
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func quickSortMutationCodesForNotSB(keys []MutationCodeForNotSB) {
}
pivotIndex := len(keys) / 2
pivot := keys[pivotIndex]
// 피벗을 마지막 요소와 교환합니다.
keys[pivotIndex], keys[len(keys)-1] = keys[len(keys)-1], keys[pivotIndex]

storeIndex := 0
Expand All @@ -172,7 +171,6 @@ func quickSortMutationCodesForNotSB(keys []MutationCodeForNotSB) {
storeIndex++
}
}
// 피벗을 올바른 위치로 이동합니다.
keys[storeIndex], keys[len(keys)-1] = keys[len(keys)-1], keys[storeIndex]

quickSortMutationCodesForNotSB(keys[:storeIndex])
Expand Down
6 changes: 2 additions & 4 deletions gnovm/stdlibs/testing/fuzzing/parser_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,15 @@ func TestMutateArg(t *testing.T) {
ms := fuzzing.NewMutSample(seed)

for idx, original := range seed.Content {
t.Logf("원본 인자 [idx=%d]: %v", idx, original)
t.Logf("original args [idx=%d]: %v", idx, original)
for iter := 0; iter < 5; iter++ {
mutatedArg, mutationInfo := ms.MutateArg(original, 3, idx)
t.Logf(" Iteration %d: mutated value: %v, mutation info: %+v", iter, mutatedArg, mutationInfo)
}
}

keys, cum := ms.Seed.HashNumber, []uint64{0}
t.Logf("MutSample 내부 전략 캐시 (예시): keys=%v, cum=%v", keys, cum)

fmt.Println("테스트가 완료되었습니다.")
t.Logf("MutSample's strategy cache (example): keys=%v, cum=%v", keys, cum)
}

// TestSort tests boundary-based selection logic for mappedGeneratingNumber.
Expand Down

0 comments on commit 415eecc

Please sign in to comment.