diff options
| author | ruki <[email protected]> | 2018-05-11 00:44:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-05-10 22:25:32 +0800 |
| commit | e43926b47af1b535d066dabe0bde86317cf85648 (patch) | |
| tree | 7969df770ae8dae92e7686cd6d77b41d2591f89a /tests/projects | |
| parent | 6cf4df42c737fc71012c68a0943edc0bf30c3649 (diff) | |
seperate qt and wdk rules
Diffstat (limited to 'tests/projects')
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.c | 407 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.h | 34 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.man | 101 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/kcs.rc | 1 | ||||
| -rw-r--r-- | tests/projects/wdk/kmdf/perfcounters/xmake.lua | 13 |
5 files changed, 556 insertions, 0 deletions
diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.c b/tests/projects/wdk/kmdf/perfcounters/kcs.c new file mode 100644 index 000000000..9996addcb --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.c @@ -0,0 +1,407 @@ +/*++
+
+Copyright (c) Microsoft Corporation. All rights reserved.
+
+ THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
+ PURPOSE.
+
+Module Name:
+
+ kcs.c
+
+Abstract:
+
+ This module contains sample code to demonstrate how to provide
+ counter data from a kernel driver.
+
+Environment:
+
+ Kernel mode only.
+
+--*/
+
+
+#include <wdm.h>
+#include "kcs.h"
+#include "kcsCounters.h"
+
+#pragma code_seg("PAGE")
+
+DRIVER_INITIALIZE DriverEntry;
+DRIVER_UNLOAD KcsUnload;
+
+NTSTATUS
+KcsAddGeometricInstance (
+ _In_ PPCW_BUFFER Buffer,
+ _In_ PCWSTR Name,
+ _In_ ULONG MinimalValue,
+ _In_ ULONG Amplitude
+ )
+
+/*++
+
+Routine Description:
+
+ This utility function adds instance to the callback buffer.
+
+Arguments:
+
+ Buffer - Data will be returned in this buffer.
+
+ Name - Name of instances to be added.
+
+ MinimalValue - Minimum value of the wave.
+
+ Amplitude - Amplitude of the wave.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ ULONG Index;
+ LARGE_INTEGER Timestamp;
+ UNICODE_STRING UnicodeName;
+ GEOMETRIC_WAVE_VALUES Values;
+
+ PAGED_CODE();
+
+ KeQuerySystemTime(&Timestamp);
+
+ Index = (Timestamp.QuadPart / 10000000) % 10;
+
+ Values.Triangle = MinimalValue + Amplitude * abs(5 - Index) / 5;
+ Values.Square = MinimalValue + Amplitude * (Index < 5);
+
+ RtlInitUnicodeString(&UnicodeName, Name);
+
+ return KcsAddGeometricWave(Buffer, &UnicodeName, 0, &Values);
+}
+
+NTSTATUS NTAPI
+KcsGeometricWaveCallback (
+ _In_ PCW_CALLBACK_TYPE Type,
+ _In_ PPCW_CALLBACK_INFORMATION Info,
+ _In_opt_ PVOID Context
+ )
+
+/*++
+
+Routine Description:
+
+ This function returns the list of counter instances and counter data.
+
+Arguments:
+
+ Type - Request type.
+
+ Info - Buffer for returned data.
+
+ Context - Not used.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ NTSTATUS Status;
+ UNICODE_STRING UnicodeName;
+
+ UNREFERENCED_PARAMETER(Context);
+
+ PAGED_CODE();
+
+ switch (Type) {
+ case PcwCallbackEnumerateInstances:
+
+ //
+ // Instances are being enumerated, so we add them without values.
+ //
+
+ RtlInitUnicodeString(&UnicodeName, L"Small Wave");
+ Status = KcsAddGeometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ RtlInitUnicodeString(&UnicodeName, L"Medium Wave");
+ Status = KcsAddGeometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ RtlInitUnicodeString(&UnicodeName, L"Large Wave");
+ Status = KcsAddGeometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ break;
+
+ case PcwCallbackCollectData:
+
+ //
+ // Add values for 3 instances of Geometric Wave Counter Set.
+ //
+
+ Status = KcsAddGeometricInstance(Info->CollectData.Buffer,
+ L"Small Wave",
+ 40,
+ 20);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ Status = KcsAddGeometricInstance(Info->CollectData.Buffer,
+ L"Medium Wave",
+ 30,
+ 40);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ Status = KcsAddGeometricInstance(Info->CollectData.Buffer,
+ L"Large Wave",
+ 20,
+ 60);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ break;
+ }
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+KcsAddTrignometricInstance (
+ _In_ PPCW_BUFFER Buffer,
+ _In_ PCWSTR Name,
+ _In_ ULONG MinimalValue,
+ _In_ ULONG Amplitude
+ )
+
+/*++
+
+Routine Description:
+
+ This utility function adds instance to the callback buffer.
+
+Arguments:
+
+ Buffer - Data will be returned in this buffer.
+
+ Name - Name of instances to be added.
+
+ MinimalValue - Minimum value of the wave.
+
+ Amplitude - Amplitude of the wave.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ double Angle;
+ KFLOATING_SAVE FloatSave;
+ NTSTATUS Status;
+ LARGE_INTEGER Timestamp;
+ UNICODE_STRING UnicodeName;
+ TRIGNOMETRIC_WAVE_VALUES Values;
+
+ PAGED_CODE();
+
+ Status = KeSaveFloatingPointState(&FloatSave);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ KeQuerySystemTime(&Timestamp);
+
+ Angle = (double)(Timestamp.QuadPart / 400000) * (22/7) / 180;
+
+ Values.Constant = MinimalValue;
+ Values.Cosine = (ULONG)(MinimalValue + Amplitude * cos(Angle));
+ Values.Sine = (ULONG)(MinimalValue + Amplitude * sin(Angle));
+
+ KeRestoreFloatingPointState(&FloatSave);
+
+ //
+ // Add instance name & values to the caller's buffer.
+ //
+
+ RtlInitUnicodeString(&UnicodeName, Name);
+
+ return KcsAddTrignometricWave(Buffer, &UnicodeName, 0, &Values);
+}
+
+NTSTATUS NTAPI
+KcsTrignometricWaveCallback (
+ _In_ PCW_CALLBACK_TYPE Type,
+ _In_ PPCW_CALLBACK_INFORMATION Info,
+ _In_opt_ PVOID Context
+ )
+
+/*++
+
+Routine Description:
+
+ This function returns the list of counter instances and counter data.
+
+Arguments:
+
+ Type - Request type.
+
+ Info - Buffer for returned data.
+
+ Context - Not used.
+
+Return Value:
+
+ NTSTATUS indicating if the function succeeded.
+
+--*/
+
+{
+ NTSTATUS Status;
+ UNICODE_STRING UnicodeName;
+
+ UNREFERENCED_PARAMETER(Context);
+
+ PAGED_CODE();
+
+ switch (Type) {
+ case PcwCallbackEnumerateInstances:
+ RtlInitUnicodeString(&UnicodeName, L"default");
+ Status = KcsAddTrignometricWave(Info->EnumerateInstances.Buffer,
+ &UnicodeName,
+ 0,
+ NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ break;
+
+ case PcwCallbackCollectData:
+
+ //
+ // Add values for Single Instance of Trignometirc Wave Counter Set.
+ //
+
+ return KcsAddTrignometricInstance(Info->CollectData.Buffer,
+ L"default",
+ 50,
+ 30);
+ }
+
+ return STATUS_SUCCESS;
+}
+
+VOID
+KcsUnload (
+ _In_ PDRIVER_OBJECT DriverObject
+ )
+
+/*++
+
+Routine Description:
+
+ This function unregisters countersets
+
+Arguments:
+
+ DriverObject - Not used.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+ UNREFERENCED_PARAMETER(DriverObject);
+
+ PAGED_CODE();
+
+ //
+ // Unregister Countersets.
+ //
+
+ KcsUnregisterGeometricWave();
+ KcsUnregisterTrignometricWave();
+}
+
+NTSTATUS
+DriverEntry (
+ _In_ PDRIVER_OBJECT DriverObject,
+ _In_ PUNICODE_STRING RegistryPath
+ )
+
+/*++
+
+Routine Description:
+
+ This function registers countersets on initial loading of the driver.
+
+Arguments:
+
+ DriverObject - Supplies the driver object of the driver being loaded.
+
+ RegistryPath - Not used.
+
+Return Value:
+
+ NTSTATUS indicating if driver was properly loaded.
+
+--*/
+
+{
+ NTSTATUS Status;
+
+ UNREFERENCED_PARAMETER(RegistryPath);
+
+ PAGED_CODE();
+
+ //
+ // Register Countersets.
+ //
+
+ Status = KcsRegisterGeometricWave(KcsGeometricWaveCallback, NULL);
+ if (!NT_SUCCESS(Status)) {
+ return Status;
+ }
+
+ Status = KcsRegisterTrignometricWave(KcsTrignometricWaveCallback, NULL);
+ if (!NT_SUCCESS(Status)) {
+ KcsUnregisterTrignometricWave();
+ return Status;
+ }
+
+ //
+ // Success path - set up unload routine and return success.
+ //
+
+ DriverObject->DriverUnload = KcsUnload;
+
+ return STATUS_SUCCESS;
+}
+
diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.h b/tests/projects/wdk/kmdf/perfcounters/kcs.h new file mode 100644 index 000000000..f575b816d --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.h @@ -0,0 +1,34 @@ +/*++
+
+Copyright (c) Microsoft Corporation. All rights reserved.
+
+ THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
+ PURPOSE.
+
+Module Name:
+
+ kcs.h
+
+Abstract:
+
+ This module contains sample code to demonstrate how to provide
+ counter data from a kernel driver.
+
+Environment:
+
+ Kernel mode only.
+
+--*/
+
+typedef struct _GEOMETRIC_WAVE_VALUES {
+ ULONG Square;
+ ULONG Triangle;
+} GEOMETRIC_WAVE_VALUES, *PGEOMETRIC_WAVE_VALUES;
+
+typedef struct _TRIGNOMETRIC_WAVE_VALUES {
+ ULONG Constant;
+ ULONG Cosine;
+ ULONG Sine;
+} TRIGNOMETRIC_WAVE_VALUES, *PTRIGNOMETRIC_WAVE_VALUES;
\ No newline at end of file diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.man b/tests/projects/wdk/kmdf/perfcounters/kcs.man new file mode 100644 index 000000000..a5a16ffbd --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.man @@ -0,0 +1,101 @@ +<instrumentationManifest + xmlns="http://schemas.microsoft.com/win/2004/08/events" + xmlns:trace="http://schemas.microsoft.com/win/2004/08/events/trace" + xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" + > + <instrumentation> + <counters + xmlns="http://schemas.microsoft.com/win/2005/12/counters" + xmlns:auto-ns1="http://schemas.microsoft.com/win/2004/08/events" + schemaVersion="1.1" + > + <provider callback = "custom" + applicationIdentity = "Kcs.sys" + providerType = "kernelMode" + providerName = "KernelCountersSample" + providerGuid = "{d2ffffff-965a-4cf9-9c07-fe25378c2a23}"> + <counterSet guid = "{d2ffffff-c923-4794-b696-70577630b5cf}" + uri = "Microsoft.Wdk.Samples.Kcs.GeometricWave" + name = "Geometric Waves" + description = "This counter set displays a Triangle and a Square wave" + symbol = "GeometricWave" + instances = "multipleAggregate" + > + <structs> + <struct name="GeometricWaveValues" type="GEOMETRIC_WAVE_VALUES"/> + </structs> + <counter id = "1" + uri = "Microsoft.Wdk.Samples.Kcs.GeometricWave.Triangle" + name = "Triangle" + struct = "GeometricWaveValues" + field = "Triangle" + description = "This counter displays triangle wave" + aggregate = "avg" + type = "perf_counter_rawcount" + detailLevel = "standard"> + </counter> + + <counter id = "2" + uri = "Microsoft.Wdk.Samples.Kcs.GeometricWave.Square" + name = "Square Wave" + struct = "GeometricWaveValues" + field = "Square" + description = "This counter displays Square Wave" + aggregate = "avg" + type = "perf_counter_rawcount" + detailLevel = "standard"> + </counter> + </counterSet> + <counterSet guid = "{ffffffff-eaa6-45ba-bf6d-4c7cb0d6ef73}" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave" + name = "Trignometric Waves" + description = "This counter set displays a sine, cosine and a constant wave" + symbol = "TrignometricWave" + instances = "single"> + <structs> + <struct name="TrignometricWaveValues" type="TRIGNOMETRIC_WAVE_VALUES"/> + </structs> + <counter id = "1" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave.Sine" + name = "Sine Wave" + description = "This counter displays Sine Wave" + struct = "TrignometricWaveValues" + field = "Sine" + type = "perf_counter_rawcount" + detailLevel = "standard"> + <counterAttributes> + <counterAttribute name = "reference" /> + </counterAttributes> + </counter> + <counter id = "2" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave.Cosine" + name = "Cosine Wave" + description = "This counter displays Cosine Wave" + struct = "TrignometricWaveValues" + field = "Cosine" + type = "perf_counter_rawcount" + detailLevel = "standard"> + <counterAttributes> + <counterAttribute name = "reference" /> + </counterAttributes> + </counter> + <counter id = "3" + uri = "Microsoft.Wdk.Samples.Kcs.TrignometricWave.Constant" + name = "Constant Value" + description = "This counter displays Constant Value" + struct = "TrignometricWaveValues" + field = "Constant" + type = "perf_counter_rawcount" + detailLevel = "standard"> + <counterAttributes> + <counterAttribute name = "reference" /> + </counterAttributes> + </counter> + </counterSet> + </provider> + </counters> + </instrumentation> +</instrumentationManifest>
\ No newline at end of file diff --git a/tests/projects/wdk/kmdf/perfcounters/kcs.rc b/tests/projects/wdk/kmdf/perfcounters/kcs.rc new file mode 100644 index 000000000..7ebb6b97b --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/kcs.rc @@ -0,0 +1 @@ +#include "kcsCounters.rc"
diff --git a/tests/projects/wdk/kmdf/perfcounters/xmake.lua b/tests/projects/wdk/kmdf/perfcounters/xmake.lua new file mode 100644 index 000000000..3e6e0bb63 --- /dev/null +++ b/tests/projects/wdk/kmdf/perfcounters/xmake.lua @@ -0,0 +1,13 @@ + +-- add modes: debug and release +add_rules("mode.debug", "mode.release") + +-- add target +target("kcs") + + -- add rules + add_rules("wdk.kmdf.driver") + + -- add files + add_files("*.c", "*.rc", "*.man") + |
