From 72eefb7a68abc69f765bb225e36524a53a28276c Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Wed, 10 Aug 2016 20:50:36 +0000 Subject: [PATCH] [KMTESTS:FSRTL] Add a stress test for tunnel cache implementation, where we have fun adding duplicated entries. It doesn't seem to go well. These tests are also known as "Learn your English ordinals", or as "Learn how to count in English". My pleasure. CORE-11819 svn path=/trunk/; revision=72192 --- rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c | 112 ++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c b/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c index 1afe176ffca..206b3c80ced 100644 --- a/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c +++ b/rostests/kmtests/ntos_fsrtl/FsRtlTunnel.c @@ -121,6 +121,116 @@ void TestFsRtlDeleteKeyFromTunnelCache(ULONGLONG a) FsRtlDeleteKeyFromTunnelCache(T, a); } +static +void DuplicatesTest() +{ + UNICODE_STRING ShortName, LongName, OutShort, OutLong, ShortName2, LongName2; + ULONG First, Second, OutLength, OutData; + PTUNNEL Tunnel; + PVOID Buffer; + + First = 1; + Second = 2; + RtlInitUnicodeString(&ShortName, L"LONGFI~1.TXT"); + RtlInitUnicodeString(&LongName, L"Longfilename.txt"); + RtlInitUnicodeString(&ShortName2, L"LONGFI~2.TXT"); + RtlInitUnicodeString(&LongName2, L"Longfilenamr.txt"); + Tunnel = ExAllocatePool(NonPagedPool, sizeof(TUNNEL)); + RtlZeroMemory(Tunnel, sizeof(TUNNEL)); + OutShort.MaximumLength = 13 * sizeof(WCHAR); + OutShort.Buffer = ExAllocatePool(PagedPool, OutShort.MaximumLength); + OutLong.MaximumLength = 17 * sizeof(WCHAR); + OutLong.Buffer = Buffer = ExAllocatePool(PagedPool, OutLong.MaximumLength); + + FsRtlInitializeTunnelCache(Tunnel); + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName, &LongName, TRUE, sizeof(ULONG), &First); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "First call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + ok_eq_pointer(OutLong.Buffer, Buffer); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName, &LongName, TRUE, sizeof(ULONG), &Second); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Second call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + ok_eq_pointer(OutLong.Buffer, Buffer); + + OutLong.MaximumLength = 13 * sizeof(WCHAR); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Third call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + ok(OutLong.Buffer != Buffer, "Buffer didn't get reallocated!\n"); + ok_eq_uint(OutLong.MaximumLength, 16 * sizeof(WCHAR)); + + FsRtlDeleteKeyFromTunnelCache(Tunnel, 1); + ok_bool_false(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Fourth call"); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName, &LongName, TRUE, sizeof(ULONG), &First); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Fifth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName2, &LongName2, TRUE, sizeof(ULONG), &First); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Sixth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName2, &OutShort, &OutLong, &OutLength, &OutData), "Seventh call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName, &LongName, TRUE, sizeof(ULONG), &Second); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Eighth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName2, &OutShort, &OutLong, &OutLength, &OutData), "Ninth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName2, &LongName2, TRUE, sizeof(ULONG), &Second); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Tenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName2, &OutShort, &OutLong, &OutLength, &OutData), "Eleventh call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + + FsRtlDeleteKeyFromTunnelCache(Tunnel, 1); + ok_bool_false(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Twelfth call"); + ok_bool_false(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName2, &OutShort, &OutLong, &OutLength, &OutData), "Thirteenth call"); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName, &LongName, TRUE, sizeof(ULONG), &First); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Fourteenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName, &LongName, TRUE, sizeof(ULONG), &Second); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Fifteenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName2, &LongName2, TRUE, sizeof(ULONG), &First); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Sixteenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName2, &OutShort, &OutLong, &OutLength, &OutData), "Seventeenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 1); + + FsRtlAddToTunnelCache(Tunnel, 1, &ShortName2, &LongName2, TRUE, sizeof(ULONG), &Second); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName, &OutShort, &OutLong, &OutLength, &OutData), "Eighteenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + ok_bool_true(FsRtlFindInTunnelCache(Tunnel, 1, &ShortName2, &OutShort, &OutLong, &OutLength, &OutData), "Nineteenth call"); + ok_eq_ulong(OutLength, sizeof(ULONG)); + ok_eq_ulong(OutData, 2); + + FsRtlDeleteTunnelCache(Tunnel); + ExFreePool(OutShort.Buffer); + ExFreePool(OutLong.Buffer); + ExFreePool(Buffer); + ExFreePool(Tunnel); +} + START_TEST(FsRtlTunnel) { PUNICODE_STRING s_name; @@ -183,4 +293,6 @@ START_TEST(FsRtlTunnel) ExFreePool(Tb); ExFreePool(T); + + DuplicatesTest(); }