Use ChiakiKeyState to 32bit fix key state overflow (Fix #172) (#359)

This commit is contained in:
Sven Scharmentke 2020-11-04 11:45:05 +01:00 committed by GitHub
commit 59e6603256
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 272 additions and 108 deletions

View file

@ -9,26 +9,51 @@ static MunitResult test_key_state(const MunitParameter params[], void *user)
ChiakiKeyState state;
chiaki_key_state_init(&state);
uint64_t pos = chiaki_key_state_request_pos(&state, 0);
uint64_t pos = chiaki_key_state_request_pos(&state, 0, true);
munit_assert_uint64(pos, ==, 0);
pos = chiaki_key_state_request_pos(&state, 0x1337);
pos = chiaki_key_state_request_pos(&state, 0x1337, true);
munit_assert_uint64(pos, ==, 0x1337);
pos = chiaki_key_state_request_pos(&state, 0xffff0000);
pos = chiaki_key_state_request_pos(&state, 0xffff0000, true);
munit_assert_uint64(pos, ==, 0xffff0000);
pos = chiaki_key_state_request_pos(&state, 0x1337);
pos = chiaki_key_state_request_pos(&state, 0x1337, true);
munit_assert_uint64(pos, ==, 0x100001337);
pos = chiaki_key_state_request_pos(&state, 0xffff1337);
pos = chiaki_key_state_request_pos(&state, 0xffff1337, true);
munit_assert_uint64(pos, ==, 0xffff1337);
pos = chiaki_key_state_request_pos(&state, 0x50000000);
pos = chiaki_key_state_request_pos(&state, 0x50000000, true);
munit_assert_uint64(pos, ==, 0x150000000);
pos = chiaki_key_state_request_pos(&state, 0xb0000000);
pos = chiaki_key_state_request_pos(&state, 0xb0000000, true);
munit_assert_uint64(pos, ==, 0x1b0000000);
pos = chiaki_key_state_request_pos(&state, 0x00000000);
pos = chiaki_key_state_request_pos(&state, 0x00000000, true);
munit_assert_uint64(pos, ==, 0x200000000);
return MUNIT_OK;
}
static MunitResult test_key_state_nocommit(const MunitParameter params[], void *user)
{
ChiakiKeyState state;
chiaki_key_state_init(&state);
uint64_t pos = chiaki_key_state_request_pos(&state, 0, false);
munit_assert_uint64(pos, ==, 0);
pos = chiaki_key_state_request_pos(&state, 0x1337, false);
munit_assert_uint64(pos, ==, 0x1337);
pos = chiaki_key_state_request_pos(&state, 0xffff0000, false);
munit_assert_uint64(pos, ==, 0xffff0000);
pos = chiaki_key_state_request_pos(&state, 0x1337, false);
munit_assert_uint64(pos, ==, 0x1337);
pos = chiaki_key_state_request_pos(&state, 0xffff1337, false);
munit_assert_uint64(pos, ==, 0xffff1337);
pos = chiaki_key_state_request_pos(&state, 0x50000000, false);
munit_assert_uint64(pos, ==, 0x50000000);
pos = chiaki_key_state_request_pos(&state, 0xb0000000, false);
munit_assert_uint64(pos, ==, 0xb0000000);
pos = chiaki_key_state_request_pos(&state, 0x00000000, false);
munit_assert_uint64(pos, ==, 0);
return MUNIT_OK;
}
MunitTest tests_key_state[] = {
{
"/key_state",
@ -38,5 +63,13 @@ MunitTest tests_key_state[] = {
MUNIT_TEST_OPTION_NONE,
NULL
},
{
"/key_state_nocommit",
test_key_state_nocommit,
NULL,
NULL,
MUNIT_TEST_OPTION_NONE,
NULL
},
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};