iPXE
archive_test.c File Reference

Archive extraction self-tests. More...

#include <stdlib.h>
#include <string.h>
#include <ipxe/image.h>
#include "archive_test.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void archive_okx (struct archive_test *test, const char *file, unsigned int line)
 Report an archive extraction test result.

Detailed Description

Archive extraction self-tests.

Definition in file archive_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ archive_okx()

void archive_okx ( struct archive_test * test,
const char * file,
unsigned int line )

Report an archive extraction test result.

Parameters
testArchive extraction test
fileTest code file
lineTest code line

Definition at line 47 of file archive_test.c.

48 {
49 struct image *image;
50 struct image *extracted;
51
52 /* Construct archive image */
53 image = image_memory ( test->archive_name, test->archive,
54 test->archive_len );
55 okx ( image != NULL, file, line );
56 okx ( image->len == test->archive_len, file, line );
57 DBGC ( test, "ARCHIVE %s is:\n", test->archive_name );
58 DBGC_HDA ( test, 0, image->data, image->len );
59
60 /* Check type detection */
61 okx ( image->type == test->type, file, line );
62
63 /* Extract archive image */
64 okx ( image_extract ( image, test->extract_name, &extracted ) == 0,
65 file, line );
66 DBGC ( test, "ARCHIVE %s extracted:\n", test->archive_name );
67 DBGC_HDA ( test, 0, extracted->data, extracted->len );
68
69 /* Verify extracted image content */
70 okx ( extracted->len == test->expected_len, file, line );
71 okx ( memcmp ( extracted->data, test->expected,
72 test->expected_len ) == 0, file, line );
73
74 /* Verify extracted image name */
75 okx ( strcmp ( extracted->name, test->expected_name ) == 0,
76 file, line );
77
78 /* Unregister images */
79 unregister_image ( extracted );
81}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
int image_extract(struct image *image, const char *name, struct image **extracted)
Extract archive image.
Definition archive.c:45
static int test
Definition epic100.c:73
#define DBGC(...)
Definition compiler.h:530
#define DBGC_HDA(...)
Definition compiler.h:531
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:390
struct image * image_memory(const char *name, const void *data, size_t len)
Create registered image from block of memory.
Definition image.c:641
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
An executable image.
Definition image.h:24
struct image_type * type
Image type, if known.
Definition image.h:66
const void * data
Read-only data.
Definition image.h:51
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:63
#define okx(success, file, line)
Report test result.
Definition test.h:44

References image::data, DBGC, DBGC_HDA, image_extract(), image_memory(), image::len, memcmp(), image::name, NULL, okx, strcmp(), test, image::type, and unregister_image().