iPXE
Functions | Variables
byteswap_test.c File Reference

Byte-order swapping test functions. More...

#include <stdint.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/test.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
uint16_t test_bswap16 (uint16_t x)
 
uint32_t test_bswap32 (uint32_t x)
 
uint64_t test_bswap64 (uint64_t x)
 
void test_bswap16s (uint16_t *x)
 
void test_bswap32s (uint32_t *x)
 
void test_bswap64s (uint64_t *x)
 
static void byteswap_test_exec (void)
 Perform byte-order swapping. More...
 

Variables

struct self_test byteswap_test __self_test
 Byte-order swapping self-test. More...
 

Detailed Description

Byte-order swapping test functions.

Definition in file byteswap_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ test_bswap16()

uint16_t test_bswap16 ( uint16_t  x)

Definition at line 42 of file byteswap_test.c.

42  {
43  return __bswap_16 ( x );
44 }
#define __bswap_16(value)
Byte-swap a 16-bit value.
Definition: byteswap.h:54

References __bswap_16.

Referenced by byteswap_test_exec().

◆ test_bswap32()

uint32_t test_bswap32 ( uint32_t  x)

Definition at line 46 of file byteswap_test.c.

46  {
47  return __bswap_32 ( x );
48 }
#define __bswap_32(value)
Byte-swap a 32-bit value.
Definition: byteswap.h:66

References __bswap_32.

Referenced by byteswap_test_exec().

◆ test_bswap64()

uint64_t test_bswap64 ( uint64_t  x)

Definition at line 50 of file byteswap_test.c.

50  {
51  return __bswap_64 ( x );
52 }
#define __bswap_64(value)
Byte-swap a 64-bit value.
Definition: byteswap.h:78

References __bswap_64.

Referenced by byteswap_test_exec().

◆ test_bswap16s()

void test_bswap16s ( uint16_t x)

Definition at line 54 of file byteswap_test.c.

54  {
55  __bswap_16s ( x );
56 }

Referenced by byteswap_test_exec().

◆ test_bswap32s()

void test_bswap32s ( uint32_t x)

Definition at line 58 of file byteswap_test.c.

58  {
59  __bswap_32s ( x );
60 }

Referenced by byteswap_test_exec().

◆ test_bswap64s()

void test_bswap64s ( uint64_t x)

Definition at line 62 of file byteswap_test.c.

62  {
63  __bswap_64s ( x );
64 }

Referenced by byteswap_test_exec().

◆ byteswap_test_exec()

static void byteswap_test_exec ( void  )
static

Perform byte-order swapping.

Definition at line 70 of file byteswap_test.c.

70  {
71  uint16_t test16;
72  uint32_t test32;
73  uint64_t test64;
74 
75  ok ( test_bswap16 ( 0x1234 ) == 0x3412 );
76  ok ( test_bswap32 ( 0x12345678UL ) == 0x78563412UL );
77  ok ( test_bswap64 ( 0x123456789abcdef0ULL ) == 0xf0debc9a78563412ULL );
78 
79  test16 = 0xabcd;
80  test_bswap16s ( &test16 );
81  ok ( test16 == 0xcdab );
82 
83  test32 = 0xabcdef01UL;
84  test_bswap32s ( &test32 );
85  ok ( test32 == 0x01efcdabUL );
86 
87  test64 = 0xabcdef0123456789ULL;
88  test_bswap64s ( &test64 );
89  ok ( test64 == 0x8967452301efcdabULL );
90 }
unsigned short uint16_t
Definition: stdint.h:11
unsigned long long uint64_t
Definition: stdint.h:13
uint64_t test_bswap64(uint64_t x)
Definition: byteswap_test.c:50
void test_bswap16s(uint16_t *x)
Definition: byteswap_test.c:54
uint32_t test_bswap32(uint32_t x)
Definition: byteswap_test.c:46
unsigned int uint32_t
Definition: stdint.h:12
uint16_t test_bswap16(uint16_t x)
Definition: byteswap_test.c:42
void test_bswap64s(uint64_t *x)
Definition: byteswap_test.c:62
void test_bswap32s(uint32_t *x)
Definition: byteswap_test.c:58
#define ok(success)
Definition: test.h:46

References ok, test_bswap16(), test_bswap16s(), test_bswap32(), test_bswap32s(), test_bswap64(), and test_bswap64s().

Variable Documentation

◆ __self_test

struct self_test byteswap_test __self_test
Initial value:
= {
.name = "byteswap",
}
static void byteswap_test_exec(void)
Perform byte-order swapping.
Definition: byteswap_test.c:70

Byte-order swapping self-test.

Definition at line 93 of file byteswap_test.c.