iPXE
Functions | Variables
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 ( GPL2_OR_LATER_OR_UBDL  )
static void bitops_test_exec ( void  ) [static]

Perform bit operations self-tests.

Definition at line 45 of file bitops_test.c.

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

                                      {
        uint8_t bits[32];

        /* Initialise bits */
        memset ( bits, 0, sizeof ( bits ) );

        /* Test set_bit() */
        set_bit ( 0, bits );
        ok ( bits[0] == 0x01 );
        set_bit ( 17, bits );
        ok ( bits[2] == 0x02 );
        set_bit ( 22, bits );
        ok ( bits[2] == 0x42 );
        set_bit ( 22, bits );
        ok ( bits[2] == 0x42 );

        /* Test clear_bit() */
        clear_bit ( 0, bits );
        ok ( bits[0] == 0x00 );
        bits[5] = 0xff;
        clear_bit ( 42, bits );
        ok ( bits[5] == 0xfb );
        clear_bit ( 42, bits );
        ok ( bits[5] == 0xfb );
        clear_bit ( 44, bits );
        ok ( bits[5] == 0xeb );

        /* Test test_and_set_bit() */
        ok ( test_and_set_bit ( 0, bits ) == 0 );
        ok ( bits[0] == 0x01 );
        ok ( test_and_set_bit ( 0, bits ) != 0 );
        ok ( bits[0] == 0x01 );
        ok ( test_and_set_bit ( 69, bits ) == 0 );
        ok ( bits[8] == 0x20 );
        ok ( test_and_set_bit ( 69, bits ) != 0 );
        ok ( bits[8] == 0x20 );
        ok ( test_and_set_bit ( 69, bits ) != 0 );
        ok ( bits[8] == 0x20 );

        /* Test test_and_clear_bit() */
        ok ( test_and_clear_bit ( 0, bits ) != 0 );
        ok ( bits[0] == 0x00 );
        ok ( test_and_clear_bit ( 0, bits ) == 0 );
        ok ( bits[0] == 0x00 );
        bits[31] = 0xeb;
        ok ( test_and_clear_bit ( 255, bits ) != 0 );
        ok ( bits[31] == 0x6b );
        ok ( test_and_clear_bit ( 255, bits ) == 0 );
        ok ( bits[31] == 0x6b );
        ok ( test_and_clear_bit ( 255, bits ) == 0 );
        ok ( bits[31] == 0x6b );
}

Variable Documentation

struct self_test bitops_test __self_test
Initial value:
 {
        .name = "bitops",
        .exec = bitops_test_exec,
}

Bit operations self-test.

Definition at line 99 of file bitops_test.c.