Fix <sys/resource.h>.
The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.
We need the rlimit64 functions to be able to build strace 4.8 out of the box.
Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
2014-01-09 19:17:03 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/resource.h>
|
|
|
|
|
2015-01-05 20:06:30 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
TEST(sys_resource, rlimit_struct_size) {
|
2014-05-13 20:19:57 +02:00
|
|
|
#if defined(__LP64__) || defined(__GLIBC__)
|
Fix <sys/resource.h>.
The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.
We need the rlimit64 functions to be able to build strace 4.8 out of the box.
Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
2014-01-09 19:17:03 +01:00
|
|
|
ASSERT_EQ(sizeof(rlimit), sizeof(rlimit64));
|
|
|
|
ASSERT_EQ(8U, sizeof(rlim_t));
|
|
|
|
#else
|
|
|
|
ASSERT_NE(sizeof(rlimit), sizeof(rlimit64));
|
|
|
|
ASSERT_EQ(4U, sizeof(rlim_t));
|
|
|
|
#endif
|
2015-01-05 20:06:30 +01:00
|
|
|
}
|
Fix <sys/resource.h>.
The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.
We need the rlimit64 functions to be able to build strace 4.8 out of the box.
Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
2014-01-09 19:17:03 +01:00
|
|
|
|
2015-01-05 20:06:30 +01:00
|
|
|
class SysResourceTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
virtual void SetUp() {
|
|
|
|
ASSERT_EQ(0, getrlimit(RLIMIT_CORE, &l32_));
|
|
|
|
ASSERT_EQ(0, getrlimit64(RLIMIT_CORE, &l64_));
|
2015-10-29 01:14:48 +01:00
|
|
|
ASSERT_EQ(0, prlimit(0, RLIMIT_CORE, nullptr, &pr_l32_));
|
|
|
|
ASSERT_EQ(0, prlimit64(0, RLIMIT_CORE, nullptr, &pr_l64_));
|
2015-01-05 20:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckResourceLimits();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
rlimit l32_;
|
|
|
|
rlimit64 l64_;
|
2015-10-29 01:14:48 +01:00
|
|
|
rlimit pr_l32_;
|
2015-01-05 20:06:30 +01:00
|
|
|
rlimit64 pr_l64_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SysResourceTest::CheckResourceLimits() {
|
|
|
|
ASSERT_EQ(0, getrlimit(RLIMIT_CORE, &l32_));
|
|
|
|
ASSERT_EQ(0, getrlimit64(RLIMIT_CORE, &l64_));
|
2015-10-29 01:14:48 +01:00
|
|
|
ASSERT_EQ(0, prlimit(0, RLIMIT_CORE, nullptr, &pr_l32_));
|
|
|
|
ASSERT_EQ(0, prlimit64(0, RLIMIT_CORE, nullptr, &pr_l64_));
|
|
|
|
|
|
|
|
ASSERT_EQ(l32_.rlim_cur, pr_l32_.rlim_cur);
|
2015-01-05 20:06:30 +01:00
|
|
|
ASSERT_EQ(l64_.rlim_cur, pr_l64_.rlim_cur);
|
2015-10-29 01:14:48 +01:00
|
|
|
|
2015-01-05 20:06:30 +01:00
|
|
|
if (l64_.rlim_cur == RLIM64_INFINITY) {
|
|
|
|
ASSERT_EQ(RLIM_INFINITY, l32_.rlim_cur);
|
Fix <sys/resource.h>.
The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.
We need the rlimit64 functions to be able to build strace 4.8 out of the box.
Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
2014-01-09 19:17:03 +01:00
|
|
|
} else {
|
2015-01-05 20:06:30 +01:00
|
|
|
ASSERT_EQ(l64_.rlim_cur, l32_.rlim_cur);
|
Fix <sys/resource.h>.
The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.
We need the rlimit64 functions to be able to build strace 4.8 out of the box.
Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
2014-01-09 19:17:03 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 01:14:48 +01:00
|
|
|
ASSERT_EQ(l32_.rlim_max, pr_l32_.rlim_max);
|
2015-01-05 20:06:30 +01:00
|
|
|
ASSERT_EQ(l64_.rlim_max, pr_l64_.rlim_max);
|
2015-10-29 01:14:48 +01:00
|
|
|
|
2015-01-05 20:06:30 +01:00
|
|
|
if (l64_.rlim_max == RLIM64_INFINITY) {
|
|
|
|
ASSERT_EQ(RLIM_INFINITY, l32_.rlim_max);
|
|
|
|
} else {
|
|
|
|
ASSERT_EQ(l64_.rlim_max, l32_.rlim_max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force rlim_max to be bigger than a constant so we can continue following test.
|
|
|
|
// Change resource limit setting with "ulimit -Hc" in the shell if this test fails.
|
|
|
|
TEST_F(SysResourceTest, RLIMIT_CORE_rlim_max_not_zero) {
|
|
|
|
ASSERT_TRUE(l32_.rlim_max == RLIM_INFINITY || l32_.rlim_max >= 456U) <<
|
|
|
|
"RLIMIT_CORE rlim_max = " << l32_.rlim_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SysResourceTest, get_resource_limit_equal) {
|
|
|
|
CheckResourceLimits();
|
|
|
|
}
|
Fix <sys/resource.h>.
The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.
We need the rlimit64 functions to be able to build strace 4.8 out of the box.
Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
2014-01-09 19:17:03 +01:00
|
|
|
|
2015-01-05 20:06:30 +01:00
|
|
|
TEST_F(SysResourceTest, setrlimit) {
|
|
|
|
l32_.rlim_cur = 123U;
|
|
|
|
ASSERT_EQ(0, setrlimit(RLIMIT_CORE, &l32_));
|
|
|
|
CheckResourceLimits();
|
|
|
|
ASSERT_EQ(123U, l32_.rlim_cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SysResourceTest, setrlimit64) {
|
|
|
|
l64_.rlim_cur = 456U;
|
|
|
|
ASSERT_EQ(0, setrlimit64(RLIMIT_CORE, &l64_));
|
|
|
|
CheckResourceLimits();
|
|
|
|
ASSERT_EQ(456U, l64_.rlim_cur);
|
|
|
|
}
|
|
|
|
|
2015-10-29 01:14:48 +01:00
|
|
|
TEST_F(SysResourceTest, prlimit) {
|
|
|
|
pr_l32_.rlim_cur = pr_l32_.rlim_max;
|
|
|
|
ASSERT_EQ(0, prlimit(0, RLIMIT_CORE, &pr_l32_, nullptr));
|
|
|
|
CheckResourceLimits();
|
|
|
|
ASSERT_EQ(pr_l32_.rlim_max, pr_l32_.rlim_cur);
|
|
|
|
}
|
|
|
|
|
2015-01-05 20:06:30 +01:00
|
|
|
TEST_F(SysResourceTest, prlimit64) {
|
|
|
|
pr_l64_.rlim_cur = pr_l64_.rlim_max;
|
2015-10-29 01:14:48 +01:00
|
|
|
ASSERT_EQ(0, prlimit64(0, RLIMIT_CORE, &pr_l64_, nullptr));
|
2015-01-05 20:06:30 +01:00
|
|
|
CheckResourceLimits();
|
|
|
|
ASSERT_EQ(pr_l64_.rlim_max, pr_l64_.rlim_cur);
|
|
|
|
}
|