bcp_rand.h 3.2 KB

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
		BCP RAND TETS BENCH Header file

:set tabstop = 4
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef _BCP_RAND_H
#define _BCP_RAND_H

#define MAX_PATH_LEN 256
#define MAX_TEST_NUM 128
#define MAX_MEM_SEG  512
#define MAX_DIFF_SIZE 5
#define MEM_USED	 0x40000000
#define MAX_PORT_NUM 2000
#define RAND_PORT_BASE 12000 
#define RAND_SERVER_IP "127.0.0.1" 

#define INVALID_REQ	 0xFFFFFFFF
#define BDOOR_REQ	 0x80000000

/* Lock */
#define AI_LOCK		0x0001
#define VI_LOCK		0x0002
#define SP_LOCK		0x0004
#define DP_LOCK		0x0008
#define USB0_LOCK	0x0010
#define USB1_LOCK	0x0020
#define PI_LOCK		0x0040
#define MI_LOCK		0x0080
#define SI_LOCK		0x0100 
#define RI_LOCK		0x0200
#define LOCK_MASK   0x03FF

typedef struct {
	char test_name[MAX_PATH_LEN];	/* The Name of test */
	char test_cmd[MAX_PATH_LEN];	/* Test program */

	char test_check[MAX_PATH_LEN];	/* Test check program */
	int  ret_code;					/* Success test code */
	
	char test_log[MAX_PATH_LEN];	/* should in a+ mode */
	
	int  res_lock;					/* Resource lock */
	
	int  memory_size;				/* How much memory test needed */
	int  pri;						/* Priority 1--5(more stress) */ 

	int  max_copies;				/* Max number of copies */
	int  cur_copies;
	int  total_copies;

} BCP_RAND_TEST;

struct _BCP_RAND_PROCESS;
typedef struct  _BCP_RAND_PROCESS {
	BCP_RAND_TEST 	*ptest;			/* Which Test */

	int  test_pid;                  /* Test process ID */	
	int  port;						/* Port Number */

	int  start_addr;
	int  end_addr;

	struct _BCP_RAND_PROCESS  *next;

	/* socket connect with the test 
	   conn_sock != 0 means persistent connection */	
	int  listen_sock;					
	int  conn_sock;
	int  persist_con;
									  
	IpcPkt req;					  	/* Ipc Req packet */
	
} BCP_RAND_PROCESS;

/* Main */
static int usage(void);
static int init_rand_test_list(BCP_RAND_TEST *plist);
static int init_rand_test_process(BCP_RAND_PROCESS *);
int read_test_file(BCP_RAND_TEST *plist, char *test_file);
int display_msg(int fd, char *msg);

/* Resource */
int init_rand_res();
int alloc_mem(int size);
int find_mem(int size, int start);
int trace_resource(int lock, int pos, int alloc);
int alloc_res(int lock, int size, int *start, int *end);
int free_res(int lock, int start, int size);

/* Test part */
static int run_random_test(BCP_RAND_TEST *bcp_rand_list,  int test_num, 
						   int seconds, int ntest);

int close_fork_fdec(int sim_sock, BCP_RAND_PROCESS *p_test);
int open_simulator_sock();
int open_listen_socket(BCP_RAND_PROCESS *proc);

BCP_RAND_PROCESS *add_tests(BCP_RAND_PROCESS *proc, 
				BCP_RAND_TEST *list, int which);
BCP_RAND_PROCESS* merge_tests(int, BCP_RAND_PROCESS *, BCP_RAND_PROCESS *);
BCP_RAND_PROCESS* remove_done_tests(BCP_RAND_PROCESS *proc);

int recv_pkt_from_sock(int fd, char *buf, int len);
int send_pkt_to_sock(int fd, char *buf, int len);
int proceed_a_req(int sim_sock, BCP_RAND_PROCESS *proc);
int get_req_pkt(int sim_sock, BCP_RAND_PROCESS *proc);
int get_req_for_all(int sim_sock, BCP_RAND_PROCESS *proc);
int pick_and_run(int sim_sock,  BCP_RAND_PROCESS *proc);
int post_process(int sim_sock, BCP_RAND_PROCESS *proc);
int proceed_tests(int sim_sock, BCP_RAND_PROCESS *proc);
int run_a_test(BCP_RAND_PROCESS *proc);

#endif