apparmor/parser/tst
John Johansen 84650beb2f parser: equality tests: fix equality failure due to xtable
exec rules that specify an specific target profile generate an entry
in the xtable. The test entries containing " -> b" are an example of
this.

Currently the parser allocates the xtable entry before priorities are
applied in the backend, or minimization is done. Further more the
parser does not ref count the xtable entry to know what it is no
longer referenced.

The equality tests generate rules that are designed to completely
override and remove a lower priority rule, and remove it. Eg.

  /t { priority=1 /* ux, /f px -> b, }

and then compares the generated profile to the functionaly equivalent
profile eg.

  /t { priority=1 /* ux, }

To verify the overridden rule has been completely removed.
Unfortunately the compilation is not removing the unused xtable entry
for the specified transition, causing the equality comparison to fail.

Ideally the parser should be fixed so unused xtable entries are removed,
but that should be done in a different MR, and have its own test.

To fix the current tests, and another rule that adds an xtable entry
to the same target that can not be overriden by the x rule using
pivot_root. The parser will dedup the xtable entry resulting in the
known and test profile both having the same xtable. So the test will
pass and meet the original goal of verifying the x rule being overriden
and eliminated.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-12-23 23:36:28 -08:00
..
dirtest dirtest.sh: don't rely on apparmor_parser -N's output sort order to be deterministic 2022-07-25 10:14:31 +00:00
errors parser error tests: add filename profile deprecation checks 2020-05-05 02:16:23 -07:00
features_files parser: add equality tests for network port range 2024-09-06 09:49:59 -03:00
simple_tests parser: fix integer overflow bug in rule priority comparisons 2024-10-28 04:03:53 -07:00
caching.profile actually add caching tests 2009-11-11 11:07:50 -08:00
caching.py Change string formatting method in Python tests 2023-02-19 16:54:38 -05:00
dirtest.sh dirtest.sh: don't rely on apparmor_parser -N's output sort order to be deterministic 2022-07-25 10:14:31 +00:00
equality.sh parser: equality tests: fix equality failure due to xtable 2024-12-23 23:36:28 -08:00
errors.py parser/errors.py: convert to unittest.main() 2023-07-13 13:40:42 -05:00
gen-dbus.py Change string formatting method in Python tests 2023-02-19 16:54:38 -05:00
gen-xtrans.py Add missing comma to tuple 2023-02-19 17:13:15 -05:00
Makefile Pass parallelism arg to parser_sanity test prove invocation 2024-11-08 09:34:03 -08:00
minimize.sh parser: enable extended perms if supported by the kernel 2024-08-14 17:15:24 -07:00
mk_features_file.py Change string formatting method in Python tests 2023-02-19 16:54:38 -05:00
parser.conf parser: add empty config file for parser caching tests 2018-08-21 23:14:52 -07:00
README treewide: spelling/typo fixes in comments and docs 2020-12-01 12:47:11 -08:00
simple.pl error out on superfluous TODOs 2018-11-06 21:44:40 +01:00
testlib.py Replace sigalarm-based subprocess timeout with the built-in one 2024-10-15 16:51:17 -07:00
uservars.conf as ACKed on IRC, drop the unused $Id$ tags everywhere 2010-12-20 12:29:10 -08:00
valgrind_simple.py Change string formatting method in Python tests 2023-02-19 16:54:38 -05:00

This is the README for the AppArmor parser regression testsuite.

Running the testsuite
---------------------
Running the tests is pretty easy, a simple 'make tests' should make it
go, assuming the subdomain parser and perl are installed.

There is a user configuration file 'uservars.conf'. If you wish to test
against a different parser, or use a different set of profiles for the
simple.pl test, you can change those settings in 'uservars.conf'.

You can also override which parser is used through make by specifying
the PARSER variable. For example, to run the tests on the system parser,
run 'make PARSER=/sbin/apparmor_parser'.

Adding to the testsuite
-----------------------

The testsuite currently contains one testscript (simple.pl) and makes use
of perl's Test::Simple, Test::Harness, and prove utilities (see 'perldoc
Test::Tutorial', 'perldoc Test::Simple', 'perldoc Test::Harness', and
'man 1 prove' for more information on these).

It should be relatively easy to extend the suite with other testscripts,
as long as they're written using Test::Simple or can emulate the
Test::Harness protocol. To add a script, add it to the TESTS variable
in the Makefile, and it will included in the tests to be run.

However, in many cases, it is not necessary to add an entire new
testscript for a testcase. Instead, the simple testcase (see below)
will run all the profiles it finds on the parser, thus adding testcases
is usually as simple as writing a new profile with a couple of extra
comments.

Simple parsing tests (simple.pl)
--------------------------------
This test script tests the parser front end's ability to identify legal
profiles. It does this by running the parser against several legal and
illegal profiles (in debug mode, so as not to load them into the module
proper)

The simple script has the parser attempt to parse all of the profiles
named *.sd in the simple_tests/ subdirectory; thus, to add a new profile
to test, simply add it to the simple_tests/ directory. The simple
script also adds the testdir (simple_tests/ by default) to the parsers
include path (assuming that particular bug has been fixed :-)). There
is an includes/ subdir to place additional includes if necessary (we
purposefully choose to use different directory names versus the shipped
profiles to minimize testsuite breakage with changes in the external
policy).

The simple script looks for a few special comments in the profile,
#=DESCRIPTION, #=EXRESULT, and #=TODO:

  - #=DESCRIPTION -- all text following the keyword is considered a
    description for the test. Please try to make these meaningful.

  - #=EXRESULT -- This records the expected result of parsing this
    profile. Values can either be PASS or FAIL; if no comment is found
    that matches this pattern, then the profile is assumed to have an
    expected parse result of PASS.

  - #=TODO -- marks the test as being for a future item to implement and
    thus are expected testsuite failures and should be ignored.

  - #=DISABLED -- skips the test, and marks it as a failed TODO task.
    Useful if the particular testcase causes the parser to infinite
    loop or dump core.

Otherwise, the profile is passed on as-is to the subdomain parser.