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

[WIN32KNT_APITEST] Add NtUserSetTimer API tests #7100

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

turican0
Copy link
Contributor

@turican0 turican0 commented Jul 7, 2024

Purpose

Addition of apitests for NtUserSetTimer

JIRA issue: CORE-9141

Proposed changes

Test 1 - test of creating/canceling 20 timers and comparing the raw number of returned messages - without parent window
Test 2 - test of creating/cancelling 20 timers and comparing the raw number of returned messages - with parent window
Test 3 - test creation/cancellation of 40000 timers - without parent window
Test 4 - test of creation/cancellation of 40000 timers - with parent window
Test 5 - test creation/cancellation of 2 timers and compare their index to see if they differ - without parent window

@binarymaster binarymaster changed the title add NtUserSetTimer apitests Jul 7, 2024
@binarymaster binarymaster added the ROSTESTS Label for ROS testcases PRs. label Jul 7, 2024
@binarymaster binarymaster added this to New PRs in ReactOS PRs via automation Jul 7, 2024
int countErrors = 0;

int minMessages = (SLEEP_TIME / TEST1_INTERVAL) * (1 - TIME_TOLERANCE);
int maxMessages = (SLEEP_TIME / TEST1_INTERVAL) * (1 + TIME_TOLERANCE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SLEEP_TIME and TEST1_INTERVAL are integers; 1 is also integer but TIME_TOLERANCE is a float; I wonder whether you correctly get what you want here.
Namely, your 1 - TIME_TOLERANCE going to be zero and 1 + TIME_TOLERANCE going to be 1... 🤔 🤔

turican0 and others added 10 commits July 8, 2024 13:50
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
@turican0
Copy link
Contributor Author

turican0 commented Jul 8, 2024

HBelusca I have modified the code based on your suggestions.

@turican0
Copy link
Contributor Author

turican0 commented Jul 8, 2024

HBelusca The number of messages is highly indicative, as it takes several milliseconds to initialize, etc. That's why there is a 50% tolerance to received messages count. It worked for me without overwriting, but I understand that if we change the values, it could lead to miscalculation. Anyway, we'll see how it behaves on the server, maybe we need to give the tolerance even higher.

@turican0
Copy link
Contributor Author

turican0 commented Jul 8, 2024

I'll separate the tests without and with the window.

@binarymaster
Copy link
Member

Helped with review comments, please recheck.

ReactOS PRs automation moved this from New PRs to Approved by reviewers Jul 8, 2024
Copy link
Contributor

@Doug-Lyons Doug-Lyons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@HBelusca HBelusca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last suggestions:

  • static-ize functions that are used only within this file;
  • add a comment explaining for what they are used.
  • MessageLoop() function seems to be unused.
turican0 and others added 8 commits July 8, 2024 21:22
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Co-authored-by: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
@turican0
Copy link
Contributor Author

turican0 commented Jul 9, 2024

I'm still wondering if it would be safer to have a timer count of 32767 instead of 32768 if some application used INT instead of UINT for SetTimer. Are we sure that windows has 32768?

@HBelusca
Copy link
Contributor

I'm still wondering if it would be safer to have a timer count of 32767 instead of 32768 if some application used INT instead of UINT for SetTimer. Are we sure that windows has 32768?

You mean, for the 2nd parameter nIDEventof SetTimer(), which is an UINT_PTR ? If so, this is a parameter that has to be different to zero in order to describe a timer ID, that's it. And note that because its type is UINT_PTR, this means that in 64-bit builds, its value can go up to 2^64-1.


Sorry to ask, in case this has been already addressed and discussed: in the SetTimer() msdn page, it's written:

SetTimer can reuse timer IDs in the case where hWnd is NULL.

Is this correctly handled?

// TEST WITH MESSAGES WITHOUT WINDOW - test different ids
TEST(test3());

WNDCLASS wc = { 0 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using explicitly unicode window class & functions:

Suggested change
WNDCLASS wc = { 0 };
WNDCLASSW wc = { 0 };
Comment on lines +231 to +232
wc.lpszClassName = "TimerWindowClass";
RegisterClass(&wc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wc.lpszClassName = "TimerWindowClass";
RegisterClass(&wc);
wc.lpszClassName = L"TimerWindowClass";
RegisterClassW(&wc);

I wonder whether we should check the returned value from RegisterClass ...

wc.lpszClassName = "TimerWindowClass";
RegisterClass(&wc);

HWND hwnd = CreateWindowEx(0, "TimerWindowClass", "Timer Window", 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HWND hwnd = CreateWindowEx(0, "TimerWindowClass", "Timer Window", 0,
HWND hwnd = CreateWindowExW(0, L"TimerWindowClass", L"Timer Window", 0,

if (hwnd != NULL)
DestroyWindow(hwnd);
UnregisterClass("TimerWindowClass", GetModuleHandle(NULL));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hInstance comment:

Suggested change
UnregisterClass("TimerWindowClass", GetModuleHandle(NULL));
UnregisterClassW(L"TimerWindowClass", NULL);

2nd parameter is optional and when giving NULL it does the same thing as GetModuleHandle(NULL)

Alternatively if you want to keep GetModuleHandle explicit, I would suggest you add a

HINSTANCE hInstance = GetModuleHandle(NULL);

at the beginning of the START_TEST(...) function, and then use that hInstance variable in all these places where you need it.


WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandle(NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other hInstance comment.


HWND hwnd = CreateWindowEx(0, "TimerWindowClass", "Timer Window", 0,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other hInstance comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ROSTESTS Label for ROS testcases PRs.
5 participants