iPXE
bitops_test.c File Reference

Bit operations self-tests. More...

#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <ipxe/bitops.h>
#include <ipxe/test.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void bitops_test_exec (void)
 Perform bit operations self-tests.

Variables

struct self_test bitops_test __self_test
 Bit operations self-test.

Detailed Description

Bit operations self-tests.

Definition in file bitops_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ bitops_test_exec()

void bitops_test_exec ( void )
static

Perform bit operations self-tests.

Definition at line 45 of file bitops_test.c.

45 {
46 uint8_t bits[32];
47
48 /* Initialise bits */
49 memset ( bits, 0, sizeof ( bits ) );
50
51 /* Test set_bit() */
52 set_bit ( 0, bits );
53 ok ( bits[0] == 0x01 );
54 set_bit ( 17, bits );
55 ok ( bits[2] == 0x02 );
56 set_bit ( 22, bits );
57 ok ( bits[2] == 0x42 );
58 set_bit ( 22, bits );
59 ok ( bits[2] == 0x42 );
60
61 /* Test clear_bit() */
62 clear_bit ( 0, bits );
63 ok ( bits[0] == 0x00 );
64 bits[5] = 0xff;
65 clear_bit ( 42, bits );
66 ok ( bits[5] == 0xfb );
67 clear_bit ( 42, bits );
68 ok ( bits[5] == 0xfb );
69 clear_bit ( 44, bits );
70 ok ( bits[5] == 0xeb );
71
72 /* Test test_and_set_bit() */
73 ok ( test_and_set_bit ( 0, bits ) == 0 );
74 ok ( bits[0] == 0x01 );
75 ok ( test_and_set_bit ( 0, bits ) != 0 );
76 ok ( bits[0] == 0x01 );
77 ok ( test_and_set_bit ( 69, bits ) == 0 );
78 ok ( bits[8] == 0x20 );
79 ok ( test_and_set_bit ( 69, bits ) != 0 );
80 ok ( bits[8] == 0x20 );
81 ok ( test_and_set_bit ( 69, bits ) != 0 );
82 ok ( bits[8] == 0x20 );
83
84 /* Test test_and_clear_bit() */
85 ok ( test_and_clear_bit ( 0, bits ) != 0 );
86 ok ( bits[0] == 0x00 );
87 ok ( test_and_clear_bit ( 0, bits ) == 0 );
88 ok ( bits[0] == 0x00 );
89 bits[31] = 0xeb;
90 ok ( test_and_clear_bit ( 255, bits ) != 0 );
91 ok ( bits[31] == 0x6b );
92 ok ( test_and_clear_bit ( 255, bits ) == 0 );
93 ok ( bits[31] == 0x6b );
94 ok ( test_and_clear_bit ( 255, bits ) == 0 );
95 ok ( bits[31] == 0x6b );
96}
unsigned char uint8_t
Definition stdint.h:10
static volatile void * bits
Definition bitops.h:28
int test_and_clear_bit(unsigned int bit, volatile void *bits)
int test_and_set_bit(unsigned int bit, volatile void *bits)
void * memset(void *dest, int character, size_t len) __nonnull
#define ok(success)
Definition test.h:46
#define clear_bit(bit, loc)
Definition vxge_main.h:167
#define set_bit(bit, loc)
Definition vxge_main.h:166

References bits, clear_bit, memset(), ok, set_bit, test_and_clear_bit(), and test_and_set_bit().

Variable Documentation

◆ __self_test

struct self_test bitops_test __self_test
Initial value:
= {
.name = "bitops",
}
static void bitops_test_exec(void)
Perform bit operations self-tests.
Definition bitops_test.c:45

Bit operations self-test.

Definition at line 99 of file bitops_test.c.

99 {
100 .name = "bitops",
101 .exec = bitops_test_exec,
102};