iPXE
archive_test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * Archive extraction self-tests
29 *
30 */
31
32/* Forcibly enable assertions */
33#undef NDEBUG
34
35#include <stdlib.h>
36#include <string.h>
37#include <ipxe/image.h>
38#include "archive_test.h"
39
40/**
41 * Report an archive extraction test result
42 *
43 * @v test Archive extraction test
44 * @v file Test code file
45 * @v line Test code line
46 */
47void archive_okx ( struct archive_test *test, const char *file,
48 unsigned int line ) {
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
void archive_okx(struct archive_test *test, const char *file, unsigned int line)
Report an archive extraction test result.
static int test
Definition epic100.c:73
#define DBGC(...)
Definition compiler.h:530
#define DBGC_HDA(...)
Definition compiler.h:531
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
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
Executable images.
String functions.
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 archive extraction test.
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