Skip to content

Commit 117f4ec

Browse files
committed
Process: test exec(3) = E2BIG handling
1 parent 12e1d5d commit 117f4ec

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(base_test_SOURCES
1414
base-netstring.cpp
1515
base-object.cpp
1616
base-object-packer.cpp
17+
base-process.cpp
1718
base-serialize.cpp
1819
base-shellescape.cpp
1920
base-stacktrace.cpp
@@ -87,6 +88,7 @@ add_boost_test(base
8788
base_netstring/netstring
8889
base_object/construct
8990
base_object/getself
91+
base_process/e2big
9092
base_serialize/scalar
9193
base_serialize/array
9294
base_serialize/dictionary

test/base-process.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Icinga 2 | (c) 2023 Icinga GmbH | GPLv2+ */
2+
3+
#include "base/process.hpp"
4+
#include <BoostTestTargetConfig.h>
5+
6+
using namespace icinga;
7+
8+
BOOST_AUTO_TEST_SUITE(base_process)
9+
10+
BOOST_AUTO_TEST_CASE(e2big)
11+
{
12+
#ifndef _WIN32
13+
String placeHolder = "x";
14+
15+
for (int i = 0; i < 23; ++i) {
16+
placeHolder += placeHolder; // 2^23 = 8388608 > ARG_MAX
17+
}
18+
19+
Process::Ptr p = new Process(
20+
{"echo", "truncated_" + placeHolder + "Y", "untouched"},
21+
nullptr,
22+
{"_" + placeHolder + "Y"}
23+
);
24+
25+
p->SetTimeout(60 * 60);
26+
p->Run();
27+
28+
auto& out (p->WaitForResult().Output);
29+
30+
BOOST_CHECK(out.Contains("truncated"));
31+
BOOST_CHECK(out.Contains("x untouched"));
32+
#endif /* _WIN32 */
33+
}
34+
35+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)