LCOV - code coverage report
Current view: top level - pam/tests - pam_malcontent.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 16 18 88.9 %
Date: 2022-11-29 07:38:08 Functions: 2 2 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :            :  *
       3                 :            :  * Copyright © 2019 Endless Mobile, Inc.
       4                 :            :  *
       5                 :            :  * This library is free software; you can redistribute it and/or
       6                 :            :  * modify it under the terms of the GNU Lesser General Public
       7                 :            :  * License as published by the Free Software Foundation; either
       8                 :            :  * version 2.1 of the License, or (at your option) any later version.
       9                 :            :  *
      10                 :            :  * This library is distributed in the hope that it will be useful,
      11                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13                 :            :  * Lesser General Public License for more details.
      14                 :            :  *
      15                 :            :  * You should have received a copy of the GNU Lesser General Public
      16                 :            :  * License along with this library; if not, write to the Free Software
      17                 :            :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      18                 :            :  *
      19                 :            :  * Authors:
      20                 :            :  *  - Philip Withnall <withnall@endlessm.com>
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <dlfcn.h>
      24                 :            : #include <glib.h>
      25                 :            : #include <locale.h>
      26                 :            : #include <stdlib.h>
      27                 :            : #include "config.h"
      28                 :            : 
      29                 :            : /* Test that the `pam_malcontent.so` module can be loaded using dlopen() and
      30                 :            :  * that it exports the appropriate symbols for PAM to be able to use it. */
      31                 :            : static void
      32                 :          1 : test_pam_malcontent_dlopen (void)
      33                 :            : {
      34                 :          1 :   g_autofree gchar *module_path = NULL;
      35                 :            :   void *handle;
      36                 :            :   int retval;
      37                 :            :   void *fn;
      38                 :            : 
      39                 :          1 :   module_path = g_test_build_filename (G_TEST_BUILT, "..", "pam_malcontent.so", NULL);
      40                 :            : 
      41                 :            :   /* Installed tests version. */
      42         [ -  + ]:          1 :   if (!g_file_test (module_path, G_FILE_TEST_EXISTS))
      43                 :            :     {
      44                 :          0 :       g_free (module_path);
      45                 :          0 :       module_path = g_build_filename (PAMLIBDIR, "pam_malcontent.so", NULL);
      46                 :            :     }
      47                 :            : 
      48                 :            :   /* Check the module can be loaded. */
      49                 :          1 :   handle = dlopen (module_path, RTLD_NOW);
      50                 :          1 :   g_assert_nonnull (handle);
      51                 :            : 
      52                 :            :   /* Check the appropriate symbols exist. */
      53                 :          1 :   fn = dlsym (handle, "pam_sm_acct_mgmt");
      54                 :          1 :   g_assert_nonnull (fn);
      55                 :            : 
      56                 :          1 :   retval = dlclose (handle);
      57                 :          1 :   g_assert_cmpint (retval, ==, 0);
      58                 :          1 : }
      59                 :            : 
      60                 :            : int
      61                 :          1 : main (int    argc,
      62                 :            :       char **argv)
      63                 :            : {
      64                 :          1 :   setlocale (LC_ALL, "");
      65                 :          1 :   g_test_init (&argc, &argv, NULL);
      66                 :            : 
      67                 :          1 :   g_test_add_func ("/pam_malcontent/dlopen", test_pam_malcontent_dlopen);
      68                 :            : 
      69                 :          1 :   return g_test_run ();
      70                 :            : }

Generated by: LCOV version 1.16