LCOV - code coverage report
Current view: top level - source3/torture - test_pthreadpool_tevent.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 26 36 72.2 %
Date: 2024-04-21 15:09:00 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * Test pthreadpool_tevent
       4             :  * Copyright (C) Volker Lendecke 2016
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "includes.h"
      21             : #include "system/select.h"
      22             : #include "proto.h"
      23             : #include "lib/pthreadpool/pthreadpool_tevent.h"
      24             : 
      25             : static void job_fn(void *private_data);
      26             : 
      27           1 : bool run_pthreadpool_tevent(int dummy)
      28             : {
      29           1 :         struct tevent_context *ev;
      30           1 :         struct pthreadpool_tevent *pool;
      31           1 :         struct tevent_req *req;
      32           1 :         int ret, val;
      33           1 :         bool ok;
      34             : 
      35           1 :         ev = tevent_context_init_byname(NULL, "poll");
      36           1 :         if (ev == NULL) {
      37           0 :                 fprintf(stderr, "tevent_context_init failed\n");
      38           0 :                 return false;
      39             :         }
      40             : 
      41           1 :         ret = pthreadpool_tevent_init(ev, 100, &pool);
      42           1 :         if (ret != 0) {
      43           0 :                 fprintf(stderr, "pthreadpool_tevent_init failed: %s\n",
      44             :                         strerror(ret));
      45           0 :                 return false;
      46             :         }
      47             : 
      48           1 :         val = -1;
      49             : 
      50           1 :         req = pthreadpool_tevent_job_send(ev, ev, pool, job_fn, &val);
      51           1 :         if (req == NULL) {
      52           0 :                 fprintf(stderr, "pthreadpool_tevent_job_send failed\n");
      53           0 :                 return false;
      54             :         }
      55             : 
      56           1 :         ok = tevent_req_poll(req, ev);
      57           1 :         if (!ok) {
      58           0 :                 fprintf(stderr, "tevent_req_poll failed\n");
      59           0 :                 return false;
      60             :         }
      61             : 
      62           1 :         ret = pthreadpool_tevent_job_recv(req);
      63           1 :         if (ret != 0) {
      64           0 :                 fprintf(stderr, "pthreadpool_tevent_job failed: %s\n",
      65             :                         strerror(ret));
      66           0 :                 return false;
      67             :         }
      68             : 
      69           1 :         printf("%d\n", val);
      70             : 
      71           1 :         TALLOC_FREE(pool);
      72           1 :         TALLOC_FREE(ev);
      73           1 :         return true;
      74             : }
      75             : 
      76           1 : static void job_fn(void *private_data)
      77             : {
      78           1 :         int *pret = private_data;
      79           1 :         *pret = 4711;
      80             : 
      81           1 :         poll(NULL, 0, 100);
      82           1 : }

Generated by: LCOV version 1.14