57 #define CPIO_HEADER( mode, filesize, namesize, pname ) \ 58 "070701" "00000000" mode "00000000" "00000000" "00000001" \ 59 "00000000" filesize "00000000" "00000000" "00000000" "00000000" \ 60 namesize "00000000" pname 72 #define PAD4 "\0\0\0\0" 75 #define CPIO_TEST( NAME, LEN, CMDLINE, COUNT, EXPECTED ) \ 76 static const uint8_t NAME ## _expected[] = EXPECTED; \ 77 static struct cpio_test NAME = { \ 81 .expected = NAME ## _expected, \ 82 .expected_len = ( sizeof ( NAME ## _expected ) \ 84 .expected_count = COUNT, \ 104 DBGC (
test,
"CPIO len %#zx cmdline \"%s\"\n",
121 okx ( cpio_len >=
sizeof ( cpio ), file, line );
126 okx ( i ==
test->expected_count, file, line );
127 okx (
len ==
test->expected_len, file, line );
138 ( cpio_len -
sizeof ( cpio ) ) );
140 for ( j = 0 ; j < cpio_len ; j++ ) {
141 if ( ( j <=
sizeof ( cpio ) && ! ( ( j + 2 ) % 8 ) ) )
148 okx ( i ==
test->expected_count, file, line );
149 okx (
len ==
test->expected_len, file, line );
162 #define cpio_ok( test ) cpio_okx ( test, __FILE__, __LINE__ ) 168 CPIO_TEST ( empty_cmdline, 154,
"", 0,
"" );
171 CPIO_TEST ( all_slashes, 64,
"////", 0,
"" );
179 CPIO_TEST ( init_slash, 0x273,
"/wimboot", 1,
184 CPIO_TEST ( init_slashes, 0x94,
"///initscript", 1,
186 "///initscript" PAD1 ) );
189 CPIO_TEST ( path, 0x341,
"/usr/share/oem/config.ign", 1,
191 "/usr/share/oem/config.ign" PAD1 ) );
194 CPIO_TEST ( path_mkdir_0, 0x341,
"/usr/share/oem/config.ign mkdir=0", 1,
196 "/usr/share/oem/config.ign" PAD1 ) );
199 CPIO_TEST ( path_mkdir_1, 0x341,
"/usr/share/oem/config.ign mkdir=1", 2,
201 "/usr/share/oem" PAD4 )
203 "/usr/share/oem/config.ign" PAD1 ) );
206 CPIO_TEST ( path_mkdir_2, 0x341,
"/usr/share/oem/config.ign mkdir=2", 3,
210 "/usr/share/oem" PAD4 )
212 "/usr/share/oem/config.ign" PAD1 ) );
215 CPIO_TEST ( path_mkdir_all, 0x341,
"/usr/share/oem/config.ign mkdir=-1", 4,
221 "/usr/share/oem" PAD4 )
223 "/usr/share/oem/config.ign" PAD1 ) );
231 CPIO_TEST ( tree, 0,
"/opt/oem/scripts/ mkdir=-1", 3,
237 "/opt/oem/scripts" PAD2 ) );
242 "/sbin/init" PAD4 ) );
245 CPIO_TEST ( chaos, 73,
"///etc//init.d///runthings mode=700 mkdir=99", 3,
249 "///etc//init.d" PAD4 )
251 "///etc//init.d///runthings" PAD4 ) );
size_t expected_len
Length of expected CPIO headers.
unsigned int expected_count
Expected number of CPIO headers.
const uint8_t * expected
Expected CPIO headers.
uint16_t mode
Acceleration mode.
#define CPIO_ALIGN
CPIO header length alignment.
#define PAD3
Define a three-byte padding.
Self-test infrastructure.
const char * name
Test set name.
static size_t cpio_pad_len(size_t len)
Get CPIO header zero-padding length.
#define PAD2
Define a two-byte padding.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t cpio_header(struct image *image, unsigned int index, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
static void cpio_test_exec(void)
Perform CPIO self-test.
#define okx(success, file, line)
Report test result.
#define PAD4
Define four-byte padding.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static void cpio_okx(struct cpio_test *test, const char *file, unsigned int line)
Report a CPIO test result.
const char * cmdline
Image command line.
static void(* free)(struct refcnt *refcnt))
void * zalloc(size_t size)
Allocate cleared memory.
int image_set_name(struct image *image, const char *name)
Set image name.
static void image_put(struct image *image)
Decrement reference count on an image.
#define CPIO_HEADER(mode, filesize, namesize, pname)
Define an expected CPIO header.
int image_set_len(struct image *image, size_t len)
Set image length.
uint8_t data[48]
Additional event data.
#define CPIO_TEST(NAME, LEN, CMDLINE, COUNT, EXPECTED)
Define a CPIO test.
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
#define PAD1
Define a one-byte padding.
struct image * alloc_image(struct uri *uri)
Allocate executable image.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define NULL
NULL pointer (VOID *)
const char * name
Test name.
struct self_test cpio_test __self_test
CPIO self-test.
static const char * cpio_name(struct image *image)
Get CPIO image name.