vppinfra: add os_get_online_cpu_core() and os_get_online_cpu_node()
[vpp.git] / src / vppinfra / random.c
index e54a3bc..56362a8 100644 (file)
@@ -37,7 +37,8 @@
 
 #include <vppinfra/random.h>
 
-/** \file Random number support
+/** \file random.c
+    Random number support
  */
 
 /** \brief Default random seed for standalone version of library.
@@ -60,23 +61,29 @@ u32 standalone_random_default_seed = 1;
  * @return    d - Pearson's X2 test statistic
  */
 
-f64
-clib_chisquare (u64 * values)
+__clib_export f64
+clib_chisquare (u64 *values)
 {
-  int i;
+  u32 i, len;
   f64 d, delta_d, actual_frequency, expected_frequency;
   u64 n_observations = 0;
 
-  ASSERT (vec_len (values));
+  len = vec_len (values);
+  /*
+   * Shut up coverity. Return a huge number which should always exceed
+   * the X2 critical value.
+   */
+  if (len == 0)
+    return (f64) 1e70;
 
-  for (i = 0; i < vec_len (values); i++)
+  for (i = 0; i < len; i++)
     n_observations += values[i];
 
-  expected_frequency = (1.0 / (f64) vec_len (values)) * (f64) n_observations;
+  expected_frequency = (1.0 / (f64) len) * (f64) n_observations;
 
   d = 0.0;
 
-  for (i = 0; i < vec_len (values); i++)
+  for (i = 0; i < len; i++)
     {
       actual_frequency = ((f64) values[i]);
       delta_d = ((actual_frequency - expected_frequency)