Debian Codegraph @

crt/aws-c-common/tests/system_resource_util_test.c

raw symbols SCIP
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/byte_buf.h>
7 #include <aws/common/device_random.h>
8 #include <aws/common/system_resource_util.h>
9
10 #include <aws/testing/aws_test_harness.h>
11
12 static int s_test_memory_usage_maxrss(struct aws_allocator *allocator, void *ctx) {
13 (void)ctx;
14
15 /*
16 * Note: mem usage apis currently rely on getrusage on posix systems.
17 * On freebsd maxrss seems to return current process rss based on testing,
18 * while on every other posix platform maxrss is high water mark for rss
19 * over the program lifetime.
20 * Workaround it by allocating a buffer first. Long term using procfs should
21 * avoid the issue.
22 */
23 struct aws_byte_buf temp;
24 aws_byte_buf_init(&temp, allocator, 8 * 1024 * 1024);
25 ASSERT_SUCCESS(aws_device_random_buffer(&temp));
26
27 struct aws_memory_usage_stats mu;
28 ASSERT_SUCCESS(aws_init_memory_usage_for_current_process(&mu));
29
30 ASSERT_TRUE(mu.maxrss > 0);
31
32 aws_byte_buf_clean_up_secure(&temp);
33
34 return 0;
35 }
36
37 AWS_TEST_CASE(test_memory_usage_maxrss, s_test_memory_usage_maxrss)