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

CRC32 tests. More...

#include <stdint.h>
#include <ipxe/crc32.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  crc32_test
 A CRC32 test. More...
 

Macros

#define DATA(...)   { __VA_ARGS__ }
 Define inline data. More...
 
#define CRC32_TEST(name, DATA, SEED, CRC32)
 Define a CRC32 test. More...
 
#define crc32_ok(test)
 Report a CRC32 test result. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 CRC32_TEST (empty_test, DATA(), 0x12345678UL, 0x12345678UL)
 
 CRC32_TEST (hw_test, DATA( 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'), 0xffffffffUL, 0xf2b5ee7aUL)
 
 CRC32_TEST (hw_split_part1_test, DATA( 'h', 'e', 'l', 'l', 'o'), 0xffffffffUL, 0xc9ef5979UL)
 
 CRC32_TEST (hw_split_part2_test, DATA(' ', 'w', 'o', 'r', 'l', 'd'), 0xc9ef5979UL, 0xf2b5ee7aUL)
 
static void crc32_test_exec (void)
 Perform CRC32 self-tests. More...
 

Variables

struct self_test crc32_test __self_test
 CRC32 self-test. More...
 

Detailed Description

CRC32 tests.

Test vectors generated using Perl's Digest::CRC:

use Digest::CRC qw ( crc );

printf "%#08x", crc ( $data, 32, $seed, 0, 1, 0x04c11db7, 1 );

Definition in file crc32_test.c.

Macro Definition Documentation

◆ DATA

#define DATA (   ...)    { __VA_ARGS__ }

Define inline data.

Definition at line 47 of file crc32_test.c.

◆ CRC32_TEST

#define CRC32_TEST (   name,
  DATA,
  SEED,
  CRC32 
)
Value:
static const uint8_t name ## _data[] = DATA; \
static struct crc32_test name = { \
.data = name ## _data, \
.len = sizeof ( name ## _data ), \
.seed = SEED, \
.crc32 = CRC32, \
};
const char * name
Definition: ath9k_hw.c:1984
uint32_t seed
Seed.
Definition: crc32_test.c:56
A CRC32 test.
Definition: crc32_test.c:50
uint32_t crc32
Expected CRC32.
Definition: crc32_test.c:58
#define CRC32
Definition: amd8111e.h:616
unsigned char uint8_t
Definition: stdint.h:10
#define DATA(...)
Define inline data.
Definition: crc32_test.c:47

Define a CRC32 test.

Parameters
nameTest name
DATATest data
SEEDSeed
CRC32Expected CRC32
Return values
testCRC32 test

Definition at line 70 of file crc32_test.c.

◆ crc32_ok

#define crc32_ok (   test)
Value:
do { \
uint32_t crc32; \
crc32 = crc32_le ( (test)->seed, (test)->data, (test)->len ); \
ok ( crc32 == (test)->crc32 ); \
} while ( 0 )
uint32_t seed
Seed.
Definition: crc32_test.c:56
uint32_t crc32
Expected CRC32.
Definition: crc32_test.c:58
u32 crc32_le(u32 seed, const void *data, size_t len)
Calculate 32-bit little-endian CRC checksum.
Definition: crc32.c:39
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
static int test
Definition: epic100.c:73

Report a CRC32 test result.

Parameters
testCRC32 test

Definition at line 84 of file crc32_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ CRC32_TEST() [1/4]

CRC32_TEST ( empty_test  ,
DATA()  ,
0x12345678UL  ,
0x12345678UL   
)

◆ CRC32_TEST() [2/4]

CRC32_TEST ( hw_test  ,
DATA('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd')  ,
0xffffffffUL  ,
0xf2b5ee7aUL   
)

◆ CRC32_TEST() [3/4]

CRC32_TEST ( hw_split_part1_test  ,
DATA('h', 'e', 'l', 'l', 'o')  ,
0xffffffffUL  ,
0xc9ef5979UL   
)

◆ CRC32_TEST() [4/4]

CRC32_TEST ( hw_split_part2_test  ,
DATA(' ', 'w', 'o', 'r', 'l', 'd')  ,
0xc9ef5979UL  ,
0xf2b5ee7aUL   
)

◆ crc32_test_exec()

static void crc32_test_exec ( void  )
static

Perform CRC32 self-tests.

Definition at line 108 of file crc32_test.c.

108  {
109 
110  crc32_ok ( &empty_test );
111  crc32_ok ( &hw_test );
112  crc32_ok ( &hw_split_part1_test );
113  crc32_ok ( &hw_split_part2_test );
114 }
#define crc32_ok(test)
Report a CRC32 test result.
Definition: crc32_test.c:84

References crc32_ok.

Variable Documentation

◆ __self_test

struct self_test crc32_test __self_test
Initial value:
= {
.name = "crc32",
.exec = crc32_test_exec,
}
static void crc32_test_exec(void)
Perform CRC32 self-tests.
Definition: crc32_test.c:108

CRC32 self-test.

Definition at line 117 of file crc32_test.c.