LCOV - code coverage report
Current view: top level - cmdline - selftest.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 147 147 100.0 %
Date: 2017-11-06 22:14:04 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2011 Andrea Mazzoleni
       3             :  *
       4             :  * This program is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 3 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * This program is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "portable.h"
      19             : 
      20             : #include "snapraid.h"
      21             : #include "util.h"
      22             : #include "raid/raid.h"
      23             : #include "raid/cpu.h"
      24             : #include "raid/combo.h"
      25             : #include "raid/internal.h"
      26             : #include "raid/test.h"
      27             : #include "elem.h"
      28             : #include "state.h"
      29             : #include "support.h"
      30             : #include "tommyds/tommyhash.h"
      31             : #include "tommyds/tommyarray.h"
      32             : #include "tommyds/tommyarrayblkof.h"
      33             : #include "tommyds/tommyhashdyn.h"
      34             : 
      35             : struct hash32_test_vector {
      36             :         const char* data;
      37             :         int len;
      38             :         uint32_t digest;
      39             : };
      40             : 
      41             : struct strhash32_test_vector {
      42             :         char* data;
      43             :         uint32_t digest;
      44             : };
      45             : 
      46             : struct hash64_test_vector {
      47             :         const char* data;
      48             :         int len;
      49             :         uint64_t digest;
      50             : };
      51             : 
      52             : struct hash_test_vector {
      53             :         const char* data;
      54             :         int len;
      55             :         unsigned char digest[HASH_MAX];
      56             : };
      57             : 
      58             : /**
      59             :  * Test vectors for tommy_hash32
      60             :  */
      61             : static struct hash32_test_vector TEST_HASH32[] = {
      62             :         { "", 0, 0x8614384c },
      63             :         { "a", 1, 0x12c16c36 },
      64             :         { "abc", 3, 0xc58e8af5 },
      65             :         { "message digest", 14, 0x006b32f1 },
      66             :         { "abcdefghijklmnopqrstuvwxyz", 26, 0x7e6fcfe0 },
      67             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x8604adf8 },
      68             :         { "The quick brown fox jumps over the lazy dog", 43, 0xdeba3d3a },
      69             :         { "\x00", 1, 0x4a7d1c33 },
      70             :         { "\x16\x27", 2, 0x8b50899b },
      71             :         { "\xe2\x56\xb4", 3, 0x60406493 },
      72             :         { "\xc9\x4d\x9c\xda", 4, 0xa049144a },
      73             :         { "\x79\xf1\x29\x69\x5d", 5, 0x4da2c2f1 },
      74             :         { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x59de30cf },
      75             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x219e149c },
      76             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x25067520 },
      77             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0xa1f368d8 },
      78             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x805fc63d },
      79             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0x7f75dd0f },
      80             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0xb9154382 },
      81             :         { 0, 0, 0 }
      82             : };
      83             : 
      84             : /**
      85             :  * Test vectors for tommy_strhash32
      86             :  */
      87             : struct strhash32_test_vector TEST_STRHASH32[] = {
      88             :         { "", 0x0af1416d },
      89             :         { "a", 0x68fa0f3f },
      90             :         { "abc", 0xfc68ffc5 },
      91             :         { "message digest", 0x08477b63 },
      92             :         { "abcdefghijklmnopqrstuvwxyz", 0x5b9c25e5 },
      93             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 0x1e530ce7 },
      94             :         { "The quick brown fox jumps over the lazy dog", 0xaf93eefe },
      95             :         { "\xff", 0xfc88801b },
      96             :         { "\x16\x27", 0xcd7216db },
      97             :         { "\xe2\x56\xb4", 0x05f98d02 },
      98             :         { "\xc9\x4d\x9c\xda", 0xf65206f8 },
      99             :         { "\x79\xf1\x29\x69\x5d", 0x72bd6bda },
     100             :         { "\xff\x7e\xdf\x1e\x31\x1c", 0x57dfb9b4 },
     101             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 0x499ff634 },
     102             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 0xe896b7ce },
     103             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 0xfe3939f0 },
     104             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 0x4351d482 },
     105             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\xff\xb7\xae", 0x88e92135 },
     106             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 0x01109c16 },
     107             :         { "\x87\xd8\x61\x61\x4c\x89\x17\x4e\xa1\xa4\xef\x13\xa9", 0xbcb050dc },
     108             :         { "\xfe\xa6\x5b\xc2\xda\xe8\x95\xd4\x64\xab\x4c\x39\x58\x29", 0xbe5e1fd5 },
     109             :         { "\x94\x49\xc0\x78\xa0\x80\xda\xc7\x71\x4e\x17\x37\xa9\x7c\x40", 0x70d8c97f },
     110             :         { "\x53\x7e\x36\xb4\x2e\xc9\xb9\xcc\x18\x3e\x9a\x5f\xfc\xb7\xb0\x61", 0x957440a9 },
     111             :         { 0, 0 }
     112             : };
     113             : 
     114             : /**
     115             :  * Test vectors for tommy_hash64
     116             :  */
     117             : static struct hash64_test_vector TEST_HASH64[] = {
     118             :         { "", 0, 0x8614384cb5165fbfULL },
     119             :         { "a", 1, 0x1a2e0298a8e94a3dULL },
     120             :         { "abc", 3, 0x7555796b7a7d21ebULL },
     121             :         { "message digest", 14, 0x9411a57d04b92fb4ULL },
     122             :         { "abcdefghijklmnopqrstuvwxyz", 26, 0x3ca3f8d2b4e69832ULL },
     123             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x6dae542ba0015a4dULL },
     124             :         { "The quick brown fox jumps over the lazy dog", 43, 0xe06d8cbb3d2ea1a6ULL },
     125             :         { "\x00", 1, 0x201e664fb5f2c021ULL },
     126             :         { "\x16\x27", 2, 0xef42fa8032c4b775ULL },
     127             :         { "\xe2\x56\xb4", 3, 0x6e6c498a6688466cULL },
     128             :         { "\xc9\x4d\x9c\xda", 4, 0x5195005419905423ULL },
     129             :         { "\x79\xf1\x29\x69\x5d", 5, 0x221235b48afee7c1ULL },
     130             :         { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x1b1f18b9266f095bULL },
     131             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x2cbafa8e741d49caULL },
     132             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x4677f04c06e0758dULL },
     133             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0x5afe09e8214e2163ULL },
     134             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x115b6276d209fab6ULL },
     135             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0xd0636d2f01cf3a3eULL },
     136             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0x6d259f5fef74f93eULL },
     137             :         { 0, 0, 0 }
     138             : };
     139             : 
     140             : /**
     141             :  * Test vectors for MurmorHash3_x86_128
     142             :  */
     143             : static struct hash_test_vector TEST_MURMUR3[] = {
     144             : #include "murmur3test.c"
     145             :         { 0, 0, { 0 } }
     146             : };
     147             : 
     148             : /**
     149             :  * Test vectors for SpookyHash_128
     150             :  */
     151             : static struct hash_test_vector TEST_SPOOKY2[] = {
     152             : #include "spooky2test.c"
     153             :         { 0, 0, { 0 } }
     154             : };
     155             : 
     156             : #define HASH_TEST_MAX 512 /* tests are never longer than 512 bytes */
     157             : 
     158           1 : static void test_hash(void)
     159             : {
     160             :         unsigned i;
     161             :         unsigned char* seed_aligned;
     162             :         void* seed_alloc;
     163             :         unsigned char* buffer_aligned;
     164             :         void* buffer_alloc;
     165             :         uint32_t seed32;
     166             :         uint64_t seed64;
     167             : 
     168           1 :         seed_aligned = malloc_nofail_align(HASH_MAX, &seed_alloc);
     169           1 :         buffer_aligned = malloc_nofail_align(HASH_TEST_MAX, &buffer_alloc);
     170             : 
     171           1 :         seed32 = 0xa766795d;
     172           1 :         seed64 = 0x2f022773a766795dULL;
     173             : 
     174           1 :         seed_aligned[0] = 0x5d;
     175           1 :         seed_aligned[1] = 0x79;
     176           1 :         seed_aligned[2] = 0x66;
     177           1 :         seed_aligned[3] = 0xa7;
     178           1 :         seed_aligned[4] = 0x73;
     179           1 :         seed_aligned[5] = 0x27;
     180           1 :         seed_aligned[6] = 0x02;
     181           1 :         seed_aligned[7] = 0x2f;
     182           1 :         seed_aligned[8] = 0x6a;
     183           1 :         seed_aligned[9] = 0xa1;
     184           1 :         seed_aligned[10] = 0x9e;
     185           1 :         seed_aligned[11] = 0xc1;
     186           1 :         seed_aligned[12] = 0x14;
     187           1 :         seed_aligned[13] = 0x8c;
     188           1 :         seed_aligned[14] = 0x9e;
     189           1 :         seed_aligned[15] = 0x43;
     190             : 
     191          20 :         for (i = 0; TEST_HASH32[i].data; ++i) {
     192             :                 uint32_t digest;
     193          19 :                 memcpy(buffer_aligned, TEST_HASH32[i].data, TEST_HASH32[i].len);
     194          19 :                 digest = tommy_hash_u32(seed32, buffer_aligned, TEST_HASH32[i].len);
     195          19 :                 if (digest != TEST_HASH32[i].digest) {
     196             :                         /* LCOV_EXCL_START */
     197             :                         log_fatal("Failed hash32 test\n");
     198             :                         exit(EXIT_FAILURE);
     199             :                         /* LCOV_EXCL_STOP */
     200             :                 }
     201             :         }
     202             : 
     203          24 :         for (i = 0; TEST_STRHASH32[i].data; ++i) {
     204             :                 uint32_t digest;
     205          23 :                 memcpy(buffer_aligned, TEST_STRHASH32[i].data, strlen(TEST_STRHASH32[i].data) + 1);
     206          23 :                 digest = tommy_strhash_u32(seed32, buffer_aligned);
     207          23 :                 if (digest != TEST_STRHASH32[i].digest) {
     208             :                         /* LCOV_EXCL_START */
     209             :                         log_fatal("Failed strhash32 test\n");
     210             :                         exit(EXIT_FAILURE);
     211             :                         /* LCOV_EXCL_STOP */
     212             :                 }
     213             :         }
     214             : 
     215          20 :         for (i = 0; TEST_HASH64[i].data; ++i) {
     216             :                 uint64_t digest;
     217          19 :                 memcpy(buffer_aligned, TEST_HASH64[i].data, TEST_HASH64[i].len);
     218          19 :                 digest = tommy_hash_u64(seed64, buffer_aligned, TEST_HASH64[i].len);
     219          19 :                 if (digest != TEST_HASH64[i].digest) {
     220             :                         /* LCOV_EXCL_START */
     221             :                         log_fatal("Failed hash64 test\n");
     222             :                         exit(EXIT_FAILURE);
     223             :                         /* LCOV_EXCL_STOP */
     224             :                 }
     225             :         }
     226             : 
     227             : 
     228         264 :         for (i = 0; TEST_MURMUR3[i].data; ++i) {
     229             :                 unsigned char digest[HASH_MAX];
     230         263 :                 memcpy(buffer_aligned, TEST_MURMUR3[i].data, TEST_MURMUR3[i].len);
     231         263 :                 memhash(HASH_MURMUR3, seed_aligned, digest, buffer_aligned, TEST_MURMUR3[i].len);
     232         263 :                 if (memcmp(digest, TEST_MURMUR3[i].digest, HASH_MAX) != 0) {
     233             :                         /* LCOV_EXCL_START */
     234             :                         log_fatal("Failed Murmur3 test\n");
     235             :                         exit(EXIT_FAILURE);
     236             :                         /* LCOV_EXCL_STOP */
     237             :                 }
     238             :         }
     239             : 
     240         264 :         for (i = 0; TEST_SPOOKY2[i].data; ++i) {
     241             :                 unsigned char digest[HASH_MAX];
     242         263 :                 memcpy(buffer_aligned, TEST_SPOOKY2[i].data, TEST_SPOOKY2[i].len);
     243         263 :                 memhash(HASH_SPOOKY2, seed_aligned, digest, buffer_aligned, TEST_SPOOKY2[i].len);
     244         263 :                 if (memcmp(digest, TEST_SPOOKY2[i].digest, HASH_MAX) != 0) {
     245             :                         /* LCOV_EXCL_START */
     246             :                         log_fatal("Failed Spooky2 test\n");
     247             :                         exit(EXIT_FAILURE);
     248             :                         /* LCOV_EXCL_STOP */
     249             :                 }
     250             :         }
     251             : 
     252           1 :         free(buffer_alloc);
     253           1 :         free(seed_alloc);
     254           1 : }
     255             : 
     256             : struct crc_test_vector {
     257             :         const char* data;
     258             :         int len;
     259             :         uint32_t digest;
     260             : };
     261             : 
     262             : /**
     263             :  * Test vectors for CRC32C (Castagnoli)
     264             :  */
     265             : static struct crc_test_vector TEST_CRC32C[] = {
     266             :         { "", 0, 0 },
     267             :         { "\x61", 1, 0xc1d04330 },
     268             :         { "\x66\x6f\x6f", 3, 0xcfc4ae1d },
     269             :         { "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64", 11, 0xc99465aa },
     270             :         { "\x68\x65\x6c\x6c\x6f\x20", 6, 0x7e627e58 },
     271             :         { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32, 0x8a9136aa },
     272             :         { "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32, 0x62a8ab43 },
     273             :         { "\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00", 32, 0x113fdb5c },
     274             :         { "\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x14\x00\x00\x00\x18\x28\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 48, 0xd9963a56 },
     275             :         { "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32, 0x46dd794e },
     276             :         { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28", 40, 0x0e2c157f },
     277             :         { "\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50", 40, 0xe980ebf6 },
     278             :         { "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78", 40, 0xde74bded },
     279             :         { "\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0", 40, 0xd579c862 },
     280             :         { "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8", 40, 0xba979ad0 },
     281             :         { "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 40, 0x2b29d913 },
     282             :         { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 240, 0x24c5d375 },
     283             :         { 0, 0, 0 }
     284             : };
     285             : 
     286           1 : static void test_crc32c(void)
     287             : {
     288             :         unsigned i;
     289             : 
     290          18 :         for (i = 0; TEST_CRC32C[i].data; ++i) {
     291             :                 uint32_t digest;
     292             :                 uint32_t digest_gen;
     293             : 
     294          17 :                 digest = crc32c(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
     295          17 :                 digest_gen = crc32c_gen(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
     296             : 
     297          17 :                 if (digest != TEST_CRC32C[i].digest || digest_gen != TEST_CRC32C[i].digest) {
     298             :                         /* LCOV_EXCL_START */
     299             :                         log_fatal("Failed CRC32C test\n");
     300             :                         exit(EXIT_FAILURE);
     301             :                         /* LCOV_EXCL_STOP */
     302             :                 }
     303             :         }
     304           1 : }
     305             : 
     306             : /**
     307             :  * Size of tommy data structures.
     308             :  */
     309             : #define TOMMY_SIZE 256
     310             : 
     311         384 : static int tommy_test_search(const void* arg, const void* obj)
     312             : {
     313         384 :         return arg != obj;
     314             : }
     315             : 
     316        4324 : static int tommy_test_compare(const void* void_arg_a, const void* void_arg_b)
     317             : {
     318        4324 :         if (void_arg_a < void_arg_b)
     319        2007 :                 return -1;
     320        2317 :         if (void_arg_a > void_arg_b)
     321        2058 :                 return 1;
     322         259 :         return 0;
     323             : }
     324             : 
     325             : static unsigned tommy_test_foreach_count;
     326             : 
     327         512 : static void tommy_test_foreach(void* obj)
     328             : {
     329             :         (void)obj;
     330             : 
     331         512 :         ++tommy_test_foreach_count;
     332         512 : }
     333             : 
     334         512 : static void tommy_test_foreach_arg(void* void_arg, void* obj)
     335             : {
     336         512 :         unsigned* arg = void_arg;
     337             : 
     338             :         (void)obj;
     339             : 
     340         512 :         ++*arg;
     341         512 : }
     342             : 
     343           1 : static void test_tommy(void)
     344             : {
     345             :         tommy_array array;
     346             :         tommy_arrayblkof arrayblkof;
     347             :         tommy_list list;
     348             :         tommy_hashdyn hashdyn;
     349             :         tommy_tree tree;
     350             :         tommy_node node[TOMMY_SIZE + 1];
     351             :         unsigned i;
     352             : 
     353           1 :         tommy_array_init(&array);
     354           1 :         tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned));
     355             : 
     356         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
     357         256 :                 tommy_array_insert(&array, &node[i]);
     358         256 :                 tommy_arrayblkof_grow(&arrayblkof, i + 1);
     359         256 :                 *(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i;
     360             :         }
     361             : 
     362           1 :         tommy_array_grow(&array, TOMMY_SIZE);
     363           1 :         tommy_arrayblkof_grow(&arrayblkof, TOMMY_SIZE);
     364             : 
     365           1 :         if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*)) {
     366             :                 /* LCOV_EXCL_START */
     367             :                 goto bail;
     368             :                 /* LCOV_EXCL_STOP */
     369             :         }
     370           1 :         if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned)) {
     371             :                 /* LCOV_EXCL_START */
     372             :                 goto bail;
     373             :                 /* LCOV_EXCL_STOP */
     374             :         }
     375             : 
     376         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
     377         256 :                 if (tommy_array_get(&array, i) != &node[i]) {
     378             :                         /* LCOV_EXCL_START */
     379             :                         goto bail;
     380             :                         /* LCOV_EXCL_STOP */
     381             :                 }
     382         256 :                 if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i) {
     383             :                         /* LCOV_EXCL_START */
     384             :                         goto bail;
     385             :                         /* LCOV_EXCL_STOP */
     386             :                 }
     387             :         }
     388             : 
     389           1 :         tommy_arrayblkof_done(&arrayblkof);
     390           1 :         tommy_array_done(&array);
     391             : 
     392           1 :         tommy_list_init(&list);
     393             : 
     394           1 :         if (!tommy_list_empty(&list)) {
     395             :                 /* LCOV_EXCL_START */
     396             :                 goto bail;
     397             :                 /* LCOV_EXCL_STOP */
     398             :         }
     399             : 
     400           1 :         if (tommy_list_tail(&list)) {
     401             :                 /* LCOV_EXCL_START */
     402             :                 goto bail;
     403             :                 /* LCOV_EXCL_STOP */
     404             :         }
     405             : 
     406           1 :         if (tommy_list_head(&list)) {
     407             :                 /* LCOV_EXCL_START */
     408             :                 goto bail;
     409             :                 /* LCOV_EXCL_STOP */
     410             :         }
     411             : 
     412           1 :         tommy_list_insert_tail(&list, &node[0], &node[0]);
     413             : 
     414           1 :         if (tommy_list_tail(&list) != tommy_list_head(&list)) {
     415             :                 /* LCOV_EXCL_START */
     416             :                 goto bail;
     417             :                 /* LCOV_EXCL_STOP */
     418             :         }
     419             : 
     420           1 :         tommy_hashdyn_init(&hashdyn);
     421             : 
     422         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
     423         256 :                 tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64);
     424             : 
     425           1 :         if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE) {
     426             :                 /* LCOV_EXCL_START */
     427             :                 goto bail;
     428             :                 /* LCOV_EXCL_STOP */
     429             :         }
     430             : 
     431           1 :         if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(tommy_node)) {
     432             :                 /* LCOV_EXCL_START */
     433             :                 goto bail;
     434             :                 /* LCOV_EXCL_STOP */
     435             :         }
     436             : 
     437           1 :         tommy_test_foreach_count = 0;
     438           1 :         tommy_hashdyn_foreach(&hashdyn, tommy_test_foreach);
     439           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     440             :                 /* LCOV_EXCL_START */
     441             :                 goto bail;
     442             :                 /* LCOV_EXCL_STOP */
     443             :         }
     444             : 
     445           1 :         tommy_test_foreach_count = 0;
     446           1 :         tommy_hashdyn_foreach_arg(&hashdyn, tommy_test_foreach_arg, &tommy_test_foreach_count);
     447           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     448             :                 /* LCOV_EXCL_START */
     449             :                 goto bail;
     450             :                 /* LCOV_EXCL_STOP */
     451             :         }
     452             : 
     453         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
     454         128 :                 tommy_hashdyn_remove_existing(&hashdyn, &node[i]);
     455             : 
     456         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i) {
     457         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0) {
     458             :                         /* LCOV_EXCL_START */
     459             :                         goto bail;
     460             :                         /* LCOV_EXCL_STOP */
     461             :                 }
     462             :         }
     463         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i) {
     464         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0) {
     465             :                         /* LCOV_EXCL_START */
     466             :                         goto bail;
     467             :                         /* LCOV_EXCL_STOP */
     468             :                 }
     469             :         }
     470             : 
     471           1 :         if (tommy_hashdyn_count(&hashdyn) != 0) {
     472             :                 /* LCOV_EXCL_START */
     473             :                 goto bail;
     474             :                 /* LCOV_EXCL_STOP */
     475             :         }
     476             : 
     477           1 :         tommy_hashdyn_done(&hashdyn);
     478             : 
     479           1 :         tommy_tree_init(&tree, tommy_test_compare);
     480             : 
     481         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
     482         256 :                 tommy_tree_insert(&tree, &node[i], (void*)(uintptr_t)(i + 1));
     483             : 
     484             :         /* try to insert a duplicate, count should not change */
     485           1 :         tommy_tree_insert(&tree, &node[TOMMY_SIZE], (void*)(uintptr_t)1);
     486             : 
     487           1 :         if (tommy_tree_count(&tree) != TOMMY_SIZE) {
     488             :                 /* LCOV_EXCL_START */
     489             :                 goto bail;
     490             :                 /* LCOV_EXCL_STOP */
     491             :         }
     492           1 :         if (tommy_tree_memory_usage(&tree) < TOMMY_SIZE * sizeof(tommy_node)) {
     493             :                 /* LCOV_EXCL_START */
     494             :                 goto bail;
     495             :                 /* LCOV_EXCL_STOP */
     496             :         }
     497           1 :         if (tommy_tree_search(&tree, (void*)1) != (void*)1) {
     498             :                 /* LCOV_EXCL_START */
     499             :                 goto bail;
     500             :                 /* LCOV_EXCL_STOP */
     501             :         }
     502           1 :         if (tommy_tree_search(&tree, (void*)-1) != 0) {
     503             :                 /* LCOV_EXCL_START */
     504             :                 goto bail;
     505             :                 /* LCOV_EXCL_STOP */
     506             :         }
     507           1 :         if (tommy_tree_search_compare(&tree, tommy_test_compare, (void*)1) != (void*)1) {
     508             :                 /* LCOV_EXCL_START */
     509             :                 goto bail;
     510             :                 /* LCOV_EXCL_STOP */
     511             :         }
     512           1 :         if (tommy_tree_search_compare(&tree, tommy_test_compare, (void*)-1) != 0) {
     513             :                 /* LCOV_EXCL_START */
     514             :                 goto bail;
     515             :                 /* LCOV_EXCL_STOP */
     516             :         }
     517             : 
     518           1 :         tommy_test_foreach_count = 0;
     519           1 :         tommy_tree_foreach(&tree, tommy_test_foreach);
     520           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     521             :                 /* LCOV_EXCL_START */
     522             :                 goto bail;
     523             :                 /* LCOV_EXCL_STOP */
     524             :         }
     525             : 
     526           1 :         tommy_test_foreach_count = 0;
     527           1 :         tommy_tree_foreach_arg(&tree, tommy_test_foreach_arg, &tommy_test_foreach_count);
     528           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     529             :                 /* LCOV_EXCL_START */
     530             :                 goto bail;
     531             :                 /* LCOV_EXCL_STOP */
     532             :         }
     533             : 
     534         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
     535         128 :                 tommy_tree_remove_existing(&tree, &node[i]);
     536             : 
     537         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i) {
     538         128 :                 if (tommy_tree_remove(&tree, (void*)(uintptr_t)(i + 1)) != 0) {
     539             :                         /* LCOV_EXCL_START */
     540             :                         goto bail;
     541             :                         /* LCOV_EXCL_STOP */
     542             :                 }
     543             :         }
     544             : 
     545         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i) {
     546         128 :                 if (tommy_tree_remove(&tree, (void*)(uintptr_t)(i + 1)) == 0) {
     547             :                         /* LCOV_EXCL_START */
     548             :                         goto bail;
     549             :                         /* LCOV_EXCL_STOP */
     550             :                 }
     551             :         }
     552             : 
     553           1 :         if (tommy_tree_count(&tree) != 0) {
     554             :                 /* LCOV_EXCL_START */
     555             :                 goto bail;
     556             :                 /* LCOV_EXCL_STOP */
     557             :         }
     558             : 
     559           2 :         return;
     560             : bail:
     561             :         /* LCOV_EXCL_START */
     562             :         log_fatal("Failed tommy test\n");
     563             :         exit(EXIT_FAILURE);
     564             :         /* LCOV_EXCL_STOP */
     565             : }
     566             : 
     567           1 : void selftest(void)
     568             : {
     569           1 :         log_tag("selftest:\n");
     570           1 :         log_flush();
     571             : 
     572           1 :         msg_progress("Self test...\n");
     573             : 
     574             :         /* large file check */
     575             :         if (sizeof(off_t) < sizeof(uint64_t)) {
     576             :                 /* LCOV_EXCL_START */
     577             :                 log_fatal("Missing support for large files\n");
     578             :                 exit(EXIT_FAILURE);
     579             :                 /* LCOV_EXCL_STOP */
     580             :         }
     581             : 
     582           1 :         test_hash();
     583           1 :         test_crc32c();
     584           1 :         test_tommy();
     585           1 :         if (raid_selftest() != 0) {
     586             :                 /* LCOV_EXCL_START */
     587             :                 log_fatal("Failed SELF test\n");
     588             :                 exit(EXIT_FAILURE);
     589             :                 /* LCOV_EXCL_STOP */
     590             :         }
     591           1 :         if (raid_test_sort() != 0) {
     592             :                 /* LCOV_EXCL_START */
     593             :                 log_fatal("Failed SORT test\n");
     594             :                 exit(EXIT_FAILURE);
     595             :                 /* LCOV_EXCL_STOP */
     596             :         }
     597           1 :         if (raid_test_insert() != 0) {
     598             :                 /* LCOV_EXCL_START */
     599             :                 log_fatal("Failed INSERT test\n");
     600             :                 exit(EXIT_FAILURE);
     601             :                 /* LCOV_EXCL_STOP */
     602             :         }
     603           1 :         if (raid_test_combo() != 0) {
     604             :                 /* LCOV_EXCL_START */
     605             :                 log_fatal("Failed COMBO test\n");
     606             :                 exit(EXIT_FAILURE);
     607             :                 /* LCOV_EXCL_STOP */
     608             :         }
     609           1 :         if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) {
     610             :                 /* LCOV_EXCL_START */
     611             :                 log_fatal("Failed GEN Vandermonde test\n");
     612             :                 exit(EXIT_FAILURE);
     613             :                 /* LCOV_EXCL_STOP */
     614             :         }
     615           1 :         if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) {
     616             :                 /* LCOV_EXCL_START */
     617             :                 log_fatal("Failed REC Vandermonde test\n");
     618             :                 exit(EXIT_FAILURE);
     619             :                 /* LCOV_EXCL_STOP */
     620             :         }
     621           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) {
     622             :                 /* LCOV_EXCL_START */
     623             :                 log_fatal("Failed GEN Cauchy test\n");
     624             :                 exit(EXIT_FAILURE);
     625             :                 /* LCOV_EXCL_STOP */
     626             :         }
     627           1 :         if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) {
     628             :                 /* LCOV_EXCL_START */
     629             :                 log_fatal("Failed REC Cauchy test\n");
     630             :                 exit(EXIT_FAILURE);
     631             :                 /* LCOV_EXCL_STOP */
     632             :         }
     633           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) {
     634             :                 /* LCOV_EXCL_START */
     635             :                 log_fatal("Failed GEN Cauchy test sigle data disk\n");
     636             :                 exit(EXIT_FAILURE);
     637             :                 /* LCOV_EXCL_STOP */
     638             :         }
     639           1 : }
     640             : 

Generated by: LCOV version 1.13