LCOV - code coverage report
Current view: top level - nsswitch - b15464-testcase.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 42 44 95.5 %
Date: 2024-05-31 13:13:24 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "replace.h"
       2             : #include "system/wait.h"
       3             : #include "system/threads.h"
       4             : #include <assert.h>
       5             : 
       6           1 : int main(int argc, const char *argv[])
       7             : {
       8           1 :         pid_t pid;
       9           1 :         int wstatus;
      10           1 :         pthread_key_t k1;
      11           1 :         pthread_key_t k2;
      12           1 :         pthread_key_t k3;
      13           1 :         char *val = NULL;
      14           1 :         const char *nss_winbind = (argc >= 2 ? argv[1] : "bin/plugins/libnss_winbind.so.2");
      15           1 :         void *nss_winbind_handle = NULL;
      16           1 :         union {
      17             :                 int (*fn)(void);
      18             :                 void *symbol;
      19           1 :         } nss_winbind_endpwent = { .symbol = NULL, };
      20             : 
      21             :         /*
      22             :          * load and invoke something simple like
      23             :          * _nss_winbind_endpwent in order to
      24             :          * get the libnss_winbind internal going
      25             :          */
      26           1 :         nss_winbind_handle = dlopen(nss_winbind, RTLD_NOW);
      27           1 :         printf("%d: nss_winbind[%s] nss_winbind_handle[%p]\n",
      28             :                getpid(), nss_winbind, nss_winbind_handle);
      29           1 :         assert(nss_winbind_handle != NULL);
      30             : 
      31           1 :         nss_winbind_endpwent.symbol = dlsym(nss_winbind_handle,
      32             :                                             "_nss_winbind_endpwent");
      33           1 :         printf("%d: nss_winbind_handle[%p] _nss_winbind_endpwent[%p]\n",
      34             :                getpid(), nss_winbind_handle, nss_winbind_endpwent.symbol);
      35           1 :         assert(nss_winbind_endpwent.symbol != NULL);
      36           1 :         (void)nss_winbind_endpwent.fn();
      37             : 
      38           1 :         val = malloc(1);
      39           1 :         assert(val != NULL);
      40             : 
      41           1 :         pthread_key_create(&k1, NULL);
      42           1 :         pthread_setspecific(k1, val);
      43           1 :         printf("%d: k1=%d\n", getpid(), k1);
      44             : 
      45           1 :         pid = fork();
      46           2 :         if (pid) {
      47           1 :                 free(val);
      48           1 :                 wait(&wstatus);
      49           1 :                 return WEXITSTATUS(wstatus);
      50             :         }
      51             : 
      52           1 :         pthread_key_create(&k2, NULL);
      53           1 :         pthread_setspecific(k2, val);
      54             : 
      55           1 :         printf("%d: Hello after fork, k1=%d, k2=%d\n", getpid(), k1, k2);
      56             : 
      57           1 :         pid = fork();
      58             : 
      59           2 :         if (pid) {
      60           1 :                 free(val);
      61           1 :                 wait(&wstatus);
      62           1 :                 return WEXITSTATUS(wstatus);
      63             :         }
      64             : 
      65           1 :         pthread_key_create(&k3, NULL);
      66           1 :         pthread_setspecific(k3, val);
      67             : 
      68           1 :         printf("%d: Hello after fork2, k1=%d, k2=%d, k3=%d\n", getpid(), k1, k2, k3);
      69             : 
      70           1 :         if (k1 == k2 || k2 == k3) {
      71           0 :                 printf("%d: FAIL inconsistent keys\n", getpid());
      72           0 :                 return 1;
      73             :         }
      74             : 
      75           1 :         printf("%d: OK consistent keys\n", getpid());
      76           1 :         return 0;
      77             : }

Generated by: LCOV version 1.14