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

gzip image tests More...

#include <stdint.h>
#include <ipxe/image.h>
#include <ipxe/gzip.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  gzip_test
 A gzip test. More...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define GZIP(name, COMPRESSED, EXPECTED)
 Define a gzip test. More...
 
#define gzip_ok(test)   gzip_okx ( test, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 GZIP (hello_world, DATA(0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x00, 0x52, 0x9e, 0xd6, 0x8b, 0x0b, 0x00, 0x00, 0x00), DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64))
 "Hello world" More...
 
 GZIP (hello_filename, DATA(0x1f, 0x8b, 0x08, 0x08, 0xeb, 0x5b, 0x96, 0x60, 0x00, 0x03, 0x68, 0x77, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x48, 0xcb, 0xcc, 0x49, 0xcd, 0x4b, 0xcc, 0x4d, 0x05, 0x00, 0x69, 0x37, 0x25, 0x3c, 0x0e, 0x00, 0x00, 0x00), DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65))
 "Hello filename" More...
 
 GZIP (hello_headers, DATA(0x1f, 0x8b, 0x08, 0x1c, 0x11, 0x5c, 0x96, 0x60, 0x00, 0x03, 0x05, 0x00, 0x41, 0x70, 0x01, 0x00, 0x0d, 0x68, 0x77, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x2f, 0x2f, 0x77, 0x68, 0x79, 0x3f, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x48, 0x2c, 0x2e, 0xce, 0x2f, 0x2a, 0x49, 0x4d, 0x51, 0xc8, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x2a, 0x06, 0x00, 0x59, 0xa4, 0x19, 0x61, 0x16, 0x00, 0x00, 0x00), DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x61, 0x73, 0x73, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73))
 "Hello assorted headers" More...
 
static void gzip_okx (struct gzip_test *test, const char *file, unsigned int line)
 Report gzip test result. More...
 
static void gzip_test_exec (void)
 Perform gzip self-test. More...
 

Variables

struct self_test gzip_test __self_test
 gzip self-test More...
 

Detailed Description

gzip image tests

Definition in file gzip_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 57 of file gzip_test.c.

◆ GZIP

#define GZIP (   name,
  COMPRESSED,
  EXPECTED 
)
Value:
static const uint8_t name ## _compressed[] = COMPRESSED; \
static const uint8_t name ## _expected[] = EXPECTED; \
static struct gzip_test name = { \
.compressed_name = #name ".gz", \
.compressed = name ## _compressed, \
.compressed_len = sizeof ( name ## _compressed ), \
.expected = name ## _expected, \
.expected_len = sizeof ( name ## _expected ), \
};
#define EXPECTED(...)
Define inline expected HMAC.
Definition: hmac_test.c:49
const char * name
Definition: ath9k_hw.c:1984
A gzip test.
Definition: gzip_test.c:41
const void * expected
Expected uncompressed data.
Definition: gzip_test.c:51
unsigned char uint8_t
Definition: stdint.h:10
const char * expected_name
Expected uncompressed name.
Definition: gzip_test.c:49
size_t expected_len
Length of expected uncompressed data.
Definition: gzip_test.c:53

Define a gzip test.

Definition at line 60 of file gzip_test.c.

◆ gzip_ok

#define gzip_ok (   test)    gzip_okx ( test, __FILE__, __LINE__ )

Definition at line 143 of file gzip_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ GZIP() [1/3]

GZIP ( hello_world  ,
DATA(0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x00, 0x52, 0x9e, 0xd6, 0x8b, 0x0b, 0x00, 0x00, 0x00)  ,
DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64)   
)

"Hello world"

◆ GZIP() [2/3]

GZIP ( hello_filename  ,
DATA(0x1f, 0x8b, 0x08, 0x08, 0xeb, 0x5b, 0x96, 0x60, 0x00, 0x03, 0x68, 0x77, 0x2e, 0x74, 0x78, 0x74, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x48, 0xcb, 0xcc, 0x49, 0xcd, 0x4b, 0xcc, 0x4d, 0x05, 0x00, 0x69, 0x37, 0x25, 0x3c, 0x0e, 0x00, 0x00, 0x00)  ,
DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65)   
)

"Hello filename"

◆ GZIP() [3/3]

GZIP ( hello_headers  ,
DATA(0x1f, 0x8b, 0x08, 0x1c, 0x11, 0x5c, 0x96, 0x60, 0x00, 0x03, 0x05, 0x00, 0x41, 0x70, 0x01, 0x00, 0x0d, 0x68, 0x77, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x2f, 0x2f, 0x77, 0x68, 0x79, 0x3f, 0x00, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x48, 0x2c, 0x2e, 0xce, 0x2f, 0x2a, 0x49, 0x4d, 0x51, 0xc8, 0x48, 0x4d, 0x4c, 0x49, 0x2d, 0x2a, 0x06, 0x00, 0x59, 0xa4, 0x19, 0x61, 0x16, 0x00, 0x00, 0x00)  ,
DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x61, 0x73, 0x73, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73)   
)

"Hello assorted headers"

◆ gzip_okx()

static void gzip_okx ( struct gzip_test test,
const char *  file,
unsigned int  line 
)
static

Report gzip test result.

Parameters
testgzip test
fileTest code file
lineTest code line

Definition at line 111 of file gzip_test.c.

112  {
113  struct image *image;
114  struct image *extracted;
115 
116  /* Construct compressed image */
117  image = image_memory ( test->compressed_name,
118  virt_to_user ( test->compressed ),
119  test->compressed_len );
120  okx ( image != NULL, file, line );
121  okx ( image->len == test->compressed_len, file, line );
122 
123  /* Check type detection */
124  okx ( image->type == &gzip_image_type, file, line );
125 
126  /* Extract archive image */
127  okx ( image_extract ( image, NULL, &extracted ) == 0, file, line );
128 
129  /* Verify extracted image content */
130  okx ( extracted->len == test->expected_len, file, line );
131  okx ( memcmp_user ( extracted->data, 0,
132  virt_to_user ( test->expected ), 0,
133  test->expected_len ) == 0, file, line );
134 
135  /* Verify extracted image name */
136  okx ( strcmp ( extracted->name, test->expected_name ) == 0,
137  file, line );
138 
139  /* Unregister images */
140  unregister_image ( extracted );
142 }
userptr_t data
Raw file image.
Definition: image.h:41
struct image_type * type
Image type, if known.
Definition: image.h:46
struct image * image_memory(const char *name, userptr_t data, size_t len)
Create registered image from block of memory.
Definition: image.c:550
An executable image.
Definition: image.h:24
#define okx(success, file, line)
Report test result.
Definition: test.h:44
int image_extract(struct image *image, const char *name, struct image **extracted)
Extract archive image.
Definition: archive.c:44
size_t len
Length of raw file image.
Definition: image.h:43
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:303
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
int memcmp_user(userptr_t first, off_t first_off, userptr_t second, off_t second_off, size_t len)
Compare data between user buffers.
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
char * name
Name.
Definition: image.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int test
Definition: epic100.c:73

References image::data, image_extract(), image_memory(), image::len, memcmp_user(), image::name, NULL, okx, strcmp(), test, image::type, unregister_image(), and virt_to_user().

◆ gzip_test_exec()

static void gzip_test_exec ( void  )
static

Perform gzip self-test.

Definition at line 149 of file gzip_test.c.

149  {
150 
151  gzip_ok ( &hello_world );
152  gzip_ok ( &hello_filename );
153  gzip_ok ( &hello_headers );
154 }
#define gzip_ok(test)
Definition: gzip_test.c:143

References gzip_ok.

Variable Documentation

◆ __self_test

struct self_test gzip_test __self_test
Initial value:
= {
.name = "gzip",
.exec = gzip_test_exec,
}
static void gzip_test_exec(void)
Perform gzip self-test.
Definition: gzip_test.c:149

gzip self-test

Definition at line 157 of file gzip_test.c.