2
* Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
* You can also choose to distribute this program under the terms of
20
* the Unmodified Binary Distribution Licence (as given in the file
21
* COPYING.UBDL), provided that you have satisfied its requirements.
24
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
28
* Bit operations self-tests
32
/* Forcibly enable assertions */
38
#include <ipxe/bitops.h>
39
#include <ipxe/test.h>
42
* Perform bit operations self-tests
45
static void bitops_test_exec ( void ) {
49
memset ( bits, 0, sizeof ( bits ) );
53
ok ( bits[0] == 0x01 );
55
ok ( bits[2] == 0x02 );
57
ok ( bits[2] == 0x42 );
59
ok ( bits[2] == 0x42 );
61
/* Test clear_bit() */
62
clear_bit ( 0, bits );
63
ok ( bits[0] == 0x00 );
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 );
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 );
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 );
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 );
98
/** Bit operations self-test */
99
struct self_test bitops_test __self_test = {
101
.exec = bitops_test_exec,