Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

tmovmem.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1993 Digital Equipment Corporation 00004 00005 Module Name: 00006 00007 tmovmem.c 00008 00009 Abstract: 00010 00011 This module implements a test of the operation of the RtlMoveMemory 00012 function by running an exhaustive test of every case of string offset, 00013 move length, and relative overlap of the two strings up to and a little 00014 beyond one 32-byte cache line. This represents several hundred thousand 00015 test cases. It is assumed any bugs that exist will be found within this 00016 range. If only the error count summary is desired, type "tmovmem > nul" 00017 instead. 00018 00019 Author: 00020 00021 Thomas Van Baak (tvb) 13-Jan-1993 00022 00023 Environment: 00024 00025 User mode. 00026 00027 Revision History: 00028 00029 --*/ 00030 00031 #include <nt.h> 00032 #include <ntrtl.h> 00033 #include <stdio.h> 00034 #include "localrtl.h" 00035 00036 // 00037 // Two strings are defined within a large buffer. The target string is 00038 // initially below the source string with a small gap between the two 00039 // strings. A margin around the strings ensures any bytes accidentally 00040 // changed outside the strings are detectable. As the length of the strings 00041 // and the offset of the source string are varied, the target string wanders 00042 // from well below, through, and well above the source string. 00043 // 00044 00045 #define MIN_OVERLAP (-(MAX_LENGTH + MAX_MARGIN)) 00046 #define MAX_OVERLAP (MAX_LENGTH + MAX_MARGIN - 1) 00047 00048 #define BUFFER_SIZE (MAX_MARGIN + MAX_LENGTH + MAX_MARGIN + MAX_OFFSET + MAX_LENGTH + MAX_MARGIN + MAX_LENGTH + MAX_MARGIN) 00049 00050 UCHAR Buffer0[BUFFER_SIZE]; 00051 UCHAR Buffer1[BUFFER_SIZE]; 00052 UCHAR Buffer2[BUFFER_SIZE]; 00053 00054 void 00055 __cdecl 00056 main() 00057 { 00058 ULONG ErrorCount; 00059 ULONG Length; 00060 ULONG Offset; 00061 LONG Overlap; 00062 ULONG Result; 00063 ULONG Source; 00064 ULONG Target; 00065 ULONG TestCases; 00066 00067 fprintf(stderr, "Testing RtlMoveMemory\n"); 00068 ErrorCount = 0; 00069 TestCases = 0; 00070 00071 // 00072 // Make a call to RtlMoveMemory for all possible source string offsets 00073 // within a cache line, for a large set of string lengths, and a wide 00074 // range of positions of the target string relative to the source string, 00075 // including all possible overlapping string configurations. 00076 // 00077 00078 for (Offset = 0; Offset <= MAX_OFFSET; Offset += 1) { 00079 for (Length = 0; Length <= MAX_LENGTH; Length += 1) { 00080 for (Overlap = MIN_OVERLAP; Overlap <= MAX_OVERLAP; Overlap += 1) { 00081 00082 // 00083 // The same string configuration is made in two different 00084 // buffers. RtlMoveMemory is used on the two strings in one 00085 // buffer and the trusted LocalMoveMemory on the two strings 00086 // in the other buffer. The entire buffers are compared to 00087 // determine if the two move functions agree. 00088 // 00089 00090 FillPattern(Buffer1, BUFFER_SIZE); 00091 FillPattern(Buffer2, BUFFER_SIZE); 00092 00093 Source = MAX_MARGIN + MAX_LENGTH + MAX_MARGIN + Offset; 00094 Target = Source + Overlap; 00095 00096 LocalMoveMemory(&Buffer1[Target], &Buffer1[Source], Length); 00097 RtlMoveMemory(&Buffer2[Target], &Buffer2[Source], Length); 00098 00099 Result = LocalCompareMemory(Buffer1, Buffer2, BUFFER_SIZE); 00100 00101 TestCases += 1; 00102 if (Result != BUFFER_SIZE) { 00103 ErrorCount += 1; 00104 00105 printf("ERROR: Offset = %d, Length = %d, Overlap = %d\n", 00106 Offset, Length, Overlap); 00107 printf("RtlMoveMemory( &Buffer[ %d ], &Buffer[ %d ], %d )\n", 00108 Target, Source, Length); 00109 00110 FillPattern(Buffer0, BUFFER_SIZE); 00111 printf(" Original Source = %lx: <%.*s>\n", 00112 &Buffer0[Source], Length, &Buffer0[Source]); 00113 printf(" Expected Target = %lx: <%.*s>\n", 00114 &Buffer1[Target], Length, &Buffer1[Target]); 00115 printf(" Actual Target = %lx: <%.*s>\n", 00116 &Buffer2[Target], Length, &Buffer2[Target]); 00117 printf("\n"); 00118 printf("Buffers differ starting at byte %d:\n", Result); 00119 printf("Buffer1 = <%*s>\n", BUFFER_SIZE, Buffer1); 00120 printf("Buffer2 = <%*s>\n", BUFFER_SIZE, Buffer2); 00121 printf("\n"); 00122 } 00123 } 00124 } 00125 } 00126 00127 fprintf(stderr, "Test of RtlMoveMemory completed: "); 00128 fprintf(stderr, "%d test cases, %d errors found.\n", TestCases, ErrorCount); 00129 }

Generated on Sat May 15 19:42:00 2004 for test by doxygen 1.3.7