LCOV - code coverage report
Current view: top level - cmdline - selftest.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 147 148 99.3 %
Date: 2026-03-15 15:58:19 Functions: 9 9 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             :         uint32_t seed;
      40             : };
      41             : 
      42             : struct strhash32_test_vector {
      43             :         char* data;
      44             :         uint32_t digest;
      45             :         uint32_t seed;
      46             : };
      47             : 
      48             : struct hash64_test_vector {
      49             :         const char* data;
      50             :         int len;
      51             :         uint64_t digest;
      52             :         uint64_t seed;
      53             : };
      54             : 
      55             : struct hash_test_vector {
      56             :         const char* data;
      57             :         int len;
      58             :         unsigned char digest[HASH_MAX];
      59             :         unsigned char seed[HASH_MAX];
      60             : };
      61             : 
      62             : /**
      63             :  * Test vectors for tommy_hash32
      64             :  */
      65             : static struct hash32_test_vector TEST_HASH32[] = {
      66             :         { "", 0, 0x8614384c, 0xa766795d },
      67             :         { "a", 1, 0x12c16c36, 0xa766795d },
      68             :         { "abc", 3, 0xc58e8af5, 0xa766795d },
      69             :         { "message digest", 14, 0x006b32f1, 0xa766795d },
      70             :         { "abcdefghijklmnopqrstuvwxyz", 26, 0x7e6fcfe0, 0xa766795d },
      71             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x8604adf8, 0xa766795d },
      72             :         { "The quick brown fox jumps over the lazy dog", 43, 0xdeba3d3a, 0xa766795d },
      73             :         { "\x00", 1, 0x4a7d1c33, 0xa766795d },
      74             :         { "\x16\x27", 2, 0x8b50899b, 0xa766795d },
      75             :         { "\xe2\x56\xb4", 3, 0x60406493, 0xa766795d },
      76             :         { "\xc9\x4d\x9c\xda", 4, 0xa049144a, 0xa766795d },
      77             :         { "\x79\xf1\x29\x69\x5d", 5, 0x4da2c2f1, 0xa766795d },
      78             :         { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x59de30cf, 0xa766795d },
      79             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x219e149c, 0xa766795d },
      80             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x25067520, 0xa766795d },
      81             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0xa1f368d8, 0xa766795d },
      82             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x805fc63d, 0xa766795d },
      83             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0x7f75dd0f, 0xa766795d },
      84             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0xb9154382, 0xa766795d },
      85             :         { 0, 0, 0, 0 }
      86             : };
      87             : 
      88             : /**
      89             :  * Test vectors for tommy_strhash32
      90             :  */
      91             : struct strhash32_test_vector TEST_STRHASH32[] = {
      92             :         { "", 0x0af1416d, 0xa766795d },
      93             :         { "a", 0x68fa0f3f, 0xa766795d },
      94             :         { "abc", 0xfc68ffc5, 0xa766795d },
      95             :         { "message digest", 0x08477b63, 0xa766795d },
      96             :         { "abcdefghijklmnopqrstuvwxyz", 0x5b9c25e5, 0xa766795d },
      97             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 0x1e530ce7, 0xa766795d },
      98             :         { "The quick brown fox jumps over the lazy dog", 0xaf93eefe, 0xa766795d },
      99             :         { "\xff", 0xfc88801b, 0xa766795d },
     100             :         { "\x16\x27", 0xcd7216db, 0xa766795d },
     101             :         { "\xe2\x56\xb4", 0x05f98d02, 0xa766795d },
     102             :         { "\xc9\x4d\x9c\xda", 0xf65206f8, 0xa766795d },
     103             :         { "\x79\xf1\x29\x69\x5d", 0x72bd6bda, 0xa766795d },
     104             :         { "\xff\x7e\xdf\x1e\x31\x1c", 0x57dfb9b4, 0xa766795d },
     105             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 0x499ff634, 0xa766795d },
     106             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 0xe896b7ce, 0xa766795d },
     107             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 0xfe3939f0, 0xa766795d },
     108             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 0x4351d482, 0xa766795d },
     109             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\xff\xb7\xae", 0x88e92135, 0xa766795d },
     110             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 0x01109c16, 0xa766795d },
     111             :         { "\x87\xd8\x61\x61\x4c\x89\x17\x4e\xa1\xa4\xef\x13\xa9", 0xbcb050dc, 0xa766795d },
     112             :         { "\xfe\xa6\x5b\xc2\xda\xe8\x95\xd4\x64\xab\x4c\x39\x58\x29", 0xbe5e1fd5, 0xa766795d },
     113             :         { "\x94\x49\xc0\x78\xa0\x80\xda\xc7\x71\x4e\x17\x37\xa9\x7c\x40", 0x70d8c97f, 0xa766795d },
     114             :         { "\x53\x7e\x36\xb4\x2e\xc9\xb9\xcc\x18\x3e\x9a\x5f\xfc\xb7\xb0\x61", 0x957440a9, 0xa766795d },
     115             :         { 0, 0, 0 }
     116             : };
     117             : 
     118             : /**
     119             :  * Test vectors for tommy_hash64
     120             :  */
     121             : static struct hash64_test_vector TEST_HASH64[] = {
     122             :         { "", 0, 0x8614384cb5165fbfULL, 0x2f022773a766795dULL },
     123             :         { "a", 1, 0x1a2e0298a8e94a3dULL, 0x2f022773a766795dULL },
     124             :         { "abc", 3, 0x7555796b7a7d21ebULL, 0x2f022773a766795dULL },
     125             :         { "message digest", 14, 0x9411a57d04b92fb4ULL, 0x2f022773a766795dULL },
     126             :         { "abcdefghijklmnopqrstuvwxyz", 26, 0x3ca3f8d2b4e69832ULL, 0x2f022773a766795dULL },
     127             :         { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x6dae542ba0015a4dULL, 0x2f022773a766795dULL },
     128             :         { "The quick brown fox jumps over the lazy dog", 43, 0xe06d8cbb3d2ea1a6ULL, 0x2f022773a766795dULL },
     129             :         { "\x00", 1, 0x201e664fb5f2c021ULL, 0x2f022773a766795dULL },
     130             :         { "\x16\x27", 2, 0xef42fa8032c4b775ULL, 0x2f022773a766795dULL },
     131             :         { "\xe2\x56\xb4", 3, 0x6e6c498a6688466cULL, 0x2f022773a766795dULL },
     132             :         { "\xc9\x4d\x9c\xda", 4, 0x5195005419905423ULL, 0x2f022773a766795dULL },
     133             :         { "\x79\xf1\x29\x69\x5d", 5, 0x221235b48afee7c1ULL, 0x2f022773a766795dULL },
     134             :         { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x1b1f18b9266f095bULL, 0x2f022773a766795dULL },
     135             :         { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x2cbafa8e741d49caULL, 0x2f022773a766795dULL },
     136             :         { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x4677f04c06e0758dULL, 0x2f022773a766795dULL },
     137             :         { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0x5afe09e8214e2163ULL, 0x2f022773a766795dULL },
     138             :         { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x115b6276d209fab6ULL, 0x2f022773a766795dULL },
     139             :         { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0xd0636d2f01cf3a3eULL, 0x2f022773a766795dULL },
     140             :         { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0x6d259f5fef74f93eULL, 0x2f022773a766795dULL },
     141             :         { 0, 0, 0, 0 }
     142             : };
     143             : 
     144             : /**
     145             :  * Test vectors for MurmorHash3_x86_128
     146             :  */
     147             : static struct hash_test_vector TEST_MURMUR3[] = {
     148             : #include "murmur3test.c"
     149             :         { 0, 0, { 0 }, { 0 } }
     150             : };
     151             : 
     152             : /**
     153             :  * Test vectors for SpookyHash_128
     154             :  */
     155             : static struct hash_test_vector TEST_SPOOKY2[] = {
     156             : #include "spooky2test.c"
     157             :         { 0, 0, { 0 }, { 0 } }
     158             : };
     159             : 
     160             : /**
     161             :  * Test vectors for MetroHash_128_1
     162             :  */
     163             : static struct hash_test_vector TEST_METRO[] = {
     164             : #include "metrotest.c"
     165             :         { 0, 0, { 0 }, { 0 } }
     166             : };
     167             : 
     168             : /**
     169             :  * Test vectors for MuseAirLoong
     170             :  */
     171             : static struct hash_test_vector TEST_MUSEAIR[] = {
     172             : #include "museairtest.c"
     173             :         { 0, 0, { 0 }, { 0 } }
     174             : };
     175             : 
     176             : #define HASH_TEST_MAX 512 /* tests are never longer than 512 bytes */
     177             : 
     178           1 : static void test_hash(void)
     179             : {
     180             :         unsigned i;
     181             :         unsigned char* seed_aligned;
     182             :         void* seed_alloc;
     183             :         unsigned char* buffer_aligned;
     184             :         void* buffer_alloc;
     185             : 
     186           1 :         seed_aligned = malloc_nofail_align(HASH_MAX, &seed_alloc);
     187           1 :         buffer_aligned = malloc_nofail_align(HASH_TEST_MAX, &buffer_alloc);
     188             : 
     189          20 :         for (i = 0; TEST_HASH32[i].data; ++i) {
     190             :                 uint32_t digest;
     191          19 :                 memcpy(buffer_aligned, TEST_HASH32[i].data, TEST_HASH32[i].len);
     192          19 :                 digest = tommy_hash_u32(TEST_HASH32[i].seed, buffer_aligned, TEST_HASH32[i].len);
     193          19 :                 if (digest != TEST_HASH32[i].digest) {
     194             :                         /* LCOV_EXCL_START */
     195             :                         log_fatal(EINTERNAL, "Failed hash32 test\n");
     196             :                         exit(EXIT_FAILURE);
     197             :                         /* LCOV_EXCL_STOP */
     198             :                 }
     199             :         }
     200             : 
     201          24 :         for (i = 0; TEST_STRHASH32[i].data; ++i) {
     202             :                 uint32_t digest;
     203          23 :                 memcpy(buffer_aligned, TEST_STRHASH32[i].data, strlen(TEST_STRHASH32[i].data) + 1);
     204          23 :                 digest = tommy_strhash_u32(TEST_STRHASH32[i].seed, buffer_aligned);
     205          23 :                 if (digest != TEST_STRHASH32[i].digest) {
     206             :                         /* LCOV_EXCL_START */
     207             :                         log_fatal(EINTERNAL, "Failed strhash32 test\n");
     208             :                         exit(EXIT_FAILURE);
     209             :                         /* LCOV_EXCL_STOP */
     210             :                 }
     211             :         }
     212             : 
     213          20 :         for (i = 0; TEST_HASH64[i].data; ++i) {
     214             :                 uint64_t digest;
     215          19 :                 memcpy(buffer_aligned, TEST_HASH64[i].data, TEST_HASH64[i].len);
     216          19 :                 digest = tommy_hash_u64(TEST_HASH64[i].seed, buffer_aligned, TEST_HASH64[i].len);
     217          19 :                 if (digest != TEST_HASH64[i].digest) {
     218             :                         /* LCOV_EXCL_START */
     219             :                         log_fatal(EINTERNAL, "Failed hash64 test\n");
     220             :                         exit(EXIT_FAILURE);
     221             :                         /* LCOV_EXCL_STOP */
     222             :                 }
     223             :         }
     224             : 
     225             : 
     226         264 :         for (i = 0; TEST_MURMUR3[i].data; ++i) {
     227             :                 unsigned char digest[HASH_MAX];
     228         263 :                 memcpy(buffer_aligned, TEST_MURMUR3[i].data, TEST_MURMUR3[i].len);
     229         263 :                 memcpy(seed_aligned, TEST_MURMUR3[i].seed, HASH_MAX);
     230         263 :                 memhash(HASH_MURMUR3, seed_aligned, digest, buffer_aligned, TEST_MURMUR3[i].len);
     231         263 :                 if (memcmp(digest, TEST_MURMUR3[i].digest, HASH_MAX) != 0) {
     232             :                         /* LCOV_EXCL_START */
     233             :                         log_fatal(EINTERNAL, "Failed Murmur3 test\n");
     234             :                         exit(EXIT_FAILURE);
     235             :                         /* LCOV_EXCL_STOP */
     236             :                 }
     237             :         }
     238             : 
     239         264 :         for (i = 0; TEST_SPOOKY2[i].data; ++i) {
     240             :                 unsigned char digest[HASH_MAX];
     241         263 :                 memcpy(buffer_aligned, TEST_SPOOKY2[i].data, TEST_SPOOKY2[i].len);
     242         263 :                 memcpy(seed_aligned, TEST_SPOOKY2[i].seed, HASH_MAX);
     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(EINTERNAL, "Failed Spooky2 test\n");
     247             :                         exit(EXIT_FAILURE);
     248             :                         /* LCOV_EXCL_STOP */
     249             :                 }
     250             :         }
     251             : 
     252         266 :         for (i = 0; TEST_METRO[i].data; ++i) {
     253             :                 unsigned char digest[HASH_MAX];
     254         265 :                 memcpy(buffer_aligned, TEST_METRO[i].data, TEST_METRO[i].len);
     255         265 :                 memcpy(seed_aligned, TEST_METRO[i].seed, HASH_MAX);
     256         265 :                 memhash(HASH_METRO, seed_aligned, digest, buffer_aligned, TEST_METRO[i].len);
     257         265 :                 if (memcmp(digest, TEST_METRO[i].digest, HASH_MAX) != 0) {
     258             :                         /* LCOV_EXCL_START */
     259             :                         log_fatal(EINTERNAL, "Failed Metro test\n");
     260             :                         exit(EXIT_FAILURE);
     261             :                         /* LCOV_EXCL_STOP */
     262             :                 }
     263             :         }
     264             : 
     265         226 :         for (i = 0; TEST_MUSEAIR[i].data; ++i) {
     266             :                 unsigned char digest[HASH_MAX];
     267         225 :                 memcpy(buffer_aligned, TEST_MUSEAIR[i].data, TEST_MUSEAIR[i].len);
     268         225 :                 memcpy(seed_aligned, TEST_MUSEAIR[i].seed, HASH_MAX);
     269         225 :                 memhash(HASH_MUSEAIR, seed_aligned, digest, buffer_aligned, TEST_MUSEAIR[i].len);
     270         225 :                 if (memcmp(digest, TEST_MUSEAIR[i].digest, HASH_MAX) != 0) {
     271             :                         /* LCOV_EXCL_START */
     272             :                         log_fatal(EINTERNAL, "Failed MuseAir test\n");
     273             :                         exit(EXIT_FAILURE);
     274             :                         /* LCOV_EXCL_STOP */
     275             :                 }
     276             :         }
     277             : 
     278           1 :         free(buffer_alloc);
     279           1 :         free(seed_alloc);
     280           1 : }
     281             : 
     282             : struct crc_test_vector {
     283             :         const char* data;
     284             :         int len;
     285             :         uint32_t digest;
     286             : };
     287             : 
     288             : /**
     289             :  * Test vectors for CRC32C (Castagnoli)
     290             :  */
     291             : static struct crc_test_vector TEST_CRC32C[] = {
     292             :         { "", 0, 0 },
     293             :         { "\x61", 1, 0xc1d04330 },
     294             :         { "\x66\x6f\x6f", 3, 0xcfc4ae1d },
     295             :         { "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64", 11, 0xc99465aa },
     296             :         { "\x68\x65\x6c\x6c\x6f\x20", 6, 0x7e627e58 },
     297             :         { "\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 },
     298             :         { "\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 },
     299             :         { "\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 },
     300             :         { "\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 },
     301             :         { "\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 },
     302             :         { "\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 },
     303             :         { "\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 },
     304             :         { "\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 },
     305             :         { "\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 },
     306             :         { "\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 },
     307             :         { "\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 },
     308             :         { "\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 },
     309             :         { 0, 0, 0 }
     310             : };
     311             : 
     312           1 : static void test_crc32c(void)
     313             : {
     314             :         unsigned i;
     315             : 
     316          18 :         for (i = 0; TEST_CRC32C[i].data; ++i) {
     317             :                 uint32_t digest;
     318             :                 uint32_t digest_gen;
     319             : 
     320          17 :                 digest = crc32c(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
     321          17 :                 digest_gen = crc32c_gen(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len);
     322             : 
     323          17 :                 if (digest != TEST_CRC32C[i].digest || digest_gen != TEST_CRC32C[i].digest) {
     324             :                         /* LCOV_EXCL_START */
     325             :                         log_fatal(EINTERNAL, "Failed CRC32C test\n");
     326             :                         exit(EXIT_FAILURE);
     327             :                         /* LCOV_EXCL_STOP */
     328             :                 }
     329             :         }
     330           1 : }
     331             : 
     332             : /**
     333             :  * Size of tommy data structures.
     334             :  */
     335             : #define TOMMY_SIZE 256
     336             : 
     337         384 : static int tommy_test_search(const void* arg, const void* obj)
     338             : {
     339         384 :         return arg != obj;
     340             : }
     341             : 
     342        4324 : static int tommy_test_compare(const void* void_arg_a, const void* void_arg_b)
     343             : {
     344        4324 :         if (void_arg_a < void_arg_b)
     345        2007 :                 return -1;
     346        2317 :         if (void_arg_a > void_arg_b)
     347        2058 :                 return 1;
     348         259 :         return 0;
     349             : }
     350             : 
     351             : static unsigned tommy_test_foreach_count;
     352             : 
     353         512 : static void tommy_test_foreach(void* obj)
     354             : {
     355             :         (void)obj;
     356             : 
     357         512 :         ++tommy_test_foreach_count;
     358         512 : }
     359             : 
     360         512 : static void tommy_test_foreach_arg(void* void_arg, void* obj)
     361             : {
     362         512 :         unsigned* arg = void_arg;
     363             : 
     364             :         (void)obj;
     365             : 
     366         512 :         ++*arg;
     367         512 : }
     368             : 
     369           1 : static void test_tommy(void)
     370             : {
     371             :         tommy_array array;
     372             :         tommy_arrayblkof arrayblkof;
     373             :         tommy_list list;
     374             :         tommy_hashdyn hashdyn;
     375             :         tommy_tree tree;
     376             :         tommy_node node[TOMMY_SIZE + 1];
     377             :         unsigned i;
     378             : 
     379           1 :         tommy_array_init(&array);
     380           1 :         tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned));
     381             : 
     382         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
     383         256 :                 tommy_array_insert(&array, &node[i]);
     384         256 :                 tommy_arrayblkof_grow(&arrayblkof, i + 1);
     385         256 :                 *(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i;
     386             :         }
     387             : 
     388           1 :         tommy_array_grow(&array, TOMMY_SIZE);
     389           1 :         tommy_arrayblkof_grow(&arrayblkof, TOMMY_SIZE);
     390             : 
     391           1 :         if (tommy_array_memory_usage(&array) < TOMMY_SIZE * sizeof(void*)) {
     392             :                 /* LCOV_EXCL_START */
     393             :                 goto bail;
     394             :                 /* LCOV_EXCL_STOP */
     395             :         }
     396           1 :         if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned)) {
     397             :                 /* LCOV_EXCL_START */
     398             :                 goto bail;
     399             :                 /* LCOV_EXCL_STOP */
     400             :         }
     401             : 
     402         257 :         for (i = 0; i < TOMMY_SIZE; ++i) {
     403         256 :                 if (tommy_array_get(&array, i) != &node[i]) {
     404             :                         /* LCOV_EXCL_START */
     405             :                         goto bail;
     406             :                         /* LCOV_EXCL_STOP */
     407             :                 }
     408         256 :                 if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i) {
     409             :                         /* LCOV_EXCL_START */
     410             :                         goto bail;
     411             :                         /* LCOV_EXCL_STOP */
     412             :                 }
     413             :         }
     414             : 
     415           1 :         tommy_arrayblkof_done(&arrayblkof);
     416           1 :         tommy_array_done(&array);
     417             : 
     418           1 :         tommy_list_init(&list);
     419             : 
     420           1 :         if (!tommy_list_empty(&list)) {
     421             :                 /* LCOV_EXCL_START */
     422             :                 goto bail;
     423             :                 /* LCOV_EXCL_STOP */
     424             :         }
     425             : 
     426           1 :         if (tommy_list_tail(&list)) {
     427             :                 /* LCOV_EXCL_START */
     428             :                 goto bail;
     429             :                 /* LCOV_EXCL_STOP */
     430             :         }
     431             : 
     432           1 :         if (tommy_list_head(&list)) {
     433             :                 /* LCOV_EXCL_START */
     434             :                 goto bail;
     435             :                 /* LCOV_EXCL_STOP */
     436             :         }
     437             : 
     438           1 :         tommy_list_insert_tail(&list, &node[0], &node[0]);
     439             : 
     440           1 :         if (tommy_list_tail(&list) != tommy_list_head(&list)) {
     441             :                 /* LCOV_EXCL_START */
     442             :                 goto bail;
     443             :                 /* LCOV_EXCL_STOP */
     444             :         }
     445             : 
     446           1 :         tommy_hashdyn_init(&hashdyn);
     447             : 
     448         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
     449         256 :                 tommy_hashdyn_insert(&hashdyn, &node[i], &node[i], i % 64);
     450             : 
     451           1 :         if (tommy_hashdyn_count(&hashdyn) != TOMMY_SIZE) {
     452             :                 /* LCOV_EXCL_START */
     453             :                 goto bail;
     454             :                 /* LCOV_EXCL_STOP */
     455             :         }
     456             : 
     457           1 :         if (tommy_hashdyn_memory_usage(&hashdyn) < TOMMY_SIZE * sizeof(tommy_node)) {
     458             :                 /* LCOV_EXCL_START */
     459             :                 goto bail;
     460             :                 /* LCOV_EXCL_STOP */
     461             :         }
     462             : 
     463           1 :         tommy_test_foreach_count = 0;
     464           1 :         tommy_hashdyn_foreach(&hashdyn, tommy_test_foreach);
     465           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     466             :                 /* LCOV_EXCL_START */
     467             :                 goto bail;
     468             :                 /* LCOV_EXCL_STOP */
     469             :         }
     470             : 
     471           1 :         tommy_test_foreach_count = 0;
     472           1 :         tommy_hashdyn_foreach_arg(&hashdyn, tommy_test_foreach_arg, &tommy_test_foreach_count);
     473           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     474             :                 /* LCOV_EXCL_START */
     475             :                 goto bail;
     476             :                 /* LCOV_EXCL_STOP */
     477             :         }
     478             : 
     479         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
     480         128 :                 tommy_hashdyn_remove_existing(&hashdyn, &node[i]);
     481             : 
     482         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i) {
     483         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) != 0) {
     484             :                         /* LCOV_EXCL_START */
     485             :                         goto bail;
     486             :                         /* LCOV_EXCL_STOP */
     487             :                 }
     488             :         }
     489         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i) {
     490         128 :                 if (tommy_hashdyn_remove(&hashdyn, tommy_test_search, &node[i], i % 64) == 0) {
     491             :                         /* LCOV_EXCL_START */
     492             :                         goto bail;
     493             :                         /* LCOV_EXCL_STOP */
     494             :                 }
     495             :         }
     496             : 
     497           1 :         if (tommy_hashdyn_count(&hashdyn) != 0) {
     498             :                 /* LCOV_EXCL_START */
     499             :                 goto bail;
     500             :                 /* LCOV_EXCL_STOP */
     501             :         }
     502             : 
     503           1 :         tommy_hashdyn_done(&hashdyn);
     504             : 
     505           1 :         tommy_tree_init(&tree, tommy_test_compare);
     506             : 
     507         257 :         for (i = 0; i < TOMMY_SIZE; ++i)
     508         256 :                 tommy_tree_insert(&tree, &node[i], (void*)(uintptr_t)(i + 1));
     509             : 
     510             :         /* try to insert a duplicate, count should not change */
     511           1 :         tommy_tree_insert(&tree, &node[TOMMY_SIZE], (void*)(uintptr_t)1);
     512             : 
     513           1 :         if (tommy_tree_count(&tree) != TOMMY_SIZE) {
     514             :                 /* LCOV_EXCL_START */
     515             :                 goto bail;
     516             :                 /* LCOV_EXCL_STOP */
     517             :         }
     518           1 :         if (tommy_tree_memory_usage(&tree) < TOMMY_SIZE * sizeof(tommy_node)) {
     519             :                 /* LCOV_EXCL_START */
     520             :                 goto bail;
     521             :                 /* LCOV_EXCL_STOP */
     522             :         }
     523           1 :         if (tommy_tree_search(&tree, (void*)1) != (void*)1) {
     524             :                 /* LCOV_EXCL_START */
     525             :                 goto bail;
     526             :                 /* LCOV_EXCL_STOP */
     527             :         }
     528           1 :         if (tommy_tree_search(&tree, (void*)-1) != 0) {
     529             :                 /* LCOV_EXCL_START */
     530             :                 goto bail;
     531             :                 /* LCOV_EXCL_STOP */
     532             :         }
     533           1 :         if (tommy_tree_search_compare(&tree, tommy_test_compare, (void*)1) != (void*)1) {
     534             :                 /* LCOV_EXCL_START */
     535             :                 goto bail;
     536             :                 /* LCOV_EXCL_STOP */
     537             :         }
     538           1 :         if (tommy_tree_search_compare(&tree, tommy_test_compare, (void*)-1) != 0) {
     539             :                 /* LCOV_EXCL_START */
     540             :                 goto bail;
     541             :                 /* LCOV_EXCL_STOP */
     542             :         }
     543             : 
     544           1 :         tommy_test_foreach_count = 0;
     545           1 :         tommy_tree_foreach(&tree, tommy_test_foreach);
     546           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     547             :                 /* LCOV_EXCL_START */
     548             :                 goto bail;
     549             :                 /* LCOV_EXCL_STOP */
     550             :         }
     551             : 
     552           1 :         tommy_test_foreach_count = 0;
     553           1 :         tommy_tree_foreach_arg(&tree, tommy_test_foreach_arg, &tommy_test_foreach_count);
     554           1 :         if (tommy_test_foreach_count != TOMMY_SIZE) {
     555             :                 /* LCOV_EXCL_START */
     556             :                 goto bail;
     557             :                 /* LCOV_EXCL_STOP */
     558             :         }
     559             : 
     560         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i)
     561         128 :                 tommy_tree_remove_existing(&tree, &node[i]);
     562             : 
     563         129 :         for (i = 0; i < TOMMY_SIZE / 2; ++i) {
     564         128 :                 if (tommy_tree_remove(&tree, (void*)(uintptr_t)(i + 1)) != 0) {
     565             :                         /* LCOV_EXCL_START */
     566             :                         goto bail;
     567             :                         /* LCOV_EXCL_STOP */
     568             :                 }
     569             :         }
     570             : 
     571         129 :         for (i = TOMMY_SIZE / 2; i < TOMMY_SIZE; ++i) {
     572         128 :                 if (tommy_tree_remove(&tree, (void*)(uintptr_t)(i + 1)) == 0) {
     573             :                         /* LCOV_EXCL_START */
     574             :                         goto bail;
     575             :                         /* LCOV_EXCL_STOP */
     576             :                 }
     577             :         }
     578             : 
     579           1 :         if (tommy_tree_count(&tree) != 0) {
     580             :                 /* LCOV_EXCL_START */
     581             :                 goto bail;
     582             :                 /* LCOV_EXCL_STOP */
     583             :         }
     584             : 
     585           1 :         return;
     586           0 : bail:
     587             :         /* LCOV_EXCL_START */
     588             :         log_fatal(EINTERNAL, "Failed tommy test\n");
     589             :         exit(EXIT_FAILURE);
     590             :         /* LCOV_EXCL_STOP */
     591             : }
     592             : 
     593             : struct {
     594             :         const char* pattern;
     595             :         const char* text;
     596             :         int result;
     597             : } WNMATCH_TEST[] = {
     598             :         /* basic literal matching */
     599             :         { "hello", "hello", 0 },
     600             :         { "hello", "world", 1 },
     601             :         { "", "", 0 },
     602             :         { "hello", "", 1 },
     603             :         { "", "hello", 1 },
     604             : 
     605             :         /* single asterisk (*) */
     606             :         { "*", "anything", 0 },
     607             :         { "*", "", 0 },
     608             :         { "*.txt", "file.txt", 0 },
     609             :         { "*.txt", "file.doc", 1 },
     610             :         { "*file*", "myfile.txt", 0 },
     611             :         { "f*le", "file", 0 },
     612             :         { "f*le", "fiiiile", 0 },
     613             :         { "f*le", "folder", 1 },
     614             :         { "a*b*c", "abc", 0 },
     615             :         { "a*b*c", "aXbYc", 0 },
     616             :         { "a*b*c", "aXXbYYc", 0 },
     617             :         { "a*b*c", "ac", 1 },
     618             :         { "***", "anything", 0 },
     619             :         { "*.txt", "notes.txt", 0 },
     620             :         { "*.txt", "folder/notes.txt", 1 },
     621             :         { "*.js", "main.jsx", 1 },
     622             : 
     623             :         /* single asterisk with / */
     624             :         { "*", "a/b", 1 },
     625             :         { "*.txt", "dir/file.txt", 1 },
     626             :         { "dir/*.txt", "dir/file.txt", 0 },
     627             :         { "*/*.txt", "dir/file.txt", 0 },
     628             :         { "*/*.txt", "a/b/file.txt", 1 },
     629             : 
     630             :         /* question mark (?) */
     631             :         { "?", "a", 0 },
     632             :         { "?", "ab", 1 },
     633             :         { "?", "", 1 },
     634             :         { "file?.txt", "file1.txt", 0 },
     635             :         { "file?.txt", "fileA.txt", 0 },
     636             :         { "file?.txt", "file10.txt", 1 },
     637             :         { "???", "abc", 0 },
     638             :         { "???", "ab", 1 },
     639             :         { "a?c", "abc", 0 },
     640             :         { "a?c", "ac", 1 },
     641             :         { "file?.txt", "file1.txt", 0 },
     642             :         { "file?.txt", "file12.txt", 1 },
     643             : 
     644             :         /* question mark with / */
     645             :         { "?", "/", 1 },
     646             :         { "dir?file", "dir/file", 1 },
     647             :         { "dir?file", "dirAfile", 0 },
     648             : 
     649             :         /* character classes [...] */
     650             :         { "[abc]", "a", 0 },
     651             :         { "[abc]", "b", 0 },
     652             :         { "[abc]", "c", 0 },
     653             :         { "[abc]", "d", 1 },
     654             :         { "[abc]", "", 1 },
     655             :         { "file[0-9].txt", "file5.txt", 0 },
     656             :         { "file[0-9].txt", "fileA.txt", 1 },
     657             :         { "[a-z]", "m", 0 },
     658             :         { "[A-Z]", "M", 0 },
     659             :         { "[0-9a-f]", "a", 0 },
     660             :         { "[0-9a-f]", "5", 0 },
     661             :         { "[0-9a-f]", "g", 1 },
     662             :         { "[a-z].js", "p.js", 0 },
     663             :         { "[a-z].js", "1.js", 1 },
     664             :         { "[0-9].txt", "a.txt", 1 },
     665             :         { "[!a-z].js", "b.js", 1 },
     666             : 
     667             :         /* negated character classes [!...] */
     668             :         { "[!abc]", "d", 0 },
     669             :         { "[!abc]", "a", 1 },
     670             :         { "[!0-9]", "a", 0 },
     671             :         { "[!0-9]", "5", 1 },
     672             :         { "file[!0-9].txt", "filea.txt", 0 },
     673             :         { "file[!0-9].txt", "file5.txt", 1 },
     674             :         { "[^abc]", "d", 0 },
     675             :         { "[^abc]", "a", 1 },
     676             : 
     677             :         /* character classes with / */
     678             :         { "[a-z]", "/", 1 },
     679             :         { "dir[/]file", "dir/file", 1 },
     680             : 
     681             : #ifdef WIN32
     682             :         /* case */
     683             :         { "hello", "HELLO", 0 },
     684             :         { "Hello", "hello", 0 },
     685             :         { "*.TXT", "file.txt", 0 },
     686             :         { "FILE.txt", "file.TXT", 0 },
     687             :         { "[a-z]", "A", 0 },
     688             :         { "[ABC]", "b", 0 },
     689             :         { "[a-z].js", "A.js", 0 },
     690             :         { "[a-z]", "M", 0 },
     691             : #else
     692             :         { "hello", "HELLO", 1 },
     693             :         { "Hello", "hello", 1 },
     694             :         { "*.TXT", "file.txt", 1 },
     695             :         { "FILE.txt", "file.TXT", 1 },
     696             :         { "[a-z]", "A", 1 },
     697             :         { "[ABC]", "b", 1 },
     698             :         { "[a-z].js", "A.js", 1 },
     699             :         { "[a-z]", "M", 1 },
     700             : #endif
     701             : 
     702             :         /* the /xx/ collapse case */
     703             :         { "a/**/b", "a/b", 0 },
     704             :         { "a/**/b", "a/x/b", 0 },
     705             : 
     706             :         /* double asterisk (xx/) at start */
     707             :         { "**/*.txt", "file.txt", 0 },
     708             :         { "**/*.txt", "dir/file.txt", 0 },
     709             :         { "**/*.txt", "a/b/c/file.txt", 0 },
     710             :         { "**/*.txt", "file.doc", 1 },
     711             :         { "**/test.txt", "test.txt", 0 },
     712             :         { "**/test.txt", "a/b/test.txt", 0 },
     713             :         { "**/test.txt", "a/b/other.txt", 1 },
     714             :         { "**/*file*", "myfile.txt", 0 },
     715             :         { "**/*file*", "dir/myfile.txt", 0 },
     716             : 
     717             :         /* double asterisk (/xx) at end */
     718             :         { "src/**", "src/", 0 },
     719             :         { "src/**", "src/file.c", 0 },
     720             :         { "src/**", "src/a/b/c/file.c", 0 },
     721             :         { "src/**", "other/file.c", 1 },
     722             :         { "src/**", "src", 1 },
     723             :         { "dir/**", "dir/subdir/", 0 },
     724             : 
     725             :         /* double asterisk (/xx/) in middle */
     726             :         { "src/**/*.c", "src/file.c", 0 },
     727             :         { "src/**/*.c", "src/lib/file.c", 0 },
     728             :         { "src/**/*.c", "src/lib/util/file.c", 0 },
     729             :         { "src/**/*.c", "src/file.h", 1 },
     730             :         { "src/**/*.c", "other/file.c", 1 },
     731             :         { "a/**/b/**/c", "a/b/c", 0 },
     732             :         { "a/**/b/**/c", "a/x/b/y/c", 0 },
     733             :         { "a/**/b/**/c", "a/x/y/b/z/w/c", 0 },
     734             :         { "a/**/b", "a/x/y/z/b", 0 },
     735             :         { "/docs/**/api.md", "/docs/api.md", 0 },
     736             :         { "a/**/b", "a/xb", 1 },
     737             :         { "a/**/b", "ax/b", 1 },
     738             :         { "a/**/b", "a/c/xb", 1 },
     739             :         { "a/**/b", "ax/c/b", 1 },
     740             :         { "a/**/b", "a/x/y/c", 1 },
     741             :         { "a/**/b", "axb", 1 },
     742             : 
     743             :         /* multiple recursion segments */
     744             :         { "**/**/file", "file", 0 },
     745             :         { "**/**/file", "a/b/c/file", 0 },
     746             :         { "a/**/b/**/c", "a/b/c", 0 },
     747             :         { "a/**/b/**/c", "a/1/b/2/c", 0 },
     748             : 
     749             :         /* combined patterns */
     750             :         { "*.{txt,doc}", "file.txt", 1 },
     751             :         { "file[0-9]*.txt", "file5abc.txt", 0 },
     752             :         { "dir/*/file?.txt", "dir/sub/file1.txt", 0 },
     753             :         { "**/src/**/*.c", "project/src/lib/file.c", 0 },
     754             : 
     755             :         /* edge cases */
     756             :         { "**", "anything", 0 },
     757             :         { "a/**", "a/b", 0 },
     758             :         { "a**", "aaa", 0 },
     759             :         { "**a", "xxa", 0 },
     760             :         { "a/**/", "a/b/", 0 },
     761             :         { "a/**/b", "a/b", 0 },
     762             :         { "a/**/b", "a//b", 0 },
     763             :         { "*/**/file.txt", "a/file.txt", 0 },
     764             :         { "*/**/file.txt", "a/b/c/file.txt", 0 },
     765             :         { "a**/file.txt", "afile.txt", 1 },
     766             :         { "/*/**/file.txt", "/file.txt", 1 },
     767             :         { "*/**/file.txt", "/file.txt", 0 },
     768             :         { "src/**/**/file.txt", "src/file.txt", 0 },
     769             :         { "src/**/**/file.txt", "src/sub/file.txt", 0 },
     770             :         { "src/***/file.txt", "src/file.txt", 0 },
     771             :         { "src/***/file.txt", "src/sub/file.txt", 0 },
     772             :         { "src/***/file.txt", "src/sub/sub/file.txt", 0 },
     773             :         { "src/****/file.txt", "src/file.txt", 0 },
     774             :         { "src/****/file.txt", "src/sub/file.txt", 0 },
     775             :         { "src/****/file.txt", "src/sub/sub/file.txt", 0 },
     776             :         { "**/build", "a/b/build", 0 },
     777             :         { "src/**/test.js", "src/ui/test.js", 0 },
     778             :         { "dist/**", "dist/bin/app.exe", 0 },
     779             :         { "src-**", "src-folder/file.js", 1 },
     780             :         { "**pkg/init.py", "libs/core/pkg/init.py", 1 },
     781             :         { "**.log", "error.log", 0 },
     782             :         { "**.log", "var/log/sys.log", 1 },
     783             :         { "src/**.js", "src/app.js", 0 },
     784             :         { "src/**.js", "src/components/ui/button.js", 0 }, /* <<<<< .GITIGNORE DIFFERS */
     785             :         { "a**b.txt", "ab.txt", 0 },
     786             :         { "a**b.txt", "axxb.txt", 0 },
     787             :         { "a**b.txt", "a/b.txt", 1 },
     788             :         { "a**b.txt", "a/subdir/b.txt", 1 },
     789             :         { "a**b.txt", "a_folder/sub/b.txt", 1 },
     790             :         { "a**b.txt", "a_folder/sub/folter_b.txt", 1 },
     791             :         { "**/build", "build", 0 },
     792             :         { "**/build", "project/out/build", 0 },
     793             : 
     794             :         /* negative tests */
     795             :         { "/docs/**/api.md", "docs/api.txt", 1 },
     796             :         { "a/**/b", "a/b/c", 1 },
     797             :         { "static/**", "static", 1 },
     798             :         { "src/*.js", "src/ui/app.js", 1 },
     799             :         { "/config.*", "etc/config.json", 1 },
     800             :         { "*/*/*.c", "main.c", 1 },
     801             :         { "a/*/b", "a/b", 1 },
     802             :         { "a/**/b", "axb", 1 },
     803             :         { "a/**/b", "ab", 1 },
     804             :         { "/**/logs", "logs", 1 },
     805             :         { "/src/**/logs", "src/web/log", 1 },
     806             :         { "foo//bar", "foo/bar", 1 },
     807             :         { "a/**/b", "a/b/", 1 },
     808             :         { "a**b**c", "acb", 1 },
     809             :         { "src-**-pkg", "src-pkg", 1 },
     810             :         { "**/test/*.js", "test/ui/app.js", 1 },
     811             : 
     812             :         /* complex real-world patterns */
     813             :         { "**/.git/**", ".git/config", 0 },
     814             :         { "**/.git/**", "project/.git/hooks/pre-commit", 0 },
     815             :         { "**/node_modules/**", "node_modules/pkg/index.js", 0 },
     816             :         { "**/node_modules/**", "app/node_modules/pkg/file.js", 0 },
     817             :         { "src/**/*.{c,h}", "src/main.c", 1 },
     818             :         { "**/test_*.py", "test_example.py", 0 },
     819             :         { "**/test_*.py", "tests/test_feature.py", 0 },
     820             : 
     821             :         /* performance/stress patterns */
     822             :         { "a*b*c*d*e*f*g*h*i*j*k", "abcdefghijk", 0 },
     823             :         { "a*b*c*d*e*f*g*h*i*j*k", "aXbXcXdXeXfXgXhXiXjXk", 0 },
     824             :         { "**/**/**/*.txt", "a/b/c/d/e/f.txt", 0 },
     825             : 
     826             :         /* trailing/leading slashes */
     827             :         { "dir/", "dir/", 0 },
     828             :         { "/root/*", "/root/file", 0 },
     829             : 
     830             :         /* complex embedded patterns */
     831             :         { "src-**-pkg/*.js", "src-web-pkg/main.js", 0 },
     832             :         { "src-**-pkg/*.js", "src-lazy-load-ui-pkg/main.js", 0 },
     833             :         { "src-**-pkg/*.js", "src-web-pkg/subdir/main.js", 1 },
     834             : 
     835             :         /* anchoring and slashes */
     836             :         { "/root.txt", "root.txt", 1 },
     837             :         { "/root.txt", "subdir/root.txt", 1 },
     838             :         { "docs/", "docs", 1 },
     839             :         { "docs/", "docs/", 0 },
     840             :         { "**/temp/", "src/temp/", 0 },
     841             :         { "**/temp/", "src/temp", 1 },
     842             : 
     843             :         { 0 }
     844             : };
     845             : 
     846           1 : static void test_wnmatch(void)
     847             : {
     848         191 :         for (int i = 0; WNMATCH_TEST[i].pattern; ++i) {
     849         190 :                 if (wnmatch(WNMATCH_TEST[i].pattern, WNMATCH_TEST[i].text) != WNMATCH_TEST[i].result) {
     850             :                         /* LCOV_EXCL_START */
     851             :                         log_fatal(EINTERNAL, "Failed wnmatch test %s %s, expected %d\n", WNMATCH_TEST[i].pattern, WNMATCH_TEST[i].text, WNMATCH_TEST[i].result);
     852             :                         exit(EXIT_FAILURE);
     853             :                         /* LCOV_EXCL_STOP */
     854             :                 }
     855             :         }
     856           1 : }
     857             : 
     858           1 : void selftest(void)
     859             : {
     860           1 :         log_tag("selftest:\n");
     861           1 :         log_flush();
     862             : 
     863           1 :         msg_progress("Self-test...\n");
     864             : 
     865             :         /* large file check */
     866             :         if (sizeof(off_t) < sizeof(uint64_t)) {
     867             :                 /* LCOV_EXCL_START */
     868             :                 log_fatal(EINTERNAL, "Missing support for large files\n");
     869             :                 exit(EXIT_FAILURE);
     870             :                 /* LCOV_EXCL_STOP */
     871             :         }
     872             : 
     873           1 :         if (util_selftest() != 0) {
     874             :                 /* LCOV_EXCL_START */
     875             :                 log_fatal(EINTERNAL, "Failed UTIL test\n");
     876             :                 exit(EXIT_FAILURE);
     877             :                 /* LCOV_EXCL_STOP */
     878             :         }
     879           1 :         test_hash();
     880           1 :         test_crc32c();
     881           1 :         test_tommy();
     882           1 :         test_wnmatch();
     883           1 :         if (raid_selftest() != 0) {
     884             :                 /* LCOV_EXCL_START */
     885             :                 log_fatal(EINTERNAL, "Failed SELF test\n");
     886             :                 exit(EXIT_FAILURE);
     887             :                 /* LCOV_EXCL_STOP */
     888             :         }
     889           1 :         if (raid_test_sort() != 0) {
     890             :                 /* LCOV_EXCL_START */
     891             :                 log_fatal(EINTERNAL, "Failed SORT test\n");
     892             :                 exit(EXIT_FAILURE);
     893             :                 /* LCOV_EXCL_STOP */
     894             :         }
     895           1 :         if (raid_test_insert() != 0) {
     896             :                 /* LCOV_EXCL_START */
     897             :                 log_fatal(EINTERNAL, "Failed INSERT test\n");
     898             :                 exit(EXIT_FAILURE);
     899             :                 /* LCOV_EXCL_STOP */
     900             :         }
     901           1 :         if (raid_test_combo() != 0) {
     902             :                 /* LCOV_EXCL_START */
     903             :                 log_fatal(EINTERNAL, "Failed COMBO test\n");
     904             :                 exit(EXIT_FAILURE);
     905             :                 /* LCOV_EXCL_STOP */
     906             :         }
     907           1 :         if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) {
     908             :                 /* LCOV_EXCL_START */
     909             :                 log_fatal(EINTERNAL, "Failed GEN Vandermonde test\n");
     910             :                 exit(EXIT_FAILURE);
     911             :                 /* LCOV_EXCL_STOP */
     912             :         }
     913           1 :         if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) {
     914             :                 /* LCOV_EXCL_START */
     915             :                 log_fatal(EINTERNAL, "Failed REC Vandermonde test\n");
     916             :                 exit(EXIT_FAILURE);
     917             :                 /* LCOV_EXCL_STOP */
     918             :         }
     919           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) {
     920             :                 /* LCOV_EXCL_START */
     921             :                 log_fatal(EINTERNAL, "Failed GEN Cauchy test\n");
     922             :                 exit(EXIT_FAILURE);
     923             :                 /* LCOV_EXCL_STOP */
     924             :         }
     925           1 :         if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) {
     926             :                 /* LCOV_EXCL_START */
     927             :                 log_fatal(EINTERNAL, "Failed REC Cauchy test\n");
     928             :                 exit(EXIT_FAILURE);
     929             :                 /* LCOV_EXCL_STOP */
     930             :         }
     931           1 :         if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) {
     932             :                 /* LCOV_EXCL_START */
     933             :                 log_fatal(EINTERNAL, "Failed GEN Cauchy test single data disk\n");
     934             :                 exit(EXIT_FAILURE);
     935             :                 /* LCOV_EXCL_STOP */
     936             :         }
     937           1 : }
     938             : 

Generated by: LCOV version 1.0