elf_core_dump_unittest: skip test if setrlimit will fail
Some systems have constrained rlimits for core files (the CrOS chroot is an example of this). Fail gracefully in this case, rather than breaking the user's tests. Bug: b:235999011 Change-Id: I5649b42d3e6fd9b4f9b11e1fd9d0d4a1083d300f Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3722724 Reviewed-by: Mark Mentovai <mark@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
ad8a43f367
commit
a8e8a69591
3 changed files with 20 additions and 3 deletions
|
@ -130,9 +130,13 @@ TEST(ElfCoreDumpTest, TestElfHeader) {
|
||||||
TEST(ElfCoreDumpTest, ValidCoreFile) {
|
TEST(ElfCoreDumpTest, ValidCoreFile) {
|
||||||
CrashGenerator crash_generator;
|
CrashGenerator crash_generator;
|
||||||
if (!crash_generator.HasDefaultCorePattern()) {
|
if (!crash_generator.HasDefaultCorePattern()) {
|
||||||
fprintf(stderr, "ElfCoreDumpTest.ValidCoreFile test is skipped "
|
GTEST_SKIP() << "ElfCoreDumpTest.ValidCoreFile test is skipped "
|
||||||
"due to non-default core pattern");
|
"due to non-default core pattern";
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
if (!crash_generator.HasResourceLimitsAmenableToCrashCollection()) {
|
||||||
|
GTEST_SKIP() << "ElfCoreDumpTest.ValidCoreFile test is skipped "
|
||||||
|
"due to inadequate system resource limits";
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned kNumOfThreads = 3;
|
const unsigned kNumOfThreads = 3;
|
||||||
|
|
|
@ -169,6 +169,15 @@ bool CrashGenerator::SetCoreFileSizeLimit(rlim_t limit) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CrashGenerator::HasResourceLimitsAmenableToCrashCollection() const {
|
||||||
|
struct rlimit limits;
|
||||||
|
if (getrlimit(RLIMIT_CORE, &limits) == -1) {
|
||||||
|
perror("CrashGenerator: Failed to get core file size limit");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return limits.rlim_max >= kCoreSizeLimit;
|
||||||
|
}
|
||||||
|
|
||||||
bool CrashGenerator::CreateChildCrash(
|
bool CrashGenerator::CreateChildCrash(
|
||||||
unsigned num_threads, unsigned crash_thread, int crash_signal,
|
unsigned num_threads, unsigned crash_thread, int crash_signal,
|
||||||
pid_t* child_pid) {
|
pid_t* child_pid) {
|
||||||
|
|
|
@ -65,6 +65,10 @@ class CrashGenerator {
|
||||||
// Returns the directory of a copy of proc files of the child process.
|
// Returns the directory of a copy of proc files of the child process.
|
||||||
string GetDirectoryOfProcFilesCopy() const;
|
string GetDirectoryOfProcFilesCopy() const;
|
||||||
|
|
||||||
|
// Returns whether current resource limits would prevent `CreateChildCrash`
|
||||||
|
// from operating.
|
||||||
|
bool HasResourceLimitsAmenableToCrashCollection() const;
|
||||||
|
|
||||||
// Creates a crash (and a core dump file) by creating a child process with
|
// Creates a crash (and a core dump file) by creating a child process with
|
||||||
// |num_threads| threads, and the terminating the child process by sending
|
// |num_threads| threads, and the terminating the child process by sending
|
||||||
// a signal with number |crash_signal| to the |crash_thread|-th thread.
|
// a signal with number |crash_signal| to the |crash_thread|-th thread.
|
||||||
|
|
Loading…
Reference in a new issue