1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <fwk_assert.h>
9 #include <fwk_macros.h>
10 #include <fwk_test.h>
11 
12 static void test_fwk_macros_array_size(void);
13 static void test_fwk_macros_align_next(void);
14 static void test_fwk_macros_align_previous(void);
15 
16 static const struct fwk_test_case_desc test_case_table[] = {
17     FWK_TEST_CASE(test_fwk_macros_array_size),
18     FWK_TEST_CASE(test_fwk_macros_align_next),
19     FWK_TEST_CASE(test_fwk_macros_align_previous)
20 };
21 
22 struct fwk_test_suite_desc test_suite = {
23     .name = "fwk_macros",
24     .test_case_count = FWK_ARRAY_SIZE(test_case_table),
25     .test_case_table = test_case_table,
26 };
27 
test_fwk_macros_array_size(void)28 static void test_fwk_macros_array_size(void)
29 {
30     unsigned int element_no;
31     unsigned int array_uint[5];
32     char array_char[3];
33 
34     element_no = FWK_ARRAY_SIZE(array_uint);
35     assert(element_no == 5);
36 
37     element_no = FWK_ARRAY_SIZE(array_char);
38     assert(element_no == 3);
39 }
40 
test_fwk_macros_align_next(void)41 static void test_fwk_macros_align_next(void)
42 {
43     unsigned int value;
44     unsigned int interval;
45     unsigned int result;
46 
47     value = 0;
48     interval = 32;
49 
50     /* Precedence test */
51     result = FWK_ALIGN_NEXT(value | 1, interval + 32);
52     assert(result == 64);
53 
54     value = 0;
55     interval = 32;
56     result = FWK_ALIGN_NEXT(value, interval);
57     assert(result == 0);
58 
59     value = 8;
60     interval = 8;
61     result = FWK_ALIGN_NEXT(value, interval);
62     assert(result == 8);
63 
64     value = 9;
65     interval = 8;
66     result = FWK_ALIGN_NEXT(value, interval);
67     assert(result == 16);
68 }
69 
test_fwk_macros_align_previous(void)70 static void test_fwk_macros_align_previous(void)
71 {
72     unsigned int value;
73     unsigned int interval;
74     unsigned int result;
75 
76     value = 65;
77     interval = 32;
78 
79     /* Precedence test */
80     result = FWK_ALIGN_PREVIOUS(value & 1, interval + 32);
81     assert(result == 0);
82 
83     value = 0;
84     interval = 32;
85     result = FWK_ALIGN_PREVIOUS(value, interval);
86     assert(result == 0);
87 
88     value = 8;
89     interval = 8;
90     result = FWK_ALIGN_PREVIOUS(value, interval);
91     assert(result == 8);
92 
93     value = 9;
94     interval = 8;
95     result = FWK_ALIGN_PREVIOUS(value, interval);
96     assert(result == 8);
97 }
98