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: 2016-12-01 18:45:36 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.11