home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
SOFTWARE
/
LIBS
/
EMSIF24A.ZIP
/
EMSTEST2.C
(
.txt
)
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-01
|
42KB
|
1,063 lines
/***************************************************************************
* emstest2.c *
* MODULE: EMSIF *
* OS: DOS *
* VERSION: 1.2 *
* DATE: 12/01/91 *
* *
* Copyright (c) 1991 James W. Birdsall. All Rights Reserved. *
* *
* Requires emsif.h, testutil.h, and emstest.h to compile. *
* Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.0A. *
* *
* Regression test and example for EMSIF. See EMSTEST.C for more detail. *
* *
***************************************************************************/
/*
** system includes <>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
** custom includes ""
*/
#include "testutil.h"
#include "emsif.h"
#include "emstest.h"
/*
** local #defines
*/
#define UCF unsigned char far
/*
** Checks to see if a region of memory is still incrementing word values,
** handles cleanup and exit if not.
*/
#define WORDCHECK(buf, len, msg) \
if (farincwordcheck((UCF *) (buf), (len), 0) != 0) { \
printf("Copy corrupted %s.\n", (msg)); EMMfree(handle); \
free(testbuf); exit(3); }
/*
** Check source and destination buffers, respectively.
*/
#define SRCWORDCHECK(buf, len) WORDCHECK(buf, len, "source buffer")
#define CPYWORDCHECK(buf, len) WORDCHECK(buf, len, "copied bytes")
/*
** Checks to see if a region of memory is still filled with a given value,
** handles cleanup and exit if not.
*/
#define MEMCHECK(buf, len, val) \
if (farmemcheck((UCF *) (buf), (len), (val)) != 0) { \
printf("Copy corrupted destination.\n"); \
EMMfree(handle); free(testbuf); exit(3); }
/*
** Checks buffer for nonzero values.
*/
#define ZEROCHECK(buf, len) MEMCHECK(buf, len, '\0')
/*
** Compares two regions of memory, handles cleanup and exit if not the same.
*/
#define MEMCMP(buf1, buf2, len) \
if (FMEMCMP((void far *) (buf1), (void far *) (buf2), (len)) != 0) { \
printf("Copy corrupted copied bytes.\n"); EMMfree(handle); \
free(testbuf); exit(3); }
/*
** misc: copyright strings, version macros, etc.
*/
/*
** typedefs
*/
/*
** global variables
*/
/* see EMSTEST.C for info */
extern int testno;
extern unsigned char far *frameptr[];
extern char *gblmsg;
/*
** static globals
*/
/*
** function prototypes
*/
static void do_nshortcopy_tests(void);
static void do_ishortcopy_tests(void);
/*
** functions
*/
/***************************************************************************
* FUNCTION: DO_SHORTCOPY_TESTS *
* *
* DESCRIPTION: *
* *
* Central dispatching function for short copy tests. *
* *
* ENTRY: *
* *
* Void. *
* *
* EXIT: *
* *
* Void. *
* *
* CONSTRAINTS/SIDE EFFECTS: *
* *
***************************************************************************/
void do_shortcopy_tests(void)
{
do_nshortcopy_tests();
do_ishortcopy_tests();
return;
} /* end of do_shortcopy_tests() */
/***************************************************************************
* FUNCTION: DO_NSHORTCOPY_TESTS (STATIC) *
* *
* DESCRIPTION: *
* *
* Tests EMSIF functions EMMcopyto() and EMMcopyfrom() with copies *
* shorter than one EMS page ( <= 16384 bytes ). *
* *
* ENTRY: *
* *
* Void. *
* *
* EXIT: *
* *
* Void. *
* *
* CONSTRAINTS/SIDE EFFECTS: *
* *
***************************************************************************/
static void do_nshortcopy_tests(void)
{
unsigned char *testbuf;
int handle;
int status;
unsigned long ticks, totticks;
int loop;
/* allocate memory to test against */
testbuf = (unsigned char *) malloc(16384);
if (testbuf == (unsigned char *) NULL)
{
printf("Cannot allocate test memory. Aborting.\n");
exit(1);
}
/* now allocate a page of EMS to test with */
handle = test_EMMallocpages(1);
/* fill test buffer with incrementing word pattern */
farincwordfill((UCF *) testbuf, 16384, 0);
/* fill EMS page with a different pattern */
test_EMMmappage(0, handle, 0);
FMEMSET(frameptr[0], 0, 16384);
/* try a bad copy first */
TESTHEADER();
printf("Calling EMMcopyto() with bad offset.\n");
printf("Should fail.\n");
status = EMMcopyto(5L, (UCF *) testbuf, handle, 20000L);
nofailcheck("EMMcopyto()", status, testbuf, handle, 0);
weirdretchk("EMMcopyto()", status, testbuf, handle, 0);
weirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
SRCWORDCHECK(testbuf, 16384);
test_EMMmappage(0, handle, 0);
ZEROCHECK(frameptr[0], 16384);
printf("EMMcopyto() failed OK.\n");
TESTTAILER();
/* and another */
TESTHEADER();
printf("Calling EMMcopyto() with block that runs off end of EMS.\n");
printf("Should fail.\n");
status = EMMcopyto(500L, (UCF *) testbuf, handle, 16000L);
nofailcheck("EMMcopyto()", status, testbuf, handle, 0);
weirdretchk("EMMcopyto()", status, testbuf, handle, 0);
weirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
SRCWORDCHECK(testbuf, 16384);
test_EMMmappage(0, handle, 0);
ZEROCHECK(frameptr[0], 16384);
printf("EMMcopyto() failed OK.\n");
TESTTAILER();
/* test zero-length copy */
TESTHEADER();
printf("Calling EMMc