CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
58 lines
3.2 KiB
C
58 lines
3.2 KiB
C
// RUN: %clang_scudo %s -o %t
|
|
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
|
|
// RUN: %env_scudo_opts="soft_rss_limit_mb=128" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
|
|
// RUN: %env_scudo_opts="hard_rss_limit_mb=128" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
|
|
// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
|
|
// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=1" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
|
|
// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit
|
|
// RUN: %env_scudo_opts="soft_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-softlimit-returnnull
|
|
// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
|
|
// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=1" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
|
|
// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
|
|
// RUN: %env_scudo_opts="hard_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-hardlimit
|
|
|
|
// Tests that the soft and hard RSS limits work as intended. Without limit or
|
|
// with a high limit, the test should pass without any malloc returning NULL or
|
|
// the program dying.
|
|
// If a limit is specified, it should return some NULL or die depending on
|
|
// allocator_may_return_null. This should also work without statm.
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
static const size_t kNumAllocs = 64;
|
|
static const size_t kAllocSize = 1 << 20; // 1MB.
|
|
|
|
static void *allocs[kNumAllocs];
|
|
|
|
int main(int argc, char *argv[]) {
|
|
int returned_null = 0;
|
|
for (int i = 0; i < kNumAllocs; i++) {
|
|
// sleep for 100ms every 8 allocations, to allow the RSS check to catch up.
|
|
if (i != 0 && (i & 0x7) == 0)
|
|
usleep(100000);
|
|
allocs[i] = malloc(kAllocSize);
|
|
if (allocs[i])
|
|
memset(allocs[i], 0xff, kAllocSize); // Dirty the pages.
|
|
else
|
|
returned_null++;
|
|
}
|
|
for (int i = 0; i < kNumAllocs; i++)
|
|
free(allocs[i]);
|
|
if (returned_null == 0)
|
|
printf("All malloc calls succeeded\n");
|
|
else
|
|
printf("%d malloc calls returned NULL\n", returned_null);
|
|
return 0;
|
|
}
|
|
|
|
// CHECK-nolimit: All malloc calls succeeded
|
|
// CHECK-softlimit: soft RSS limit exhausted
|
|
// CHECK-softlimit-NOT: malloc calls
|
|
// CHECK-softlimit-returnnull: soft RSS limit exhausted
|
|
// CHECK-softlimit-returnnull: malloc calls returned NULL
|
|
// CHECK-hardlimit: hard RSS limit exhausted
|
|
// CHECK-hardlimit-NOT: malloc calls
|