-
Notifications
You must be signed in to change notification settings - Fork 1
[POC] Add Tests for HandleVnodeOperation #3
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: more_testing
Are you sure you want to change the base?
Conversation
2c60594
to
cf56c0a
Compare
int* kauthError) | ||
{ | ||
/* | ||
MockCalls::RecordFunctionCall( |
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.
@pmj can you tell what's wrong with the RecordFunctionCall here? I must be missing something subtle cause it says it doesn't match what's expected.
Once I have this I can validate what we called in the test.
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.
Ouch, this is C++ at its worst. I've put a workaround up here: https://github.com/pmj/VFSForGit/tree/more_testing_handlevnodeop - I'll need to go in and finish off the argument checking implementation to know whether this'll work long term. For now, please use the workaround, I'll worry about the fallout. :-)
@@ -124,6 +124,7 @@ void ProviderMessaging_AbortOutstandingEventsForProvider(VirtualizationRootHandl | |||
Mutex_Release(s_outstandingMessagesMutex); | |||
} | |||
|
|||
#ifndef KEXT_UNIT_TESTING |
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.
Thoughts on this approach? I don't believe we have anything similar yet, and I can see this being the only function we'd want to leave out for now.
There is also the swap approach suggested in this PR. microsoft#732 (review) , but I wasn't fully sure on implementation.
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.
I think the swap approach is going to be the long term solution, but for now this is fine, at least as long as we'r not trying to write tests for ProviderMessaging_TrySendRequestAndWaitForResponse
itself. We can eventually also expand MockCalls to generate a function to swap with automatically, so we don't have to have these dummy functions forwarding to MockCalls::RecordFunctionCall
everywhere; it'll be super slick to use if we can pull off the gnarly C++ template back-end.
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.
Thoughts on this approach?
@jeschu1 I don't think we need the #ifndef KEXT_UNIT_TESTING
here, because it looks like we don't need to compile ProviderMessaging.cpp
as part of PrjFSKextTestable
at all (I pushed a branch with this change, see wilbaker@6acd456)
I think this approach is OK for now if we find spots that need it, but at this point I'm not sure if the unit tests need to call any of the functions in ProviderMessaging.cpp
.
cc: @pmj for his thoughts as well
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.
Related, can anyone remember if there was a need to compile ProviderMessaging.cpp
as part of Testable
?
I'm thinking this might have just been picked up by mistake (and didn't cause any issues until now).
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.
Related, can anyone remember if there was a need to compile
ProviderMessaging.cpp
as part ofTestable
?I'm thinking this might have just been picked up by mistake (and didn't cause any issues until now).
I think I included it when moving those functions to the new file to ensure that they successfully compiled in the user space/testable build environment, and that I hadn’t for example missed some headers. We can certainly take it back out of the testable build for now, I don’t think any of my WIP PRs will be testing those functions just yet.
@@ -22,3 +22,43 @@ proc_t vfs_context_proc(vfs_context_t ctx) | |||
{ | |||
return NULL; | |||
} | |||
|
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 doing this work, it highlighted 2 more areas to unit test
- CurrentProcessWasSpawnedByRegularUser
- UseMainForkIfNamedStream
// Register provider for the repository path (Simulate a mount) | ||
VirtualizationRootResult result = VirtualizationRoot_RegisterProviderForPath(&dummyClient, dummyClientPid, repoPath); | ||
XCTAssertEqual(result.error, 0); | ||
vnode_put(s_virtualizationRoots[result.root].rootVNode); |
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.
@pmj I saw the same lines in your unit test. How will the system clean this up for real scenarios?
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.
This is normally done in ActiveProvider_Disconnect()
which last I checked wasn't quite ready to be called from unit tests yet. You could give it a go if you like (and the situation may have since improved).
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.
This is looking good!
@@ -124,6 +124,7 @@ void ProviderMessaging_AbortOutstandingEventsForProvider(VirtualizationRootHandl | |||
Mutex_Release(s_outstandingMessagesMutex); | |||
} | |||
|
|||
#ifndef KEXT_UNIT_TESTING |
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.
I think the swap approach is going to be the long term solution, but for now this is fine, at least as long as we'r not trying to write tests for ProviderMessaging_TrySendRequestAndWaitForResponse
itself. We can eventually also expand MockCalls to generate a function to swap with automatically, so we don't have to have these dummy functions forwarding to MockCalls::RecordFunctionCall
everywhere; it'll be super slick to use if we can pull off the gnarly C++ template back-end.
int* kauthError) | ||
{ | ||
/* | ||
MockCalls::RecordFunctionCall( |
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.
Ouch, this is C++ at its worst. I've put a workaround up here: https://github.com/pmj/VFSForGit/tree/more_testing_handlevnodeop - I'll need to go in and finish off the argument checking implementation to know whether this'll work long term. For now, please use the workaround, I'll worry about the fallout. :-)
- This will mark the file as D in placeholders.dat and insert into modifiedPaths.dat - This cleans up the existing ModifiedFile event which was also being used as the initial switch from placeholders.dat
0cc09f9
to
6948945
Compare
|
||
// Ensure a directory is Deleted | ||
expectedMessageType[0] = MessageType_KtoU_NotifyDirectoryPreDelete; | ||
expectedMessageType[1] = MessageType_KtoU_RecursivelyEnumerateDirectory; |
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.
@pmj FYI
If we verify DidCallFunction with args it could come up as too separate functions.
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.
Yep, I fully intend to be able to check call sequences; maybe not in the first iteration though.
@wilbaker @ jrbriggs this is still a WIP but I'm super happy about the direction. I was able to reuse a lot of the good work @pmj did in this PR microsoft#908 to test from the top level. Next steps here are
|
…e Access is requested Mac: Add PreConvertToFull when Write Access is requested
Additional Kext Tests
Workaround for kext testing MockCalls::RecordFunctionCall issues Additional Vnode Tests Moved to a new file
6948945
to
276cc19
Compare
276cc19
to
f6cc7c1
Compare
This is obviously an incomplete first pass at trying to test from top level HandleVnodeOperation.
I have several questions that I've put inline.