Skip to content

Commit

Permalink
Merge pull request #3029 from MirServer/fix-3019
Browse files Browse the repository at this point in the history
Ensure the signatures of our drm intercept functions are correct
  • Loading branch information
Saviq authored Aug 31, 2023
2 parents 82c6c01 + 98250e9 commit a67f858
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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);
}
}

0 comments on commit a67f858

Please sign in to comment.