LCOV - code coverage report
Current view: top level - mockatests/drivers - test-tapdisk-nbdserver.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 18 100.0 %
Date: 2024-12-18 23:41:32 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2020, Citrix Systems, Inc.
       3                 :            :  *
       4                 :            :  * All rights reserved.
       5                 :            :  *
       6                 :            :  * Redistribution and use in source and binary forms, with or without
       7                 :            :  * modification, are permitted provided that the following conditions are met:
       8                 :            :  * 
       9                 :            :  *  1. Redistributions of source code must retain the above copyright
      10                 :            :  *     notice, this list of conditions and the following disclaimer.
      11                 :            :  *  2. Redistributions in binary form must reproduce the above copyright
      12                 :            :  *     notice, this list of conditions and the following disclaimer in the
      13                 :            :  *     documentation and/or other materials provided with the distribution.
      14                 :            :  *  3. Neither the name of the copyright holder nor the names of its 
      15                 :            :  *     contributors may be used to endorse or promote products derived from 
      16                 :            :  *     this software without specific prior written permission.
      17                 :            :  *
      18                 :            :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      19                 :            :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      20                 :            :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      21                 :            :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
      22                 :            :  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
      23                 :            :  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      24                 :            :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
      25                 :            :  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
      26                 :            :  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
      27                 :            :  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      28                 :            :  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      29                 :            :  */
      30                 :            : 
      31                 :            : #include <stddef.h>
      32                 :            : #include <stdarg.h>
      33                 :            : #include <setjmp.h>
      34                 :            : #include <cmocka.h>
      35                 :            : #include <stdlib.h>
      36                 :            : 
      37                 :            : #include "test-suites.h"
      38                 :            : #include "tapdisk.h"
      39                 :            : #include "tapdisk-nbdserver.h"
      40                 :            : #include "tapdisk-protocol-new.h"
      41                 :            : 
      42                 :            : void
      43                 :          1 : test_nbdserver_new_protocol_handshake(void **state)
      44                 :            : {
      45                 :            :         td_nbdserver_client_t client;
      46                 :            :         td_nbdserver_t server;
      47                 :          1 :         int new_fd =123 ;
      48                 :            : 
      49                 :          1 :         uint16_t gflags = (NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES);
      50                 :            :         struct nbd_new_handshake handshake;
      51                 :          1 :         bzero(&handshake, sizeof(handshake));
      52                 :          1 :         handshake.nbdmagic = htobe64 (NBD_MAGIC);
      53                 :          1 :         handshake.version = htobe64 (NBD_NEW_VERSION);
      54                 :          1 :         handshake.gflags = htobe16 (gflags);
      55                 :            : 
      56                 :            :         /* Check input to send */
      57                 :          1 :         expect_memory(__wrap_send, buf, &handshake, sizeof(handshake));
      58                 :          1 :         expect_value(__wrap_send, fd, new_fd);
      59                 :          1 :         expect_value(__wrap_send, size, sizeof(handshake));
      60                 :          1 :         expect_value(__wrap_send, flags, 0);
      61                 :          1 :         will_return(__wrap_send, sizeof(handshake));
      62                 :            : 
      63                 :          1 :         client.server = &server;
      64                 :            : 
      65                 :          1 :         expect_value(__wrap_tapdisk_server_register_event, cb, tapdisk_nbdserver_handshake_cb);
      66                 :          1 :         expect_value(__wrap_tapdisk_server_register_event, mode, SCHEDULER_POLL_READ_FD);
      67                 :          1 :         int err = tapdisk_nbdserver_new_protocol_handshake(&client, new_fd);
      68                 :          1 :         assert_int_equal(err, 0);
      69                 :          1 : }

Generated by: LCOV version 1.13