2017-11-16 00:40:27 +08:00
|
|
|
// RUN: %clang_scudo %s -o %t
|
|
|
|
// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-nolimit
|
2019-01-24 23:56:54 +08:00
|
|
|
// 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
|
2017-11-16 00:40:27 +08:00
|
|
|
|
|
|
|
// 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>
|
|
|
|
|
2019-01-24 23:56:54 +08:00
|
|
|
static const size_t kNumAllocs = 64;
|
2017-11-16 00:40:27 +08:00
|
|
|
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++) {
|
[scudo] Delay allocations in the RSS check test
Summary:
D57116 fails on the armv7 bots, which is I assume due to the timing of
the RSS check on the platform. While I don't have a platform to test
that change on, I assume this would do.
The test could be made more reliable by either delaying more the
allocations, or allocating more large-chunks, but both those options
have a somewhat non negligible impact (more memory used, longer test).
Hence me trying to keep the additional sleeping/allocating to a
minimum.
Reviewers: eugenis, yroux
Reviewed By: yroux
Subscribers: javed.absar, kristof.beyls, delcypher, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D57241
llvm-svn: 352220
2019-01-26 01:23:29 +08:00
|
|
|
// sleep for 100ms every 8 allocations, to allow the RSS check to catch up.
|
|
|
|
if (i != 0 && (i & 0x7) == 0)
|
2019-01-24 23:56:54 +08:00
|
|
|
usleep(100000);
|
2017-11-16 00:40:27 +08:00
|
|
|
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
|