root/lib/common/tests/procfs/pcmk__procfs_has_pids_true_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. has_pids

   1 /*
   2  * Copyright 2022 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 
  14 #include "mock_private.h"
  15 
  16 #include <unistd.h>
  17 #include <string.h>
  18 #include <errno.h>
  19 
  20 static void
  21 has_pids(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  22 {
  23     char path[PATH_MAX];
  24 
  25     snprintf(path, PATH_MAX, "/proc/%u/exe", getpid());
  26 
  27     // Set readlink() errno and link contents (for /proc/PID/exe)
  28     pcmk__mock_readlink = true;
  29 
  30     expect_string(__wrap_readlink, path, path);
  31     expect_any(__wrap_readlink, buf);
  32     expect_value(__wrap_readlink, bufsize, PATH_MAX - 1);
  33     will_return(__wrap_readlink, 0);
  34     will_return(__wrap_readlink, "/ok");
  35 
  36     assert_true(pcmk__procfs_has_pids());
  37 
  38     pcmk__mock_readlink = false;
  39 }
  40 
  41 PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(has_pids))

/* [previous][next][first][last][top][bottom][index][help] */