xref: /spdk/test/unit/lib/util/math.c/math_ut.c (revision fecffda6ecf8853b82edccde429b68252f0a62c5)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2020 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "spdk/stdinc.h"
7 
8 #include "spdk_cunit.h"
9 
10 #include "util/math.c"
11 
12 static void
13 test_serial_number_arithmetic(void)
14 {
15 	CU_ASSERT(spdk_sn32_add(0, 1) == 1);
16 	CU_ASSERT(spdk_sn32_add(1, 1) == 2);
17 	CU_ASSERT(spdk_sn32_add(1, 2) == 3);
18 	CU_ASSERT(spdk_sn32_add(1, UINT32_MAX) == 0);
19 	CU_ASSERT(spdk_sn32_add(UINT32_MAX, UINT32_MAX) == UINT32_MAX - 1);
20 	CU_ASSERT(spdk_sn32_gt(1, 0) == true);
21 	CU_ASSERT(spdk_sn32_gt(2, 1) == true);
22 	CU_ASSERT(spdk_sn32_gt(UINT32_MAX, UINT32_MAX - 1) == true);
23 	CU_ASSERT(spdk_sn32_gt(0, UINT32_MAX) == true);
24 	CU_ASSERT(spdk_sn32_gt(100, UINT32_MAX - 100) == true);
25 	CU_ASSERT(spdk_sn32_lt(1, 0) == false);
26 	CU_ASSERT(spdk_sn32_lt(2, 1) == false);
27 	CU_ASSERT(spdk_sn32_lt(UINT32_MAX, UINT32_MAX - 1) == false);
28 	CU_ASSERT(spdk_sn32_lt(0, UINT32_MAX) == false);
29 	CU_ASSERT(spdk_sn32_lt(100, UINT32_MAX - 100) == false);
30 }
31 
32 int
33 main(int argc, char **argv)
34 {
35 	CU_pSuite	suite = NULL;
36 	unsigned int	num_failures;
37 
38 	CU_set_error_action(CUEA_ABORT);
39 	CU_initialize_registry();
40 
41 	suite = CU_add_suite("math", NULL, NULL);
42 
43 	CU_ADD_TEST(suite, test_serial_number_arithmetic);
44 
45 	CU_basic_set_mode(CU_BRM_VERBOSE);
46 
47 	CU_basic_run_tests();
48 
49 	num_failures = CU_get_number_of_failures();
50 	CU_cleanup_registry();
51 
52 	return num_failures;
53 }
54