LCOV - code coverage report
Current view: top level - cmdline - selftest.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 145 145 100.0 %
Date: 2016-11-21 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 :         if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*)) {
     363             :                 /* LCOV_EXCL_START */
     364             :                 goto bail;
     365             :                 /* LCOV_EXCL_STOP */
     366             :         }
     367           1 :         if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned)) {
     368             :                 /* LCOV_EXCL_START */
     369             :                 goto bail;
     370             :                 /* LCOV_EXCL_STOP */
     371             :         }
     372             : 
     373         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
     374         256 :                 if (tommy_array_get(&array, i) != &node[i]) {
     375             :                         /* LCOV_EXCL_START */
     376             :                         goto bail;
     377             :                         /* LCOV_EXCL_STOP */
     378             :                 }
     379         256 :                 if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i) {
     380             :                         /* LCOV_EXCL_START */
     381             :                         goto bail;
     382             :                         /* LCOV_EXCL_STOP */
     383             :                 }
     384             :         }
     385             : 
     386           1 :         tommy_arrayblkof_done(&arrayblkof);
     387           1 :         tommy_array_done(&array);
     388             : 
     389           1 :         tommy_list_init(&list);
     390             : 
     391           1 :         if (!tommy_list_empty(&list)) {
     392             :                 /* LCOV_EXCL_START */
     393             :                 goto bail;
     394             :                 /* LCOV_EXCL_STOP */
     395             :         }
     396             : 
     397           1 :         if (tommy_list_tail(&list)) {
     398             :                 /* LCOV_EXCL_START */
     399             :                 goto bail;
     400             :                 /* LCOV_EXCL_STOP */
     401             :         }
     402             : 
     403           1 :         if (tommy_list_head(&list)) {
     404             :                 /* LCOV_EXCL_START */
     405             :                 goto bail;
     406             :                 /* LCOV_EXCL_STOP */
     407             :         }
     408             : 
     409           1 :         tommy_list_insert_tail(&list, &node[0], &node[0]);
     410             : 
     411           1 :         if (tommy_list_tail(&list) != tommy_list_head(&list)) {
     412             :                 /* LCOV_EXCL_START */
     413             :                 goto bail;
     414             :                 /* LCOV_EXCL_STOP */
     415             :         }
     416             : 
     417           1 :         tommy_hashdyn_init(&hashdyn);
     418             : 
     419         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
     420         256 :                 tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64);
     421             : 
     422           1 :         if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE) {
     423             :                 /* LCOV_EXCL_START */
     424             :                 goto bail;
     425             :                 /* LCOV_EXCL_STOP */
     426             :         }
     427             : 
     428           1 :         if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(tommy_node)) {
     429             :                 /* LCOV_EXCL_START */
     430             :                 goto bail;
     431             :                 /* LCOV_EXCL_STOP */
     432             :         }
     433             : 
     434           1 :         tommy_test_foreach_count = 0;
     435           1 :         tommy_hashdyn_foreach(&hashdyn, tommy_test_foreach);
     436           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     437             :                 /* LCOV_EXCL_START */
     438             :                 goto bail;
     439             :                 /* LCOV_EXCL_STOP */
     440             :         }
     441             : 
     442           1 :         tommy_test_foreach_count = 0;
     443           1 :         tommy_hashdyn_foreach_arg(&hashdyn, tommy_test_foreach_arg, &tommy_test_foreach_count);
     444           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     445             :                 /* LCOV_EXCL_START */
     446             :                 goto bail;
     447             :                 /* LCOV_EXCL_STOP */
     448             :         }
     449             : 
     450         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
     451         128 :                 tommy_hashdyn_remove_existing(&hashdyn, &node[i]);
     452             : 
     453         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i) {
     454         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0) {
     455             :                         /* LCOV_EXCL_START */
     456             :                         goto bail;
     457             :                         /* LCOV_EXCL_STOP */
     458             :                 }
     459             :         }
     460         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i) {
     461         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0) {
     462             :                         /* LCOV_EXCL_START */
     463             :                         goto bail;
     464             :                         /* LCOV_EXCL_STOP */
     465             :                 }
     466             :         }
     467             : 
     468           1 :         if (tommy_hashdyn_count(&hashdyn) != 0) {
     469             :                 /* LCOV_EXCL_START */
     470             :                 goto bail;
     471             :                 /* LCOV_EXCL_STOP */
     472             :         }
     473             : 
     474           1 :         tommy_hashdyn_done(&hashdyn);
     475             : 
     476           1 :         tommy_tree_init(&tree, tommy_test_compare);
     477             : 
     478         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
     479         256 :                 tommy_tree_insert(&tree, &node[i], (void*)(uintptr_t)(i + 1));
     480             : 
     481             :         /* try to insert a duplicate, count should not change */
     482           1 :         tommy_tree_insert(&tree, &node[TOMMY_SIZE], (void*)(uintptr_t)1);
     483             : 
     484           1 :         if (tommy_tree_count(&tree) != TOMMY_SIZE) {
     485             :                 /* LCOV_EXCL_START */
     486             :                 goto bail;
     487             :                 /* LCOV_EXCL_STOP */
     488             :         }
     489           1 :         if (tommy_tree_memory_usage(&tree) < TOMMY_SIZE * sizeof(tommy_node)) {
     490             :                 /* LCOV_EXCL_START */
     491             :                 goto bail;
     492             :                 /* LCOV_EXCL_STOP */
     493             :         }
     494           1 :         if (tommy_tree_search(&tree, (void*)1) != (void*)1) {
     495             :                 /* LCOV_EXCL_START */
     496             :                 goto bail;
     497             :                 /* LCOV_EXCL_STOP */
     498             :         }
     499           1 :         if (tommy_tree_search(&tree, (void*)-1) != 0) {
     500             :                 /* LCOV_EXCL_START */
     501             :                 goto bail;
     502             :                 /* LCOV_EXCL_STOP */
     503             :         }
     504           1 :         if (tommy_tree_search_compare(&tree, tommy_test_compare, (void*)1) != (void*)1) {
     505             :                 /* LCOV_EXCL_START */
     506             :                 goto bail;
     507             :                 /* LCOV_EXCL_STOP */
     508             :         }
     509           1 :         if (tommy_tree_search_compare(&tree, tommy_test_compare, (void*)-1) != 0) {
     510             :                 /* LCOV_EXCL_START */
     511             :                 goto bail;
     512             :                 /* LCOV_EXCL_STOP */
     513             :         }
     514             : 
     515           1 :         tommy_test_foreach_count = 0;
     516           1 :         tommy_tree_foreach(&tree, tommy_test_foreach);
     517           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     518             :                 /* LCOV_EXCL_START */
     519             :                 goto bail;
     520             :                 /* LCOV_EXCL_STOP */
     521             :         }
     522             : 
     523           1 :         tommy_test_foreach_count = 0;
     524           1 :         tommy_tree_foreach_arg(&tree, tommy_test_foreach_arg, &tommy_test_foreach_count);
     525           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     526             :                 /* LCOV_EXCL_START */
     527             :                 goto bail;
     528             :                 /* LCOV_EXCL_STOP */
     529             :         }
     530             : 
     531         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
     532         128 :                 tommy_tree_remove_existing(&tree, &node[i]);
     533             : 
     534         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i) {
     535         128 :                 if (tommy_tree_remove(&tree, (void*)(uintptr_t)(i + 1)) != 0) {
     536             :                         /* LCOV_EXCL_START */
     537             :                         goto bail;
     538             :                         /* LCOV_EXCL_STOP */
     539             :                 }
     540             :         }
     541             : 
     542         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i) {
     543         128 :                 if (tommy_tree_remove(&tree, (void*)(uintptr_t)(i + 1)) == 0) {
     544             :                         /* LCOV_EXCL_START */
     545             :                         goto bail;
     546             :                         /* LCOV_EXCL_STOP */
     547             :                 }
     548             :         }
     549             : 
     550           1 :         if (tommy_tree_count(&tree) != 0) {
     551             :                 /* LCOV_EXCL_START */
     552             :                 goto bail;
     553             :                 /* LCOV_EXCL_STOP */
     554             :         }
     555             : 
     556           2 :         return;
     557             : bail:
     558             :         /* LCOV_EXCL_START */
     559             :         log_fatal("Failed tommy test\n");
     560             :         exit(EXIT_FAILURE);
     561             :         /* LCOV_EXCL_STOP */
     562             : }
     563             : 
     564           1 : void selftest(void)
     565             : {
     566           1 :         log_tag("selftest:\n");
     567           1 :         log_flush();
     568             : 
     569           1 :         msg_progress("Self test...\n");
     570             : 
     571             :         /* large file check */
     572             :         if (sizeof(off_t) < sizeof(uint64_t)) {
     573             :                 /* LCOV_EXCL_START */
     574             :                 log_fatal("Missing support for large files\n");
     575             :                 exit(EXIT_FAILURE);
     576             :                 /* LCOV_EXCL_STOP */
     577             :         }
     578             : 
     579           1 :         test_hash();
     580           1 :         test_crc32c();
     581           1 :         test_tommy();
     582           1 :         if (raid_selftest() != 0) {
     583             :                 /* LCOV_EXCL_START */
     584             :                 log_fatal("Failed SELF test\n");
     585             :                 exit(EXIT_FAILURE);
     586             :                 /* LCOV_EXCL_STOP */
     587             :         }
     588           1 :         if (raid_test_sort() != 0) {
     589             :                 /* LCOV_EXCL_START */
     590             :                 log_fatal("Failed SORT test\n");
     591             :                 exit(EXIT_FAILURE);
     592             :                 /* LCOV_EXCL_STOP */
     593             :         }
     594           1 :         if (raid_test_insert() != 0) {
     595             :                 /* LCOV_EXCL_START */
     596             :                 log_fatal("Failed INSERT test\n");
     597             :                 exit(EXIT_FAILURE);
     598             :                 /* LCOV_EXCL_STOP */
     599             :         }
     600           1 :         if (raid_test_combo() != 0) {
     601             :                 /* LCOV_EXCL_START */
     602             :                 log_fatal("Failed COMBO test\n");
     603             :                 exit(EXIT_FAILURE);
     604             :                 /* LCOV_EXCL_STOP */
     605             :         }
     606           1 :         if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) {
     607             :                 /* LCOV_EXCL_START */
     608             :                 log_fatal("Failed GEN Vandermonde test\n");
     609             :                 exit(EXIT_FAILURE);
     610             :                 /* LCOV_EXCL_STOP */
     611             :         }
     612           1 :         if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) {
     613             :                 /* LCOV_EXCL_START */
     614             :                 log_fatal("Failed REC Vandermonde test\n");
     615             :                 exit(EXIT_FAILURE);
     616             :                 /* LCOV_EXCL_STOP */
     617             :         }
     618           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) {
     619             :                 /* LCOV_EXCL_START */
     620             :                 log_fatal("Failed GEN Cauchy test\n");
     621             :                 exit(EXIT_FAILURE);
     622             :                 /* LCOV_EXCL_STOP */
     623             :         }
     624           1 :         if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) {
     625             :                 /* LCOV_EXCL_START */
     626             :                 log_fatal("Failed REC Cauchy test\n");
     627             :                 exit(EXIT_FAILURE);
     628             :                 /* LCOV_EXCL_STOP */
     629             :         }
     630           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) {
     631             :                 /* LCOV_EXCL_START */
     632             :                 log_fatal("Failed GEN Cauchy test sigle data disk\n");
     633             :                 exit(EXIT_FAILURE);
     634             :                 /* LCOV_EXCL_STOP */
     635             :         }
     636           1 : }
     637             : 

Generated by: LCOV version 1.10