• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..17-Dec-2021-

data/H03-May-2022-1,5931,453

Makefile.amH A D17-Dec-202112.7 KiB428315

READMEH A D17-Dec-20213.3 KiB9667

addr_lib_test.cH A D17-Dec-20215.2 KiB157117

aix_process_test.cH A D17-Dec-20213.5 KiB145111

arg_split_test.cH A D17-Dec-20216.1 KiB235173

assoc_test.cH A D17-Dec-2021351 2116

avahi_config_test.cH A D17-Dec-20211.6 KiB6251

cf_upgrade_test.cH A D17-Dec-20214.6 KiB10393

changes_migration_test.cH A D17-Dec-20216 KiB200144

class_test.cH A D17-Dec-20213.5 KiB122105

cmockery.cH A D17-Dec-202170.8 KiB2,0721,604

cmockery.hH A D17-Dec-202121.6 KiB477280

connection_management_test.cH A D17-Dec-20214.6 KiB15295

conversion_test.cH A D17-Dec-20217.3 KiB218162

crypto_symmetric_test.cH A D17-Dec-20213.4 KiB11584

db_concurrent_test.cH A D17-Dec-20213.2 KiB14898

db_stubs.cH A D17-Dec-20211 KiB315

db_test.cH A D17-Dec-20216.7 KiB259183

domainname_test.cH A D17-Dec-20213.4 KiB11491

dynamic_dependency_test.shH A D17-Dec-20213 KiB8439

enterprise_extension_test.cH A D17-Dec-20212.2 KiB7853

enterprise_extension_test_lib.cH A D17-Dec-2021993 3527

eval_context_test.cH A D17-Dec-20213.9 KiB145102

evalfunction_test.cH A D17-Dec-20213.7 KiB136113

exec-config-test.cH A D17-Dec-20216 KiB173134

expand_test.cH A D17-Dec-202118.8 KiB601486

file_name_test.cH A D17-Dec-20218.6 KiB325252

files_copy_test.cH A D17-Dec-202115 KiB564379

files_interfaces_test.cH A D17-Dec-20212.5 KiB11388

files_lib_test.cH A D17-Dec-20214.1 KiB130104

findhub_test.cH A D17-Dec-20218.3 KiB318256

gcov-stub.cH A D17-Dec-2021868 5134

generic_agent_test.cH A D17-Dec-20215.5 KiB163118

granules_test.cH A D17-Dec-20212.1 KiB6444

init_script_test.shH A D17-Dec-202116 KiB378269

init_script_test_helper.cH A D17-Dec-20215.5 KiB207149

item_lib_test.cH A D17-Dec-20211.6 KiB5539

item_test.cH A D17-Dec-202111.9 KiB390308

iteration_test.cH A D17-Dec-202114.4 KiB367276

key_test.cH A D17-Dec-20212.6 KiB10585

lastseen_migration_test.cH A D17-Dec-20216.4 KiB287199

lastseen_test.cH A D17-Dec-202118.9 KiB684400

linux_process_test.cH A D17-Dec-20213.7 KiB169141

logging_test.cH A D17-Dec-20213.6 KiB11690

matching_test.cH A D17-Dec-20211.4 KiB4841

mon_cpu_test.cH A D17-Dec-20211.8 KiB8772

mon_load_test.cH A D17-Dec-2021844 3831

mon_processes_test.cH A D17-Dec-20214.3 KiB160130

mustache_test.cH A D17-Dec-20213 KiB10585

new_packages_promise_test.cH A D17-Dec-20212.7 KiB9063

nfs_test.cH A D17-Dec-20212.3 KiB4737

package_versions_compare_test.cH A D17-Dec-20219.1 KiB325268

parsemode_test.cH A D17-Dec-20211.5 KiB7160

parser_test.cH A D17-Dec-20217.4 KiB274221

passopenfile_test.cH A D17-Dec-202136.5 KiB1,4121,129

persistent_lock_test.cH A D17-Dec-2021827 4632

policy_server_test.cH A D17-Dec-20215.9 KiB193142

policy_test.cH A D17-Dec-202113.9 KiB490385

process_terminate_unix_test.cH A D17-Dec-20216.9 KiB372277

process_test.cH A D17-Dec-20217.3 KiB263176

protocol_test.cH A D17-Dec-202114 KiB464303

redirection_test.cH A D17-Dec-20212.3 KiB8762

redirection_test_stub.cH A D17-Dec-2021414 2220

regex_test.cH A D17-Dec-20211.4 KiB5948

rlist_test.cH A D17-Dec-202123.4 KiB889713

schema.hH A D17-Dec-20216.3 KiB156148

scope_test.cH A D17-Dec-2021535 3226

set_domainname_test.cH A D17-Dec-20212.2 KiB9072

solaris_process_test.cH A D17-Dec-20213.8 KiB179143

sort_test.cH A D17-Dec-20214 KiB159109

split_process_line_test.cH A D17-Dec-202144.2 KiB921731

string_expressions_test.cH A D17-Dec-20212.4 KiB9177

strlist_test.cH A D17-Dec-202110.9 KiB295207

syntax_test.cH A D17-Dec-20216.4 KiB186146

sysinfo_test.cH A D17-Dec-20213 KiB120106

tar_portability_test.shH A D17-Dec-2021180 147

test.cH A D17-Dec-20211.2 KiB6651

test.hH A D17-Dec-20211.4 KiB5936

var_expressions_test.cH A D17-Dec-20215.6 KiB203181

variable_test.cH A D17-Dec-202111.5 KiB390311

verify_databases_test.cH A D17-Dec-20212.2 KiB7454

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