ReactOS 0.4.16-dev-975-g3b8cfa4
NtStartProfile.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Test for NtStartProfile
5 * COPYRIGHT: Copyright 2021 Thomas Faber (thomas.faber@reactos.org)
6 */
7
8#include "precomp.h"
9#include <versionhelpers.h>
10
11#define SIZEOF_MDL (5 * sizeof(PVOID) + 2 * sizeof(ULONG))
13/* Maximum size that can be described by an MDL on 2003 and earlier */
14#define MAX_MDL_BUFFER_SIZE ((MAXUSHORT - SIZEOF_MDL) / sizeof(PFN_NUMBER) * PAGE_SIZE + PAGE_SIZE - 1)
15
18static ULONG DummyBuffer[4096];
19
20/* The "Buffer[Offset]++;" should likely be within 128 bytes of the start
21 * of the function on any architecture we support
22 */
23#define LOOP_FUNCTION_SIZE_SHIFT 7
24#define LOOP_FUNCTION_SIZE (1UL << LOOP_FUNCTION_SIZE_SHIFT)
26typedef void LOOP_FUNCTION(volatile ULONG *, ULONG, ULONG);
27static
28void
31 _In_ ULONG BufferSizeInElements,
32 _In_ ULONG LoopCount)
33{
34 ULONG i;
36
37 for (i = 0; i < LoopCount; i++)
38 {
39 for (Offset = 0; Offset < BufferSizeInElements; Offset++)
40 {
41 Buffer[Offset]++;
42 }
43 }
44}
45
46static
47void
52 _In_range_(0, BufferSize / sizeof(ULONG)) ULONG BufferOffset
53 )
54{
56 HANDLE ProfileHandle;
57 ULONG Buffer1Value;
58
59 Status = NtCreateProfile(&ProfileHandle,
64 Buffer,
69 if (!NT_SUCCESS(Status))
70 {
71 skip("Failed to create profile\n");
72 return;
73 }
74
75 Status = NtStartProfile(ProfileHandle);
77
78 /* Can't validate Buffer contents here, since we don't know what's next to our function */
79
80 /*
81 * This takes around 10-12 seconds on my machine, which is not ideal.
82 * But on my Win2003 VM it only results in counts of 10-12,
83 * which means we can't really make it shorter.
84 */
85
86 /* Run a long loop */
89 1000000);
90
91 /* The buffer should get live updates */
92 Buffer1Value = Buffer[BufferOffset];
93 ok(Buffer1Value != 0, "Buffer[%lu] = %lu\n", BufferOffset, Buffer1Value);
94
95 /* Run a shorter loop, we should see a smaller increase */
98 200000);
99
100 ok(Buffer[BufferOffset] > Buffer1Value,
101 "Buffer[%lu] = %lu, expected more than %lu\n",
102 BufferOffset, Buffer[BufferOffset], Buffer1Value);
103
104 Status = NtStopProfile(ProfileHandle);
106
107 /* The expectation is that Buffer[BufferOffset] is somewhere around 20% larger than Buffer1Value.
108 * Allow anywhere from one more count to twice as many to make the test robust.
109 */
110 ok(Buffer[BufferOffset] > Buffer1Value,
111 "Buffer[%lu] = %lu, expected more than %lu\n", BufferOffset, Buffer[BufferOffset], Buffer1Value);
112 ok(Buffer[BufferOffset] < 2 * Buffer1Value,
113 "Buffer[%lu] = %lu, expected less than %lu\n", BufferOffset, Buffer[BufferOffset], 2 * Buffer1Value);
114
115 trace("Buffer1Value = %lu\n", Buffer1Value);
116 trace("Buffer[%lu] = %lu\n", BufferOffset - 1, Buffer[BufferOffset - 1]);
117 trace("Buffer[%lu] = %lu\n", BufferOffset, Buffer[BufferOffset]);
118 trace("Buffer[%lu] = %lu\n", BufferOffset + 1, Buffer[BufferOffset + 1]);
119
120 Status = NtClose(ProfileHandle);
122}
123
125{
127 ULONG StackBuffer[3] = { 0 };
129
131
133
134 /* Parameter validation is pretty simple... */
137
138 /* Do an actual simple profile */
140 StackBuffer,
141 sizeof(StackBuffer),
142 1);
143}
static void LoopFunction(_Inout_updates_all_(BufferSize) volatile ULONG *Buffer, _In_ ULONG BufferSizeInElements, _In_ ULONG LoopCount)
void LOOP_FUNCTION(volatile ULONG *, ULONG, ULONG)
static BOOL IsWow64
#define LOOP_FUNCTION_SIZE
#define LOOP_FUNCTION_SIZE_SHIFT
static void ProfileLoopFunction(_In_ LOOP_FUNCTION *Function, _Out_writes_bytes_(BufferSize) PULONG Buffer, _In_ ULONG BufferSize, _In_range_(0, BufferSize/sizeof(ULONG)) ULONG BufferOffset)
static KAFFINITY SystemAffinityMask
static ULONG DummyBuffer[4096]
ULONG_PTR PFN_NUMBER
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
Definition: bufpool.h:45
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
ULONG_PTR KAFFINITY
Definition: compat.h:85
#define GetCurrentProcess()
Definition: compat.h:759
#define IsWow64Process
Definition: compat.h:760
BOOL WINAPI GetProcessAffinityMask(IN HANDLE hProcess, OUT PDWORD_PTR lpProcessAffinityMask, OUT PDWORD_PTR lpSystemAffinityMask)
Definition: proc.c:863
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ ProcessAffinityMask
Definition: winternl.h:877
@ ProfileTime
Definition: winternl.h:2123
#define C_ASSERT(e)
Definition: intsafe.h:73
#define _In_
Definition: no_sal2.h:158
#define _In_range_(l, h)
Definition: no_sal2.h:368
#define _Out_writes_bytes_(s)
Definition: no_sal2.h:178
#define _Inout_updates_all_(s)
Definition: no_sal2.h:200
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtStopProfile(IN HANDLE ProfileHandle)
Definition: profile.c:420
NTSTATUS NTAPI NtCreateProfile(OUT PHANDLE ProfileHandle, IN HANDLE Process OPTIONAL, IN PVOID RangeBase, IN SIZE_T RangeSize, IN ULONG BucketSize, IN PVOID Buffer, IN ULONG BufferSize, IN KPROFILE_SOURCE ProfileSource, IN KAFFINITY Affinity)
Definition: profile.c:89
NTSTATUS NTAPI NtStartProfile(IN HANDLE ProfileHandle)
Definition: profile.c:328
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254