-
Notifications
You must be signed in to change notification settings - Fork 99
Optimize neotest in coverage mode #4101
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,6 @@ import ( | |||||||||||||||||||
|
|
||||||||||||||||||||
| "github.com/nspcc-dev/neo-go/pkg/compiler" | ||||||||||||||||||||
| "github.com/nspcc-dev/neo-go/pkg/util" | ||||||||||||||||||||
| "github.com/nspcc-dev/neo-go/pkg/vm" | ||||||||||||||||||||
| "github.com/nspcc-dev/neo-go/pkg/vm/opcode" | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -118,17 +117,32 @@ func isCoverageEnabled(t testing.TB) bool { | |||||||||||||||||||
| return coverageEnabled | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var coverageHook vm.OnExecHook = func(scriptHash util.Uint160, offset int, opcode opcode.Opcode) { | ||||||||||||||||||||
| coverageLock.Lock() | ||||||||||||||||||||
| defer coverageLock.Unlock() | ||||||||||||||||||||
| if cov, ok := rawCoverage[scriptHash]; ok { | ||||||||||||||||||||
| func (e *Executor) coverageHook(scriptHash util.Uint160, offset int, _ opcode.Opcode) { | ||||||||||||||||||||
| e.coverageLock.Lock() | ||||||||||||||||||||
| defer e.coverageLock.Unlock() | ||||||||||||||||||||
| if cov, ok := e.rawCoverage[scriptHash]; ok { | ||||||||||||||||||||
| cov.offsetsVisited = append(cov.offsetsVisited, offset) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func reportCoverage(t testing.TB) { | ||||||||||||||||||||
| func (e *Executor) reportCoverage(t testing.TB) { | ||||||||||||||||||||
| coverageLock.Lock() | ||||||||||||||||||||
| defer coverageLock.Unlock() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| e.coverageLock.RLock() | ||||||||||||||||||||
| for h, cov := range e.rawCoverage { | ||||||||||||||||||||
| fullCov := rawCoverage[h] | ||||||||||||||||||||
| if fullCov == nil { | ||||||||||||||||||||
| fullCov = &scriptRawCoverage{ | ||||||||||||||||||||
| debugInfo: cov.debugInfo, | ||||||||||||||||||||
| } | ||||||||||||||||||||
| rawCoverage[h] = fullCov | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fullCov.offsetsVisited = append(fullCov.offsetsVisited, cov.offsetsVisited...) | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can break with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lines 454 to 462 in 93fe450
So right now it looks like we don't fully support parallel coverage collection. Do we need an issue for that?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, would be nice to have one since it's not obvious. Should be mentioned in neotest docs then. |
||||||||||||||||||||
| } | ||||||||||||||||||||
| e.coverageLock.RUnlock() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| f, err := os.Create(coverProfile) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| t.Fatalf("coverage: can't create file '%s' to write coverage report", coverProfile) | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this one probably doesn't require any locking since it's executed as the test cleanup function, Executor should be done by that time.