iPXE
Data Structures | Macros | Functions | Variables
deflate_test.c File Reference

DEFLATE tests. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <ipxe/deflate.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  deflate_test
 A DEFLATE test. More...
 
struct  deflate_test_fragments
 A DEFLATE fragment list. More...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define DEFLATE(name, FORMAT, COMPRESSED, EXPECTED)
 Define a DEFLATE test. More...
 
#define deflate_ok(deflate, test, frags)   deflate_okx ( deflate, test, frags, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 DEFLATE (empty_literal, DEFLATE_RAW, DATA(0x01, 0x00, 0x00, 0xff, 0xff), DATA())
 
 DEFLATE (literal, DEFLATE_RAW, DATA(0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45), DATA(0x69, 0x50, 0x58, 0x45))
 
 DEFLATE (split_literal, DEFLATE_RAW, DATA(0x00, 0x02, 0x00, 0xfd, 0xff, 0x69, 0x50, 0x01, 0x02, 0x00, 0xfd, 0xff, 0x58, 0x45), DATA(0x69, 0x50, 0x58, 0x45))
 
 DEFLATE (empty, DEFLATE_RAW, DATA(0x03, 0x00), DATA())
 
 DEFLATE (hello_world, DEFLATE_RAW, DATA(0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x00), DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64))
 
 DEFLATE (hello_hello_world, DEFLATE_RAW, DATA(0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0xc8, 0x00, 0x93, 0xe5, 0xf9, 0x45, 0x39, 0x29, 0x00), DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64))
 
 DEFLATE (rfc_sentence, DEFLATE_RAW, DATA(0x0d, 0xc6, 0xdb, 0x09, 0x00, 0x21, 0x0c, 0x04, 0xc0, 0x56, 0xb6, 0x28, 0x1b, 0x08, 0x79, 0x70, 0x01, 0x35, 0xe2, 0xa6, 0x7f, 0xce, 0xf9, 0x9a, 0xf1, 0x25, 0xc1, 0xe3, 0x9a, 0x91, 0x2a, 0x9d, 0xb5, 0x61, 0x1e, 0xb9, 0x9d, 0x10, 0xcc, 0x22, 0xa7, 0x93, 0xd0, 0x5a, 0xe7, 0xbe, 0xb8, 0xc1, 0xa4, 0x05, 0x51, 0x77, 0x49, 0xff), DATA(0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x73, 0x20, 0x61, 0x20, 0x6c, 0x6f, 0x73, 0x73, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74))
 
 DEFLATE (zlib, DEFLATE_ZLIB, DATA(0x78, 0x01, 0x8b, 0xf2, 0xf1, 0x74, 0x52, 0x70, 0xce, 0xcf, 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0x51, 0x70, 0x49, 0x2c, 0x49, 0x54, 0x70, 0xcb, 0x2f, 0xca, 0x4d, 0x2c, 0x51, 0x08, 0x2e, 0x48, 0x4d, 0xce, 0x4c, 0xcb, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x03, 0x00, 0x2c, 0x0e, 0x0e, 0xeb), DATA(0x5a, 0x4c, 0x49, 0x42, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x44, 0x61, 0x74, 0x61, 0x20, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e))
 
static void deflate_okx (struct deflate *deflate, struct deflate_test *test, struct deflate_test_fragments *frags, const char *file, unsigned int line)
 Report DEFLATE test result. More...
 
static void deflate_test_exec (void)
 Perform DEFLATE self-test. More...
 

Variables

static struct deflate_test_fragments zlib_fragments []
 
struct self_test deflate_test __self_test
 DEFLATE self-test. More...
 

Detailed Description

DEFLATE tests.

Definition in file deflate_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 62 of file deflate_test.c.

◆ DEFLATE

#define DEFLATE (   name,
  FORMAT,
  COMPRESSED,
  EXPECTED 
)
Value:
static const uint8_t name ## _compressed[] = COMPRESSED; \
static const uint8_t name ## _expected[] = EXPECTED; \
static struct deflate_test name = { \
.format = FORMAT, \
.compressed = name ## _compressed, \
.compressed_len = sizeof ( name ## _compressed ), \
.expected = name ## _expected, \
.expected_len = sizeof ( name ## _expected ), \
};
const char * name
Definition: ath9k_hw.c:1984
unsigned char uint8_t
Definition: stdint.h:10
const void * expected
Expected uncompressed data.
Definition: deflate_test.c:50
#define EXPECTED(...)
Define inline expected result point.
Definition: elliptic_test.h:38
A DEFLATE test.
Definition: deflate_test.c:42
size_t expected_len
Length of expected uncompressed data.
Definition: deflate_test.c:52

Define a DEFLATE test.

Definition at line 65 of file deflate_test.c.

◆ deflate_ok

#define deflate_ok (   deflate,
  test,
  frags 
)    deflate_okx ( deflate, test, frags, __FILE__, __LINE__ )

Definition at line 209 of file deflate_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ DEFLATE() [1/8]

DEFLATE ( empty_literal  ,
DEFLATE_RAW  ,
DATA(0x01, 0x00, 0x00, 0xff, 0xff)  ,
DATA()   
)

◆ DEFLATE() [2/8]

DEFLATE ( literal  ,
DEFLATE_RAW  ,
DATA(0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45)  ,
DATA(0x69, 0x50, 0x58, 0x45)   
)

◆ DEFLATE() [3/8]

DEFLATE ( split_literal  ,
DEFLATE_RAW  ,
DATA(0x00, 0x02, 0x00, 0xfd, 0xff, 0x69, 0x50, 0x01, 0x02, 0x00, 0xfd, 0xff, 0x58, 0x45)  ,
DATA(0x69, 0x50, 0x58, 0x45)   
)

◆ DEFLATE() [4/8]

DEFLATE ( empty  ,
DEFLATE_RAW  ,
DATA(0x03, 0x00)  ,
DATA()   
)

◆ DEFLATE() [5/8]

DEFLATE ( hello_world  ,
DEFLATE_RAW  ,
DATA(0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x00)  ,
DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64)   
)

◆ DEFLATE() [6/8]

DEFLATE ( hello_hello_world  ,
DEFLATE_RAW  ,
DATA(0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0xc8, 0x00, 0x93, 0xe5, 0xf9, 0x45, 0x39, 0x29, 0x00)  ,
DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64)   
)

◆ DEFLATE() [7/8]

DEFLATE ( rfc_sentence  ,
DEFLATE_RAW  ,
DATA(0x0d, 0xc6, 0xdb, 0x09, 0x00, 0x21, 0x0c, 0x04, 0xc0, 0x56, 0xb6, 0x28, 0x1b, 0x08, 0x79, 0x70, 0x01, 0x35, 0xe2, 0xa6, 0x7f, 0xce, 0xf9, 0x9a, 0xf1, 0x25, 0xc1, 0xe3, 0x9a, 0x91, 0x2a, 0x9d, 0xb5, 0x61, 0x1e, 0xb9, 0x9d, 0x10, 0xcc, 0x22, 0xa7, 0x93, 0xd0, 0x5a, 0xe7, 0xbe, 0xb8, 0xc1, 0xa4, 0x05, 0x51, 0x77, 0x49, 0xff)  ,
DATA(0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x73, 0x20, 0x61, 0x20, 0x6c, 0x6f, 0x73, 0x73, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74)   
)

◆ DEFLATE() [8/8]

DEFLATE ( zlib  ,
DEFLATE_ZLIB  ,
DATA(0x78, 0x01, 0x8b, 0xf2, 0xf1, 0x74, 0x52, 0x70, 0xce, 0xcf, 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0x51, 0x70, 0x49, 0x2c, 0x49, 0x54, 0x70, 0xcb, 0x2f, 0xca, 0x4d, 0x2c, 0x51, 0x08, 0x2e, 0x48, 0x4d, 0xce, 0x4c, 0xcb, 0x4c, 0x4e, 0x2c, 0xc9, 0xcc, 0xcf, 0x03, 0x00, 0x2c, 0x0e, 0x0e, 0xeb)  ,
DATA(0x5a, 0x4c, 0x49, 0x42, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x44, 0x61, 0x74, 0x61, 0x20, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e)   
)

◆ deflate_okx()

static void deflate_okx ( struct deflate deflate,
struct deflate_test test,
struct deflate_test_fragments frags,
const char *  file,
unsigned int  line 
)
static

Report DEFLATE test result.

Parameters
deflateDecompressor
testDeflate test
fragsFragment list, or NULL
fileTest code file
lineTest code line

Definition at line 155 of file deflate_test.c.

158  {
159  uint8_t buf[ test->expected_len ];
160  const void *data = test->compressed;
161  size_t remaining = test->compressed_len;
162  size_t frag_len = -1UL;
163  struct deflate_chunk out;
164  unsigned int i;
165 
166  /* Initialise decompressor */
167  deflate_init ( deflate, test->format );
168 
169  /* Initialise output chunk */
170  deflate_chunk_init ( &out, buf, 0, sizeof ( buf ) );
171 
172  /* Process input (in fragments, if applicable) */
173  for ( i = 0 ; i < ( sizeof ( frags->len ) /
174  sizeof ( frags->len[0] ) ) ; i++ ) {
175 
176  /* Initialise input chunk */
177  if ( frags )
178  frag_len = frags->len[i];
179  if ( frag_len > remaining )
180  frag_len = remaining;
181 
182  /* Decompress this fragment */
183  okx ( deflate_inflate ( deflate, data, frag_len,
184  &out ) == 0, file, line );
185  okx ( deflate->in == ( data + frag_len ), file, line );
186  okx ( deflate->end == ( data + frag_len ), file, line );
187 
188  /* Move to next fragment */
189  data += frag_len;
190  remaining -= frag_len;
191  if ( ! remaining )
192  break;
193 
194  /* Check that decompression has not terminated early */
195  okx ( ! deflate_finished ( deflate ), file, line );
196  }
197 
198  /* Check decompression has terminated as expected */
199  okx ( deflate_finished ( deflate ), file, line );
200  okx ( deflate->in == ( test->compressed + test->compressed_len ),
201  file, line );
202  okx ( deflate->end == ( test->compressed + test->compressed_len ),
203  file, line );
204  okx ( out.offset == test->expected_len, file, line );
205  okx ( out.data == buf, file, line );
206  okx ( memcmp ( out.data, test->expected, test->expected_len ) == 0,
207  file, line );
208 }
__be32 out[4]
Definition: CIB_PRM.h:36
struct velocity_frag frags[7]
Definition: velocity.h:14
A chunk of data.
Definition: deflate.h:245
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
Definition: deflate.c:991
#define okx(success, file, line)
Report test result.
Definition: test.h:44
static int deflate_finished(struct deflate *deflate)
Check if decompression has finished.
Definition: deflate.h:277
unsigned char uint8_t
Definition: stdint.h:10
int deflate_inflate(struct deflate *deflate, const void *data, size_t len, struct deflate_chunk *out)
Inflate compressed data.
Definition: deflate.c:483
const uint8_t * in
Current input data pointer.
Definition: deflate.h:166
const uint8_t * end
End of input data pointer.
Definition: deflate.h:168
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
static int test
Definition: epic100.c:73
Decompressor.
Definition: deflate.h:155

References data, deflate_finished(), deflate_inflate(), deflate_init(), deflate::end, frags, deflate::in, memcmp(), okx, out, and test.

◆ deflate_test_exec()

static void deflate_test_exec ( void  )
static

Perform DEFLATE self-test.

Definition at line 216 of file deflate_test.c.

216  {
217  struct deflate *deflate;
218  unsigned int i;
219 
220  /* Allocate shared structure */
221  deflate = malloc ( sizeof ( *deflate ) );
222  ok ( deflate != NULL );
223 
224  /* Perform self-tests */
225  if ( deflate ) {
226 
227  /* Test as a single pass */
228  deflate_ok ( deflate, &empty_literal, NULL );
229  deflate_ok ( deflate, &literal, NULL );
230  deflate_ok ( deflate, &split_literal, NULL );
231  deflate_ok ( deflate, &empty, NULL );
232  deflate_ok ( deflate, &hello_world, NULL );
233  deflate_ok ( deflate, &hello_hello_world, NULL );
234  deflate_ok ( deflate, &rfc_sentence, NULL );
235  deflate_ok ( deflate, &zlib, NULL );
236 
237  /* Test fragmentation */
238  for ( i = 0 ; i < ( sizeof ( zlib_fragments ) /
239  sizeof ( zlib_fragments[0] ) ) ; i++ ) {
240  deflate_ok ( deflate, &zlib, &zlib_fragments[i] );
241  }
242  }
243 
244  /* Free shared structure */
245  free ( deflate );
246 }
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:620
#define deflate_ok(deflate, test, frags)
Definition: deflate_test.c:209
static struct deflate_test_fragments zlib_fragments[]
Definition: deflate_test.c:137
#define ok(success)
Definition: test.h:46
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Decompressor.
Definition: deflate.h:155

References deflate_ok, free, malloc(), NULL, ok, and zlib_fragments.

Variable Documentation

◆ zlib_fragments

struct deflate_test_fragments zlib_fragments[]
static
Initial value:
= {
{ { -1UL, } },
{ { 0, 1, 5, -1UL, } },
{ { 0, 0, 1, 0, 0, 1, -1UL } },
{ { 10, 8, 4, 7, 11, -1UL } },
{ { 45, -1UL } },
{ { 48, -1UL } },
}

Definition at line 137 of file deflate_test.c.

Referenced by deflate_test_exec().

◆ __self_test

struct self_test deflate_test __self_test
Initial value:
= {
.name = "deflate",
}
static void deflate_test_exec(void)
Perform DEFLATE self-test.
Definition: deflate_test.c:216

DEFLATE self-test.

Definition at line 249 of file deflate_test.c.