1 README for security-tests project
3 ==WHAT IS======================================================================
5 security-tests is repository for testing packages from domain Security.
7 ==WHAT FOR=====================================================================
9 The security-tests repository is designed for testing packages mentioned below
10 with binaries provided for testing them:
15 libprivilege-control-test
17 security-server-tests-client-smack
18 security-server-tests-stress
19 security-server-tests-server
20 security-server-tests-api-speed
21 security-server-tests-password
22 security-server-tests-privilege
23 security-server-tests-dbus
25 security-manager-tests
29 ==HOW TO RUN===================================================================
31 Each test suite may be run with options:
32 --output=<output type> --output=<output type> ...
35 test-binary --output=text --output=xml --file=output.xml
36 --only-from-xml=<xml file> Run only testcases specified in XML file
37 --regexp='regexp' Only selected tests which names match regexp run
38 --start=<test id> Start from concrete test id
39 --group=<group name> Run tests only from one group
40 --runignored Run also ignored tests
41 --list Show a list of Test IDs
42 --listgroups Show a list of Test Group names
43 --only-from-xml=<xml file> Run only testcases specified in XML file
44 XML name is taken from attribute id="part1_part2" as whole.
45 If part1 is not found (no _) then it is implicitily set according to
46 suite part1 from binary tests
47 --listingroup=<group name> Show a list of Test IDS in one group
48 --allowchildlogs Allow to print logs from child process on screen.
49 When active child process will be able to print logs on stdout and
50 stderr. Both descriptors will be closed after test.
53 They can be run also by scripts:
57 Each test can end with one of three possible statuses:
62 ==HOW TO WRITE=================================================================
64 security-tests is based on extended dpl framework providing different macros.
65 Below are categories with macros listed as below:
71 --Test group registering macro-------------------------------------------------
75 RUNNER_TEST_GROUP_INIT
76 Registers group of tests. Test are registered under this group until
77 another group registering macro is called.
79 --Test registering macros------------------------------------------------------
80 Adding/removing those macro calls will add/remove test cases they provide. To
81 change tests, change body of those macro calls. Registered tests are run within
87 Function registered by this macro will be run in the same process as
88 framework. No forking allowed unless forked process does not throw
92 Function registered by this macro will be run in child process. No
93 forking allowed unless forked process does not throw any exception.
94 test_runner_multiprocess.h
95 RUNNER_MULTIPROCESS_TEST
96 Function registered by this macro will be run in the same process as
97 framework. Forking allowed. Exception of every process will be
102 Same as RUNNER_TEST but run only with smack enabled.
104 Same as RUNNER_TEST but run only with smack disabled.
105 RUNNER_CHILD_TEST_SMACK
106 Same as RUNNER_TEST_CHILD but run only with smack enabled.
107 RUNNER_CHILD_TEST_NOSMACK
108 Same as RUNNER_TEST_CHILD but run only with smack disabled.
109 RUNNER_MULTIPROCESS_TEST_SMACK
110 Same as RUNNER_TEST_MULTIPROCESS but run only with smack enabled.
111 RUNNER_MULTIPROCESS_TEST_NOSMACK
112 Same as RUNNER_TEST_MULTIPROCESS but run only with smack disabled.
114 --Assert macros----------------------------------------------------------------
115 Used within test registering macros.
120 Assertion with message with backtrace information appended.
121 RUNNER_ASSERT_ERRNO_MSG
122 Assertion with message, error string and backtrace information
125 Assertion with error string and backtrace information appended.
127 Fail with message and backtrace information appended.
129 Assertion with backtrace information appended.
131 Assertion with message classified as ignored.
133 --Performence macros-----------------------------------------------------------
134 Used to do the time measurement.
138 RUNNER_PERF_TEST_BEGIN
139 Start time measurement.
141 End time measurement.
143 --Collectors-------------------------------------------------------------------
144 Collectors are classes which collect test results. Each class does it differently.
145 Collectors can be registered by --output parameter (see HOW TO RUN section) but
146 there is also another collector created to write summary.
151 Collector writing tests summary. Call SummaryCollector::Register() to
154 --Usage example----------------------------------------------------------------
156 #include <test_runner.h>
157 #include <tests_common.h>
158 #include <summary_collector.h>
160 #include <sys/stat.h>
164 RUNNER_TEST_GROUP_INIT(foo_module)
166 RUNNER_TEST_SMACK(bar_allways_fails)
168 RUNNER_ASSERT(false);
171 RUNNER_TEST(bar_allways_passses)
176 RUNNER_TEST(bar_file1)
178 cosnt char *file = "bar_file1";
179 int fd = TEMP_FAILURE_RETRY(open(file, O_RDONLY));
180 RUNNER_ASSERT_ERRNO_MSG(fd != -1, "Cannot open " << file << " file");
184 RUNNER_CHILD_TEST_NOSMACK(bar_file2_dropped_root)
186 RUNNER_ASSERT_ERRNO(setgid(5000) == 0);
187 RUNNER_ASSERT_ERRNO(setuid(5000) == 0);
189 cosnt char *file = "bar_file2";
190 int fd = TEMP_FAILURE_RETRY(open(file, O_RDONLY));
193 RUNNER_FAIL_MSG("file " << file << "should not be opened");
195 RUNNER_ASSERT_ERRNO_MSG(errno == EACCESS,
196 "Wrong errno on opening " << " file");
199 int main(int argc, char *argv[])
201 SummaryCollector::Register();
202 return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
205 --Notes------------------------------------------------------------------------
207 While changing body of test cases, be sure to remove functions and global
208 variables if not used by any other tests.
209 Use const variables instead of #define's.
210 Use mechanisms already provided in common library.