1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/common/math.h>
7 
aws_round_up_to_power_of_two_harness()8 void aws_round_up_to_power_of_two_harness() {
9     size_t test_val;
10     size_t result;
11     int rval = aws_round_up_to_power_of_two(test_val, &result);
12 
13 #if ULONG_MAX == SIZE_MAX
14     int popcount = __builtin_popcountl(result);
15 #elif ULLONG_MAX == SIZE_MAX
16     int popcount = __builtin_popcountll(result);
17 #else
18 #    error
19 #endif
20     if (rval == AWS_OP_SUCCESS) {
21         assert(popcount == 1);
22         assert(test_val <= result);
23         assert(test_val >= result >> 1);
24     } else {
25         // Only fail if rounding up would cause us to overflow.
26         assert(test_val > ((SIZE_MAX >> 1) + 1));
27     }
28 }
29