Debian Codegraph @

crt/s2n/tests/unit/s2n_connection_size_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include "s2n_test.h"
17 #include "tls/s2n_connection.h"
18
19 bool is_32_bit_platform()
20 {
21 return (sizeof(void *) == 4);
22 }
23
24 /* Test s2n_connection does not grow too much.
25 * s2n_connection is a very large structure. We should be working to reduce its
26 * size, not increasing it.
27 * This test documents changes to its size for reviewers so that we can
28 * make very deliberate choices about increasing memory usage.
29 *
30 * We can't easily enforce an exact size for s2n_connection because it varies
31 * based on some settings (like how many KEM groups are supported).
32 */
33 int main(int argc, char **argv)
34 {
35 BEGIN_TEST();
36
37 /* We don't run this test on 32 bit platforms. The goal of this test is
38 * accomplished as long as it is running on any platform in our CI, and
39 * just running it on a single platform keeps us from having to maintain
40 * multiple static constants.
41 */
42 if (is_32_bit_platform()) {
43 END_TEST();
44 }
45
46 /* Carefully consider any increases to this number. */
47 const uint16_t max_connection_size = 4443;
48 const uint16_t min_connection_size = max_connection_size * 0.9;
49
50 size_t connection_size = sizeof(struct s2n_connection);
51
52 if (connection_size > max_connection_size || connection_size < min_connection_size) {
53 const char message[] = "s2n_connection size (%zu) no longer in (%i, %i). "
54 "Please verify that this change was intentional and then update this test.";
55 char message_buffer[sizeof(message) + 100] = { 0 };
56 int r = snprintf(message_buffer, sizeof(message_buffer), message,
57 connection_size, min_connection_size, max_connection_size);
58 EXPECT_TRUE(r < sizeof(message_buffer));
59 FAIL_MSG(message_buffer);
60 }
61
62 END_TEST();
63 }