LCOV - code coverage report
Current view: top level - lib/replace/tests - testsuite.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 540 664 81.3 %
Date: 2024-02-29 22:57:05 Functions: 49 49 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    libreplace tests
       5             : 
       6             :    Copyright (C) Jelmer Vernooij 2006
       7             : 
       8             :      ** NOTE! The following LGPL license applies to the talloc
       9             :      ** library. This does NOT imply that all of Samba is released
      10             :      ** under the LGPL
      11             : 
      12             :    This library is free software; you can redistribute it and/or
      13             :    modify it under the terms of the GNU Lesser General Public
      14             :    License as published by the Free Software Foundation; either
      15             :    version 3 of the License, or (at your option) any later version.
      16             : 
      17             :    This library is distributed in the hope that it will be useful,
      18             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      19             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      20             :    Lesser General Public License for more details.
      21             : 
      22             :    You should have received a copy of the GNU Lesser General Public
      23             :    License along with this library; if not, see <http://www.gnu.org/licenses/>.
      24             : */
      25             : 
      26             : #include "replace.h"
      27             : #include "replace-test.h"
      28             : #include "replace-testsuite.h"
      29             : 
      30             : /*
      31             :   we include all the system/ include files here so that libreplace tests
      32             :   them in the build farm
      33             : */
      34             : #include "system/capability.h"
      35             : #include "system/dir.h"
      36             : #include "system/filesys.h"
      37             : #include "system/glob.h"
      38             : #include "system/iconv.h"
      39             : #include "system/locale.h"
      40             : #include "system/network.h"
      41             : #include "system/passwd.h"
      42             : #include "system/readline.h"
      43             : #include "system/select.h"
      44             : #include "system/shmem.h"
      45             : #include "system/syslog.h"
      46             : #include "system/terminal.h"
      47             : #include "system/time.h"
      48             : #include "system/wait.h"
      49             : 
      50             : #define TESTFILE "testfile.dat"
      51             : 
      52             : 
      53             : /*
      54             :   test ftruncate() function
      55             :  */
      56           4 : static int test_ftruncate(void)
      57             : {
      58           1 :         struct stat st;
      59           1 :         int fd;
      60           4 :         const int size = 1234;
      61           4 :         printf("test: ftruncate\n");
      62           4 :         unlink(TESTFILE);
      63           4 :         fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
      64           4 :         if (fd == -1) {
      65           0 :                 printf("failure: ftruncate [\n"
      66           0 :                            "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
      67           0 :                 return false;
      68             :         }
      69           4 :         if (ftruncate(fd, size) != 0) {
      70           0 :                 printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
      71           0 :                 close(fd);
      72           0 :                 return false;
      73             :         }
      74           4 :         if (fstat(fd, &st) != 0) {
      75           0 :                 printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
      76           0 :                 close(fd);
      77           0 :                 return false;
      78             :         }
      79           4 :         if (st.st_size != size) {
      80           0 :                 printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
      81           0 :                        (int)st.st_size, size);
      82           0 :                 close(fd);
      83           0 :                 return false;
      84             :         }
      85           4 :         unlink(TESTFILE);
      86           4 :         printf("success: ftruncate\n");
      87           4 :         close(fd);
      88           4 :         return true;
      89             : }
      90             : 
      91             : /*
      92             :   test strlcpy() function.
      93             :   see http://www.gratisoft.us/todd/papers/strlcpy.html
      94             :  */
      95           4 : static int test_strlcpy(void)
      96             : {
      97           1 :         char buf[4];
      98           1 :         const struct {
      99             :                 const char *src;
     100             :                 size_t result;
     101           4 :         } tests[] = {
     102             :                 { "abc", 3 },
     103             :                 { "abcdef", 6 },
     104             :                 { "abcd", 4 },
     105             :                 { "", 0 },
     106             :                 { NULL, 0 }
     107             :         };
     108           1 :         int i;
     109           4 :         printf("test: strlcpy\n");
     110          21 :         for (i=0;tests[i].src;i++) {
     111          16 :                 if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
     112           0 :                         printf("failure: strlcpy [\ntest %d failed\n]\n", i);
     113           0 :                         return false;
     114             :                 }
     115             :         }
     116           4 :         printf("success: strlcpy\n");
     117           4 :         return true;
     118             : }
     119             : 
     120           4 : static int test_strlcat(void)
     121             : {
     122           1 :         char tmp[10];
     123           4 :         printf("test: strlcat\n");
     124           4 :         strlcpy(tmp, "", sizeof(tmp));
     125           4 :         if (strlcat(tmp, "bla", 3) != 3) {
     126           0 :                 printf("failure: strlcat [\ninvalid return code\n]\n");
     127           0 :                 return false;
     128             :         }
     129           4 :         if (strcmp(tmp, "bl") != 0) {
     130           0 :                 printf("failure: strlcat [\nexpected \"bl\", got \"%s\"\n]\n",
     131             :                            tmp);
     132           0 :                 return false;
     133             :         }
     134             : 
     135           4 :         strlcpy(tmp, "da", sizeof(tmp));
     136           4 :         if (strlcat(tmp, "me", 4) != 4) {
     137           0 :                 printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n",
     138             :                            tmp);
     139           0 :                 return false;
     140             :         }
     141             : 
     142           4 :         printf("success: strlcat\n");
     143           4 :         return true;
     144             : }
     145             : 
     146           3 : static int test_mktime(void)
     147             : {
     148             :         /* FIXME */
     149           3 :         return true;
     150             : }
     151             : 
     152           3 : static int test_initgroups(void)
     153             : {
     154             :         /* FIXME */
     155           3 :         return true;
     156             : }
     157             : 
     158           3 : static int test_memmove(void)
     159             : {
     160             :         /* FIXME */
     161           3 :         return true;
     162             : }
     163             : 
     164           4 : static int test_strdup(void)
     165             : {
     166           1 :         char *x;
     167           1 :         int cmp;
     168             : 
     169           4 :         printf("test: strdup\n");
     170           4 :         x = strdup("bla");
     171             : 
     172           4 :         cmp = strcmp("bla", x);
     173           4 :         if (cmp != 0) {
     174           0 :                 printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n",
     175             :                            x);
     176           0 :                 free(x);
     177           0 :                 return false;
     178             :         }
     179           4 :         free(x);
     180           4 :         printf("success: strdup\n");
     181           4 :         return true;
     182             : }
     183             : 
     184           4 : static int test_setlinebuf(void)
     185             : {
     186           4 :         printf("test: setlinebuf\n");
     187           4 :         setlinebuf(stdout);
     188           4 :         printf("success: setlinebuf\n");
     189           4 :         return true;
     190             : }
     191             : 
     192           3 : static int test_vsyslog(void)
     193             : {
     194             :         /* FIXME */
     195           3 :         return true;
     196             : }
     197             : 
     198           3 : static int test_timegm(void)
     199             : {
     200             :         /* FIXME */
     201           3 :         return true;
     202             : }
     203             : 
     204           4 : static int test_setenv(void)
     205             : {
     206             : #define TEST_SETENV(key, value, overwrite, result) do { \
     207             :         int _ret; \
     208             :         char *_v; \
     209             :         _ret = setenv(key, value, overwrite); \
     210             :         if (_ret != 0) { \
     211             :                 printf("failure: setenv [\n" \
     212             :                         "setenv(%s, %s, %d) failed\n" \
     213             :                         "]\n", \
     214             :                         key, value, overwrite); \
     215             :                 return false; \
     216             :         } \
     217             :         _v=getenv(key); \
     218             :         if (!_v) { \
     219             :                 printf("failure: setenv [\n" \
     220             :                         "getenv(%s) returned NULL\n" \
     221             :                         "]\n", \
     222             :                         key); \
     223             :                 return false; \
     224             :         } \
     225             :         if (strcmp(result, _v) != 0) { \
     226             :                 printf("failure: setenv [\n" \
     227             :                         "getenv(%s): '%s' != '%s'\n" \
     228             :                         "]\n", \
     229             :                         key, result, _v); \
     230             :                 return false; \
     231             :         } \
     232             : } while(0)
     233             : 
     234             : #define TEST_UNSETENV(key) do { \
     235             :         char *_v; \
     236             :         unsetenv(key); \
     237             :         _v=getenv(key); \
     238             :         if (_v) { \
     239             :                 printf("failure: setenv [\n" \
     240             :                         "getenv(%s): NULL != '%s'\n" \
     241             :                         "]\n", \
     242             :                         SETENVTEST_KEY, _v); \
     243             :                 return false; \
     244             :         } \
     245             : } while (0)
     246             : 
     247             : #define SETENVTEST_KEY "SETENVTESTKEY"
     248             : #define SETENVTEST_VAL "SETENVTESTVAL"
     249             : 
     250           4 :         printf("test: setenv\n");
     251           4 :         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1");
     252           4 :         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1");
     253           4 :         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3");
     254           4 :         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4");
     255           4 :         TEST_UNSETENV(SETENVTEST_KEY);
     256           4 :         TEST_UNSETENV(SETENVTEST_KEY);
     257           4 :         TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5");
     258           4 :         TEST_UNSETENV(SETENVTEST_KEY);
     259           4 :         TEST_UNSETENV(SETENVTEST_KEY);
     260           4 :         printf("success: setenv\n");
     261           4 :         return true;
     262             : }
     263             : 
     264           4 : static int test_strndup(void)
     265             : {
     266           1 :         char *x;
     267           1 :         int cmp;
     268             : 
     269           4 :         printf("test: strndup\n");
     270           4 :         x = strndup("bla", 0);
     271           4 :         cmp = strcmp(x, "");
     272           4 :         free(x);
     273           4 :         if (cmp != 0) {
     274           0 :                 printf("failure: strndup [\ninvalid\n]\n");
     275           0 :                 return false;
     276             :         }
     277             : 
     278           4 :         x = strndup("bla", 2);
     279           4 :         cmp = strcmp(x, "bl");
     280           4 :         free(x);
     281           4 :         if (cmp != 0) {
     282           0 :                 printf("failure: strndup [\ninvalid\n]\n");
     283           0 :                 return false;
     284             :         }
     285             : 
     286             : #ifdef __GNUC__
     287             : # if __GNUC__ < 11
     288             :         /*
     289             :          * This code will not compile with gcc11 -O3 anymore.
     290             :          *
     291             :          * error: ‘strndup’ specified bound 10 exceeds source size 4 [-Werror=stringop-overread]
     292             :          *          x = strndup("bla", 10);
     293             :          *          ^~~~~~~~~~~~~~~~~~
     294             :          */
     295             :         x = strndup("bla", 10);
     296             :         cmp = strcmp(x, "bla");
     297             :         free(x);
     298             :         if (cmp != 0) {
     299             :                 printf("failure: strndup [\ninvalid\n]\n");
     300             :                 return false;
     301             :         }
     302             : # endif
     303             : #endif /* __GNUC__ */
     304             : 
     305           4 :         printf("success: strndup\n");
     306           4 :         return true;
     307             : }
     308             : 
     309           4 : static int test_strnlen(void)
     310             : {
     311           4 :         char longlen[20] = { 0 };
     312             : 
     313           4 :         printf("test: strnlen\n");
     314           4 :         if (strnlen("bla", 2) != 2) {
     315           0 :                 printf("failure: strnlen [\nunexpected length\n]\n");
     316           0 :                 return false;
     317             :         }
     318             : 
     319           4 :         if (strnlen("some text\n", 0) != 0) {
     320           0 :                 printf("failure: strnlen [\nunexpected length\n]\n");
     321           0 :                 return false;
     322             :         }
     323             : 
     324           4 :         memcpy(longlen, "some text", 10);
     325             : 
     326           4 :         if (strnlen(longlen, 20) != 9) {
     327           0 :                 printf("failure: strnlen [\nunexpected length\n]\n");
     328           0 :                 return false;
     329             :         }
     330             : 
     331           4 :         printf("success: strnlen\n");
     332           4 :         return true;
     333             : }
     334             : 
     335           3 : static int test_waitpid(void)
     336             : {
     337             :         /* FIXME */
     338           3 :         return true;
     339             : }
     340             : 
     341           3 : static int test_seteuid(void)
     342             : {
     343             :         /* FIXME */
     344           3 :         return true;
     345             : }
     346             : 
     347           3 : static int test_setegid(void)
     348             : {
     349             :         /* FIXME */
     350           3 :         return true;
     351             : }
     352             : 
     353           4 : static int test_asprintf(void)
     354             : {
     355           4 :         char *x = NULL;
     356             : 
     357           4 :         printf("test: asprintf\n");
     358           4 :         if (asprintf(&x, "%d", 9) != 1) {
     359           0 :                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
     360           0 :                 free(x);
     361           0 :                 return false;
     362             :         }
     363           4 :         if (strcmp(x, "9") != 0) {
     364           0 :                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
     365           0 :                 free(x);
     366           0 :                 return false;
     367             :         }
     368           4 :         if (asprintf(&x, "dat%s", "a") != 4) {
     369           0 :                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
     370           0 :                 free(x);
     371           0 :                 return false;
     372             :         }
     373           4 :         if (strcmp(x, "data") != 0) {
     374           0 :                 printf("failure: asprintf [\ngenerate asprintf\n]\n");
     375           0 :                 free(x);
     376           0 :                 return false;
     377             :         }
     378           4 :         free(x);
     379           4 :         printf("success: asprintf\n");
     380           4 :         return true;
     381             : }
     382             : 
     383           4 : static int test_snprintf(void)
     384             : {
     385           1 :         char tmp[10];
     386           4 :         printf("test: snprintf\n");
     387           4 :         if (snprintf(tmp, 3, "foo%d", 9) != 4) {
     388           0 :                 printf("failure: snprintf [\nsnprintf return code failed\n]\n");
     389           0 :                 return false;
     390             :         }
     391             : 
     392           4 :         if (strcmp(tmp, "fo") != 0) {
     393           0 :                 printf("failure: snprintf [\nsnprintf failed\n]\n");
     394           0 :                 return false;
     395             :         }
     396             : 
     397           4 :         printf("success: snprintf\n");
     398           4 :         return true;
     399             : }
     400             : 
     401           3 : static int test_vasprintf(void)
     402             : {
     403             :         /* FIXME */
     404           3 :         return true;
     405             : }
     406             : 
     407           3 : static int test_vsnprintf(void)
     408             : {
     409             :         /* FIXME */
     410           3 :         return true;
     411             : }
     412             : 
     413           3 : static int test_opendir(void)
     414             : {
     415             :         /* FIXME */
     416           3 :         return true;
     417             : }
     418             : 
     419           4 : static int test_readdir(void)
     420             : {
     421           4 :         printf("test: readdir\n");
     422           4 :         if (test_readdir_os2_delete() != 0) {
     423           0 :                 return false;
     424             :         }
     425           4 :         printf("success: readdir\n");
     426           4 :         return true;
     427             : }
     428             : 
     429           3 : static int test_telldir(void)
     430             : {
     431             :         /* FIXME */
     432           3 :         return true;
     433             : }
     434             : 
     435           3 : static int test_seekdir(void)
     436             : {
     437             :         /* FIXME */
     438           3 :         return true;
     439             : }
     440             : 
     441           3 : static int test_dlopen(void)
     442             : {
     443             :         /* FIXME: test dlopen, dlsym, dlclose, dlerror */
     444           3 :         return true;
     445             : }
     446             : 
     447             : 
     448           3 : static int test_chroot(void)
     449             : {
     450             :         /* FIXME: chroot() */
     451           3 :         return true;
     452             : }
     453             : 
     454           3 : static int test_bzero(void)
     455             : {
     456             :         /* FIXME: bzero */
     457           3 :         return true;
     458             : }
     459             : 
     460           3 : static int test_strerror(void)
     461             : {
     462             :         /* FIXME */
     463           3 :         return true;
     464             : }
     465             : 
     466           4 : static int test_errno(void)
     467             : {
     468           4 :         printf("test: errno\n");
     469           4 :         errno = 3;
     470           4 :         if (errno != 3) {
     471           0 :                 printf("failure: errno [\nerrno failed\n]\n");
     472           0 :                 return false;
     473             :         }
     474             : 
     475           4 :         printf("success: errno\n");
     476           4 :         return true;
     477             : }
     478             : 
     479           3 : static int test_mkdtemp(void)
     480             : {
     481             :         /* FIXME */
     482           3 :         return true;
     483             : }
     484             : 
     485           3 : static int test_mkstemp(void)
     486             : {
     487             :         /* FIXME */
     488           3 :         return true;
     489             : }
     490             : 
     491           3 : static int test_pread(void)
     492             : {
     493             :         /* FIXME */
     494           3 :         return true;
     495             : }
     496             : 
     497           3 : static int test_pwrite(void)
     498             : {
     499             :         /* FIXME */
     500           3 :         return true;
     501             : }
     502             : 
     503           3 : static int test_inet_ntoa(void)
     504             : {
     505             :         /* FIXME */
     506           3 :         return true;
     507             : }
     508             : 
     509             : #define TEST_STRTO_X(type,fmt,func,str,base,res,diff,rrnoo) do {\
     510             :         type _v; \
     511             :         char _s[64]; \
     512             :         char *_p = NULL;\
     513             :         char *_ep = NULL; \
     514             :         strlcpy(_s, str, sizeof(_s));\
     515             :         if (diff >= 0) { \
     516             :                 _ep = &_s[diff]; \
     517             :         } \
     518             :         errno = 0; \
     519             :         _v = func(_s, &_p, base); \
     520             :         if (errno != rrnoo) { \
     521             :                 printf("failure: %s [\n" \
     522             :                        "\t%s\n" \
     523             :                        "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
     524             :                        "\terrno: %d != %d\n" \
     525             :                        "]\n", \
     526             :                         __STRING(func), __location__, __STRING(func), \
     527             :                        str, diff, base, res, _v, rrnoo, errno); \
     528             :                 return false; \
     529             :         } else if (_v != res) { \
     530             :                 printf("failure: %s [\n" \
     531             :                        "\t%s\n" \
     532             :                        "\t%s(\"%s\",%d,%d): " fmt " != " fmt "\n" \
     533             :                        "]\n", \
     534             :                        __STRING(func), __location__, __STRING(func), \
     535             :                        str, diff, base, res, _v); \
     536             :                 return false; \
     537             :         } else if (_p != _ep) { \
     538             :                 printf("failure: %s [\n" \
     539             :                        "\t%s\n" \
     540             :                        "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \
     541             :                        "\tptr: %p - %p = %d != %d\n" \
     542             :                        "]\n", \
     543             :                        __STRING(func), __location__, __STRING(func), \
     544             :                        str, diff, base, res, _v, _ep, _p, (int)(diff - (_ep - _p)), diff); \
     545             :                 return false; \
     546             :         } \
     547             : } while (0)
     548             : 
     549           4 : static int test_strtoll(void)
     550             : {
     551           4 :         printf("test: strtoll\n");
     552             : 
     553             : #define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(long long int, "%lld", strtoll,str,base,res,diff,errnoo)
     554             : 
     555           4 :         TEST_STRTOLL("15",    10,     15LL,   2, 0);
     556           4 :         TEST_STRTOLL("  15",  10,     15LL,   4, 0);
     557           4 :         TEST_STRTOLL("15",    0,      15LL,   2, 0);
     558           4 :         TEST_STRTOLL(" 15 ",  0,      15LL,   3, 0);
     559           4 :         TEST_STRTOLL("+15",   10,     15LL,   3, 0);
     560           4 :         TEST_STRTOLL("  +15", 10,     15LL,   5, 0);
     561           4 :         TEST_STRTOLL("+15",   0,      15LL,   3, 0);
     562           4 :         TEST_STRTOLL(" +15 ", 0,      15LL,   4, 0);
     563           4 :         TEST_STRTOLL("-15",   10,     -15LL,  3, 0);
     564           4 :         TEST_STRTOLL("  -15", 10,     -15LL,  5, 0);
     565           4 :         TEST_STRTOLL("-15",   0,      -15LL,  3, 0);
     566           4 :         TEST_STRTOLL(" -15 ", 0,      -15LL,  4, 0);
     567           4 :         TEST_STRTOLL("015",   10,     15LL,   3, 0);
     568           4 :         TEST_STRTOLL("  015", 10,     15LL,   5, 0);
     569           4 :         TEST_STRTOLL("015",   0,      13LL,   3, 0);
     570           4 :         TEST_STRTOLL("  015", 0,      13LL,   5, 0);
     571           4 :         TEST_STRTOLL("0x15",  10,     0LL,    1, 0);
     572           4 :         TEST_STRTOLL("  0x15",        10,     0LL,    3, 0);
     573           4 :         TEST_STRTOLL("0x15",  0,      21LL,   4, 0);
     574           4 :         TEST_STRTOLL("  0x15",        0,      21LL,   6, 0);
     575             : 
     576           4 :         TEST_STRTOLL("10",    16,     16LL,   2, 0);
     577           4 :         TEST_STRTOLL("  10 ", 16,     16LL,   4, 0);
     578           4 :         TEST_STRTOLL("0x10",  16,     16LL,   4, 0);
     579           4 :         TEST_STRTOLL("0x10",  0,      16LL,   4, 0);
     580           4 :         TEST_STRTOLL(" 0x10 ",        0,      16LL,   5, 0);
     581           4 :         TEST_STRTOLL("+10",   16,     16LL,   3, 0);
     582           4 :         TEST_STRTOLL("  +10 ",        16,     16LL,   5, 0);
     583           4 :         TEST_STRTOLL("+0x10", 16,     16LL,   5, 0);
     584           4 :         TEST_STRTOLL("+0x10", 0,      16LL,   5, 0);
     585           4 :         TEST_STRTOLL(" +0x10 ",       0,      16LL,   6, 0);
     586           4 :         TEST_STRTOLL("-10",   16,     -16LL,  3, 0);
     587           4 :         TEST_STRTOLL("  -10 ",        16,     -16LL,  5, 0);
     588           4 :         TEST_STRTOLL("-0x10", 16,     -16LL,  5, 0);
     589           4 :         TEST_STRTOLL("-0x10", 0,      -16LL,  5, 0);
     590           4 :         TEST_STRTOLL(" -0x10 ",       0,      -16LL,  6, 0);
     591           4 :         TEST_STRTOLL("010",   16,     16LL,   3, 0);
     592           4 :         TEST_STRTOLL("  010 ",        16,     16LL,   5, 0);
     593           4 :         TEST_STRTOLL("-010",  16,     -16LL,  4, 0);
     594             : 
     595           4 :         TEST_STRTOLL("11",    8,      9LL,    2, 0);
     596           4 :         TEST_STRTOLL("011",   8,      9LL,    3, 0);
     597           4 :         TEST_STRTOLL("011",   0,      9LL,    3, 0);
     598           4 :         TEST_STRTOLL("-11",   8,      -9LL,   3, 0);
     599           4 :         TEST_STRTOLL("-011",  8,      -9LL,   4, 0);
     600           4 :         TEST_STRTOLL("-011",  0,      -9LL,   4, 0);
     601             : 
     602           4 :         TEST_STRTOLL("011",   8,      9LL,    3, 0);
     603           4 :         TEST_STRTOLL("011",   0,      9LL,    3, 0);
     604           4 :         TEST_STRTOLL("-11",   8,      -9LL,   3, 0);
     605           4 :         TEST_STRTOLL("-011",  8,      -9LL,   4, 0);
     606           4 :         TEST_STRTOLL("-011",  0,      -9LL,   4, 0);
     607             : 
     608           4 :         TEST_STRTOLL("Text",  0,      0LL,    0, 0);
     609             : 
     610           4 :         TEST_STRTOLL("9223372036854775807",   10,     9223372036854775807LL,  19, 0);
     611           4 :         TEST_STRTOLL("9223372036854775807",   0,      9223372036854775807LL,  19, 0);
     612           4 :         TEST_STRTOLL("9223372036854775808",   0,      9223372036854775807LL,  19, ERANGE);
     613           4 :         TEST_STRTOLL("9223372036854775808",   10,     9223372036854775807LL,  19, ERANGE);
     614           4 :         TEST_STRTOLL("0x7FFFFFFFFFFFFFFF",    0,      9223372036854775807LL,  18, 0);
     615           4 :         TEST_STRTOLL("0x7FFFFFFFFFFFFFFF",    16,     9223372036854775807LL,  18, 0);
     616           4 :         TEST_STRTOLL("7FFFFFFFFFFFFFFF",      16,     9223372036854775807LL,  16, 0);
     617           4 :         TEST_STRTOLL("0x8000000000000000",    0,      9223372036854775807LL,  18, ERANGE);
     618           4 :         TEST_STRTOLL("0x8000000000000000",    16,     9223372036854775807LL,  18, ERANGE);
     619           4 :         TEST_STRTOLL("80000000000000000",     16,     9223372036854775807LL,  17, ERANGE);
     620           4 :         TEST_STRTOLL("0777777777777777777777",        0,      9223372036854775807LL,  22, 0);
     621           4 :         TEST_STRTOLL("0777777777777777777777",        8,      9223372036854775807LL,  22, 0);
     622           4 :         TEST_STRTOLL("777777777777777777777", 8,      9223372036854775807LL,  21, 0);
     623           4 :         TEST_STRTOLL("01000000000000000000000",       0,      9223372036854775807LL,  23, ERANGE);
     624           4 :         TEST_STRTOLL("01000000000000000000000",       8,      9223372036854775807LL,  23, ERANGE);
     625           4 :         TEST_STRTOLL("1000000000000000000000",        8,      9223372036854775807LL,  22, ERANGE);
     626             : 
     627           4 :         TEST_STRTOLL("-9223372036854775808",  10,     -9223372036854775807LL -1,      20, 0);
     628           4 :         TEST_STRTOLL("-9223372036854775808",  0,      -9223372036854775807LL -1,      20, 0);
     629           4 :         TEST_STRTOLL("-9223372036854775809",  0,      -9223372036854775807LL -1,      20, ERANGE);
     630           4 :         TEST_STRTOLL("-9223372036854775809",  10,     -9223372036854775807LL -1,      20, ERANGE);
     631           4 :         TEST_STRTOLL("-0x8000000000000000",   0,      -9223372036854775807LL -1,      19, 0);
     632           4 :         TEST_STRTOLL("-0x8000000000000000",   16,     -9223372036854775807LL -1,      19, 0);
     633           4 :         TEST_STRTOLL("-8000000000000000",     16,     -9223372036854775807LL -1,      17, 0);
     634           4 :         TEST_STRTOLL("-0x8000000000000001",   0,      -9223372036854775807LL -1,      19, ERANGE);
     635           4 :         TEST_STRTOLL("-0x8000000000000001",   16,     -9223372036854775807LL -1,      19, ERANGE);
     636           4 :         TEST_STRTOLL("-80000000000000001",    16,     -9223372036854775807LL -1,      18, ERANGE);
     637           4 :         TEST_STRTOLL("-01000000000000000000000",0,    -9223372036854775807LL -1,      24, 0);
     638           4 :         TEST_STRTOLL("-01000000000000000000000",8,    -9223372036854775807LL -1,      24, 0);
     639           4 :         TEST_STRTOLL("-1000000000000000000000",       8,      -9223372036854775807LL -1,      23, 0);
     640           4 :         TEST_STRTOLL("-01000000000000000000001",0,    -9223372036854775807LL -1,      24, ERANGE);
     641           4 :         TEST_STRTOLL("-01000000000000000000001",8,    -9223372036854775807LL -1,      24, ERANGE);
     642           4 :         TEST_STRTOLL("-1000000000000000000001",       8,      -9223372036854775807LL -1,      23, ERANGE);
     643             : 
     644           4 :         printf("success: strtoll\n");
     645           4 :         return true;
     646             : }
     647             : 
     648           4 : static int test_strtoull(void)
     649             : {
     650           4 :         printf("test: strtoull\n");
     651             : 
     652             : #define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(long long unsigned int,"%llu",strtoull,str,base,res,diff,errnoo)
     653             : 
     654           4 :         TEST_STRTOULL("15",   10,     15LLU,  2, 0);
     655           4 :         TEST_STRTOULL("  15", 10,     15LLU,  4, 0);
     656           4 :         TEST_STRTOULL("15",   0,      15LLU,  2, 0);
     657           4 :         TEST_STRTOULL(" 15 ", 0,      15LLU,  3, 0);
     658           4 :         TEST_STRTOULL("+15",  10,     15LLU,  3, 0);
     659           4 :         TEST_STRTOULL("  +15",        10,     15LLU,  5, 0);
     660           4 :         TEST_STRTOULL("+15",  0,      15LLU,  3, 0);
     661           4 :         TEST_STRTOULL(" +15 ",        0,      15LLU,  4, 0);
     662           4 :         TEST_STRTOULL("-15",  10,     18446744073709551601LLU,        3, 0);
     663           4 :         TEST_STRTOULL("  -15",        10,     18446744073709551601LLU,        5, 0);
     664           4 :         TEST_STRTOULL("-15",  0,      18446744073709551601LLU,        3, 0);
     665           4 :         TEST_STRTOULL(" -15 ",        0,      18446744073709551601LLU,        4, 0);
     666           4 :         TEST_STRTOULL("015",  10,     15LLU,  3, 0);
     667           4 :         TEST_STRTOULL("  015",        10,     15LLU,  5, 0);
     668           4 :         TEST_STRTOULL("015",  0,      13LLU,  3, 0);
     669           4 :         TEST_STRTOULL("  015",        0,      13LLU,  5, 0);
     670           4 :         TEST_STRTOULL("0x15", 10,     0LLU,   1, 0);
     671           4 :         TEST_STRTOULL("  0x15",       10,     0LLU,   3, 0);
     672           4 :         TEST_STRTOULL("0x15", 0,      21LLU,  4, 0);
     673           4 :         TEST_STRTOULL("  0x15",       0,      21LLU,  6, 0);
     674             : 
     675           4 :         TEST_STRTOULL("10",   16,     16LLU,  2, 0);
     676           4 :         TEST_STRTOULL("  10 ",        16,     16LLU,  4, 0);
     677           4 :         TEST_STRTOULL("0x10", 16,     16LLU,  4, 0);
     678           4 :         TEST_STRTOULL("0x10", 0,      16LLU,  4, 0);
     679           4 :         TEST_STRTOULL(" 0x10 ",       0,      16LLU,  5, 0);
     680           4 :         TEST_STRTOULL("+10",  16,     16LLU,  3, 0);
     681           4 :         TEST_STRTOULL("  +10 ",       16,     16LLU,  5, 0);
     682           4 :         TEST_STRTOULL("+0x10",        16,     16LLU,  5, 0);
     683           4 :         TEST_STRTOULL("+0x10",        0,      16LLU,  5, 0);
     684           4 :         TEST_STRTOULL(" +0x10 ",      0,      16LLU,  6, 0);
     685           4 :         TEST_STRTOULL("-10",  16,     -16LLU, 3, 0);
     686           4 :         TEST_STRTOULL("  -10 ",       16,     -16LLU, 5, 0);
     687           4 :         TEST_STRTOULL("-0x10",        16,     -16LLU, 5, 0);
     688           4 :         TEST_STRTOULL("-0x10",        0,      -16LLU, 5, 0);
     689           4 :         TEST_STRTOULL(" -0x10 ",      0,      -16LLU, 6, 0);
     690           4 :         TEST_STRTOULL("010",  16,     16LLU,  3, 0);
     691           4 :         TEST_STRTOULL("  010 ",       16,     16LLU,  5, 0);
     692           4 :         TEST_STRTOULL("-010", 16,     -16LLU, 4, 0);
     693             : 
     694           4 :         TEST_STRTOULL("11",   8,      9LLU,   2, 0);
     695           4 :         TEST_STRTOULL("011",  8,      9LLU,   3, 0);
     696           4 :         TEST_STRTOULL("011",  0,      9LLU,   3, 0);
     697           4 :         TEST_STRTOULL("-11",  8,      -9LLU,  3, 0);
     698           4 :         TEST_STRTOULL("-011", 8,      -9LLU,  4, 0);
     699           4 :         TEST_STRTOULL("-011", 0,      -9LLU,  4, 0);
     700             : 
     701           4 :         TEST_STRTOULL("011",  8,      9LLU,   3, 0);
     702           4 :         TEST_STRTOULL("011",  0,      9LLU,   3, 0);
     703           4 :         TEST_STRTOULL("-11",  8,      -9LLU,  3, 0);
     704           4 :         TEST_STRTOULL("-011", 8,      -9LLU,  4, 0);
     705           4 :         TEST_STRTOULL("-011", 0,      -9LLU,  4, 0);
     706             : 
     707           4 :         TEST_STRTOULL("Text", 0,      0LLU,   0, 0);
     708             : 
     709           4 :         TEST_STRTOULL("9223372036854775807",  10,     9223372036854775807LLU, 19, 0);
     710           4 :         TEST_STRTOULL("9223372036854775807",  0,      9223372036854775807LLU, 19, 0);
     711           4 :         TEST_STRTOULL("9223372036854775808",  0,      9223372036854775808LLU, 19, 0);
     712           4 :         TEST_STRTOULL("9223372036854775808",  10,     9223372036854775808LLU, 19, 0);
     713           4 :         TEST_STRTOULL("0x7FFFFFFFFFFFFFFF",   0,      9223372036854775807LLU, 18, 0);
     714           4 :         TEST_STRTOULL("0x7FFFFFFFFFFFFFFF",   16,     9223372036854775807LLU, 18, 0);
     715           4 :         TEST_STRTOULL("7FFFFFFFFFFFFFFF",     16,     9223372036854775807LLU, 16, 0);
     716           4 :         TEST_STRTOULL("0x8000000000000000",   0,      9223372036854775808LLU, 18, 0);
     717           4 :         TEST_STRTOULL("0x8000000000000000",   16,     9223372036854775808LLU, 18, 0);
     718           4 :         TEST_STRTOULL("8000000000000000",     16,     9223372036854775808LLU, 16, 0);
     719           4 :         TEST_STRTOULL("0777777777777777777777",       0,      9223372036854775807LLU, 22, 0);
     720           4 :         TEST_STRTOULL("0777777777777777777777",       8,      9223372036854775807LLU, 22, 0);
     721           4 :         TEST_STRTOULL("777777777777777777777",        8,      9223372036854775807LLU, 21, 0);
     722           4 :         TEST_STRTOULL("01000000000000000000000",0,    9223372036854775808LLU, 23, 0);
     723           4 :         TEST_STRTOULL("01000000000000000000000",8,    9223372036854775808LLU, 23, 0);
     724           4 :         TEST_STRTOULL("1000000000000000000000",       8,      9223372036854775808LLU, 22, 0);
     725             : 
     726           4 :         TEST_STRTOULL("-9223372036854775808", 10,     9223372036854775808LLU, 20, 0);
     727           4 :         TEST_STRTOULL("-9223372036854775808", 0,      9223372036854775808LLU, 20, 0);
     728           4 :         TEST_STRTOULL("-9223372036854775809", 0,      9223372036854775807LLU, 20, 0);
     729           4 :         TEST_STRTOULL("-9223372036854775809", 10,     9223372036854775807LLU, 20, 0);
     730           4 :         TEST_STRTOULL("-0x8000000000000000",  0,      9223372036854775808LLU, 19, 0);
     731           4 :         TEST_STRTOULL("-0x8000000000000000",  16,     9223372036854775808LLU, 19, 0);
     732           4 :         TEST_STRTOULL("-8000000000000000",    16,     9223372036854775808LLU, 17, 0);
     733           4 :         TEST_STRTOULL("-0x8000000000000001",  0,      9223372036854775807LLU, 19, 0);
     734           4 :         TEST_STRTOULL("-0x8000000000000001",  16,     9223372036854775807LLU, 19, 0);
     735           4 :         TEST_STRTOULL("-8000000000000001",    16,     9223372036854775807LLU, 17, 0);
     736           4 :         TEST_STRTOULL("-01000000000000000000000",0,   9223372036854775808LLU, 24, 0);
     737           4 :         TEST_STRTOULL("-01000000000000000000000",8,   9223372036854775808LLU, 24, 0);
     738           4 :         TEST_STRTOULL("-1000000000000000000000",8,    9223372036854775808LLU, 23, 0);
     739           4 :         TEST_STRTOULL("-01000000000000000000001",0,   9223372036854775807LLU, 24, 0);
     740           4 :         TEST_STRTOULL("-01000000000000000000001",8,   9223372036854775807LLU, 24, 0);
     741           4 :         TEST_STRTOULL("-1000000000000000000001",8,    9223372036854775807LLU, 23, 0);
     742             : 
     743           4 :         TEST_STRTOULL("18446744073709551615", 0,      18446744073709551615LLU,        20, 0);
     744           4 :         TEST_STRTOULL("18446744073709551615", 10,     18446744073709551615LLU,        20, 0);
     745           4 :         TEST_STRTOULL("18446744073709551616", 0,      18446744073709551615LLU,        20, ERANGE);
     746           4 :         TEST_STRTOULL("18446744073709551616", 10,     18446744073709551615LLU,        20, ERANGE);
     747           4 :         TEST_STRTOULL("0xFFFFFFFFFFFFFFFF",   0,      18446744073709551615LLU,        18, 0);
     748           4 :         TEST_STRTOULL("0xFFFFFFFFFFFFFFFF",   16,     18446744073709551615LLU,        18, 0);
     749           4 :         TEST_STRTOULL("FFFFFFFFFFFFFFFF",     16,     18446744073709551615LLU,        16, 0);
     750           4 :         TEST_STRTOULL("0x10000000000000000",  0,      18446744073709551615LLU,        19, ERANGE);
     751           4 :         TEST_STRTOULL("0x10000000000000000",  16,     18446744073709551615LLU,        19, ERANGE);
     752           4 :         TEST_STRTOULL("10000000000000000",    16,     18446744073709551615LLU,        17, ERANGE);
     753           4 :         TEST_STRTOULL("01777777777777777777777",0,    18446744073709551615LLU,        23, 0);
     754           4 :         TEST_STRTOULL("01777777777777777777777",8,    18446744073709551615LLU,        23, 0);
     755           4 :         TEST_STRTOULL("1777777777777777777777",       8,      18446744073709551615LLU,        22, 0);
     756           4 :         TEST_STRTOULL("02000000000000000000000",0,    18446744073709551615LLU,        23, ERANGE);
     757           4 :         TEST_STRTOULL("02000000000000000000000",8,    18446744073709551615LLU,        23, ERANGE);
     758           4 :         TEST_STRTOULL("2000000000000000000000",       8,      18446744073709551615LLU,        22, ERANGE);
     759             : 
     760           4 :         TEST_STRTOULL("-18446744073709551615",        0,      1LLU,                           21, 0);
     761           4 :         TEST_STRTOULL("-18446744073709551615",        10,     1LLU,                           21, 0);
     762           4 :         TEST_STRTOULL("-18446744073709551616",        0,      18446744073709551615LLU,        21, ERANGE);
     763           4 :         TEST_STRTOULL("-18446744073709551616",        10,     18446744073709551615LLU,        21, ERANGE);
     764           4 :         TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF",  0,      1LLU,                           19, 0);
     765           4 :         TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF",  16,     1LLU,                           19, 0);
     766           4 :         TEST_STRTOULL("-FFFFFFFFFFFFFFFF",    16,     1LLU,                           17, 0);
     767           4 :         TEST_STRTOULL("-0x10000000000000000", 0,      18446744073709551615LLU,        20, ERANGE);
     768           4 :         TEST_STRTOULL("-0x10000000000000000", 16,     18446744073709551615LLU,        20, ERANGE);
     769           4 :         TEST_STRTOULL("-10000000000000000",   16,     18446744073709551615LLU,        18, ERANGE);
     770           4 :         TEST_STRTOULL("-01777777777777777777777",0,   1LLU,                           24, 0);
     771           4 :         TEST_STRTOULL("-01777777777777777777777",8,   1LLU,                           24, 0);
     772           4 :         TEST_STRTOULL("-1777777777777777777777",8,    1LLU,                           23, 0);
     773           4 :         TEST_STRTOULL("-02000000000000000000000",0,   18446744073709551615LLU,        24, ERANGE);
     774           4 :         TEST_STRTOULL("-02000000000000000000000",8,   18446744073709551615LLU,        24, ERANGE);
     775           4 :         TEST_STRTOULL("-2000000000000000000000",8,    18446744073709551615LLU,        23, ERANGE);
     776             : 
     777           4 :         printf("success: strtoull\n");
     778           4 :         return true;
     779             : }
     780             : 
     781             : /*
     782             : FIXME:
     783             : Types:
     784             : bool
     785             : socklen_t
     786             : uint{8,16,32,64}_t
     787             : int{8,16,32,64}_t
     788             : intptr_t
     789             : 
     790             : Constants:
     791             : PATH_NAME_MAX
     792             : UINT{16,32,64}_MAX
     793             : INT32_MAX
     794             : */
     795             : 
     796           3 : static int test_va_copy(void)
     797             : {
     798             :         /* FIXME */
     799           3 :         return true;
     800             : }
     801             : 
     802           4 : static int test_FUNCTION(void)
     803             : {
     804           5 :         printf("test: FUNCTION\n");
     805           4 :         if (strcmp(__FUNCTION__, "test_FUNCTION") != 0) {
     806           0 :                 printf("failure: FUNCTION [\nFUNCTION invalid\n]\n");
     807           0 :                 return false;
     808             :         }
     809           4 :         printf("success: FUNCTION\n");
     810           4 :         return true;
     811             : }
     812             : 
     813           4 : static int test_MIN(void)
     814             : {
     815           5 :         printf("test: MIN\n");
     816           1 :         if (MIN(20, 1) != 1) {
     817             :                 printf("failure: MIN [\nMIN invalid\n]\n");
     818             :                 return false;
     819             :         }
     820           1 :         if (MIN(1, 20) != 1) {
     821             :                 printf("failure: MIN [\nMIN invalid\n]\n");
     822             :                 return false;
     823             :         }
     824           4 :         printf("success: MIN\n");
     825           4 :         return true;
     826             : }
     827             : 
     828           4 : static int test_MAX(void)
     829             : {
     830           5 :         printf("test: MAX\n");
     831           1 :         if (MAX(20, 1) != 20) {
     832             :                 printf("failure: MAX [\nMAX invalid\n]\n");
     833             :                 return false;
     834             :         }
     835           1 :         if (MAX(1, 20) != 20) {
     836             :                 printf("failure: MAX [\nMAX invalid\n]\n");
     837             :                 return false;
     838             :         }
     839           4 :         printf("success: MAX\n");
     840           4 :         return true;
     841             : }
     842             : 
     843           4 : static int test_socketpair(void)
     844             : {
     845           1 :         int sock[2];
     846           1 :         char buf[20];
     847             : 
     848           4 :         printf("test: socketpair\n");
     849             : 
     850           4 :         if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
     851           0 :                 printf("failure: socketpair [\n"
     852             :                            "socketpair() failed\n"
     853             :                            "]\n");
     854           0 :                 return false;
     855             :         }
     856             : 
     857           4 :         if (write(sock[1], "automatisch", 12) != 12) {
     858           0 :                 printf("failure: socketpair [\n"
     859             :                            "write() failed: %s\n"
     860           0 :                            "]\n", strerror(errno));
     861           0 :                 return false;
     862             :         }
     863             : 
     864           4 :         if (read(sock[0], buf, 12) != 12) {
     865           0 :                 printf("failure: socketpair [\n"
     866             :                            "read() failed: %s\n"
     867           0 :                            "]\n", strerror(errno));
     868           0 :                 return false;
     869             :         }
     870             : 
     871           4 :         if (strcmp(buf, "automatisch") != 0) {
     872           0 :                 printf("failure: socketpair [\n"
     873             :                            "expected: automatisch, got: %s\n"
     874             :                            "]\n", buf);
     875           0 :                 return false;
     876             :         }
     877             : 
     878           4 :         printf("success: socketpair\n");
     879             : 
     880           4 :         return true;
     881             : }
     882             : 
     883             : extern int libreplace_test_strptime(void);
     884             : 
     885           4 : static int test_strptime(void)
     886             : {
     887           4 :         return libreplace_test_strptime();
     888             : }
     889             : 
     890             : extern int getifaddrs_test(void);
     891             : 
     892           4 : static int test_getifaddrs(void)
     893             : {
     894             : 
     895           4 :         printf("test: getifaddrs\n");
     896             : 
     897           4 :         if (getifaddrs_test() != 0) {
     898           0 :                 printf("failure: getifaddrs\n");
     899           0 :                 return false;
     900             :         }
     901             : 
     902           4 :         printf("success: getifaddrs\n");
     903           4 :         return true;
     904             : }
     905             : 
     906           4 : static int test_utime(void)
     907             : {
     908           1 :         struct utimbuf u;
     909           1 :         struct stat st1, st2, st3;
     910           1 :         int fd;
     911             : 
     912           4 :         printf("test: utime\n");
     913           4 :         unlink(TESTFILE);
     914             : 
     915           4 :         fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
     916           4 :         if (fd == -1) {
     917           0 :                 printf("failure: utime [\n"
     918             :                        "creating '%s' failed - %s\n]\n",
     919           0 :                        TESTFILE, strerror(errno));
     920           0 :                 return false;
     921             :         }
     922             : 
     923           4 :         if (fstat(fd, &st1) != 0) {
     924           0 :                 printf("failure: utime [\n"
     925             :                        "fstat (1) failed - %s\n]\n",
     926           0 :                        strerror(errno));
     927           0 :                 close(fd);
     928           0 :                 return false;
     929             :         }
     930             : 
     931           4 :         u.actime = st1.st_atime + 300;
     932           4 :         u.modtime = st1.st_mtime - 300;
     933           4 :         if (utime(TESTFILE, &u) != 0) {
     934           0 :                 printf("failure: utime [\n"
     935             :                        "utime(&u) failed - %s\n]\n",
     936           0 :                        strerror(errno));
     937           0 :                 close(fd);
     938           0 :                 return false;
     939             :         }
     940             : 
     941           4 :         if (fstat(fd, &st2) != 0) {
     942           0 :                 printf("failure: utime [\n"
     943             :                        "fstat (2) failed - %s\n]\n",
     944           0 :                        strerror(errno));
     945           0 :                 close(fd);
     946           0 :                 return false;
     947             :         }
     948             : 
     949           4 :         if (utime(TESTFILE, NULL) != 0) {
     950           0 :                 printf("failure: utime [\n"
     951             :                        "utime(NULL) failed - %s\n]\n",
     952           0 :                        strerror(errno));
     953           0 :                 close(fd);
     954           0 :                 return false;
     955             :         }
     956             : 
     957           4 :         if (fstat(fd, &st3) != 0) {
     958           0 :                 printf("failure: utime [\n"
     959             :                        "fstat (3) failed - %s\n]\n",
     960           0 :                        strerror(errno));
     961           0 :                 close(fd);
     962           0 :                 return false;
     963             :         }
     964             : 
     965             : #define CMP_VAL(a,c,b) do { \
     966             :         if (a c b) { \
     967             :                 printf("failure: utime [\n" \
     968             :                        "%s: %s(%d) %s %s(%d)\n]\n", \
     969             :                        __location__, \
     970             :                        #a, (int)a, #c, #b, (int)b); \
     971             :                 close(fd); \
     972             :                 return false; \
     973             :         } \
     974             : } while(0)
     975             : #define EQUAL_VAL(a,b) CMP_VAL(a,!=,b)
     976             : #define GREATER_VAL(a,b) CMP_VAL(a,<=,b)
     977             : #define LESSER_VAL(a,b) CMP_VAL(a,>=,b)
     978             : 
     979           4 :         EQUAL_VAL(st2.st_atime, st1.st_atime + 300);
     980           4 :         EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300);
     981           4 :         LESSER_VAL(st3.st_atime, st2.st_atime);
     982           4 :         GREATER_VAL(st3.st_mtime, st2.st_mtime);
     983             : 
     984             : #undef CMP_VAL
     985             : #undef EQUAL_VAL
     986             : #undef GREATER_VAL
     987             : #undef LESSER_VAL
     988             : 
     989           4 :         unlink(TESTFILE);
     990           4 :         printf("success: utime\n");
     991           4 :         close(fd);
     992           4 :         return true;
     993             : }
     994             : 
     995           4 : static int test_utimes(void)
     996             : {
     997           1 :         struct timeval tv[2];
     998           1 :         struct stat st1, st2;
     999           1 :         int fd;
    1000             : 
    1001           4 :         printf("test: utimes\n");
    1002           4 :         unlink(TESTFILE);
    1003             : 
    1004           4 :         fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
    1005           4 :         if (fd == -1) {
    1006           0 :                 printf("failure: utimes [\n"
    1007             :                        "creating '%s' failed - %s\n]\n",
    1008           0 :                        TESTFILE, strerror(errno));
    1009           0 :                 return false;
    1010             :         }
    1011             : 
    1012           4 :         if (fstat(fd, &st1) != 0) {
    1013           0 :                 printf("failure: utimes [\n"
    1014             :                        "fstat (1) failed - %s\n]\n",
    1015           0 :                        strerror(errno));
    1016           0 :                 close(fd);
    1017           0 :                 return false;
    1018             :         }
    1019             : 
    1020           4 :         ZERO_STRUCT(tv);
    1021           4 :         tv[0].tv_sec = st1.st_atime + 300;
    1022           4 :         tv[1].tv_sec = st1.st_mtime - 300;
    1023           4 :         if (utimes(TESTFILE, tv) != 0) {
    1024           0 :                 printf("failure: utimes [\n"
    1025             :                        "utimes(tv) failed - %s\n]\n",
    1026           0 :                        strerror(errno));
    1027           0 :                 close(fd);
    1028           0 :                 return false;
    1029             :         }
    1030             : 
    1031           4 :         if (fstat(fd, &st2) != 0) {
    1032           0 :                 printf("failure: utimes [\n"
    1033             :                        "fstat (2) failed - %s\n]\n",
    1034           0 :                        strerror(errno));
    1035           0 :                 close(fd);
    1036           0 :                 return false;
    1037             :         }
    1038             : 
    1039             : #define EQUAL_VAL(a,b) do { \
    1040             :         if (a != b) { \
    1041             :                 printf("failure: utimes [\n" \
    1042             :                        "%s: %s(%d) != %s(%d)\n]\n", \
    1043             :                        __location__, \
    1044             :                        #a, (int)a, #b, (int)b); \
    1045             :                 close(fd); \
    1046             :                 return false; \
    1047             :         } \
    1048             : } while(0)
    1049             : 
    1050           4 :         EQUAL_VAL(st2.st_atime, st1.st_atime + 300);
    1051           4 :         EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300);
    1052             : 
    1053             : #undef EQUAL_VAL
    1054             : 
    1055           4 :         unlink(TESTFILE);
    1056           4 :         printf("success: utimes\n");
    1057           4 :         close(fd);
    1058           4 :         return true;
    1059             : }
    1060             : 
    1061           4 : static int test_memmem(void)
    1062             : {
    1063           1 :         char *s;
    1064             : 
    1065           4 :         printf("test: memmem\n");
    1066             : 
    1067           4 :         s = (char *)memmem("foo", 3, "fo", 2);
    1068           4 :         if (strcmp(s, "foo") != 0) {
    1069           0 :                 printf(__location__ ": Failed memmem\n");
    1070           0 :                 return false;
    1071             :         }
    1072             : 
    1073           4 :         s = (char *)memmem("foo", 3, "", 0);
    1074             :         /* it is allowable for this to return NULL (as happens on
    1075             :            FreeBSD) */
    1076           4 :         if (s && strcmp(s, "foo") != 0) {
    1077           0 :                 printf(__location__ ": Failed memmem\n");
    1078           0 :                 return false;
    1079             :         }
    1080             : 
    1081           4 :         s = (char *)memmem("foo", 4, "o", 1);
    1082           4 :         if (strcmp(s, "oo") != 0) {
    1083           0 :                 printf(__location__ ": Failed memmem\n");
    1084           0 :                 return false;
    1085             :         }
    1086             : 
    1087           4 :         s = (char *)memmem("foobarfodx", 11, "fod", 3);
    1088           4 :         if (strcmp(s, "fodx") != 0) {
    1089           0 :                 printf(__location__ ": Failed memmem\n");
    1090           0 :                 return false;
    1091             :         }
    1092             : 
    1093           4 :         printf("success: memmem\n");
    1094             : 
    1095           4 :         return true;
    1096             : }
    1097             : 
    1098           4 : static bool test_closefrom(void)
    1099             : {
    1100           1 :         int i, fd;
    1101             : 
    1102         404 :         for (i=0; i<100; i++) {
    1103         400 :                 fd = dup(0);
    1104         400 :                 if (fd == -1) {
    1105           0 :                         perror("dup failed");
    1106           0 :                         closefrom(3);
    1107           0 :                         return false;
    1108             :                 }
    1109             : 
    1110             :                 /* 1000 is just an arbitrarily chosen upper bound */
    1111             : 
    1112         400 :                 if (fd >= 1000) {
    1113           0 :                         printf("fd=%d\n", fd);
    1114           0 :                         closefrom(3);
    1115           0 :                         return false;
    1116             :                 }
    1117             :         }
    1118             : 
    1119           4 :         closefrom(3);
    1120             : 
    1121         414 :         for (i=3; i<=fd; i++) {
    1122         103 :                 off_t off;
    1123         409 :                 off = lseek(i, 0, SEEK_CUR);
    1124         409 :                 if ((off != (off_t)-1) || (errno != EBADF)) {
    1125           0 :                         printf("fd %d not closed\n", i);
    1126           0 :                         return false;
    1127             :                 }
    1128             :         }
    1129             : 
    1130           3 :         return true;
    1131             : }
    1132             : 
    1133           4 : static bool test_array_del_element(void)
    1134             : {
    1135           4 :         int a[] = { 1,2,3,4,5 };
    1136             : 
    1137           5 :         printf("test: array_del_element\n");
    1138             : 
    1139           1 :         ARRAY_DEL_ELEMENT(a, 4, ARRAY_SIZE(a));
    1140             : 
    1141           4 :         if ((a[0] != 1) ||
    1142           3 :             (a[1] != 2) ||
    1143           3 :             (a[2] != 3) ||
    1144           3 :             (a[3] != 4) ||
    1145           3 :             (a[4] != 5)) {
    1146           0 :                 return false;
    1147             :         }
    1148             : 
    1149           4 :         ARRAY_DEL_ELEMENT(a, 0, ARRAY_SIZE(a));
    1150             : 
    1151           4 :         if ((a[0] != 2) ||
    1152           3 :             (a[1] != 3) ||
    1153           3 :             (a[2] != 4) ||
    1154           3 :             (a[3] != 5) ||
    1155           3 :             (a[4] != 5)) {
    1156           0 :                 return false;
    1157             :         }
    1158             : 
    1159           4 :         ARRAY_DEL_ELEMENT(a, 2, ARRAY_SIZE(a));
    1160             : 
    1161           4 :         if ((a[0] != 2) ||
    1162           3 :             (a[1] != 3) ||
    1163           3 :             (a[2] != 5) ||
    1164           3 :             (a[3] != 5) ||
    1165           3 :             (a[4] != 5)) {
    1166           0 :                 return false;
    1167             :         }
    1168             : 
    1169           4 :         printf("success: array_del_element\n");
    1170             : 
    1171           4 :         return true;
    1172             : }
    1173             : 
    1174           4 : bool torture_local_replace(struct torture_context *ctx)
    1175             : {
    1176           4 :         bool ret = true;
    1177           4 :         ret &= test_ftruncate();
    1178           4 :         ret &= test_strlcpy();
    1179           4 :         ret &= test_strlcat();
    1180           4 :         ret &= test_mktime();
    1181           4 :         ret &= test_initgroups();
    1182           4 :         ret &= test_memmove();
    1183           4 :         ret &= test_strdup();
    1184           4 :         ret &= test_setlinebuf();
    1185           4 :         ret &= test_vsyslog();
    1186           4 :         ret &= test_timegm();
    1187           4 :         ret &= test_setenv();
    1188           4 :         ret &= test_strndup();
    1189           4 :         ret &= test_strnlen();
    1190           4 :         ret &= test_waitpid();
    1191           4 :         ret &= test_seteuid();
    1192           4 :         ret &= test_setegid();
    1193           4 :         ret &= test_asprintf();
    1194           4 :         ret &= test_snprintf();
    1195           4 :         ret &= test_vasprintf();
    1196           4 :         ret &= test_vsnprintf();
    1197           4 :         ret &= test_opendir();
    1198           4 :         ret &= test_readdir();
    1199           4 :         ret &= test_telldir();
    1200           4 :         ret &= test_seekdir();
    1201           4 :         ret &= test_dlopen();
    1202           4 :         ret &= test_chroot();
    1203           4 :         ret &= test_bzero();
    1204           4 :         ret &= test_strerror();
    1205           4 :         ret &= test_errno();
    1206           4 :         ret &= test_mkdtemp();
    1207           4 :         ret &= test_mkstemp();
    1208           4 :         ret &= test_pread();
    1209           4 :         ret &= test_pwrite();
    1210           4 :         ret &= test_inet_ntoa();
    1211           4 :         ret &= test_strtoll();
    1212           4 :         ret &= test_strtoull();
    1213           4 :         ret &= test_va_copy();
    1214           4 :         ret &= test_FUNCTION();
    1215           4 :         ret &= test_MIN();
    1216           4 :         ret &= test_MAX();
    1217           4 :         ret &= test_socketpair();
    1218           4 :         ret &= test_strptime();
    1219           4 :         ret &= test_getifaddrs();
    1220           4 :         ret &= test_utime();
    1221           4 :         ret &= test_utimes();
    1222           4 :         ret &= test_memmem();
    1223           4 :         ret &= test_closefrom();
    1224           4 :         ret &= test_array_del_element();
    1225             : 
    1226           4 :         return ret;
    1227             : }

Generated by: LCOV version 1.14