Make libsepol tests pass again
cover Make libsepol tests pass again
Hello,
A few months ago I saw that "make -C libsepol test" succeeded even though it displayed what looked like a failure:
./libsepol-tests
CUnit - A unit testing framework for C - Version 2.1-3
http://cunit.sourceforge.net/
Suite: cond
Test: cond_expr_equal ...passed
Suite: linker
Test: linker_indexes ...passed
Test: linker_types ...passed
Test: linker_roles ...
role o1_b_role_1 has 0 types, 1 expected
role o1_b_role_1 has 0 types, 1 expected
role o1_m1_role_1 has 0 types, 1 expected
sym g_b_role_2 has 1 decls, 2 expected
Role o1_b_role_2 had type o1_b_type_1 not in types array role o1_b_role_2 has 0 types, 1 expected
Role g_b_role_4 had type g_m1_type_2 not in types array role g_b_role_4 has 0 types, 1 expected
role o3_b_role_1 has 0 types, 1 expected
role o3_b_role_1 has 0 types, 1 expected
role o4_b_role_1 has 0 types, 1 expected
Role o4_b_role_1 had type g_m1_type_1 not in types array
FAILED
1. test-common.c:216 - found == len
2. test-common.c:216 - found == len
3. test-common.c:216 - found == len
4. test-common.c:43 - scope->decl_ids_len == len
5. test-common.c:52 - found == 1
6. test-common.c:213 - new == 1
7. test-common.c:216 - found == len
8. test-common.c:213 - new == 1
9. test-common.c:216 - found == len
10. test-common.c:216 - found == len
11. test-common.c:216 - found == len
12. test-common.c:216 - found == len
13. test-common.c:213 - new == 1
Test: linker_cond ...passed
Suite: expander
Test: expander_indexes ...passed
Test: expander_attr_mapping ...passed
Test: expander_role_mapping ...passed
Test: expander_user_mapping ...passed
Test: expander_alias ...passed
Suite: deps
Test: deps_modreq_global ...passed
Test: deps_modreq_opt ...passed
Suite: downgrade
Test: downgrade ...passed
Run Summary: Type Total Ran Passed Failed Inactive
suites 5 5 n/a 0 0
tests 13 13 12 1 0
asserts 1269 1269 1256 13 n/a
Elapsed time = 1.420 seconds
I can see 3 reasons behind such a failure report:
* there is a bug somewhere in libsepol and the tests detect it,
* the tests are out-dated and they need to be either removed or updated, or
* my test system is configured in a way that make the tests fail even though they should not.
Moreover, even though the tests are failing, it is quite disturbing that "make test" is succeeding. This is because the CUnit tests only exit with a failed error code when an error occured in the CUnit framework, not in tests. The last patch of this series fixes this.
As I did not understood anything at first when I read the code of libsepol tests, I wrote some code to dump some tables of the loaded policy (p->symtab[SYM_ROLES], and p->decl_val_to_struct[...]->symtab[SYM_ROLES])
Here is an extract of this dump:
p->p_roles[object_r]: scope 2 {1, 9, 14},
types { }
p->p_roles[g_b_role_1]: scope 2 {1},
types { g_b_type_1 },
dominates g_b_role_1
p->p_roles[o1_b_role_1]: scope 2 {2},
types { o1_b_type_1 }
p->p_roles[o3_b_role_1]: scope 2 {4, 12},
types { o3_b_type_1 o3_m1_type_1 }
p->p_roles[o4_b_role_1]: scope 2 {5, 9, 14},
types { g_m1_type_1 g_m1_type_2 g_m2_type_1 },
dominates o4_b_role_1
p->p_roles[g_b_role_3]: scope 2 {1, 9, 14},
types { g_b_type_2 g_m1_type_2 g_m2_type_2 },
dominates g_b_role_3
p->p_roles[g_b_role_2]: scope 2 {1},
types { g_b_type_2 g_m1_type_1 },
dominates g_b_role_2
p->p_roles[o1_b_role_2]: scope 2 {2, 9},
types { o1_b_type_1 g_m1_type_1 },
dominates o1_b_role_2[...]
decl[2]->p_roles[o1_b_role_1]: scope 2 {2},
types { }, dominates o1_b_role_1
decl[2]->p_roles[o1_b_role_2]: scope 2 {2, 9},
types { }, dominates o1_b_role_2
decl[4]->p_roles[o3_b_role_1]: scope 2 {4, 12},
types { }, dominates o3_b_role_1
decl[5]->p_roles[o4_b_role_1]: scope 2 {5, 9, 14},
types { }, dominates o4_b_role_1
It seems strange that "p->p_roles" hashmap handles all role-types associations but that the domination information lies in "p->decl_val_to_struct[scope-1]->p_roles" for roles in optional blocks. This association is performed in define_role_types() function in checkpolicy/policy_define.c. Using the "local role" (result of get_local_role function) there fixes most asserion failures. This is what the first patch does.
Afterwards the only failure which remains is:
sym g_b_role_2 has 1 decls, 2 expected
Even though g_b_role_2 is used both in tests/policies/test-linker/small-base.conf and tests/policies/test-linker/module1.conf, it seems to only exists in the scope of the base policy. The second patch updates the test accordingly.
Nicolas Iooss (3):
checkpolicy: add types associated to a role in the current scope when
parsing
libsepol: tests: fix g_b_role_2 test
libsepol: make "make test" fails when a CUnit test fails
checkpolicy/policy_define.c | 1 + libsepol/tests/libsepol-tests.c | 11 +++++++---- libsepol/tests/test-linker-roles.c | 3 +-- 3 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/3 checkpolicy: add types associated to a role in the current scope when parsing
This fixes most of the errors reported in "make -C libsepol test":
./libsepol-tests
CUnit - A unit testing framework for C - Version 2.1-3
http://cunit.sourceforge.net/
Suite: cond
Test: cond_expr_equal ...passed
Suite: linker
Test: linker_indexes ...passed
Test: linker_types ...passed
Test: linker_roles ...
role o1_b_role_1 has 0 types, 1 expected
role o1_b_role_1 has 0 types, 1 expected
role o1_m1_role_1 has 0 types, 1 expected
sym g_b_role_2 has 1 decls, 2 expected
Role o1_b_role_2 had type o1_b_type_1 not in types array role o1_b_role_2 has 0 types, 1 expected
Role g_b_role_4 had type g_m1_type_2 not in types array role g_b_role_4 has 0 types, 1 expected
role o3_b_role_1 has 0 types, 1 expected
role o3_b_role_1 has 0 types, 1 expected
role o4_b_role_1 has 0 types, 1 expected
Role o4_b_role_1 had type g_m1_type_1 not in types array
FAILED
1. test-common.c:216 - found == len
2. test-common.c:216 - found == len
3. test-common.c:216 - found == len
4. test-common.c:43 - scope->decl_ids_len == len
5. test-common.c:52 - found == 1
6. test-common.c:213 - new == 1
7. test-common.c:216 - found == len
8. test-common.c:213 - new == 1
9. test-common.c:216 - found == len
10. test-common.c:216 - found == len
11. test-common.c:216 - found == len
12. test-common.c:216 - found == len
13. test-common.c:213 - new == 1
Test: linker_cond ...passed
Suite: expander
Test: expander_indexes ...passed
Test: expander_attr_mapping ...passed
Test: expander_role_mapping ...passed
Test: expander_user_mapping ...passed
Test: expander_alias ...passed
Suite: deps
Test: deps_modreq_global ...passed
Test: deps_modreq_opt ...passed
Suite: downgrade
Test: downgrade ...passed
Run Summary: Type Total Ran Passed Failed Inactive
suites 5 5 n/a 0 0
tests 13 13 12 1 0
asserts 1269 1269 1256 13 n/a
--- checkpolicy/policy_define.c | 1 + 1 file changed, 1 insertion(+)
checkpolicy/policy_define.c +1 -0
@@ -2614,6 +2614,7 @@ int define_role_types(void)free (id);return -1 ; } + role =get_local_role (id, role->s.value, (role->flavor ==ROLE_ATTRIB ));while ((id =queue_remove (id_queue))) {if (set_types (&role->types, id, &add,0 ))
Signature · 1 line
2.9.3
PATCH 2/3 libsepol: tests: fix g_b_role_2 test
In reply to Nicolas IoossEven though g_b_role_2 is used both in tests/policies/test-linker/small-base.conf and tests/policies/test-linker/module1.conf, it seems to only exists in the scope of the base policy.
This fixes the following failure of "make -C libsepol test":
./libsepol-tests
CUnit - A unit testing framework for C - Version 2.1-3
http://cunit.sourceforge.net/
Suite: cond
Test: cond_expr_equal ...passed
Suite: linker
Test: linker_indexes ...passed
Test: linker_types ...passed
Test: linker_roles ...sym g_b_role_2 has 1 decls, 2 expected
FAILED
1. test-common.c:43 - scope->decl_ids_len == len
2. test-common.c:52 - found == 1
Test: linker_cond ...passed
Suite: expander
Test: expander_indexes ...passed
Test: expander_attr_mapping ...passed
Test: expander_role_mapping ...passed
Test: expander_user_mapping ...passed
Test: expander_alias ...passed
Suite: deps
Test: deps_modreq_global ...passed
Test: deps_modreq_opt ...passed
Suite: downgrade
Test: downgrade ...passed
Run Summary: Type Total Ran Passed Failed Inactive
suites 5 5 n/a 0 0
tests 13 13 12 1 0
asserts 1274 1274 1272 2 n/a
--- libsepol/tests/test-linker-roles.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libsepol/tests/test-linker-roles.c +1 -2
@@ -132,8 +132,7 @@ void module_role_tests(policydb_t * base)/**** test for type added to base role in module 1 (global) ****/ decls[0 ] = (test_find_decl_by_sym (base,SYM_TYPES ,"tag_g_b" ))->decl_id; - decls[1 ] = (test_find_decl_by_sym (base,SYM_TYPES ,"tag_g_m1" ))->decl_id; -test_sym_presence (base,"g_b_role_2" ,SYM_ROLES ,SCOPE_DECL , decls,2 ); +test_sym_presence (base,"g_b_role_2" ,SYM_ROLES ,SCOPE_DECL , decls,1 );/* make sure it has the correct type set (g_m1_type_1, no negset, no flags) */ types[0 ] ="g_b_type_2" ;/* added in base when declared */ types[1 ] ="g_m1_type_1" ;/* added in module */
Signature · 1 line
2.9.3
PATCH 3/3 libsepol: make "make test" fails when a CUnit test fails
In reply to Nicolas Iooss--- libsepol/tests/libsepol-tests.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
libsepol/tests/libsepol-tests.c +7 -4
@@ -28,6 +28,7 @@#include <CUnit/Console.h> #include <CUnit/TestDB.h> +#include <stdbool.h> #include <stdio.h> #include <getopt.h> #include <stdlib.h>
@@ -51,9 +52,10 @@ static void usage(char *progname)printf ("\t-i, --interactive\t\tinteractive console\n" ); } -static int do_tests (int interactive,int verbose) +static bool do_tests (int interactive,int verbose) {CU_pSuite suite =NULL ; +unsigned int num_failures;if (CUE_SUCCESS !=CU_initialize_registry ())return CU_get_error ();
@@ -73,8 +75,9 @@ static int do_tests(int interactive, int verbose)CU_console_run_tests (); elseCU_basic_run_tests (); + num_failures =CU_get_number_of_tests_failed ();CU_cleanup_registry (); -return CU_get_error (); +return CU_get_error () ==CUE_SUCCESS && num_failures ==0 ; }
@@ -106,12 +109,12 @@ int main(int argc, char **argv)/* first do the non-mls tests */ mls =0 ; -if (do_tests (interactive, verbose)) +if (!do_tests (interactive, verbose))return -1 ;/* then with mls */ mls =1 ; -if (do_tests (interactive, verbose)) +if (!do_tests (interactive, verbose))return -1 ;return 0 ;
Signature · 1 line
2.9.3
Stephen Smalley
AppliedQuoted 134 lines · Nicolas Iooss
Hello,
A few months ago I saw that "make -C libsepol test" succeeded even though it displayed what looked like a failure:
./libsepol-tests
CUnit - A unit testing framework for C - Version 2.1-3
http://cunit.sourceforge.net/
Suite: cond
Test:cond_expr_equal...passed
Suite: linker
Test:linker_indexes...passed
Test:linker_types...passed
Test:linker_roles...
roleo1_b_role_1has 0 types, 1 expected
roleo1_b_role_1has 0 types, 1 expected
roleo1_m1_role_1has 0 types, 1 expected
symg_b_role_2has 1 decls, 2 expected
Roleo1_b_role_2had typeo1_b_type_1not in types array roleo1_b_role_2has 0 types, 1 expected
Roleg_b_role_4had typeg_m1_type_2not in types array roleg_b_role_4has 0 types, 1 expected
roleo3_b_role_1has 0 types, 1 expected
roleo3_b_role_1has 0 types, 1 expected
roleo4_b_role_1has 0 types, 1 expected
Roleo4_b_role_1had typeg_m1_type_1not in types arrayFAILED
1. test-common.c:216 - found == len
2. test-common.c:216 - found == len
3. test-common.c:216 - found == len
4. test-common.c:43 -scope->decl_ids_len== len
5. test-common.c:52 - found == 1
6. test-common.c:213 - new == 1
7. test-common.c:216 - found == len
8. test-common.c:213 - new == 1
9. test-common.c:216 - found == len
10. test-common.c:216 - found == len
11. test-common.c:216 - found == len
12. test-common.c:216 - found == len
13. test-common.c:213 - new == 1
Test:linker_cond...passed
Suite: expander
Test:expander_indexes...passed
Test:expander_attr_mapping...passed
Test:expander_role_mapping...passed
Test:expander_user_mapping...passed
Test:expander_alias...passed
Suite: deps
Test:deps_modreq_global...passed
Test:deps_modreq_opt...passed
Suite: downgrade
Test: downgrade ...passedRun Summary: Type Total Ran Passed Failed Inactive
suites 5 5 n/a 0 0
tests 13 13 12 1 0
asserts 1269 1269 1256 13 n/a
Elapsed time = 1.420 secondsI can see 3 reasons behind such a failure report:
* there is a bug somewhere in libsepol and the tests detect it,
* the tests are out-dated and they need to be either removed or updated, or
* my test system is configured in a way that make the tests fail even though they should not.Moreover, even though the tests are failing, it is quite disturbing that "make test" is succeeding. This is because the CUnit tests only exit with a failed error code when an error occured in the CUnit framework, not in tests. The last patch of this series fixes this.
As I did not understood anything at first when I read the code of libsepol tests, I wrote some code to dump some tables of the loaded policy (p->symtab[SYM_ROLES], and p->decl_val_to_struct[...]->symtab[SYM_ROLES])
Here is an extract of this dump:p->p_roles[object_r]: scope 2 {1, 9, 14}, types { } p->p_roles[g_b_role_1]: scope 2 {1}, types { g_b_type_1 }, dominates g_b_role_1 p->p_roles[o1_b_role_1]: scope 2 {2}, types { o1_b_type_1 } p->p_roles[o3_b_role_1]: scope 2 {4, 12}, types { o3_b_type_1 o3_m1_type_1 } p->p_roles[o4_b_role_1]: scope 2 {5, 9, 14}, types { g_m1_type_1 g_m1_type_2 g_m2_type_1 }, dominates o4_b_role_1 p->p_roles[g_b_role_3]: scope 2 {1, 9, 14}, types { g_b_type_2 g_m1_type_2 g_m2_type_2 }, dominates g_b_role_3 p->p_roles[g_b_role_2]: scope 2 {1}, types { g_b_type_2 g_m1_type_1 }, dominates g_b_role_2 p->p_roles[o1_b_role_2]: scope 2 {2, 9}, types { o1_b_type_1 g_m1_type_1 }, dominates o1_b_role_2[...]
decl[2]->p_roles[o1_b_role_1]: scope 2 {2},
types { }, dominateso1_b_role_1
decl[2]->p_roles[o1_b_role_2]: scope 2 {2, 9},
types { }, dominateso1_b_role_2
decl[4]->p_roles[o3_b_role_1]: scope 2 {4, 12},
types { }, dominateso3_b_role_1
decl[5]->p_roles[o4_b_role_1]: scope 2 {5, 9, 14},
types { }, dominateso4_b_role_1It seems strange that "
p->p_roles" hashmap handles all role-types associations but that the domination information lies in "p->decl_val_to_struct[scope-1]->p_roles" for roles in optional blocks. This association is performed indefine_role_types()function incheckpolicy/policy_define.c. Using the "local role" (result ofget_local_rolefunction) there fixes most asserion failures. This is what the first patch does.Afterwards the only failure which remains is:
sym
g_b_role_2has 1 decls, 2 expectedEven though
g_b_role_2is used both intests/policies/test-linker/small-base.confandtests/policies/test-linker/module1.conf, it seems to only exists in the scope of the base policy. The second patch updates the test accordingly.Nicolas Iooss (3):
checkpolicy: add types associated to a role in the current scope when
parsing
libsepol: tests: fixg_b_role_2test
libsepol: make "make test" fails when a CUnit test fails
Quoted 4 lines
checkpolicy/policy_define.c | 1 + libsepol/tests/libsepol-tests.c | 11 +++++++---- libsepol/tests/test-linker-roles.c | 3 +-- 3 files changed, 9 insertions(+), 6 deletions(-)
Thanks, applied all three.