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

zlib image tests More...

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

Go to the source code of this file.

Data Structures

struct  zlib_test
 A zlib test. More...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define ZLIB(name, COMPRESSED, EXPECTED)
 Define a zlib test. More...
 
#define zlib_ok(test)   zlib_okx ( test, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 ZLIB (hello_world, DATA(0x78, 0x9c, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x00, 0x18, 0xab, 0x04, 0x3d), DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64))
 "Hello world" More...
 
static void zlib_okx (struct zlib_test *test, const char *file, unsigned int line)
 Report zlib test result. More...
 
static void zlib_test_exec (void)
 Perform zlib self-test. More...
 

Variables

struct self_test zlib_test __self_test
 zlib self-test More...
 

Detailed Description

zlib image tests

Definition in file zlib_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 57 of file zlib_test.c.

◆ ZLIB

#define ZLIB (   name,
  COMPRESSED,
  EXPECTED 
)
Value:
static const uint8_t name ## _compressed[] = COMPRESSED; \
static const uint8_t name ## _expected[] = EXPECTED; \
static struct zlib_test name = { \
.compressed_name = #name ".z", \
.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
const char * expected_name
Expected uncompressed name.
Definition: zlib_test.c:49
unsigned char uint8_t
Definition: stdint.h:10
size_t expected_len
Length of expected uncompressed data.
Definition: zlib_test.c:53
A zlib test.
Definition: zlib_test.c:41
const void * expected
Expected uncompressed data.
Definition: zlib_test.c:51

Define a zlib test.

Definition at line 60 of file zlib_test.c.

◆ zlib_ok

#define zlib_ok (   test)    zlib_okx ( test, __FILE__, __LINE__ )

Definition at line 118 of file zlib_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ZLIB()

ZLIB ( hello_world  ,
DATA(0x78, 0x9c, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0x01, 0x00, 0x18, 0xab, 0x04, 0x3d)  ,
DATA(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64)   
)

"Hello world"

◆ zlib_okx()

static void zlib_okx ( struct zlib_test test,
const char *  file,
unsigned int  line 
)
static

Report zlib test result.

Parameters
testzlib test
fileTest code file
lineTest code line

Definition at line 86 of file zlib_test.c.

87  {
88  struct image *image;
89  struct image *extracted;
90 
91  /* Construct compressed image */
92  image = image_memory ( test->compressed_name,
93  virt_to_user ( test->compressed ),
94  test->compressed_len );
95  okx ( image != NULL, file, line );
96  okx ( image->len == test->compressed_len, file, line );
97 
98  /* Check type detection */
99  okx ( image->type == &zlib_image_type, file, line );
100 
101  /* Extract archive image */
102  okx ( image_extract ( image, NULL, &extracted ) == 0, file, line );
103 
104  /* Verify extracted image content */
105  okx ( extracted->len == test->expected_len, file, line );
106  okx ( memcmp_user ( extracted->data, 0,
107  virt_to_user ( test->expected ), 0,
108  test->expected_len ) == 0, file, line );
109 
110  /* Verify extracted image name */
111  okx ( strcmp ( extracted->name, test->expected_name ) == 0,
112  file, line );
113 
114  /* Unregister images */
115  unregister_image ( extracted );
117 }
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().

◆ zlib_test_exec()

static void zlib_test_exec ( void  )
static

Perform zlib self-test.

Definition at line 124 of file zlib_test.c.

124  {
125 
126  zlib_ok ( &hello_world );
127 }
#define zlib_ok(test)
Definition: zlib_test.c:118

References zlib_ok.

Variable Documentation

◆ __self_test

struct self_test zlib_test __self_test
Initial value:
= {
.name = "zlib",
.exec = zlib_test_exec,
}
static void zlib_test_exec(void)
Perform zlib self-test.
Definition: zlib_test.c:124

zlib self-test

Definition at line 130 of file zlib_test.c.