GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> LDT / dev > encdec_unit_test / linux-gcc


Interface   Data Structures   File List   Data Fields   Globals  

encdec_unit_test.c File Reference

Tests the encode/decode library 'encdec'. More...

#include <LDT/APM.h>
#include <LDT/APE.h>
#include <LDT/APD.h>
#include <LDT/HUFF.h>
#include <LDT/../src/TMR.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include <LDT/../src/TMR.c>

Classes

struct  _Ctl
struct  _MethodCommon
struct  _MethodResult
struct  _Test

Typedefs

typedef enum _Options Options
typedef struct _Ctl Ctl
typedef struct _MethodCommon MethodCommon
typedef struct _MethodResult MethodResult
typedef struct _Test Test

Enumerations

enum  _Options { OPT_M_HCODE = 0x1 }

Functions

int test_conductor (int argc, char **argv)
 Tests the Arithmetic Probability and Huffman Encoding/Decoding for byte-sized tables.
static int test_driver (const char *banner, unsigned int options, const unsigned int *freqs, int nfreqs, const unsigned char *symbols, int nsymbols, unsigned int *table, unsigned char *ebuf, unsigned int esiz, unsigned char *dbuf, unsigned int dsiz)
 Does a of the Arithmetic Probability Encoding and Huffman encoders using a byte-wide table.
static int cheap_testA (unsigned int options)
 Cheap test of the encode/decode of a test distribution.
static int cheap_test0 (unsigned int options)
 Cheap test of the encode/decode of a test distribution.
static int cheap_test1 (unsigned int options)
 Cheap test of the encode/decode of a test distribution.
static int cheap_test2 (unsigned int options)
 Cheap test of the encode/decode of a test distribution. This uses a table with an odd number of symbols, just to make sure that the binary search in the symbol lookup does not have problems.
static int cheap_test3 (unsigned int options)
 Cheap test of the encode/decode of a test distribution.
static int ap_composite_test (unsigned int options)
 Composite test of byte encoder.
static int ap_file_test (const char *fileName, unsigned int options)
 Tests the encoding/decoding of the specified file.
static int ap_self_encdec (const char *banner, unsigned int options, const unsigned char *symbols, int nsymbols)
 Encodes, then decodes the specified set of symbols.
static int ap_test (MethodResult *result, const unsigned int *freqs, int nfreqs, const unsigned char *symbols, int nsymbols, unsigned int *table, unsigned char *ebuf, unsigned int esiz, unsigned char *dbuf, unsigned int dsiz)
static int huff_test (MethodResult *result, const unsigned int *freqs, int nfreqs, const unsigned char *symbols, int nsymbols, unsigned int *table, unsigned char *ebuf, unsigned int esiz, unsigned char *dbuf, unsigned int dsiz)
static int check (const unsigned int *table)
static unsigned int get_ctl (Ctl *ctl, int argc, char *const argv[])
 Examines the command line parameters and fills in the test control structure.
static unsigned const char * get_contents (const char *fileName, int *rsize)
 Reads in the specified file.
static void report_test (const Test *test, unsigned int options)
static double get_byte_esize (const unsigned int *freqs, int nfreqs, const unsigned char *samples, int nsamples)
 Calculates the size, in bits, of the sample distribution based on the specified frequency table.
int main (int argc, char **argv)
 Main program, it takes no arguments.

Variables

const unsigned int Freqs []
 Frequency distribution used in many of the tests.


Detailed Description

Tests the encode/decode library 'encdec'.

Author:
JJRussell - russell@slac.stanford.edu
   CVS $Id: encdec_unit_test.c,v 1.8 2011/03/31 18:39:36 russell Exp $

Enumeration Type Documentation

enum _Options

Enumerator:
OPT_M_HCODE  Print huffman table of codes


Function Documentation

static int ap_composite_test ( unsigned int  options  )  [static]

Composite test of byte encoder.

Return values:
0 if successful
2 if failure
Parameters:
options An output options flag word
This tests the ability to use multiple encoding tables. The encoding tables for two distributions are computed from two separate distributions. The probablity distributions are then encoding by picking a symbol first from one distribution then the other. The decoding is then done with the result being checked against the original

References get_byte_esize().

Referenced by test_conductor().

static int ap_file_test ( const char *  fileName,
unsigned int  options 
) [static]

Tests the encoding/decoding of the specified file.

Parameters:
fileName The name of the file to encode
options An output options flag word

References ap_self_encdec(), and get_contents().

Referenced by test_conductor().

static int ap_self_encdec ( const char *  banner,
unsigned int  options,
const unsigned char *  symbols,
int  nsymbols 
) [static]

Encodes, then decodes the specified set of symbols.

Returns:
Status, 0 if successful
Parameters:
banner Arbitrary string to use as a title banner
options An output options word
symbols The set of symbols to encode/decode
nsymbols The number of symbols to encode/decode

References test_driver().

Referenced by ap_file_test().

static int cheap_test0 ( unsigned int  options  )  [static]

Cheap test of the encode/decode of a test distribution.

Parameters:
options An output options flag word
Return values:
0,if successful
2,if not

References Freqs, and test_driver().

Referenced by test_conductor().

static int cheap_test1 ( unsigned int  options  )  [static]

Cheap test of the encode/decode of a test distribution.

Parameters:
options An output options flag word
Return values:
0,if successful
2,if not

References Freqs, and test_driver().

Referenced by test_conductor().

static int cheap_test2 ( unsigned int  options  )  [static]

Cheap test of the encode/decode of a test distribution. This uses a table with an odd number of symbols, just to make sure that the binary search in the symbol lookup does not have problems.

Parameters:
options An output options flag word
Return values:
0,if successful
2,if not

References Freqs, and test_driver().

Referenced by test_conductor().

static int cheap_test3 ( unsigned int  options  )  [static]

Cheap test of the encode/decode of a test distribution.

Parameters:
options An output options flag word
Return values:
0,if successful
2,if not

References Freqs, and test_driver().

Referenced by test_conductor().

static int cheap_testA ( unsigned int  options  )  [static]

Cheap test of the encode/decode of a test distribution.

Parameters:
options An output options flag word
Return values:
0,if successful
2,if not

References Freqs, and test_driver().

Referenced by test_conductor().

static int check ( const unsigned int *  table  )  [static]

printf ("Symbol = %d\n", sym1);

static double get_byte_esize ( const unsigned int *  freqs,
int  nfreqs,
const unsigned char *  samples,
int  nsamples 
) [static]

Calculates the size, in bits, of the sample distribution based on the specified frequency table.

Returns:
The size, int bits, of the sample distribution
Parameters:
freqs The frequency table
nfreqs The number of entries in the frequency table
samples The array of samples
nsamples The number of samples

Referenced by ap_composite_test(), and test_driver().

static const unsigned char * get_contents ( const char *  fileName,
int *  rsize 
) [static]

Reads in the specified file.

Returns:
A pointer to the file's content and, in an argument, its size in bytes
Parameters:
fileName The name of the file to encode
rsize Pointer to receive the size of the file's content

Referenced by ap_file_test().

static unsigned int get_ctl ( Ctl *  ctl,
int  argc,
char *const   argv[] 
) [static]

Examines the command line parameters and fills in the test control structure.

Parameters:
ctl The test control structure
argc The number of command line parameters.
argv The array of pointers to the command line parameters.
Returns:
Status

References OPT_M_HCODE.

Referenced by test_conductor().

int main ( int  argc,
char **  argv 
)

Main program, it takes no arguments.

Returns:
0 if successful, else bit mask of those tests that failed

References test_conductor(), and TMR_initialize().

int test_conductor ( int  argc,
char **  argv 
)

Tests the Arithmetic Probability and Huffman Encoding/Decoding for byte-sized tables.

Return values:
0 if successful
2 if failure

References ap_composite_test(), ap_file_test(), cheap_test0(), cheap_test1(), cheap_test2(), cheap_test3(), cheap_testA(), and get_ctl().

Referenced by main().

static int test_driver ( const char *  banner,
unsigned int  options,
const unsigned int *  freqs,
int  nfreqs,
const unsigned char *  symbols,
int  nsymbols,
unsigned int *  table,
unsigned char *  ebuf,
unsigned int  esiz,
unsigned char *  dbuf,
unsigned int  dsiz 
) [static]

Does a of the Arithmetic Probability Encoding and Huffman encoders using a byte-wide table.

Return values:
0,if successful
2,if not
Parameters:
banner The title of this test
options Reporting options
freqs The frequency distribution
nfreqs The number of entries in the frequency table
symbols The symbols to encode
nsymbols The number of symbols to encode
table Storage for the encoding table
ebuf The encode buffer
esiz The encode buffer size, in bytes
dbuf The decord buffer
dsiz The decode buffer size, in bytes

References get_byte_esize(), and OPT_M_HCODE.

Referenced by ap_self_encdec(), cheap_test0(), cheap_test1(), cheap_test2(), cheap_test3(), and cheap_testA().


Variable Documentation

const unsigned int Freqs

Initial value:

{
  1195,
  190,
  102,
  160,
  187,
  64,
  157,
  405,
  1
}
Frequency distribution used in many of the tests.

Referenced by cheap_test0(), cheap_test1(), cheap_test2(), cheap_test3(), and cheap_testA().


Generated on Thu Mar 31 11:41:19 2011 by  doxygen 1.5.8