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

Add unit test for ListIPForwardRows #6673

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tnqn
Copy link
Member

@tnqn tnqn commented Sep 14, 2024

No description provided.

@tnqn tnqn added area/test Issues or PRs related to unit and integration tests. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Sep 14, 2024
@tnqn tnqn force-pushed the unit-test-copy-rows branch 3 times, most recently from a30bd29 to b2e1f7a Compare September 14, 2024 14:17
syscallN := func(trap uintptr, args ...uintptr) (r1, r2 uintptr, err syscall.Errno) {
// This mocks the 1st call to syscallN made by getIPForwardTable. It makes args[1] point to the table.
if len(args) > 1 {
ptr := unsafe.Pointer(args[1])
Copy link
Member Author

@tnqn tnqn Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow checkptr thinks "pointer arithmetic result points to invalid allocation".
There is no problem when -race is not used. Need more investigation.

@tnqn tnqn force-pushed the unit-test-copy-rows branch 2 times, most recently from fd4d9c8 to 7ed92a0 Compare September 14, 2024 16:09
@@ -307,11 +307,14 @@ type NetIOInterface interface {
}

type netIO struct {
syscallN func(trap uintptr, args ...uintptr) (r1, r2 uintptr, err syscall.Errno)
syscallN func(trap uintptr, args ...uintptr) (r1, r2 uintptr, err syscall.Errno)
getIPForwardTableFn func(family uint16, ipForwardTable **MibIPForwardTable) (errcode error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't we just fake syscallN in tests, instead of faking individual functions like getIPForwardTable? It seems that getIPForwardTable is just a thin wrapper around a syscallN call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I did in an earlier version: b2e1f7a. However, checkptr failed when --race is enabled, as I commented in #6673 (comment). The error can be found here: https://github.com/antrea-io/antrea/actions/runs/10863106542/job/30146883490.

I suspect the compiler doesn't recognize the fake syscall and mistakenly raise the error. But even the latest version failed due to another checkptr error in code (as opposed the previous error in test code), and this error seems valid: the code shouldn't assign uintptr to a variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/test Issues or PRs related to unit and integration tests. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants