LCOV - code coverage report
Current view: top level - tests/gpg - t-thread-keylist.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 18 88.9 %
Date: 2018-11-15 08:49:49 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* t-thread-verify.c - Regression test.
       2             :    Copyright (C) 2015 by Bundesamt für Sicherheit in der Informationstechnik
       3             :    Software engineering by Intevation GmbH
       4             : 
       5             :    This file is part of GPGME.
       6             : 
       7             :    GPGME is free software; you can redistribute it and/or modify it
       8             :    under the terms of the GNU Lesser General Public License as
       9             :    published by the Free Software Foundation; either version 2.1 of
      10             :    the License, or (at your option) any later version.
      11             : 
      12             :    GPGME is distributed in the hope that it will be useful, but
      13             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :    Lesser General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU Lesser General Public
      18             :    License along with this program; if not, write to the Free Software
      19             :    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
      20             :    02111-1307, USA.  */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : 
      26             : #include <stdlib.h>
      27             : #include <stdio.h>
      28             : #include <string.h>
      29             : 
      30             : #include <gpgme.h>
      31             : 
      32             : #include <pthread.h>
      33             : 
      34             : #include "t-support.h"
      35             : 
      36             : #define THREAD_COUNT 10
      37             : 
      38             : void *
      39          10 : start_keylist (void *arg)
      40             : {
      41             :   gpgme_error_t err;
      42             :   gpgme_ctx_t ctx;
      43             :   gpgme_key_t key;
      44             : 
      45             :   (void) arg;
      46          10 :   err = gpgme_new (&ctx);
      47          10 :   fail_if_err (err);
      48             : 
      49          10 :   err = gpgme_op_keylist_start (ctx, NULL, 0);
      50          10 :   fail_if_err (err);
      51             : 
      52         290 :   while (!(err = gpgme_op_keylist_next (ctx, &key)))
      53             :     {
      54         270 :       gpgme_key_unref (key);
      55             :     }
      56             : 
      57          10 :   gpgme_release (ctx);
      58             : 
      59          10 :   return NULL;
      60             : }
      61             : 
      62             : int
      63           1 : main (int argc, char *argv[])
      64             : {
      65             :   int i;
      66             :   pthread_t keylist_threads[THREAD_COUNT];
      67           1 :   init_gpgme (GPGME_PROTOCOL_OpenPGP);
      68             : 
      69             :   (void)argc;
      70             :   (void)argv;
      71             : 
      72          11 :   for (i = 0; i < THREAD_COUNT; i++)
      73             :     {
      74          10 :       if (pthread_create(&keylist_threads[i], NULL, start_keylist, NULL))
      75             :         {
      76           0 :           fprintf(stderr, "%s:%i: failed to create threads \n",
      77             :                        __FILE__, __LINE__);
      78           0 :           exit(1);
      79             :         }
      80             :    }
      81          11 :   for (i = 0; i < THREAD_COUNT; i++)
      82             :     {
      83          10 :       pthread_join (keylist_threads[i], NULL);
      84             :     }
      85           1 :   return 0;
      86             : }

Generated by: LCOV version 1.13