iPXE
Macros | Functions | Variables
uuid_test.c File Reference

UUID tests. More...

#include <string.h>
#include <byteswap.h>
#include <ipxe/uuid.h>
#include <ipxe/test.h>

Go to the source code of this file.

Macros

#define UUID(A, B, C, D, E0, E1, E2, E3, E4, E5)
 Define an inline UUID value. More...
 
#define uuid_ntoa_ok(value, text)
 
#define uuid_aton_ok(text, value)
 
#define uuid_aton_fail_ok(text)   uuid_aton_fail_okx ( text, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void uuid_ntoa_okx (const union uuid *uuid, const char *text, const char *file, unsigned int line)
 Report a uuid_ntoa() test result. More...
 
static void uuid_aton_okx (const char *text, const union uuid *uuid, const char *file, unsigned int line)
 Report a uuid_aton() test result. More...
 
static void uuid_aton_fail_okx (const char *text, const char *file, unsigned int line)
 Report a uuid_aton() failure test result. More...
 
static void uuid_test_exec (void)
 Perform UUID self-tests. More...
 

Variables

struct self_test uuid_test __self_test
 UUID self-test. More...
 

Detailed Description

UUID tests.

Definition in file uuid_test.c.

Macro Definition Documentation

◆ UUID

#define UUID (   A,
  B,
  C,
  D,
  E0,
  E1,
  E2,
  E3,
  E4,
  E5 
)
Value:
{ \
.a = htonl ( A ), \
.b = htons ( B ), \
.c = htons ( C ), \
.d = htons ( D ), \
.e = { E0, E1, E2, E3, E4, E5 }, \
}
#define htonl(value)
Definition: byteswap.h:133
#define htons(value)
Definition: byteswap.h:135

Define an inline UUID value.

Definition at line 41 of file uuid_test.c.

◆ uuid_ntoa_ok

#define uuid_ntoa_ok (   value,
  text 
)
Value:
do { \
static const union uuid uuid = { \
}; \
uuid_ntoa_okx ( &uuid, text, __FILE__, __LINE__ ); \
} while ( 0 )
A universally unique ID.
Definition: uuid.h:15
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct uuid::@648 canonical
Canonical form (00000000-0000-0000-0000-000000000000)

Definition at line 71 of file uuid_test.c.

◆ uuid_aton_ok

#define uuid_aton_ok (   text,
  value 
)
Value:
do { \
static const union uuid uuid = { \
}; \
uuid_aton_okx ( text, &uuid, __FILE__, __LINE__ ); \
} while ( 0 )
A universally unique ID.
Definition: uuid.h:15
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct uuid::@648 canonical
Canonical form (00000000-0000-0000-0000-000000000000)

Definition at line 95 of file uuid_test.c.

◆ uuid_aton_fail_ok

#define uuid_aton_fail_ok (   text)    uuid_aton_fail_okx ( text, __FILE__, __LINE__ )

Definition at line 116 of file uuid_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ uuid_ntoa_okx()

static void uuid_ntoa_okx ( const union uuid uuid,
const char *  text,
const char *  file,
unsigned int  line 
)
static

Report a uuid_ntoa() test result.

Parameters
uuidUUID
textExpected textual representation
fileTest code file
lineTest code line

Definition at line 57 of file uuid_test.c.

58  {
59  const char *actual;
60 
61  /* Format address */
62  actual = uuid_ntoa ( uuid );
63  DBG ( "uuid_ntoa ( %08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x ) = "
64  "\"%s\"\n", ntohl ( uuid->canonical.a ),
66  ntohs ( uuid->canonical.d ), uuid->canonical.e[0],
67  uuid->canonical.e[1], uuid->canonical.e[2], uuid->canonical.e[3],
68  uuid->canonical.e[4], uuid->canonical.e[5], actual );
69  okx ( strcmp ( actual, text ) == 0, file, line );
70 }
uint32_t a
8 hex digits, big-endian
Definition: uuid.h:19
uint16_t c
2 hex digits, big-endian
Definition: uuid.h:23
A universally unique ID.
Definition: uuid.h:15
#define ntohl(value)
Definition: byteswap.h:134
uint16_t d
2 hex digits, big-endian
Definition: uuid.h:25
#define ntohs(value)
Definition: byteswap.h:136
#define okx(success, file, line)
Report test result.
Definition: test.h:44
uint16_t b
2 hex digits, big-endian
Definition: uuid.h:21
struct uuid::@648 canonical
Canonical form (00000000-0000-0000-0000-000000000000)
uint8_t e[6]
12 hex digits, big-endian
Definition: uuid.h:27
const char * uuid_ntoa(const union uuid *uuid)
Convert UUID to printable string.
Definition: uuid.c:45
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References uuid::a, uuid::b, uuid::c, uuid::canonical, uuid::d, DBG, uuid::e, ntohl, ntohs, okx, strcmp(), and uuid_ntoa().

◆ uuid_aton_okx()

static void uuid_aton_okx ( const char *  text,
const union uuid uuid,
const char *  file,
unsigned int  line 
)
static

Report a uuid_aton() test result.

Parameters
textTextual representation
uuidExpected UUID
fileTest code file
lineTest code line

Definition at line 86 of file uuid_test.c.

87  {
88  union uuid actual;
89 
90  /* Parse address */
91  okx ( uuid_aton ( text, &actual ) == 0, file, line );
92  DBG ( "uuid_aton ( \"%s\" ) = %s\n", text, uuid_ntoa ( &actual ) );
93  okx ( memcmp ( &actual, uuid, sizeof ( actual ) ) == 0, file, line );
94 };
A universally unique ID.
Definition: uuid.h:15
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
Definition: uuid.c:66
#define okx(success, file, line)
Report test result.
Definition: test.h:44
const char * uuid_ntoa(const union uuid *uuid)
Convert UUID to printable string.
Definition: uuid.c:45
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114

References DBG, memcmp(), okx, uuid_aton(), and uuid_ntoa().

◆ uuid_aton_fail_okx()

static void uuid_aton_fail_okx ( const char *  text,
const char *  file,
unsigned int  line 
)
static

Report a uuid_aton() failure test result.

Parameters
textTextual representation
fileTest code file
lineTest code line

Definition at line 109 of file uuid_test.c.

110  {
111  union uuid actual;
112 
113  /* Attempt to parse address */
114  okx ( uuid_aton ( text, &actual ) != 0, file, line );
115 }
A universally unique ID.
Definition: uuid.h:15
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
Definition: uuid.c:66
#define okx(success, file, line)
Report test result.
Definition: test.h:44

References okx, and uuid_aton().

◆ uuid_test_exec()

static void uuid_test_exec ( void  )
static

Perform UUID self-tests.

Definition at line 123 of file uuid_test.c.

123  {
124 
125  /* uuid_ntoa() tests */
126  uuid_ntoa_ok ( UUID ( 0x18725ca6, 0xd699, 0x4e4d, 0xb501,
127  0xc3, 0x80, 0x91, 0xd2, 0xa4, 0x33 ),
128  "18725ca6-d699-4e4d-b501-c38091d2a433" );
129  uuid_ntoa_ok ( UUID ( 0x1a969b23, 0xc7d5, 0x40fe, 0xb79a,
130  0xc9, 0x2e, 0xa3, 0x4a ,0xb4, 0x5b ),
131  "1a969b23-c7d5-40fe-b79a-c92ea34ab45b" );
132 
133  /* uuid_aton() tests */
134  uuid_aton_ok ( "62b907a8-e1a7-460e-82f7-667d84270c84",
135  UUID ( 0x62b907a8, 0xe1a7, 0x460e, 0x82f7,
136  0x66, 0x7d, 0x84, 0x27, 0x0c, 0x84 ) );
137  uuid_aton_ok ( "F5D0349C-EF7C-4AD4-B40B-FC2E522A7327",
138  UUID ( 0xf5d0349c, 0xef7c, 0x4ad4, 0xb40b,
139  0xfc, 0x2e, 0x52, 0x2a, 0x73, 0x27 ) );
140  uuid_aton_ok ( "4edd80ff7b43465589a02b1e7cffa196",
141  UUID ( 0x4edd80ff, 0x7b43, 0x4655, 0x89a0,
142  0x2b, 0x1e, 0x7c, 0xff, 0xa1, 0x96 ) );
143 
144  /* uuid_aton() failure tests */
145  uuid_aton_fail_ok ( "628d677b-cf38-471e-9ad9-c8a5d9220055b6" );
146  uuid_aton_fail_ok ( "5071ca26-fc5f-4580-887a-46d9a103e4" );
147  uuid_aton_fail_ok ( "453aee96:0fb5-4aeb-aecd-d060b2121218" );
148  uuid_aton_fail_ok ( "1ccb524a-b8b9-4b17-x5e2-7996867edc7d" );
149  uuid_aton_fail_ok ( "" );
150 }
#define UUID(A, B, C, D, E0, E1, E2, E3, E4, E5)
Define an inline UUID value.
Definition: uuid_test.c:41
#define uuid_aton_fail_ok(text)
Definition: uuid_test.c:116
#define uuid_aton_ok(text, value)
Definition: uuid_test.c:95
#define uuid_ntoa_ok(value, text)
Definition: uuid_test.c:71

References UUID, uuid_aton_fail_ok, uuid_aton_ok, and uuid_ntoa_ok.

Variable Documentation

◆ __self_test

struct self_test uuid_test __self_test
Initial value:
= {
.name = "uuid",
.exec = uuid_test_exec,
}
static void uuid_test_exec(void)
Perform UUID self-tests.
Definition: uuid_test.c:123

UUID self-test.

Definition at line 153 of file uuid_test.c.