LCOV - code coverage report
Current view: top level - tests - test-byte-order.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 21 100.0 %
Date: 2016-09-14 01:02:56 Functions: 3 3 100.0 %
Branches: 15 30 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2010, 2011 Nicira, Inc.
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :            :  * you may not use this file except in compliance with the License.
       6                 :            :  * You may obtain a copy of the License at:
       7                 :            :  *
       8                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :            :  *
      10                 :            :  * Unless required by applicable law or agreed to in writing, software
      11                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :            :  * See the License for the specific language governing permissions and
      14                 :            :  * limitations under the License.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <config.h>
      18                 :            : #undef NDEBUG
      19                 :            : #include "byte-order.h"
      20                 :            : #include <assert.h>
      21                 :            : #include <inttypes.h>
      22                 :            : #include "ovstest.h"
      23                 :            : 
      24                 :            : static void
      25                 :          1 : test_byte_order_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
      26                 :            : {
      27                 :            : #ifndef __CHECKER__
      28                 :            :     /* I picked some random numbers. */
      29                 :          1 :     const uint16_t s = 0xc9bd;
      30                 :          1 :     const uint32_t l = 0xffe56ae8;
      31                 :          1 :     const uint64_t ll = UINT64_C(0xb6fe878a9117ecdb);
      32                 :            : 
      33         [ -  + ]:          1 :     assert(htons(ntohs(s)) == s);
      34         [ -  + ]:          1 :     assert(ntohs(htons(s)) == s);
      35         [ -  + ]:          1 :     assert(CONSTANT_HTONS(ntohs(s)) == s);
      36         [ -  + ]:          1 :     assert(ntohs(CONSTANT_HTONS(s)) == s);
      37         [ -  + ]:          1 :     assert(ntohs(CONSTANT_HTONS(l)) == (uint16_t) l);
      38         [ -  + ]:          1 :     assert(ntohs(CONSTANT_HTONS(ll)) == (uint16_t) ll);
      39                 :            : 
      40         [ -  + ]:          1 :     assert(htonl(ntohl(l)) == l);
      41         [ -  + ]:          1 :     assert(ntohl(htonl(l)) == l);
      42         [ -  + ]:          1 :     assert(CONSTANT_HTONL(ntohl(l)) == l);
      43         [ -  + ]:          1 :     assert(ntohl(CONSTANT_HTONL(l)) == l);
      44         [ -  + ]:          1 :     assert(ntohl(CONSTANT_HTONL(ll)) == (uint32_t) ll);
      45                 :            : 
      46         [ -  + ]:          1 :     assert(htonll(ntohll(ll)) == ll);
      47         [ -  + ]:          1 :     assert(ntohll(htonll(ll)) == ll);
      48         [ -  + ]:          1 :     assert(CONSTANT_HTONLL(ntohll(ll)) == ll);
      49         [ -  + ]:          1 :     assert(ntohll(CONSTANT_HTONLL(ll)));
      50                 :            : #else  /* __CHECKER__ */
      51                 :            : /* Making sparse happy with this code makes it unreadable, so don't bother. */
      52                 :            : #endif
      53                 :          1 : }
      54                 :            : 
      55                 :       1176 : OVSTEST_REGISTER("test-byte-order", test_byte_order_main);

Generated by: LCOV version 1.12