Rebase against 9e639ff1f6c2b913518501b3f99ca085c4eed6c7.

This commit is contained in:
Zebediah Figura 2024-03-18 18:41:32 -05:00
parent 6a314e5994
commit badfcbc451
2 changed files with 1 additions and 224 deletions

View File

@ -1,223 +0,0 @@
From dd46b005cfcc8aa02bf25c031326e28bd75e0ff2 Mon Sep 17 00:00:00 2001
From: Mark Jansen <mark.jansen@reactos.org>
Date: Sun, 24 Sep 2017 22:45:22 +0200
Subject: [PATCH] kernel32/tests: Add tests for job object accounting
Signed-off-by: Mark Jansen <mark.jansen@reactos.org>
---
dlls/kernel32/tests/process.c | 95 +++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index e9e8555c32e..e5a9914ca7b 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -2541,6 +2541,69 @@ static void _create_process(int line, const char *command, LPPROCESS_INFORMATION
ok_(__FILE__, line)(ret, "CreateProcess error %lu\n", GetLastError());
}
+#define test_assigned_proc(job, ...) _test_assigned_proc(__LINE__, job, __VA_ARGS__)
+static void _test_assigned_proc(int line, HANDLE job, int expected_count, ...)
+{
+ char buf[sizeof(JOBOBJECT_BASIC_PROCESS_ID_LIST) + sizeof(ULONG_PTR) * 20];
+ PJOBOBJECT_BASIC_PROCESS_ID_LIST pid_list = (JOBOBJECT_BASIC_PROCESS_ID_LIST *)buf;
+ DWORD ret_len, pid;
+ va_list valist;
+ int n;
+ BOOL ret;
+
+ memset(buf, 0, sizeof(buf));
+ ret = pQueryInformationJobObject(job, JobObjectBasicProcessIdList, pid_list, sizeof(buf), &ret_len);
+ ok_(__FILE__, line)(ret, "QueryInformationJobObject error %lu\n", GetLastError());
+ if (ret)
+ {
+ todo_wine_if(expected_count)
+ ok_(__FILE__, line)(expected_count == pid_list->NumberOfAssignedProcesses,
+ "Expected NumberOfAssignedProcesses to be %d (expected_count) is %ld\n",
+ expected_count, pid_list->NumberOfAssignedProcesses);
+ todo_wine_if(expected_count)
+ ok_(__FILE__, line)(expected_count == pid_list->NumberOfProcessIdsInList,
+ "Expected NumberOfProcessIdsInList to be %d (expected_count) is %ld\n",
+ expected_count, pid_list->NumberOfProcessIdsInList);
+
+ va_start(valist, expected_count);
+ for (n = 0; n < min(expected_count, pid_list->NumberOfProcessIdsInList); ++n)
+ {
+ pid = va_arg(valist, DWORD);
+ ok_(__FILE__, line)(pid == pid_list->ProcessIdList[n],
+ "Expected pid_list->ProcessIdList[%d] to be %lx is %Ix\n",
+ n, pid, pid_list->ProcessIdList[n]);
+ }
+ va_end(valist);
+ }
+}
+
+#define test_accounting(job, total_proc, active_proc, terminated_proc) _test_accounting(__LINE__, job, total_proc, active_proc, terminated_proc)
+static void _test_accounting(int line, HANDLE job, int total_proc, int active_proc, int terminated_proc)
+{
+ JOBOBJECT_BASIC_ACCOUNTING_INFORMATION basic_accounting;
+ DWORD ret_len;
+ BOOL ret;
+
+ memset(&basic_accounting, 0, sizeof(basic_accounting));
+ ret = pQueryInformationJobObject(job, JobObjectBasicAccountingInformation, &basic_accounting, sizeof(basic_accounting), &ret_len);
+ ok_(__FILE__, line)(ret, "QueryInformationJobObject error %lu\n", GetLastError());
+ if (ret)
+ {
+ /* Not going to check process times or page faults */
+
+ todo_wine_if(total_proc)
+ ok_(__FILE__, line)(total_proc == basic_accounting.TotalProcesses,
+ "Expected basic_accounting.TotalProcesses to be %d (total_proc) is %ld\n",
+ total_proc, basic_accounting.TotalProcesses);
+ todo_wine_if(active_proc)
+ ok_(__FILE__, line)(active_proc == basic_accounting.ActiveProcesses,
+ "Expected basic_accounting.ActiveProcesses to be %d (active_proc) is %ld\n",
+ active_proc, basic_accounting.ActiveProcesses);
+ ok_(__FILE__, line)(terminated_proc == basic_accounting.TotalTerminatedProcesses,
+ "Expected basic_accounting.TotalTerminatedProcesses to be %d (terminated_proc) is %ld\n",
+ terminated_proc, basic_accounting.TotalTerminatedProcesses);
+ }
+}
static void test_IsProcessInJob(void)
{
@@ -2566,11 +2629,15 @@ static void test_IsProcessInJob(void)
ret = pIsProcessInJob(pi.hProcess, job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(!out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job, 0);
+ test_accounting(job, 0, 0, 0);
out = TRUE;
ret = pIsProcessInJob(pi.hProcess, job2, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(!out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job2, 0);
+ test_accounting(job2, 0, 0, 0);
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(ret, "AssignProcessToJobObject error %lu\n", GetLastError());
@@ -2579,11 +2646,15 @@ static void test_IsProcessInJob(void)
ret = pIsProcessInJob(pi.hProcess, job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job, 1, pi.dwProcessId);
+ test_accounting(job, 1, 1, 0);
out = TRUE;
ret = pIsProcessInJob(pi.hProcess, job2, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(!out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job2, 0);
+ test_accounting(job2, 0, 0, 0);
out = FALSE;
ret = pIsProcessInJob(pi.hProcess, NULL, &out);
@@ -2597,6 +2668,8 @@ static void test_IsProcessInJob(void)
ret = pIsProcessInJob(pi.hProcess, job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job, 0);
+ test_accounting(job, 1, 0, 0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
@@ -2613,11 +2686,15 @@ static void test_TerminateJobObject(void)
job = pCreateJobObjectW(NULL, NULL);
ok(job != NULL, "CreateJobObject error %lu\n", GetLastError());
+ test_assigned_proc(job, 0);
+ test_accounting(job, 0, 0, 0);
create_process("wait", &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(ret, "AssignProcessToJobObject error %lu\n", GetLastError());
+ test_assigned_proc(job, 1, pi.dwProcessId);
+ test_accounting(job, 1, 1, 0);
ret = pTerminateJobObject(job, 123);
ok(ret, "TerminateJobObject error %lu\n", GetLastError());
@@ -2626,6 +2703,8 @@ static void test_TerminateJobObject(void)
dwret = WaitForSingleObject(pi.hProcess, 1000);
ok(dwret == WAIT_OBJECT_0, "WaitForSingleObject returned %lu\n", dwret);
if (dwret == WAIT_TIMEOUT) TerminateProcess(pi.hProcess, 0);
+ test_assigned_proc(job, 0);
+ test_accounting(job, 1, 0, 0);
ret = GetExitCodeProcess(pi.hProcess, &dwret);
ok(ret, "GetExitCodeProcess error %lu\n", GetLastError());
@@ -2643,6 +2722,8 @@ static void test_TerminateJobObject(void)
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(!ret, "AssignProcessToJobObject unexpectedly succeeded\n");
expect_eq_d(ERROR_ACCESS_DENIED, GetLastError());
+ test_assigned_proc(job, 0);
+ test_accounting(job, 1, 0, 0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
@@ -2841,11 +2922,15 @@ static void test_KillOnJobClose(void)
return;
}
ok(ret, "SetInformationJobObject error %lu\n", GetLastError());
+ test_assigned_proc(job, 0);
+ test_accounting(job, 0, 0, 0);
create_process("wait", &pi);
ret = pAssignProcessToJobObject(job, pi.hProcess);
ok(ret, "AssignProcessToJobObject error %lu\n", GetLastError());
+ test_assigned_proc(job, 1, pi.dwProcessId);
+ test_accounting(job, 1, 1, 0);
CloseHandle(job);
@@ -2955,6 +3040,8 @@ static HANDLE test_AddSelfToJob(void)
ret = pAssignProcessToJobObject(job, GetCurrentProcess());
ok(ret, "AssignProcessToJobObject error %lu\n", GetLastError());
+ test_assigned_proc(job, 1, GetCurrentProcessId());
+ test_accounting(job, 1, 1, 0);
return job;
}
@@ -2976,6 +3063,8 @@ static void test_jobInheritance(HANDLE job)
ret = pIsProcessInJob(pi.hProcess, job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job, 2, GetCurrentProcessId(), pi.dwProcessId);
+ test_accounting(job, 2, 2, 0);
wait_and_close_child_process(&pi);
}
@@ -3009,6 +3098,8 @@ static void test_BreakawayOk(HANDLE parent_job)
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, &si, &pi);
ok(!ret, "CreateProcessA expected failure\n");
expect_eq_d(ERROR_ACCESS_DENIED, GetLastError());
+ test_assigned_proc(job, 1, GetCurrentProcessId());
+ test_accounting(job, 2, 1, 0);
if (ret)
{
@@ -3048,6 +3139,8 @@ static void test_BreakawayOk(HANDLE parent_job)
ret = pIsProcessInJob(pi.hProcess, job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(!out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job, 1, GetCurrentProcessId());
+ test_accounting(job, 2, 1, 0);
ret = pIsProcessInJob(pi.hProcess, parent_job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
@@ -3065,6 +3158,8 @@ static void test_BreakawayOk(HANDLE parent_job)
ret = pIsProcessInJob(pi.hProcess, job, &out);
ok(ret, "IsProcessInJob error %lu\n", GetLastError());
ok(!out, "IsProcessInJob returned out=%u\n", out);
+ test_assigned_proc(job, 1, GetCurrentProcessId());
+ test_accounting(job, 2, 1, 0);
wait_and_close_child_process(&pi);
--
2.35.1

View File

@ -1 +1 @@
65864f92f22f6d4668c1c06ed6ef3fe49bfdcfa7
9e639ff1f6c2b913518501b3f99ca085c4eed6c7