www.pudn.com > vxworks0108.rar > mini.c


#include "type.h"
#include "minilzo.h"


#define IN_LEN		(20*1024L)
#define OUT_LEN		(IN_LEN + IN_LEN / 64 + 16 + 3)

static lzo_byte in  [ IN_LEN ];
static lzo_byte out [ OUT_LEN ];
static lzo_byte comp  [ IN_LEN ];


/* Work-memory needed for compression. Allocate memory in units
 * of `long' (instead of `char') to make sure it is properly aligned.
 */

#define HEAP_ALLOC(var,size) \
	long __LZO_MMODEL var [ ((size) + (sizeof(long) - 1)) / sizeof(long) ]

static HEAP_ALLOC(wrkmem,LZO1X_1_MEM_COMPRESS);


/*************************************************************************
//
**************************************************************************/

int mini(int argc, char *argv[])
{
	int r;
	int i=0;
	int irand;
        int len;
	unsigned int starttime,endtime,timefrequency,time;
	lzo_uint in_len;
	lzo_uint out_len;
	lzo_uint new_len;

#if defined(__EMX__)
	_response(&argc,&argv);
	_wildcard(&argc,&argv);
#endif

	if (argc < 0 && argv == NULL)	/* avoid warning about unused args */
		return 0;

/*
 * Step 1: initialize the LZO library
 */
 /*
	if (lzo_init() != LZO_E_OK)
	{
		printf("lzo_init() failed !!!\n");
		return 3;
	}
*/
/*
 * Step 2: prepare the input block that will get compressed.
 *         We just fill it with zeros in this example program,
 *         but you would use your real-world data here.
 */
	in_len = IN_LEN;
	for(i=0;i< IN_LEN;i++)
	{
		in[i] = *(unsigned char*)(0x100000+i);
	}		

        timefrequency =25000000;
        starttime = vxDecGet();
	r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
	endtime = vxDecGet();
	if (r == LZO_E_OK)
	{
		time = (starttime - endtime)/25;
		printf("starttime=%x,timefrequency=%d\n",starttime,timefrequency);			
		printf("compressed %lu bytes into %lu bytes,time=%dmicrosec,endtime=%x\n",
			(long) in_len, (long) out_len,time,endtime);
	}
	else
	{
		/* this should NEVER happen */
		printf("internal error - compression failed: %d\n", r);
		return 2;
	}
	/* check for an incompressible block */
	if (out_len >= in_len)
	{
		printf("This block contains incompressible data.\n");
		return 0;
	}
        
/*
 * Step 4: decompress again, now going from `out' to `in'
 */
	r = lzo1x_decompress(out,out_len,comp,&new_len,NULL);
	if (r == LZO_E_OK && new_len == in_len)
		printf("decompressed %lu bytes back into %lu bytes\n",
			(long) out_len, (long) in_len);
	else
	{
		/* this should NEVER happen */
		printf("internal error - decompression failed: %d\n", r);
		return 1;
	}
	len=IN_LEN;
        while(len--)
        {        	
        	if(comp[len]!=in[len])
        	{
        		printf("test not passed\n");
        		break;
        	}
        }
        
	printf("\nminiLZO simple compression test passed.\n");
	return 0;
}

/*
vi:ts=4
*/