dotnet / iot

This repo includes .NET Core implementations for various IoT boards, chips, displays and PCBs.
MIT License
2.12k stars 574 forks source link

Do not pass static zero IntPtr to epoll wait. Dispose driver in tests… #2291

Closed huesla closed 3 months ago

huesla commented 3 months ago

See here This PR fixes a bug introduced by the merge of #2184. The bug was introduced by an unintentional change in the behaviour of the SysFsDriver, that utilizes the native epoll_wait function to discard not needed events. Originally the binding of epoll_wait was implemented as public static extern int epoll_wait(int epfd, out epoll_event events, int maxevents, int timeout); which does not fully match the native function int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); because events is a pointer to an array.

Some new functionality in #2184 relies on epoll_wait, what prompted me to correct the binding. As a consequence I had to update calls in the SysFsDriver, but mistakenly passed IntPtr.Zero to epoll_wait, which does not seem to result in the same behaviour. The fix is to pass an actual buffer instead.

This PR also includes some additional "using" statements in the GpioControllerTestBase because during testing, some sporadic occurrences of PermissionDeniedException occured. It complained about not having root permission for changing GPIO mode of used GPIOs. I'm pretty sure that was because of not yet disposed SysFsDriver instance/s.

Microsoft Reviewers: Open in CodeFlow
pgrawehr commented 3 months ago

/azp run

azure-pipelines[bot] commented 3 months ago
Azure Pipelines successfully started running 1 pipeline(s).