⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selftest.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
 * @(#)selftest.h	1.6 98/01/12
 *
 * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies. Please refer to the file "copyright.html"
 * for further important copyright and licensing information.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

#ifndef	_SELFTEST_H_
#define	_SELFTEST_H_

/* 	Structures and typedefs in support of the Java runtime self-test. */

enum binop_operations
{
  	BINOP_ADD,
  	BINOP_SUB,
  	BINOP_MUL,
  	BINOP_DIV,
  	BINOP_REM,
  	BINOP_AND,
  	BINOP_OR,
  	BINOP_XOR
};

enum unop_operations
{
  	UNOP_NEG,
  	UNOP_SHL,
  	UNOP_ASHR, 	/* arithmetic shift right (with sign-extension) */
  	UNOP_LSHR 	/* logical shift right (no sign-extension) */
};

enum cmp_operations
{
  	CMP_EQ,
	CMP_LT,
	CMP_LE,
	CMP_NE,
	CMP_GT,
	CMP_GE,
	CMP_NULL,
	CMP_NONNULL
};

enum init_status
{
 	INIT_OK,
	INIT_UNIMP,		/* initializer is not written yet */
	INIT_ERROR 	/* an error occurred during initialization */
};

enum check_status
{
	CHECK_PASS,		/* test passed */
	CHECK_FAIL,		/* test failed */
	CHECK_UNIMP,	/* test is not written yet */
	CHECK_ERROR	/* an error occurred during checking */
};

enum word_order
{
	little,			/* loword first, then hiword */
	big			/* hiword first, then loword */
};

enum types
{
	TYPE_BOOLEAN = 4, 	/* The number 4 is from VM Spec, 3.6 */
	TYPE_CHAR,
	TYPE_FLOAT,
	TYPE_DOUBLE,
	TYPE_BYTE,
	TYPE_SHORT,
	TYPE_INT,
	TYPE_LONG,
	TYPE_OBJECT,	/* dummy type I made up for testing convenience */
	TYPE_NUMTYPES	/* keep me last */
};

/* 	Field names correspond to the names given to fields in SelfTest.java.
	If you change names or add new fields in SelfTest.java be sure to
	reflect the changes here. */
enum fields
{
	field_i1,		/* local integer field */
	field_i2,
	field_f1,		/* local float field */
	field_f2,
	field_d1,		/* local double field */
	field_d2,
	field_l1,		/* local longlong field */
	field_l2,
	field_si1,		/* static integer field */
	field_si2,
	field_sf1,		/* static float field */
	field_sf2,
	field_sd1,		/* static double field */
	field_sd2,
	field_sl1,		/* static float field */
	field_sl2,
	method_set_i1,
	method_set_i2,
	method_set_f1,
	method_set_f2,
	method_set_d1,
	method_set_d2,
	method_set_l1,
	method_set_l2,
	method_set_si1,
	method_set_si2,
	method_set_sf1,
	method_set_sf2,
	method_set_sd1,
	method_set_sd2,
	method_set_sl1,
	method_set_sl2,
	method_test_areturn,
	method_test_athrow1,
	method_test_athrow2,
	method_test_athrow3,
	method_test_athrow4,
	method_test_an_interface,
	method_equals,
	FIELD_NUMFIELDS
};

/* The structure that defines a single self-test. */
struct opcode_test
{
    /* The Java opcode */
    unsigned char opcode;

    /* A pointer to a function to initialize the PC and ExecEnv for the test */
    int (* initer) (unsigned char **, ExecEnv *, int, int);

    /* A pointer to a function to check the stack after executing the opcode */
    int (* checker) (unsigned char *, ExecEnv *, int, int);

    /* Optional parameter for polymorphic initer/checkers like iload */
    int param;

    /* Optional parameter for wide/notwide opcodes like goto */
    int wide;
};

/* 	A simple structure to store some info that describes test objects.

	The order of the elements in the objcheck[] array follows the order
	of "enum fields", e.g. objcheck[method_set_si1] will contain
	info about the method "set_s1".

	The objcheck[] array is initialized in SetupTstObjects. */
struct objcheck
{
	/* 	Pointer to fieldblock within class's fields[] array */
	struct fieldblock *fb;

	/* 	For methods, pointer to methodblock within class's methods[] array */
	struct methodblock *mb;

	/* Index of this field within constant pool */
	int cpindex;
};

#define fieldblock(field)	objcheck[field].fb
#define methodblock(field)	objcheck[field].mb
#define methodoffset(field) objcheck[field].fb->u.offset
#define objoffset(field) 	(objcheck[field].fb->u.offset / sizeof(long))
#define staticvalue(field)	objcheck[field].fb->u.static_value
#define staticaddr(field)	objcheck[field].fb->u.static_address
#define fldname(field)		objcheck[field].fb->name
#define cpindex(field)		objcheck[field].cpindex

/* 	A simple structure to store the object created to represent an array
	and its expected size.

	The order of the elements in the arraycheck[] array follows the order
	of "enum types", e.g. arraycheck[TYPE_FLOAT] will contain an object
	that is expected to describe an array of float.

	The arraycheck[] array is initialized in newarray_check1. Used by
	newarray_check1, plus the complete set of array_load and array_store
	tests. */
struct arraycheck
{
	/* 	Reference to the allocated object */
	JHandle *handle;

	/* 	Number of elements in the array */
	int numelem;
};

/*	A structure and two functions to aid in checking 64-bit
	arithmetic and conversions. */
struct longlong
{
	long msw;
	long lsw;
};

/* 	As initialized in SetupExecEnv, the currently executing frame can
	count on there being NUMLOCALS locals in the previous frame. */
#define NUMLOCALS 16

/* 	The size of the program text buffer passed to ExecuteJava. */
#define PROGTEXT_SIZE 128

/* 	Define some constants for convenience in the testing that follows */
#define MAGIC_BYTE		123
#define MAGIC_SHORT		1234
#define	MAGIC_WORD		1234567
#define MAGIC_FLOAT		1.2e34
#define MAGIC_DOUBLE	1.2e234
#define MAGIC_OBJECT	tst_object
#define FLOAT_ERROR		1.0e-3
#define DOUBLE_ERROR	1.0e-6

/* 	A list of opcode names, for printing in error messages;
	defined in opcodes.c in the build directory */
extern char * const opnames[];

/*	Test an expression and print a message if FALSE.
	NOTE: opcode names in the failure message will only be correct if the
	opcode appears as the first character of pc[] (the usual case, but
	not required.) */
#define CHECK(expr) ((expr) ? CHECK_PASS : (fprintf(stderr, "Self-Test %d FAILED, opcode: %s, file: %s, line: %d\n", testno, opnames[selftest_table[testno].opcode], __FILE__, __LINE__) , CHECK_FAIL))

/*	Compare two doubles without using == */
#if defined(NEEDSIEEE754)					/*ibm.1229*/
#define DEQUALS(d1, d2)							\
    ( dbl_lt(								\
	fabs( dbl_sub( dbl_one_const, dbl_div(d1, d2) ) )		\
    , todouble(DOUBLE_ERROR) )
#else                      					/*ibm.1229*/
#define DEQUALS(d1, d2) (fabs(1.0 - (d1) / (d2)) < DOUBLE_ERROR)
#endif                     					/*ibm.1229*/

/*	Compare two floats without using == */
#if defined(NEEDSIEEE754)					/*ibm.1229*/
#define FEQUALS(f1, f2)							\
    ( flt_lt( dbl2flt(							\
	fabs( flt2dbl( flt_sub( flt_one_const, flt_div(f1, f2)))) )	\
    , tofloat(FLOAT_ERROR) )
#else                      					/*ibm.1229*/
#define FEQUALS(f1, f2) (fabs(1.0 - (f1) / (f2)) < FLOAT_ERROR)
#endif                     					/*ibm.1229*/

/* 	For debugging the self-test; "verbose" variable comes from -v
	command-line option; define DEBUG_SELFTEST in the Makefile to
	always print a results summary even without -v. */
#if defined(DEBUG_SELFTEST)
#define PRINT_RESULTS_SUMMARY 1
#else
#define PRINT_RESULTS_SUMMARY verbose
#endif

/* 	A few miscellaneous prototypes used by the selftest */
static void	SetupExecEnv (ExecEnv *ee);
static void	SetupTstObjects (ExecEnv *ee);
static void SetupWordOrder (unsigned char *pc, ExecEnv *ee);
static void ReportSelfTestResults (int numtests, int numpasses, int numfails);
static cp_item_type *copy_constantpool (cp_item_type *src, int itemcount);
static void free_constantpool (cp_item_type *cp);
static struct longlong get_longlong (char *buf);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -