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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2008, 2009, 2010, 2014 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 "random.h"
      20                 :            : #include <stdio.h>
      21                 :            : #include <string.h>
      22                 :            : #include "ovstest.h"
      23                 :            : 
      24                 :            : static void
      25                 :          1 : test_random_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
      26                 :            : {
      27                 :            :     enum { N_ROUNDS = 10000 };
      28                 :            :     unsigned long long int total;
      29                 :            :     int hist16[8][16];
      30                 :            :     int hist2[32];
      31                 :            :     int i;
      32                 :            : 
      33                 :          1 :     random_set_seed(1);
      34                 :            : 
      35                 :          1 :     total = 0;
      36                 :          1 :     memset(hist2, 0, sizeof hist2);
      37                 :          1 :     memset(hist16, 0, sizeof hist16);
      38         [ +  + ]:      10001 :     for (i = 0; i < N_ROUNDS; i++) {
      39                 :            :         uint32_t x;
      40                 :            :         int j;
      41                 :            : 
      42                 :      10000 :         x = random_uint32();
      43                 :            : 
      44                 :      10000 :         total += x;
      45                 :            : 
      46         [ +  + ]:     330000 :         for (j = 0; j < 32; j++) {
      47         [ +  + ]:     320000 :             if (x & (1u << j)) {
      48                 :     159931 :                 hist2[j]++;
      49                 :            :             }
      50                 :            :         }
      51                 :            : 
      52         [ +  + ]:      90000 :         for (j = 0; j < 8; j++) {
      53                 :      80000 :             hist16[j][(x >> (j * 4)) & 15]++;
      54                 :            :         }
      55                 :            :     }
      56                 :            : 
      57                 :          1 :     printf("average=%08llx\n", total / N_ROUNDS);
      58                 :            : 
      59                 :          1 :     printf("\nbit      0     1\n");
      60         [ +  + ]:         33 :     for (i = 0; i < 32; i++) {
      61                 :         32 :         printf("%3d %5d %5d\n", i, N_ROUNDS - hist2[i], hist2[i]);
      62                 :            :     }
      63                 :          1 :     printf("(expected values are %d)\n", N_ROUNDS / 2);
      64                 :            : 
      65                 :          1 :     printf("\nnibble   0   1   2   3   4   5   6   7   8   9  10  11  12  "
      66                 :            :            "13  14  15\n");
      67         [ +  + ]:          9 :     for (i = 0; i < 8; i++) {
      68                 :            :         int j;
      69                 :            : 
      70                 :          8 :         printf("%6d", i);
      71         [ +  + ]:        136 :         for (j = 0; j < 16; j++) {
      72                 :        128 :             printf(" %3d", hist16[i][j]);
      73                 :            :         }
      74                 :          8 :         printf("\n");
      75                 :            :     }
      76                 :          1 :     printf("(expected values are %d)\n", N_ROUNDS / 16);
      77                 :          1 : }
      78                 :            : 
      79                 :       1176 : OVSTEST_REGISTER("test-random", test_random_main);

Generated by: LCOV version 1.12