+ unsigned int nrbits_ui, nrbits_ull, readval_ui;
+ union {
+ unsigned char c[TEST_LEN];
+ unsigned short s[TEST_LEN/sizeof(unsigned short)];
+ unsigned int i[TEST_LEN/sizeof(unsigned int)];
+ unsigned long l[TEST_LEN/sizeof(unsigned long)];
+ unsigned long long ll[TEST_LEN/sizeof(unsigned long long)];
+ } target;
+ unsigned long long readval_ull;
+ unsigned int s, l;
+
+ nrbits_ui = fls_u32(src_ui);
+
+ /* Read to unsigned integer readval output. */
+ for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
+ for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval_ui);
+ if (check_result(src_ui, readval_ui, target.c, unsigned char,
+ s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.s, unsigned char, s, l, src_ui);
+ bt_bitfield_read(target.c, unsigned short, s, l, &readval_ui);
+ if (check_result(src_ui, readval_ui, target.c, unsigned short,
+ s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.i, unsigned char, s, l, src_ui);
+ bt_bitfield_read(target.c, unsigned int, s, l, &readval_ui);
+ if (check_result(src_ui, readval_ui, target.c, unsigned int,
+ s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.l, unsigned char, s, l, src_ui);
+ bt_bitfield_read(target.c, unsigned long, s, l, &readval_ui);
+ if (check_result(src_ui, readval_ui, target.c, unsigned long,
+ s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.ll, unsigned char, s, l, src_ui);
+ bt_bitfield_read(target.c, unsigned long long, s, l, &readval_ui);
+ if (check_result(src_ui, readval_ui, target.c, unsigned long long,
+ s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+ }
+ }
+ pass(UNSIGNED_INT_READ_TEST_DESC_FMT_STR, src_ui);
+
+ nrbits_ull = fls_u64(src_ull);
+
+ /* Read to unsigned long long readval output. */
+ for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
+ for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
+ bt_bitfield_read(target.c, unsigned char, s, l, &readval_ull);
+ if (check_result(src_ull, readval_ull, target.c, unsigned char,
+ s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.s, unsigned char, s, l, src_ull);
+ bt_bitfield_read(target.c, unsigned short, s, l, &readval_ull);
+ if (check_result(src_ull, readval_ull, target.c, unsigned short,
+ s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.i, unsigned char, s, l, src_ull);
+ bt_bitfield_read(target.c, unsigned int, s, l, &readval_ull);
+ if (check_result(src_ull, readval_ull, target.c, unsigned int,
+ s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.l, unsigned char, s, l, src_ull);
+ bt_bitfield_read(target.c, unsigned long, s, l, &readval_ull);
+ if (check_result(src_ull, readval_ull, target.c, unsigned long,
+ s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+
+ init_byte_array(target.c, TEST_LEN, 0xFF);
+ bt_bitfield_write(target.ll, unsigned char, s, l, src_ull);
+ bt_bitfield_read(target.c, unsigned long long, s, l, &readval_ull);
+ if (check_result(src_ull, readval_ull, target.c, unsigned long long,
+ s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
+ return;
+ }
+ }
+ }
+ pass(UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR, src_ull);
+}
+
+void run_test_unsigned(unsigned int src_ui, unsigned long long src_ull)
+{
+ run_test_unsigned_write(src_ui, src_ull);
+ run_test_unsigned_read(src_ui, src_ull);
+}
+
+void run_test_signed_write(int src_i, long long src_ll)
+{
+ int nrbits_i, nrbits_ll;