Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 17-Dec-2021 | - | ||||
data/ | H | 03-May-2022 | - | 1,593 | 1,453 | |
Makefile.am | H A D | 17-Dec-2021 | 12.7 KiB | 428 | 315 | |
README | H A D | 17-Dec-2021 | 3.3 KiB | 96 | 67 | |
addr_lib_test.c | H A D | 17-Dec-2021 | 5.2 KiB | 157 | 117 | |
aix_process_test.c | H A D | 17-Dec-2021 | 3.5 KiB | 145 | 111 | |
arg_split_test.c | H A D | 17-Dec-2021 | 6.1 KiB | 235 | 173 | |
assoc_test.c | H A D | 17-Dec-2021 | 351 | 21 | 16 | |
avahi_config_test.c | H A D | 17-Dec-2021 | 1.6 KiB | 62 | 51 | |
cf_upgrade_test.c | H A D | 17-Dec-2021 | 4.6 KiB | 103 | 93 | |
changes_migration_test.c | H A D | 17-Dec-2021 | 6 KiB | 200 | 144 | |
class_test.c | H A D | 17-Dec-2021 | 3.5 KiB | 122 | 105 | |
cmockery.c | H A D | 17-Dec-2021 | 70.8 KiB | 2,072 | 1,604 | |
cmockery.h | H A D | 17-Dec-2021 | 21.6 KiB | 477 | 280 | |
connection_management_test.c | H A D | 17-Dec-2021 | 4.6 KiB | 152 | 95 | |
conversion_test.c | H A D | 17-Dec-2021 | 7.3 KiB | 218 | 162 | |
crypto_symmetric_test.c | H A D | 17-Dec-2021 | 3.4 KiB | 115 | 84 | |
db_concurrent_test.c | H A D | 17-Dec-2021 | 3.2 KiB | 148 | 98 | |
db_stubs.c | H A D | 17-Dec-2021 | 1 KiB | 31 | 5 | |
db_test.c | H A D | 17-Dec-2021 | 6.7 KiB | 259 | 183 | |
domainname_test.c | H A D | 17-Dec-2021 | 3.4 KiB | 114 | 91 | |
dynamic_dependency_test.sh | H A D | 17-Dec-2021 | 3 KiB | 84 | 39 | |
enterprise_extension_test.c | H A D | 17-Dec-2021 | 2.2 KiB | 78 | 53 | |
enterprise_extension_test_lib.c | H A D | 17-Dec-2021 | 993 | 35 | 27 | |
eval_context_test.c | H A D | 17-Dec-2021 | 3.9 KiB | 145 | 102 | |
evalfunction_test.c | H A D | 17-Dec-2021 | 3.7 KiB | 136 | 113 | |
exec-config-test.c | H A D | 17-Dec-2021 | 6 KiB | 173 | 134 | |
expand_test.c | H A D | 17-Dec-2021 | 18.8 KiB | 601 | 486 | |
file_name_test.c | H A D | 17-Dec-2021 | 8.6 KiB | 325 | 252 | |
files_copy_test.c | H A D | 17-Dec-2021 | 15 KiB | 564 | 379 | |
files_interfaces_test.c | H A D | 17-Dec-2021 | 2.5 KiB | 113 | 88 | |
files_lib_test.c | H A D | 17-Dec-2021 | 4.1 KiB | 130 | 104 | |
findhub_test.c | H A D | 17-Dec-2021 | 8.3 KiB | 318 | 256 | |
gcov-stub.c | H A D | 17-Dec-2021 | 868 | 51 | 34 | |
generic_agent_test.c | H A D | 17-Dec-2021 | 5.5 KiB | 163 | 118 | |
granules_test.c | H A D | 17-Dec-2021 | 2.1 KiB | 64 | 44 | |
init_script_test.sh | H A D | 17-Dec-2021 | 16 KiB | 378 | 269 | |
init_script_test_helper.c | H A D | 17-Dec-2021 | 5.5 KiB | 207 | 149 | |
item_lib_test.c | H A D | 17-Dec-2021 | 1.6 KiB | 55 | 39 | |
item_test.c | H A D | 17-Dec-2021 | 11.9 KiB | 390 | 308 | |
iteration_test.c | H A D | 17-Dec-2021 | 14.4 KiB | 367 | 276 | |
key_test.c | H A D | 17-Dec-2021 | 2.6 KiB | 105 | 85 | |
lastseen_migration_test.c | H A D | 17-Dec-2021 | 6.4 KiB | 287 | 199 | |
lastseen_test.c | H A D | 17-Dec-2021 | 18.9 KiB | 684 | 400 | |
linux_process_test.c | H A D | 17-Dec-2021 | 3.7 KiB | 169 | 141 | |
logging_test.c | H A D | 17-Dec-2021 | 3.6 KiB | 116 | 90 | |
matching_test.c | H A D | 17-Dec-2021 | 1.4 KiB | 48 | 41 | |
mon_cpu_test.c | H A D | 17-Dec-2021 | 1.8 KiB | 87 | 72 | |
mon_load_test.c | H A D | 17-Dec-2021 | 844 | 38 | 31 | |
mon_processes_test.c | H A D | 17-Dec-2021 | 4.3 KiB | 160 | 130 | |
mustache_test.c | H A D | 17-Dec-2021 | 3 KiB | 105 | 85 | |
new_packages_promise_test.c | H A D | 17-Dec-2021 | 2.7 KiB | 90 | 63 | |
nfs_test.c | H A D | 17-Dec-2021 | 2.3 KiB | 47 | 37 | |
package_versions_compare_test.c | H A D | 17-Dec-2021 | 9.1 KiB | 325 | 268 | |
parsemode_test.c | H A D | 17-Dec-2021 | 1.5 KiB | 71 | 60 | |
parser_test.c | H A D | 17-Dec-2021 | 7.4 KiB | 274 | 221 | |
passopenfile_test.c | H A D | 17-Dec-2021 | 36.5 KiB | 1,412 | 1,129 | |
persistent_lock_test.c | H A D | 17-Dec-2021 | 827 | 46 | 32 | |
policy_server_test.c | H A D | 17-Dec-2021 | 5.9 KiB | 193 | 142 | |
policy_test.c | H A D | 17-Dec-2021 | 13.9 KiB | 490 | 385 | |
process_terminate_unix_test.c | H A D | 17-Dec-2021 | 6.9 KiB | 372 | 277 | |
process_test.c | H A D | 17-Dec-2021 | 7.3 KiB | 263 | 176 | |
protocol_test.c | H A D | 17-Dec-2021 | 14 KiB | 464 | 303 | |
redirection_test.c | H A D | 17-Dec-2021 | 2.3 KiB | 87 | 62 | |
redirection_test_stub.c | H A D | 17-Dec-2021 | 414 | 22 | 20 | |
regex_test.c | H A D | 17-Dec-2021 | 1.4 KiB | 59 | 48 | |
rlist_test.c | H A D | 17-Dec-2021 | 23.4 KiB | 889 | 713 | |
schema.h | H A D | 17-Dec-2021 | 6.3 KiB | 156 | 148 | |
scope_test.c | H A D | 17-Dec-2021 | 535 | 32 | 26 | |
set_domainname_test.c | H A D | 17-Dec-2021 | 2.2 KiB | 90 | 72 | |
solaris_process_test.c | H A D | 17-Dec-2021 | 3.8 KiB | 179 | 143 | |
sort_test.c | H A D | 17-Dec-2021 | 4 KiB | 159 | 109 | |
split_process_line_test.c | H A D | 17-Dec-2021 | 44.2 KiB | 921 | 731 | |
string_expressions_test.c | H A D | 17-Dec-2021 | 2.4 KiB | 91 | 77 | |
strlist_test.c | H A D | 17-Dec-2021 | 10.9 KiB | 295 | 207 | |
syntax_test.c | H A D | 17-Dec-2021 | 6.4 KiB | 186 | 146 | |
sysinfo_test.c | H A D | 17-Dec-2021 | 3 KiB | 120 | 106 | |
tar_portability_test.sh | H A D | 17-Dec-2021 | 180 | 14 | 7 | |
test.c | H A D | 17-Dec-2021 | 1.2 KiB | 66 | 51 | |
test.h | H A D | 17-Dec-2021 | 1.4 KiB | 59 | 36 | |
var_expressions_test.c | H A D | 17-Dec-2021 | 5.6 KiB | 203 | 181 | |
variable_test.c | H A D | 17-Dec-2021 | 11.5 KiB | 390 | 311 | |
verify_databases_test.c | H A D | 17-Dec-2021 | 2.2 KiB | 74 | 54 |
README
1How to add unit tests 2===================== 3 41. Make sure what you are trying to write is actually a unit test. A unit test 5 should execute in milliseconds. If you are testing functionality that e.g. requires 6 a generic agent to be set up, consider writing an acceptance test. 7 A unit test should test a small piece of code (a function) in isolation. 8 92. You typically want to test some function of a datastructure, e.g. CfAssoc. 10 Check to see if a test suite (e.g. assoc_test.c), exists already. If not, create 11 one. 12 13 2.1 (Optional) Creating a new test suite 14 15 Create a new file, e.g. mystruct_test.c, preferably by copying some existing 16 file so you get the boilerplate. 17 18 In Makefile.am, append mystruct_test to check_PROGRAMS, and add an automake 19 entry such as 20 21 mystruct_test_SOURCES = $(MOCKERY_SOURCES) mystruct_test.c 22 mystruct_test_LDADD = ../../libpromises/libpromises.la 23 24 253. We are using cmockery as our testing framework. Google for it and read/skim 26 their basic intro page. 27 284. Suppose you want to test your new ToString function for CfAssoc. In assoc_test.c, 29 you could do the following. 30 31 4.1 Write the test 32 33 static test_to_string(void **state) 34 { 35 /* assert some condition here */ 36 } 37 38 4.2 In the main function of assoc_test.c, add the test to the suite 39 40 int main() 41 { 42 const UnitTest tests[] = 43 { 44 unit_test(test_create_destroy), 45 unit_test(test_copy), 46 unit_test(test_to_string) 47 }; 48 49 return run_tests(tests); 50 } 51 52 535. Mocking. Suppose you want to test some function that calls a database, but you 54 don't want to deal with setting up and managing the state of the database. 55 Furthermore, you don't actually want to test the database in this test. 56 57 What you need to do is to stub out the function. For example, suppose your tested 58 function calls some DB_Insert("host123", 42); 59 60 A mock function is a dummy replacement function with NOOP functionality, so in this 61 case, in your test suite, you could add a 62 63 static int written_measure = -1; 64 65 static void DB_Insert(const char* key, int measure) 66 { 67 written_measure = measure; 68 } 69 70 Then, if later your function tries to retrieve it back, you could do 71 72 static int DB_Query(const char*key) 73 { 74 return written_measure; 75 } 76 77 Now, the key is to not have the test link towards the actual definition of 78 the function, so in Makefile.am, rather than linking against all of libpromises, 79 you probably want to be more specific, for example 80 81 str_test_SOURCES = $(MOCKERY_SOURCES) str_test.c ../../libpromises/string_lib.c 82 str_test_LDADD = ../../libcompat/libcompat.la 83 84 Finally, if you made some mocking functions and you think it will be useful to 85 other tests later, consider extracting them in a separate file, e.g. db_mock.c. 86 876. Memory checking. We don't really care about the quality of code in the unit tests, 88 but we do care that the code tested is not leaking memory. So it's important 89 to free everything you allocate in the test code. Then, to check to see if your 90 code leaks, you can run 91 92 valgrind --leak-check=yes .libs/lt-mystruct_test 93 94 Valgrind can do stuff beyond simple leak checking, so learning about it could 95 be a worthwhile investment. 96