Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Mar 2024 10:59:21 +0800
From:      Kristof Provost <kp@FreeBSD.org>
To:        Igor Ostapenko <igor.ostapenko@pm.me>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Add jail execution environment support to the FreeBSD test suite
Message-ID:  <B7E897BE-3DA2-4B95-9011-929E833B1A0B@FreeBSD.org>
In-Reply-To: <BIsilmF1Kw7IA2Hn-S6XjAriQbMZf3VGECDEvbMD5tFgYIeyFvjLL-rEJyo-klhhSaqx9V9Hn2uZWLklKjbxC9MaM9jhlgwa4lQUfS3SGPY=@pm.me>
References:  <2bjQNp1msrv-_AqyamMun6kY-SCqbgPm3Q7DqVQHAYlqvFkiE1i85svfIT-QQdUG1cg3cKippyTyv8Z-5nbLu4WaMutgZQ7KT-YYo_5Pbro=@pm.me> <BIsilmF1Kw7IA2Hn-S6XjAriQbMZf3VGECDEvbMD5tFgYIeyFvjLL-rEJyo-klhhSaqx9V9Hn2uZWLklKjbxC9MaM9jhlgwa4lQUfS3SGPY=@pm.me>

next in thread | previous in thread | raw e-mail | index | archive | help

--=_MailMate_F71C8465-E854-4AF9-9342-2B9110ED52D5_=
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

<Picking this mail to resurrect the thread>

I’ve been toying with this patch. Adding only the following patch I 
can get Kyua to run the pf tests in parallel:

	diff --git a/tests/sys/netpfil/pf/Makefile 
b/tests/sys/netpfil/pf/Makefile
	index 867b98e5f6c2..c2f0f15fa798 100644
	--- a/tests/sys/netpfil/pf/Makefile
	+++ b/tests/sys/netpfil/pf/Makefile
	@@ -51,8 +51,8 @@ ATF_TESTS_PYTEST+=    frag6.py
	 ATF_TESTS_PYTEST+=     nat66.py
	 ATF_TESTS_PYTEST+=     sctp.py

	-# Tests reuse jail names and so cannot run in parallel.
	-TEST_METADATA+=        is_exclusive=true
	+TEST_METADATA+= execenv="jail"
	+TEST_METADATA+= execenv_jail="vnet allow.raw_sockets"

	 PROGS= divapp


That gets the test time, with parallelism=5, down from 22 minutes to 
5m40s.
So I’m rather keen to see this work land.

My read from the reactions here is that people are generally okay with 
the approach, especially (I assume) given that the current version lets 
us turn this on on a per-test basis.

Is there anything else anyone wants to raise before we land this?

Best regards,
Kristof

On 28 Feb 2024, at 2:32, Igor Ostapenko wrote:
> Hi,
>
> The patch was updated after the recent discussion.
>
> Currently, the patch provides the following new functionality, from 
> bottom to
> top:
>
> 1 ATF based tests
>
> - The new "execenv" metadata property can be set to explicitly ask for 
> an
>   execution environment: "host" or "jail". If it's not defined, as all
>   existing tests do, then it implicitly means "host".
>
> - The new "execenv.jail" metadata property can be optionally defined 
> to ask
>   Kyua to use specific jail(8) parameters during creation of a 
> temporary
>   jail. An example is "vnet allow.raw_sockets".
>
>
> 2 Kyuafile
>
> - The same new metadata properties can be defined on Kyuafile level:
>   "execenv" and "execenv_jail".
>
> - Note that historically ATF uses dotted style of metadata naming, 
> while
>   Kyua uses underscore style. Hence "execenv.jail" vs. "execenv_jail".
>
>
> 3 kyua.conf, kyua CLI
>
> - The new "execenv" engine configuration variable can be set to a list 
> of
>   execution environments to run only tests designed for. Tests of not 
> listed
>   environments are skipped.
>
> - By default, this variable lists all execution environments supported 
> by a
>   Kyua binary, e.g. execenv="host jail".
>
> - This variable can be changed via "kyua.conf" or via kyua CLI's "-v"
>   parameter. For example, "kyua -v execenv=host test" will run only
>   host-based tests and skip jail-based ones.
>
> - Current value of this variable can be examined with "kyua config".
>
>
> The patch is https://reviews.freebsd.org/D42350.
>
> Any help with review and testing is welcome. Its test plan covers the
> details and refers to the demo patch of how existing tests could be
> converted to be run in a jail.
>
>
> Best regards, Igor.
>
>
> On Thursday, February 22nd, 2024 at 10:57 PM, igor.ostapenko@pm.me 
> <igor.ostapenko@pm.me> wrote:
>>
>>
>> Hi FreeBSD developers,
>>
>> There is a proposal to improve the FreeBSD test suite.
>>
>>
>> 1 The Problem
>>
>> The FreeBSD test suite is based on the Kyua framework. The latter 
>> supports
>> running tests in parallel. However, some tests cannot be run in 
>> parallel and
>> are marked with is_exclusive="true" metadata, which makes Kyua run 
>> such tests
>> in sequence.
>>
>> Many tests are not meant to be exclusive conceptually, they are so 
>> for very
>> simple technical reasons. For instance, some network related tests 
>> are based
>> on jail and vnet usage. It's convenient for such tests and it 
>> provides a lot
>> of isolation already not to conflict with other tests. But they are 
>> still
>> marked as exclusive due to the shared space of jail names, routing, 
>> etc.
>>
>> The project seeks more tests, and it's kind of a trend for new tests 
>> like
>> jail/vnet based ones to be created as is_exclusive="true" from the 
>> very
>> beginning. It only piles up the suite with exclusive tests, e.g. new 
>> tests
>> from my side faced a fair question from a reviewer whether they could 
>> be
>> re-designed for a parallel run. [1]
>>
>> If such tests were 100% isolated they would be able to run in 
>> parallel and
>> decrease the test time for CI runs and for the runs within the 
>> development
>> process.
>>
>> And the problem is that trying to add more isolation by a test itself 
>> looks to
>> be a doable task from a glance, but it would add a lot of complexity 
>> to a test
>> code, or could be found as an impossible task in a specific case.
>>
>>
>> 2 The Idea
>>
>> The idea is not new. A test could be running in a jail -- it provides 
>> the
>> required isolation with minimum or zero effort from a test.
>>
>>
>> 3 The Implementation
>>
>> There is a lot of work done already and the working patch passed the 
>> initial
>> review (thanks to markj@ and ngie@). [2]
>>
>> It adds a new concept to the Kyua framework -- an execution 
>> environment. Two
>> new metadata were added for that: execenv and execenv_jail.
>>
>> execenv is a switch to select an environment. If a test's metadata 
>> defines
>> execenv="jail" then Kyua will create a temporary jail, run such test 
>> within
>> it, and remove the jail. If execenv="host" is provided or execenv 
>> metadata is
>> undefined then Kyua will run such test as it does today.
>>
>> execenv_jail metadata takes effect only in case of execenv="jail". It 
>> allows a
>> test to request specific parameters for its jail. These parameters 
>> are simply
>> arguments to jail(8), e.g. execenv_jail="vnet allow.raw_sockets".
>>
>>
>> 4 The Adoption
>>
>> ATF based tests can easily define this new metadata via Kyuafile or 
>> directly,
>> e.g. for atf-sh based tests:
>>
>> test_head()
>> {
>> atf_set descr "Test foo in case of bar"
>> atf_set require.user root
>> atf_set execenv jail
>> atf_set execenv.jail vnet allow.raw_sockets
>> }
>>
>> Non-ATF based ones will do it via Kyuafile. Our test suite does it 
>> through a
>> Makefile:
>>
>> TEST_METADATA+= execenv="jail"
>> TEST_METADATA+= execenv_jail="vnet allow.raw_sockets"
>>
>> The patch got some little evolution, I started with a single 
>> execenv_jail
>> metadata, and during the patch discussion and review, I ended up with 
>> two
>> knobs: execenv and execenv_jail. It turned out to be a cleaner and 
>> less tricky
>> interface such way. The evolution reasoning can be found in the 
>> history of the
>> respective Differential. [2]
>>
>>
>> 5 MFC Concerns
>>
>> For now, I see at least one issue from the usual project workflow 
>> perspective.
>> Let's imagine that the Kyua framework got this execenv feature 
>> committed to
>> 15-CURRENT, we started to convert existing tests and create new ones 
>> to use
>> execenv="jail". If some feature or a bug fix needs to be ported back 
>> to
>> 14-STABLE or 13-STABLE, then "old" Kyua without execenv feature will 
>> fail to
>> run such tests:
>>
>> kyua: E: Load of 'Kyuafile' failed: Failed to load Lua file 
>> 'Kyuafile': Kyuafile:9: Unknown metadata property execenv.
>>
>> From a combinatorics perspective, the first three options pop up to 
>> deal with
>> that:
>> a) Patch Kyua the same way for the supported STABLE branches so it 
>> will be
>> able to run back ported tests based on execenv="jail" (it's not 
>> system ABI
>> change after all)
>> b) Exclusively patch Kyua framework for the supported STABLE branches 
>> to
>> simply skip such tests (does not look to provide much benefit)
>> c) Do not back port tests, only the fix/feature itself (kind of a bad 
>> idea)
>>
>>
>> 6 The Demo
>>
>> My test environment showed promising run time numbers for almost the 
>> whole
>> test suite (ZFS excluded). One of the tests yielded 36 min with test
>> parallelism improvement versus 1 h 25 min without. In my case with 8 
>> cores,
>> the suite runs about 2 times faster with the improvement. [3]
>>
>>
>> 7 Action Points
>>
>> My current vision of the plan looks as follows:
>> - [ ] community: Review, testing, comments -- probably we want to 
>> change the
>> design
>> - [ ] committers: Help with the main commit -- it should hit 
>> freebsd/kyua
>> GitHub fork first [4], then vendor branch, and merge to
>> main after
>> - [ ] igoro: Provide the subsequent PRs to separate FreeBSD specifics 
>> and fix
>> existing Kyua tests
>> - [ ] igoro: Provide the PRs to add brand new tests of Kyua itself to 
>> cover
>> the new feature
>> - [ ] igoro: Provide the respective documentation updates
>> - [ ] igoro: Migrate some of the existing tests for the start, e.g. 
>> netpfil/pf
>> - [ ] committers: Help with review and respective commits/merges
>>
>> The plan is not strict, it depends on the discussion and interest of
>> volunteers.
>>
>> I hope that this proposal is found valuable for the project. If so, 
>> any help
>> is appreciated.
>>
>>
>> [1] New tests exclusivity concern: https://reviews.freebsd.org/D42314
>> [2] The Kyua patch: https://reviews.freebsd.org/D42350
>> [3] The whole test suite demo: https://reviews.freebsd.org/D42410
>> [4] The respective PR to the fork: 
>> https://github.com/freebsd/kyua/pull/224
>>
>>
>> Best regards, Igor.
--=_MailMate_F71C8465-E854-4AF9-9342-2B9110ED52D5_=
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/xhtml; charset=3Dutf-8"=
>
</head>
<body><div style=3D"font-family: sans-serif;"><div class=3D"markdown" sty=
le=3D"white-space: normal;">
<p dir=3D"auto">&lt;Picking this mail to resurrect the thread&gt;</p>
<p dir=3D"auto">I=E2=80=99ve been toying with this patch. Adding only the=
 following patch I can get Kyua to run the pf tests in parallel:</p>
<pre style=3D"margin-left: 15px; margin-right: 15px; padding: 5px; border=
: thin solid gray; overflow-x: auto; max-width: 90vw; background-color: #=
E4E4E4;"><code style=3D"padding: 0 0.25em; background-color: #E4E4E4;">di=
ff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile
index 867b98e5f6c2..c2f0f15fa798 100644
--- a/tests/sys/netpfil/pf/Makefile
+++ b/tests/sys/netpfil/pf/Makefile
@@ -51,8 +51,8 @@ ATF_TESTS_PYTEST+=3D    frag6.py
 ATF_TESTS_PYTEST+=3D     nat66.py
 ATF_TESTS_PYTEST+=3D     sctp.py

-# Tests reuse jail names and so cannot run in parallel.
-TEST_METADATA+=3D        is_exclusive=3Dtrue
+TEST_METADATA+=3D execenv=3D&quot;jail&quot;
+TEST_METADATA+=3D execenv_jail=3D&quot;vnet allow.raw_sockets&quot;

 PROGS=3D divapp
</code></pre>
<p dir=3D"auto">That gets the test time, with parallelism=3D5, down from =
22 minutes to 5m40s.<br>
So I=E2=80=99m rather keen to see this work land.</p>
<p dir=3D"auto">My read from the reactions here is that people are genera=
lly okay with the approach, especially (I assume) given that the current =
version lets us turn this on on a per-test basis.</p>
<p dir=3D"auto">Is there anything else anyone wants to raise before we la=
nd this?</p>
<p dir=3D"auto">Best regards,<br>
Kristof</p>
<p dir=3D"auto">On 28 Feb 2024, at 2:32, Igor Ostapenko wrote:</p>
</div><div class=3D"plaintext" style=3D"white-space: normal;"><blockquote=
 style=3D"margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #136=
BCE; color: #136BCE;"><p dir=3D"auto">Hi,</p>
<p dir=3D"auto">The patch was updated after the recent discussion.</p>
<p dir=3D"auto">Currently, the patch provides the following new functiona=
lity, from bottom to
<br>
top:</p>
<p dir=3D"auto">1 ATF based tests</p>
<p dir=3D"auto">- The new "execenv" metadata property can be set to expli=
citly ask for an
<br>
  execution environment: "host" or "jail". If it's not defined, as all
<br>
  existing tests do, then it implicitly means "host".</p>
<p dir=3D"auto">- The new "execenv.jail" metadata property can be optiona=
lly defined to ask
<br>
  Kyua to use specific jail(8) parameters during creation of a temporary
<br>
  jail. An example is "vnet allow.raw_sockets".</p>
<p dir=3D"auto">2 Kyuafile</p>
<p dir=3D"auto">- The same new metadata properties can be defined on Kyua=
file level:
<br>
  "execenv" and "execenv_jail".</p>
<p dir=3D"auto">- Note that historically ATF uses dotted style of metadat=
a naming, while
<br>
  Kyua uses underscore style. Hence "execenv.jail" vs. "execenv_jail".</p=
>
<p dir=3D"auto">3 kyua.conf, kyua CLI</p>
<p dir=3D"auto">- The new "execenv" engine configuration variable can be =
set to a list of
<br>
  execution environments to run only tests designed for. Tests of not lis=
ted
<br>
  environments are skipped.</p>
<p dir=3D"auto">- By default, this variable lists all execution environme=
nts supported by a
<br>
  Kyua binary, e.g. execenv=3D"host jail".</p>
<p dir=3D"auto">- This variable can be changed via "kyua.conf" or via kyu=
a CLI's "-v"
<br>
  parameter. For example, "kyua -v execenv=3Dhost test" will run only
<br>
  host-based tests and skip jail-based ones.</p>
<p dir=3D"auto">- Current value of this variable can be examined with "ky=
ua config".</p>
<p dir=3D"auto">The patch is <a href=3D"https://reviews.freebsd.org/D4235=
0">https://reviews.freebsd.org/D42350</a>.</p>;
<p dir=3D"auto">Any help with review and testing is welcome. Its test pla=
n covers the
<br>
details and refers to the demo patch of how existing tests could be
<br>
converted to be run in a jail.</p>
<p dir=3D"auto">Best regards, Igor.</p>
<p dir=3D"auto">On Thursday, February 22nd, 2024 at 10:57 PM, igor.ostape=
nko@pm.me &lt;igor.ostapenko@pm.me&gt; wrote:</p>
<blockquote style=3D"margin: 0 0 5px; padding-left: 5px; border-left: 2px=
 solid #136BCE; border-left-color: #4B89CF; color: #4B89CF;"><p dir=3D"au=
to">Hi FreeBSD developers,</p>
<p dir=3D"auto">There is a proposal to improve the FreeBSD test suite.</p=
>
<p dir=3D"auto">1 The Problem</p>
<p dir=3D"auto">The FreeBSD test suite is based on the Kyua framework. Th=
e latter supports
<br>
running tests in parallel. However, some tests cannot be run in parallel =
and
<br>
are marked with is_exclusive=3D"true" metadata, which makes Kyua run such=
 tests
<br>
in sequence.</p>
<p dir=3D"auto">Many tests are not meant to be exclusive conceptually, th=
ey are so for very
<br>
simple technical reasons. For instance, some network related tests are ba=
sed
<br>
on jail and vnet usage. It's convenient for such tests and it provides a =
lot
<br>
of isolation already not to conflict with other tests. But they are still=

<br>
marked as exclusive due to the shared space of jail names, routing, etc.<=
/p>
<p dir=3D"auto">The project seeks more tests, and it's kind of a trend fo=
r new tests like
<br>
jail/vnet based ones to be created as is_exclusive=3D"true" from the very=

<br>
beginning. It only piles up the suite with exclusive tests, e.g. new test=
s
<br>
from my side faced a fair question from a reviewer whether they could be
<br>
re-designed for a parallel run. [1]</p>
<p dir=3D"auto">If such tests were 100% isolated they would be able to ru=
n in parallel and
<br>
decrease the test time for CI runs and for the runs within the developmen=
t
<br>
process.</p>
<p dir=3D"auto">And the problem is that trying to add more isolation by a=
 test itself looks to
<br>
be a doable task from a glance, but it would add a lot of complexity to a=
 test
<br>
code, or could be found as an impossible task in a specific case.</p>
<p dir=3D"auto">2 The Idea</p>
<p dir=3D"auto">The idea is not new. A test could be running in a jail --=
 it provides the
<br>
required isolation with minimum or zero effort from a test.</p>
<p dir=3D"auto">3 The Implementation</p>
<p dir=3D"auto">There is a lot of work done already and the working patch=
 passed the initial
<br>
review (thanks to markj@ and ngie@). [2]</p>
<p dir=3D"auto">It adds a new concept to the Kyua framework -- an executi=
on environment. Two
<br>
new metadata were added for that: execenv and execenv_jail.</p>
<p dir=3D"auto">execenv is a switch to select an environment. If a test's=
 metadata defines
<br>
execenv=3D"jail" then Kyua will create a temporary jail, run such test wi=
thin
<br>
it, and remove the jail. If execenv=3D"host" is provided or execenv metad=
ata is
<br>
undefined then Kyua will run such test as it does today.</p>
<p dir=3D"auto">execenv_jail metadata takes effect only in case of execen=
v=3D"jail". It allows a
<br>
test to request specific parameters for its jail. These parameters are si=
mply
<br>
arguments to jail(8), e.g. execenv_jail=3D"vnet allow.raw_sockets".</p>
<p dir=3D"auto">4 The Adoption</p>
<p dir=3D"auto">ATF based tests can easily define this new metadata via K=
yuafile or directly,
<br>
e.g. for atf-sh based tests:</p>
<p dir=3D"auto">test_head()
<br>
{
<br>
atf_set descr "Test foo in case of bar"
<br>
atf_set require.user root
<br>
atf_set execenv jail
<br>
atf_set execenv.jail vnet allow.raw_sockets
<br>
}</p>
<p dir=3D"auto">Non-ATF based ones will do it via Kyuafile. Our test suit=
e does it through a
<br>
Makefile:</p>
<p dir=3D"auto">TEST_METADATA+=3D execenv=3D"jail"
<br>
TEST_METADATA+=3D execenv_jail=3D"vnet allow.raw_sockets"</p>
<p dir=3D"auto">The patch got some little evolution, I started with a sin=
gle execenv_jail
<br>
metadata, and during the patch discussion and review, I ended up with two=

<br>
knobs: execenv and execenv_jail. It turned out to be a cleaner and less t=
ricky
<br>
interface such way. The evolution reasoning can be found in the history o=
f the
<br>
respective Differential. [2]</p>
<p dir=3D"auto">5 MFC Concerns</p>
<p dir=3D"auto">For now, I see at least one issue from the usual project =
workflow perspective.
<br>
Let's imagine that the Kyua framework got this execenv feature committed =
to
<br>
15-CURRENT, we started to convert existing tests and create new ones to u=
se
<br>
execenv=3D"jail". If some feature or a bug fix needs to be ported back to=

<br>
14-STABLE or 13-STABLE, then "old" Kyua without execenv feature will fail=
 to
<br>
run such tests:</p>
<p dir=3D"auto">kyua: E: Load of 'Kyuafile' failed: Failed to load Lua fi=
le 'Kyuafile': Kyuafile:9: Unknown metadata property execenv.</p>
<p dir=3D"auto">From a combinatorics perspective, the first three options=
 pop up to deal with
<br>
that:
<br>
a) Patch Kyua the same way for the supported STABLE branches so it will b=
e
<br>
able to run back ported tests based on execenv=3D"jail" (it's not system =
ABI
<br>
change after all)
<br>
b) Exclusively patch Kyua framework for the supported STABLE branches to
<br>
simply skip such tests (does not look to provide much benefit)
<br>
c) Do not back port tests, only the fix/feature itself (kind of a bad ide=
a)</p>
<p dir=3D"auto">6 The Demo</p>
<p dir=3D"auto">My test environment showed promising run time numbers for=
 almost the whole
<br>
test suite (ZFS excluded). One of the tests yielded 36 min with test
<br>
parallelism improvement versus 1 h 25 min without. In my case with 8 core=
s,
<br>
the suite runs about 2 times faster with the improvement. [3]</p>
<p dir=3D"auto">7 Action Points</p>
<p dir=3D"auto">My current vision of the plan looks as follows:
<br>
- [ ] community: Review, testing, comments -- probably we want to change =
the
<br>
design
<br>
- [ ] committers: Help with the main commit -- it should hit freebsd/kyua=

<br>
GitHub fork first [4], then vendor branch, and merge to
<br>
main after
<br>
- [ ] igoro: Provide the subsequent PRs to separate FreeBSD specifics and=
 fix
<br>
existing Kyua tests
<br>
- [ ] igoro: Provide the PRs to add brand new tests of Kyua itself to cov=
er
<br>
the new feature
<br>
- [ ] igoro: Provide the respective documentation updates
<br>
- [ ] igoro: Migrate some of the existing tests for the start, e.g. netpf=
il/pf
<br>
- [ ] committers: Help with review and respective commits/merges</p>
<p dir=3D"auto">The plan is not strict, it depends on the discussion and =
interest of
<br>
volunteers.</p>
<p dir=3D"auto">I hope that this proposal is found valuable for the proje=
ct. If so, any help
<br>
is appreciated.</p>
<p dir=3D"auto">[1] New tests exclusivity concern: <a href=3D"https://rev=
iews.freebsd.org/D42314">https://reviews.freebsd.org/D42314</a>;
<br>
[2] The Kyua patch: <a href=3D"https://reviews.freebsd.org/D42350">https:=
//reviews.freebsd.org/D42350</a>
<br>
[3] The whole test suite demo: <a href=3D"https://reviews.freebsd.org/D42=
410">https://reviews.freebsd.org/D42410</a>;
<br>
[4] The respective PR to the fork: <a href=3D"https://github.com/freebsd/=
kyua/pull/224">https://github.com/freebsd/kyua/pull/224</a></p>;
<br></blockquote></blockquote></div>
<div class=3D"markdown" style=3D"white-space: normal;">
<blockquote style=3D"margin: 0 0 5px; padding-left: 5px; border-left: 2px=
 solid #136BCE; color: #136BCE;">
<blockquote style=3D"margin: 0 0 5px; padding-left: 5px; border-left: 2px=
 solid #136BCE; border-left-color: #4B89CF; color: #4B89CF;">
<p dir=3D"auto">Best regards, Igor.</p>
</blockquote>
</blockquote>

</div>
</div>
</body>

</html>

--=_MailMate_F71C8465-E854-4AF9-9342-2B9110ED52D5_=--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B7E897BE-3DA2-4B95-9011-929E833B1A0B>