test: tmovmem.c File Reference

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

# tmovmem.c File Reference

`#include <nt.h>`
`#include <ntrtl.h>`
`#include <stdio.h>`
`#include "localrtl.h"`

Go to the source code of this file.

## Defines

#define | MIN_OVERLAP (-(MAX_LENGTH + MAX_MARGIN))
#define | MAX_OVERLAP (MAX_LENGTH + MAX_MARGIN - 1)
#define | BUFFER_SIZE (MAX_MARGIN + MAX_LENGTH + MAX_MARGIN + MAX_OFFSET + MAX_LENGTH + MAX_MARGIN + MAX_LENGTH + MAX_MARGIN)

## Functions

void __cdecl | main ()

## Variables

UCHAR | Buffer0 [BUFFER_SIZE]
UCHAR | Buffer1 [BUFFER_SIZE]
UCHAR | Buffer2 [BUFFER_SIZE]

## Define Documentation

#define BUFFER_SIZE (MAX_MARGIN + MAX_LENGTH + MAX_MARGIN + MAX_OFFSET + MAX_LENGTH + MAX_MARGIN + MAX_LENGTH + MAX_MARGIN)

| Definition at line 48 of file tmovmem.c.

#define MAX_OVERLAP (MAX_LENGTH + MAX_MARGIN - 1)

| Definition at line 46 of file tmovmem.c. Referenced by main().

#define MIN_OVERLAP (-(MAX_LENGTH + MAX_MARGIN))

| Definition at line 45 of file tmovmem.c. Referenced by main().

## Function Documentation

void __cdecl main | ( |  | ) |

Definition at line 56 of file tmovmem.c.

References Buffer0, Buffer1, Buffer2, BUFFER_SIZE, FillPattern(), LocalCompareMemory(), LocalMoveMemory(), MAX_LENGTH, MAX_MARGIN, MAX_OFFSET, MAX_OVERLAP, MIN_OVERLAP, and Offset.

    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 }

## Variable Documentation

UCHAR Buffer0[BUFFER_SIZE]

| Definition at line 50 of file tmovmem.c. Referenced by main().

UCHAR Buffer1[BUFFER_SIZE]

| Definition at line 51 of file tmovmem.c.

UCHAR Buffer2[BUFFER_SIZE]

| Definition at line 52 of file tmovmem.c.