Spdk/test/unit/include/spdk/histogram_data.h/histogram_ut.c
Jim Harris 488570ebd4 Replace most BSD 3-clause license text with SPDX identifier.
Many open source projects have moved to using SPDX identifiers
to specify license information, reducing the amount of
boilerplate code in every source file.  This patch replaces
the bulk of SPDK .c, .cpp and Makefiles with the BSD-3-Clause
identifier.

Almost all of these files share the exact same license text,
and this patch only modifies the files that contain the
most common license text.  There can be slight variations
because the third clause contains company names - most say
"Intel Corporation", but there are instances for Nvidia,
Samsung, Eideticom and even "the copyright holder".

Used a bash script to automate replacement of the license text
with SPDX identifier which is checked into scripts/spdx.sh.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iaa88ab5e92ea471691dc298cfe41ebfb5d169780
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12904
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Dong Yi <dongx.yi@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: <qun.wan@intel.com>
2022-06-09 07:35:12 +00:00

134 lines
2.7 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk_cunit.h"
#include "spdk/histogram_data.h"
#include "spdk/util.h"
uint64_t g_values[] = {
1,
10,
1000,
50000,
(1ULL << 63),
UINT64_MAX
};
uint64_t *g_values_end = &g_values[SPDK_COUNTOF(g_values)];
uint64_t g_total;
uint64_t g_number_of_merged_histograms;
static void
check_values(void *ctx, uint64_t start, uint64_t end, uint64_t count,
uint64_t total, uint64_t so_far)
{
uint64_t **values = ctx;
if (count == 0) {
return;
}
CU_ASSERT(so_far == (g_total + count));
/*
* The bucket for this iteration does not include end, but
* subtract one anyways to account for the last bucket
* which will have end = 0x0 (UINT64_MAX + 1).
*/
end--;
while (1) {
CU_ASSERT(**values >= start);
/*
* We subtracted one from end above, so it's OK here for
* **values to equal end.
*/
CU_ASSERT(**values <= end);
g_total += g_number_of_merged_histograms;
count -= g_number_of_merged_histograms;
(*values)++;
if (*values == g_values_end || **values > end) {
break;
}
}
CU_ASSERT(count == 0);
}
static void
histogram_test(void)
{
struct spdk_histogram_data *h;
uint64_t *values = g_values;
uint32_t i;
h = spdk_histogram_data_alloc();
for (i = 0; i < SPDK_COUNTOF(g_values); i++) {
spdk_histogram_data_tally(h, g_values[i]);
}
g_total = 0;
g_number_of_merged_histograms = 1;
spdk_histogram_data_iterate(h, check_values, &values);
spdk_histogram_data_free(h);
}
static void
histogram_merge(void)
{
struct spdk_histogram_data *h1, *h2;
uint64_t *values = g_values;
uint32_t i;
h1 = spdk_histogram_data_alloc();
h2 = spdk_histogram_data_alloc();
for (i = 0; i < SPDK_COUNTOF(g_values); i++) {
spdk_histogram_data_tally(h1, g_values[i]);
spdk_histogram_data_tally(h2, g_values[i]);
}
spdk_histogram_data_merge(h1, h2);
g_total = 0;
g_number_of_merged_histograms = 2;
spdk_histogram_data_iterate(h1, check_values, &values);
spdk_histogram_data_free(h1);
spdk_histogram_data_free(h2);
}
int
main(int argc, char **argv)
{
CU_pSuite suite = NULL;
unsigned int num_failures;
if (CU_initialize_registry() != CUE_SUCCESS) {
return CU_get_error();
}
suite = CU_add_suite("histogram", NULL, NULL);
if (suite == NULL) {
CU_cleanup_registry();
return CU_get_error();
}
if (
CU_add_test(suite, "histogram_test", histogram_test) == NULL ||
CU_add_test(suite, "histogram_merge", histogram_merge) == NULL
) {
CU_cleanup_registry();
return CU_get_error();
}
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
num_failures = CU_get_number_of_failures();
CU_cleanup_registry();
return num_failures;
}