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

Ensure the signatures of our drm intercept functions are correct #3029

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/include/mir/test/doubles/mock_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class MockDRM
MOCK_METHOD6(drmModeCrtcGetGamma, int(int fd, uint32_t crtc_id, uint32_t size,
uint16_t* red, uint16_t* green, uint16_t* blue));
MOCK_METHOD6(drmModeCrtcSetGamma, int(int fd, uint32_t crtc_id, uint32_t size,
uint16_t* red, uint16_t* green, uint16_t* blue));
uint16_t const* red, uint16_t const* green, uint16_t const* blue));

MOCK_METHOD1(drmGetVersion, drmVersionPtr(int));
MOCK_METHOD1(drmFreeVersion, void(drmVersionPtr));
Expand Down
22 changes: 20 additions & 2 deletions tests/mir_test_doubles/mock_drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,24 @@ testing::Matcher<int> mtd::IsFdOfDevice(char const* device)
return ::testing::MakeMatcher(new mtd::MockDRM::IsFdOfDeviceMatcher(device));
}

// The signature of drmModeCrtcSetGamma() changes from passing the gamma as `uint16_t*` to `uint16_t const*`
// We need to provide a definition that matches
namespace
{
template<typename Any>
struct Decode_drmModeCrtcSetGamma_signature;

template<typename Arg>
struct Decode_drmModeCrtcSetGamma_signature<int(int fd, uint32_t crtc_id, uint32_t size, Arg red, Arg gree, Arg blue)>
{
using gamma_t = Arg;
};
using gamma_t = Decode_drmModeCrtcSetGamma_signature<decltype(drmModeCrtcSetGamma)>::gamma_t;
}

// Ensure we get a compile error if the definition doesn't match the declaration (instead of providing an overload)
extern "C"
{
int drmOpen(const char *name, const char *busid)
{
return global_mock->drmOpen(name, busid);
Expand Down Expand Up @@ -548,8 +566,7 @@ int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
return global_mock->drmModeCrtcGetGamma(fd, crtc_id, size, red, green, blue);
}

int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
uint16_t* red, uint16_t* green, uint16_t* blue)
int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size, gamma_t red, gamma_t green, gamma_t blue)
{
return global_mock->drmModeCrtcSetGamma(fd, crtc_id, size, red, green, blue);
}
Expand Down Expand Up @@ -751,3 +768,4 @@ int drmCheckModesettingSupported(char const* busid)
{
return global_mock->drmCheckModesettingSupported(busid);
}
}
Loading