r4 - 2010-07-25 - 15:44:34 - LinusKarlssonYou are here: NTP >  Dev Web > GoogleSummerOfCode > GSoC2010UnitTesting > NtpdFunctionMap
NTP users are strongly urged to take immediate action to ensure that their NTP daemons are not susceptible to being used in distributed denial-of-service (DDoS) attacks. Please also take this opportunity to defeat denial-of-service attacks by implementing Ingress and Egress filtering through BCP38.

ntp-4.2.8p13 was released on 07 March 2019. It addresses 1 medium-severity security issue in ntpd, and provides 17 non-security bugfixes and 1 other improvements over 4.2.8p12.

Please see the NTP Security Notice for vulnerability and mitigation details.

Are you using Autokey in production? If so, please contact Harlan - he's got some questions for you.

Ntpd Function Map

This page contains testing notes about ntpd. For every function I have a list of functions it calls. This is important since we don't want tests for a function to depend on others.

libntpd

ntp_control.c

  • init_control(): ctl_clr_stats()
    Initializes variables. Could check that the number of events are reset, and that there are no last event recorded.
  • ctl_error(): authencrypt(), sendpkt()
    Test that the sent error packet looks correct, for different errcodes. Also, packet should look different if authenticated NTP is used or not.
  • save_config(): ctl_putdata(), ctl_flushpkt(), time(), localtime(), strftime(), open(), fdopen(), dump_all_config_trees(), set_sys_var(), fclose()
    Test that saving is prohibited if nomodify flag is set, or if no saveconfig dir is set. Test that a filename with path separator ( / or \ ) is rejected. Test that the written filename can be retrieved as a system variable (rv 0 savedconfig)
  • process_control(): ctl_error(), authistrusted(), authdecrypt()
    Test that a packet with illegal version is rejected. Verify that a opcode requiring authentication only calls the cc-handler if authentication is ok. Test that an invalid opcode gives an error.
  • ctlpeerstatus():
    Test various combinations of flags, and see that the returned status matches.
  • ctlclkstatus():
    (#ifdef REFCLOCK) Test that returned status matches a the lastevent and current status of the sent in refclock.
  • ctlsysstatus():
    A status word containing the current clock sync'd to, the number of events an the last event. Could be tested when we know the value of these static variables, e.g after a init_control() call.
  • ctl_flushpkt(): sendpkt(), authencrypt()
    Test that the sent packet is padded to 32-bit multiple. I am not sure how async works, it should probably be tested though.. Test that an authenticated packet looks correct, and also test that a regular packet looks ok.
  • ctl_putdata(): ctl_flushpkt()
    Test with both non-binary and binary data. Test that ascii-data are "padded" with \r\n when exceeding MAXDATALINELEN. Ensure that binary data are not padded. If the data cannot be fit in the current package, flush it and put it in a new one. Test by filling a "current" package with junk, then try to put some new data in it (that's too large).
  • ctl_putstr(): ctl_putdata()
    Fake ctl_putdata(), and check that the generated buffer is correct. Test standard => tag="data" Test empty data => tag
  • ctl_putunqstr(): ctl_putdata()
    Exactly like ctl_putstr(), but without the quotes.
  • ctl_putdbl(): ctl_putdata()
    Test with both positive and negative double, should get something like tag=0.123 (three decimal places).
  • ctl_putuint(): ctl_putdata()
    Test with single unsigned long, tag=123
  • ctl_putfs(): ctl_putdata(), gmtime()
    Test that a timestamp is returned on the form: tag=201007082354, for 2010-07-08 23:54Z
  • ctl_puthex(): ctl_putdata()
    Test that a u_long is printed in hex.
  • ctl_putint(): ctl_putdata()
    Test both with positive and negative ints.
  • ctl_putts(): ctl_putdata()
    Test with a l_fp value, just print it out like tag=12341234.12341234 (in hex)
  • ctl_putadr(): ctl_putdata()
    Test both with addr set to NULL, and to a real sockaddr_u. If addr = NULL, the string should just be the IP-addr in regular format (tag=192.0.2.1). If addr NULL, the whole socket should be converted into a string with ntoa().
  • ctl_putid(): ctl_putdata()
    Prints a tag like tag=abcd, but with maxiumum 4 chars as data. Test both with <4 chars, and with >4 chars.
  • ctl_putarray(): ctl_putdata()
    Test with different starting points.
  • ctl_putsys(): ctl_putuint(), ctl_putint(), ctl_putdbl(), ctl_putdata(), and other ctl_put*()
    Test with different varid (there are a lot). Most of them only calls ctl_putuint() The most interesting one is CS_VARLIST. Test this by having a variable amount of system variables, and check that the output is something like tag="var1,var2,var3"
  • ctl_putpeer(): ctl_put*(), EVP_get_digestbynid(), OBJ_nid2ln()
    Test like ctl_putsys(), again, CP_VARLIST is the interesting one.
  • ctl_putclock(): ctl_put*()
    See ctl_putpeer(), ctl_putsys()
  • ctl_getitem(): ctl_error()
    Test with both empty tags, and tags with data (tag and tag=data). Also test multiple data items.
  • control_unspec(): findpeerbyassoc(), ctl_error(), ctlpeerstatus(), ctlsysstatus(), ctl_flushpkt()
    Test that an error is returned if the there is a association, but no corresponding peer.
  • read_status(): findpeerbyassoc(), ctl_error(), ctl_putpeer(), ctl_flushpkt(), ctlpeerstatus(), ctl_putdata()
    Test both that case where we should return a specific peer's status, and the case where we should return all peer's statuses.
  • read_peervars(): findpeerbyassoc(), ctl_error(), ctl_getitem(), ctl_putpeer(), ctl_flushpkt()
    Test that the generated packet works for peers with no, one, and many variables.
  • read_sysvars(): ctlsysstatus(), ctl_getitem(), ctl_error(), ctl_putsys(), ctl_putdata(), ctl_flushpkt()
    Test both none, single and multiple requested sys. vars.
  • read_variables(): read_peervars(), read_sysvars()
    Just a wrapper
  • write_variables(): ctl_error(), ctl_getitem(), set_sys_var(), ctl_flushpkt()
    Test that writing to a peer is always refused. Test
  • configure(): ctl_error(), ctl_putdata(), ctl_flushpkt(), config_remotely()
    Test that configuration is rejected if nomodify is set. Calls config_remotely() to do the rest of the work.
  • derive_nonce(): ntp_random(), EVP_Digest_Init(), EVP_DigestUpdate(), EVP_DigestFinal()
    Test that a correct nonce is generated (salt should be predefined to avoid ntp_random())
  • generate_nonce(): derive_nonce()
    Test that generated nonce is outputted to nonce. Tests for this function should most likely be combined with derive_nonce().
  • validate_nonce(): derive_nonce(), get_systime()
    Take the current system time, test that the generated nonce is validated ok. Test that if the time diff is >15 seconds, the validation will fail.
  • send_mru_entry(): ntp_random(), ctl_putunqstr(), ctl_putts(), ctl_putint(), ctl_putuint(), ctl_puthex()
    Entries are send in random order, so tests would have to fake ntp_random(). Apart from that, just see that the packet generated contains the values in mon.
  • send_random_tag_value(): ntp_random(), ctl_putuint()
    Need to fake ntp_random(). Test that generated string is on form: aaa.5=1234;
  • read_mru_list(): set_var(), ctl_getitem(), decodenetnum(), getinterface(), free_varlist(), validate_nonce(), ctl_error(), ctl_putts(), ctl_putunqstr(), get_systime(), generate_nounce(), send_mru_entry(), send_random_tag_value(), ctl_flushpkt()
  • send_ifstats_entry(): ntp_random(), ctl_putunqstr(), ctl_putint(), ctl_putstr(), ctl_puthex(), ctl_putuint(), send_random_tag_value()
    Sends 12 variables from the struct interface argument. Tests needs to fake ntp_random() so that entries are added in a determined order.
  • read_ifstats(): send_ifstats_entry(), ctl_flushpkt()
    Calls send_ifstats_entry() for every interface, then calls ctl_flushpkt(). Test that every interface is sent.
  • req_nonce(): generate_nonce(), ctl_putunqstr(), ctl_flushpkt()
    Test that a packet with a nonce= is generated.
  • read_clockstatus(): ctl_error(), findpeerbyassoc(), refclock_control(), ctl_getitem(), free_varlist(), ctl_putclock(), ctl_putdata(), ctl_flushpkt()
    Test that only clock peers are returned, by having a peer list with no refclocks. The sent packet should be a "CERR_BADASSOC".
  • write_clockstatus(): ctl_error()
    Always fail with CERR_PERMISSION.
  • set_trap(): ctl_error(), ctlsettrap(), ctl_flushpkt()
    Test that configuration is rejected if notrap is set. If ctlsettrap() fails, a CERR_NORESOURCE packet should be sent.
  • unset_trap(): ctlclrtrap(), ctl_error(), ctl_flushpkt()
    Not sure about what RES_LPTRAP means. If ctlclrtrap() fails, a CERR_BADASSOC packet should be sent.
  • ctlsettrap(): ctlfindtrap()
    Test that an already existing trap gets updated. Test that old traps (INUSE && CONFIGURED && time expired) are cleared out (when adding a new trap) Test that a new trap is added if there's place. Test that function returns 0 if full.
  • ctlclrtrap(): ctlfindtrap()
    Test that function returns 0 if it's not found.
  • ctlfindtrap():
    Test that an existing trap is found, and if no such trap exist, NULL is returned.
  • report_event(): ctlsysstatus(), eventstr(), refnumtoa(), stlpeerstatus(), eventstr(), record_proto_stats(), ctl_putsys(), ctl_putpeer(), refclock_control(), ctl_puthex(), ctlclkstatus(), ctl_putclock(), ctl_putdata(), free_varlist(), ctl_flushpkt()
    Test that if the last CTL_SYS_MAXEVENTS have been the same error type, the event should be ignored. If the peer argument is NULL, the sysstatus should be sent, instead of peerstatus.
  • ctl_clr_stats():
    Just sets a bunch of variables to zero. ctltimereset is set to the current time.
  • count_var():
    Returns the number of variables in a ctl_var* chain. Test that i works for an empty (NULL) list.
  • add_var(): count_var()
    Test that a new ctl_var is added to the end of the chain, with no modification to the other vars. Also check that the terminating {0, NULL, EOV} is in place.
  • set_var(): add_var()
    Test that an already existing variable, with defined data can be changed (both if the current data length is smaller or larger than the new length). Test that an already existing variable, without data (NULL) can get new data. Test that a non-existant variable gets added.
  • set_sys_var(): set_var()
    Only calls set_var() with a predefined ctl_var*-list
  • free_varlist():
    Should test that all memory is freed, all variables + their data. Not sure how to check this though.

ntp_crypto.c

  • session_key(): EVP_* calls, MD5auth_setkey(), authtrust()
    Test that the generated hash fulfils the description in function comment (hash of source addr, destination addr keyID and a private value.) Test that the returned keyid is the four first bytes of this MD5 hash. Test that the key is stored in authkeys, if the supplied lifetime > 0.
  • make_keylist(): crypto_time(), ntp_random(), authhavekey(), session_key(), auth_havekey(), EVP_* functions.
    Test that a list with size <= NTP_MAXSESSION is generated. And that all keys in this list is unique. Test that if the peer is in broadcast mode (peer->hmode == MODE_BROADCAST), the generated session should be based on zero (0) as private value. Test that the last generated keyid is saved in the peer->sndval struct.
  • crypto_recv(): EVP_get_digestbynid(), RAND_bytes(), OBJ_nid2ln(), record_crypto_stats(), crypto_verify(), cert_install(), cert_hike(), d2i_X509(), X509_free(), X509_get_pubkey(), crypto_iff(), crypto_gq(), crypto_mv(), EVP_PKEY_size(), crypto_update(), report_event()
  • crypto_xmit(): crypto_time(), crypto_send(), crypto_alice(), crypto_bob(), crypto_alice2(), crypto_bob2(), crypto_alice3(), crypto_bob3(), cert_sign(), value_free(), crypto_encrypt(), findpeerbyassoc()
  • crypto_verify(): EVP_VerifyInit(), EVP_VerifyUpdate(), EVP_VerifyFinal(), EVP_PKEY_size()
    Test the error cases, that would be: protocol, length, timestamp and filestamp.
  • crypto_encrypt(): d2i_PublicKey(), ERR_error_string(), ERR_get_error(), RSA_public_encrypt(), EVP_PKEY_free(), EVP_SignInit(), EVP_SignUpdate(), EVP_SignFinal()
    Test that an invalid package (without public key) will yield a XEVNT_PUB. Test that a timestamp of 0 will bypass the signing
  • crypto_ident(): crypto_key()
    Test by passing a peer with different crypto flags set. Test that a peer with no crypto flags returns CRYPTO_NULL.
  • crypto_args(): crypto_time()
    Test by sending in the known peer, opcode, associd and (optional) a string. Verify that the extension returned looks ok. Depends on the current timestamp. Don't forget to free the returned structure.
  • crypto_send():
    Test that the value is padded correctly with zeroes, that the timestamps are copied from value to extension pointer.
  • crypto_update(): crypto_time(), EVP_Sign*(), record_crypto_stats()
    The hostval should get a new timestamp, the public key should get a new signature. All certifications in the cinfo chain should get new signatures.
  • value_free():
    free:s and zeroes everything in the supplied vp pointer..
  • crypto_time(): get_systime()
    Test that function returns zero if time is not synchronized.
  • asn2ntp(): timegm()
    Test by sending a ASN.1 structure in, and expect a ntp-time-u_long out.
  • bighash(): EVP_bn2bin(), EVP_bin2bn, EVP_Digest*()
    Test that the generated BIGNUM is a MD5-hash.
  • Implementation of the various crypto algorithm follows. They should also be tested, preferably by someone who knows how they work.

ntp_data_structures.c

  • debug_create_priority_queue():
    Not sure if debug functions should be tested, anyhow, test by checking that front of queue is null, and the number of elements is zero.
  • destroy_queue():
    Should free all items in the queue. Not sure how to check if memory is freed though.
  • debug_get_node():
    Creates a new empty node, together with an extra byte.. Test that node_next is NULL.
  • free_node():
    Verify that the memory (including the extra bookkeeping byte is freed).
  • next_node():
    Test that the function returns a pointer the next node in a list (or NULL if there are no more nodes).
  • empty():
    Test that a NULL pointer aswell as a queue with no front element is empty.
  • queue_head():
    Test that it returns the front element, or NULL if the queue is empty or NULL.
  • enqueue():
    Test that the item is placed correcly with regard to the priority function of the queue. Test with empty, single and multiple items in the queue. Ensure that the element count is incresed.
  • dequeue():
    Test that the first element is removed (if there is such an element). Return the removed element, or NULL if there were no element left.
  • get_no_of_element():
    Just returns the no_of_elements field of the queue.
  • append_queue():
    Test with two different queues, and ensure that they get merged correctly with a real priority function.

ntp_filegen.c

  • filegen_init():
    Just sets initial values.
  • filegen_uninit():
    Frees basename in FILEGEN struct.
  • filegen_open(): caljulian(), stat(), rename(), unlink(), delete(), fopen(), fclose(), SetLastError()
    Test that the generated filename is OK (there are several options, like pid, day, month, year, age, week). Test that if such file already exists, it should be removed. And then a new file should be created.
  • filegen_setup(): fclose(), getpid(), caljulian(), caltontp(), calyearstart(), filegen_open()
    Generates an integer depending on what filename to generate in filegen_open() (pid, day and so on). Calls filegen_open with this. Tests for this function should probably be merge with filegen_open().
  • filegen_config(): valid_fileref(), fclose(), get_systime(), filegen_setup()
    Test that a invalid basename (e.g contains path sep.) is rejected. Test that FILEGEN is updated even if the file is currently opened.
  • valid_fileref():
    Test that an empty prefix is rejected. Test that an undefined basename is rejected. Test that basenames containing ".." are rejected.
  • filegen_get():
    Test that a FILEGEN with the name is returned if it exists (otherwise return null)
  • filegen_register(): filegen_init()
    Adds a new filegen to the list, test that an already existing item is overwritten. Test that a new item is added to the end.
  • filegen_unregister(): filegen_uninit()
    Test that an existing item is unlinked from the list.

ntp_intres.c

  • Threads + name resolution. I'm not sure how to test either of them...

ntp_loopfilter.c

  • init_loopfilter():
    Just an init function.
  • local_clock(): record_loop_stats(), report_event(), step_systime(), adj_systime(), record_loop_stats(), direct_freq(), reinit_timer(), rstclock(), ntp_adjtime(), poll_update()
    Ajusts the local clock in about 300 lines of code...
  • adj_host_clock(): adj_systime()
    Test that clock is not adjusted if ntp is not enabled, or if in ntpdate mode.
  • rstclock(): report_event()
    Don't know.
  • direct_freq(): ntp_adjtime(), set_freq()
    Don't know.
  • set_freq(): ntp_adjtime(), report_event()
    Not much to test i think.
  • huffpuff():
    Some sort of filter, not sure how it works. I think it can be tested quite easily though.
  • loop_config(): sigaction(), ntp_adjtime(), sigsetjmp(), report_event(), set_freq(), rstclock()
    Not sure.
  • pll_trap(): siglongjmp()
    Nothing to test.

ntp_monitor.c

  • init_mon():
  • remove_from_hash(): UNLINK_SLIST()
    Test that the supplied entry is removed from the mru_list.
  • mon_free_entry(): LINK_SLIST()
    Check that the entry is added to the list of free entries, and that it's zeroed out.
  • mon_reclaim_entry(): UNLINK_DLIST()
    Test that the entry is removed from mru list and hash map.
  • mon_getmoremem():
    Test that the number of free entries are increased by mry_incalloc.
  • mon_start(): mon_getmoremem()
    Allocates memory.. Not much to test.
  • mon_stop(): ITER_DLIST_BEGIN(), ITER_DLIST_END(), INIT_DLIST()
    Sets the status to MON_OFF, and adds free entries to free list.
  • mon_clearinterface(): ITER_DLIST_BEGIN(), ITER_DLIST_END()
    Test that all elements matching lcladr is removed from hash list and mru list.
  • ntp_monitor(): UNLINK_DLIST(), LINK_DLIST(), UNLINK_HEAD_SLIST(), TAIL_DLIST(), mon_getmoremem(), mon_reclaim_entry(), ntp_random(), LINK_SLIST()
    Test that the newly updated/added entry gets to the top in the MRU list. Test that statistics are update if an entry already exists.

ntp_peer.c

  • init_peer(): LINK_SLIST(), ntp_random()
    Initialization routine.
  • getmorepeermem(): LINK_SLIST()
    Test that INC_PEER_ALLOC new items are put in peer_free list.
  • findexistingpeer_name():
  • findexistingpeer_addr():
  • findexistingpeer():
    Test finding a peer, both by using the standard peer_list, and by supplying a node to start_peer. findexistingpeer() is the public function, the other two can be exercised through this.
  • findpeer(): set_peerdstadr()
    Test finding a peer i hash table. Try to both a single entry, multiple entries, and multiple different entries that collides in the hash table. Test that no invalid peer combination is accepted as a match.
  • findpeerbyassoc():
    Returns the peer if it's association id is in the table, otherwise null.
  • clear_all(): peer_clear()
    Test that only peers with MDF_TXONLY_MASK flag not set are cleared.
  • score_all(): score()
    Finds the minimum score in the peer list and returns it.
  • score():
    Test that few error bits yields a better score.
  • free_peer(): LINK_SLIST(), UNLINK_SLIST()
    Test that the freed peer is added to the peer_free list. Test that the peer is unlinked from the hash list and peer list (if argument is true)
  • unpeer(): report_event(), restrict_source(), set_peerdstadr(), refclock_unpeer(), free_peer()
    Is public, should probably be merged with tests for free_peer()
  • peer_config(): newpeer()
    Test that broadcast is converted to the correct flags (broadcast/multicast)
  • set_peerdstadr(): UNLINK_SLIST(), LINK_SLIST()
    Test overwriting an already set dstadr, setting a new dstadr, and removing a current dstaddr. Ensure that dstaddr->peers are updated accordingly.
  • peer_refresh_interface(): select_peerinterface(), set_peerdstadr(), peer_clear(), enable_broadcast(), enable_multicast_if()
    Selects an interface with select_peerinterface(), then updates the peers dstadr.
  • refresh_all_peerinterfaces(): peer_refresh_interface()
    Only calls peer_refresh_interface() on every item in peer_list.
  • select_peerinterface(): findbcastinter(), findinterface()
    Test that refclock address gets the loopback interface.
  • newpeer(): findexistingpeer(), findinterface(), UNLINK_HEAD_SLIST(), set_peerdstadr(), select_peerinterface(), enable_broadcast(), enable_multicast_if(), free_peer(), LINK_SLIST(), restrict_source(), report_event()
    Test that duplicates are rejected.
  • peer_clr_stats():
    Nothing to test.
  • peer_reset():
    Sets peer variables to zero..
  • peer_all_reset(): peer_reset()
    Just a loop.
  • findmanycastpeer(): Don't know.

ntp_proto.c

Also read the NTP specification for those functions that a section is mentioned in the function comment. Might give tips of what to test.

  • transmit(): peer_xmit(), poll_update(), clock_filter(), peer_unfit(), report_event(), peer_clear(), unpeer(), score_all()
  • receive(): restrictions(), process_private(), process_control(), ntp_random(), fast_xmit(), findpeer(), session_key(), authdecrypt(), findmanycastpeer(), newpeer(), report_event(), unpeer(), peer_clear(), poll_update(), crypto_recv(), process_packet()
    Phew, a function with 1017 lines.
  • process_packet(): record_raw_stats(), poll_update(), report_event(), clock_filter()
    Test that the packet is discarded if the peer is not synced (or stratum is not in wanted range).
  • clock_update(): poll_update(), addr2refid(), local_clock(), smf_maintain_instance(), scf_strerror(), clear_all(), crypto_update(), get_systime(), report_event(), leap_month()
    Test that sys_poll is set correctly when peer:s polling interval is changing. Test that ntpd is killed if clock is too much out of sync.
  • poll_update(): key_expire()
    Test that peer->nextdate is set to the (correct) next update time.
  • peer_clear(): key_expire(), value_free(), ntp_random()
    Check section 3.4.8 of ntp spec.. Not sure what this does.
  • clock_filter(): report_event(), record_peer_stats(), clock_select()
    Test that the sample is added to the shift register in peer->filter_* I'm not sure about the rest of the function.
  • clock_select(): peer_unfit(), addr2refid(), root_distance(), ntoa(), clock_combine(), report_event(), clock_update()
    Test with a selection of faked peer, and test that the correct choice is made between them.
  • clock_combine():
    Test that the value set to sys_offset and sys_jitter is correct (first analyze the algortithm though..)
  • root_distance():
    Test that the returned value is always >= to sys_mindisp.
  • peer_xmit(): get_systime(), sendpkt(), stoa(), make_keylist(), authistrusted(), key_expire(), crypto_args(), crypto_ident(), crypto_xmit(), session_key(), authencrypt(), report_event(), authtrust()
    Don't know..
  • fast_xmit(): send_via_ntp_signd(), sendpkt(), session_key(), get_systime(), authencrypt(), authtrust()
    Don't know..
  • pool_xmit(): getaddrinfo_sometime(), findexistingpeer(), restrictions(), restrict_source(), findinterface(), get_systime(), sendpkt()
    These *_xmit functions are tricky...
  • pool_name_resolved(): findpeerbyassoc(), copy_addrinfo_list(), pool_xmit()
    Test that a rescode = 0 is a failure.. Test that an unknown association generates failure.
  • key_expire(): authtrust(), value_free()
    Test that all keys in peer are marked as untrusted, and remved from peer.keylist.
  • peer_unfit():
    Test that function returns TRUE if any of the conditions stated in the code applies.
  • default_get_precision(): get_systime()
    Not sure what this does.
  • init_proto(): get_systime(), proto_clr_stats()
    Just an init function.
  • proto_config(): io_unsetbclient(), io_setbclient(), mon_start(), mon_stop(), io_multicast_add(), io_multicast_del()
    Could be tested with one test for each configuration variable, check initial value -> proto_config() -> check that the appropriate global var has changed.
  • proto_clr_stats():
    Sets a bunch of variables to zero.

ntp_request.c

  • init_request():
    Sets a bunch of variables to zero. Shouldn't need to be tested.
  • req_ack(): sendpkt()
    Test that the packet sent to sendpkt() has the correct request id, mode, size etc. Uses a static variable, "rkpt", to hold the data, could be an alternative to fake sendpkt() call for testing?
  • prepare_pkt():
    Sets some static variables to differnt values, to test this it would be required to access these static vars. The returned pointer might be used to do some ugly pointer arithmetics to gain access to the rest of the variables though.. * more_pkt():
  • flush_pkt(): req_ack(), sendpkt()
    Don't know
  • get_packet_mode():
    Test that rm_vn_mode of the sent-in data chunk is returned.
  • process_private(): req_ack(), authdecrypt(), authhavekey()
    Test that the if any of the santity checks fail, the function will return. Test that ACKs are sent with error codes, if eg. the request code is unknown. Also test that an invalid authenticated package doesn't pass through. Test that proc->handler is called with correct arguments.
  • list_peers(): prepare_pkt(), v6sizeof(), more_pkt(), flush_pkt()
    Test that IPv6-peers are ignored if the other end does not handla ipv6 addresses.
  • list_peers_sum(): prepare_pkt(), more_pkt(), flush_pkt()
    See list_peers(). Test that the extended attrs actually are added.
  • peer_info(): prepare_pkt(), v6sizeof(), findexistingpeer(), more_pkt(), flush_pkt()
  • peer_stats(): prepare_pkt(), findexistingpeer(), more_pkt(), flush_pkt()
    Test that sending stats works for both one and many packages.
  • sys_info(): prepare_pkt(), more_pkt(), flush_pkt()
    Test that IPv6-capability works (if the other end does/does not have IPv6)
  • sys_stats(): prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet.
  • mem_stats(): prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet.
  • io_stats(): prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet.
  • timer_stats(): prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet.
  • loop_info(): prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet.
  • do_conf(): req_ack(), peer_config()
    Don't know. (Not sure how multiple items are stored in the packet)
  • do_unconf(): stoa(), findexistingpeer(), req_ack()
    Don't know. (Not sure how multiple items are stored in the packet)
  • set_sys_flag(): setclr_flags()
    Wrapper.
  • clr_sys_flag(): setclr_flags()
    Wrapper.
  • setclr_flags(): req_ack(), loop_config()
    Check that loop_config is called if kern_enabled changes during the call.
  • list_restrict4(): list_restrict4(), more_pkt()
    Test that the list indeed comes out in reverse order as the comments state. Make sure that v6_flag only is set if client is IPv6 compatible.
  • list_restrict6(): list_restrict6(), more_pkt()
    See list_restrict4().
  • list_restrict(): prepare_pkt(), list_restrict4(), list_restrict6(), flush_pkt()
    Test that everywith works with combination of IPv4 and IPv6 addresses.
  • do_resaddflags(): do_restrict()
    Wrapper
  • do_ressubflags(): do_restrict()
    Wrapper
  • do_unrestrict(): do_restrict()
    Wrapper
  • do_restrict(): req_ack(), hack_restrict()
    Test that only the NTPPORT flag may be set (should return otherwise).
  • mon_getlist(): req_ack()
    Wrap.
  • reset_stats(): req_ack()
    Test that the reset stats callbacks are called.
  • reset_peer(): findexistingpeer(), req_ack(), peer_reset()
    Test that reset is aborted if not every peer in the request is known.
  • do_key_reread(): rereadkeys(), req_ack()
    Wrapper
  • trust_key(): do_trustkey()
    Wrapper
  • untrust_key(): do_trustkey()
    Wrapper
  • do_trustkey(): authtrust()
    Check that every item are sent to authtrust().
  • get_auth_info(): prepare_pkt(), more_pkt(), flush_pkt()
    Adds statistic variables to packet.
  • reset_auth_stats():
    Sets some statistic variables to zero. Might be good to use in tests SetUp () function.
  • req_get_traps(): req_ack(), v6sizeof(), flush_pkt()
    Test that a INFO_ERR_NODATA is sent as return if there are no traps.
  • req_set_trap(): do_setclr_trap()
    Wrapper
  • req_clr_trap(): do_setclr_trap()
    Wrapper
  • do_setclr_trap(): req_ack(), findinterface(), ctlsettrap(), ctlclrtrap()
    Test that the function refuses more than one item at the same time.
  • set_request_keyid(): req_ack()
    Test that the function refuses more than one item at a time.
  • set_control_keyid(): req_ack()
    Test that the function refuses more than one item at a time.
  • get_ctl_stats(): prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet.
  • get_kernel_info(): req_ack(), prepare_pkt(), more_pkt(), flush_pkt()
    Simply puts some stats in the packet. Should send a INFO_ERR_NODATA if pll_control is false.
  • get_clock_info(): prepare_pkt(), findexistingpeer(), req_ack(), refclock_control(), free_varlist(), flush_pkt()
    Test that an error is sent back if the requested peer is not a refclock, or if it doesn't exist.
  • set_clock_fudge(): findexistingpeer(), req_ack(), refclock_control()
    Test that an error is sent back if the requested peer is not a refclock, or if it doesn't exist.
  • get_clkbug_info(): prepare_pkt(), findexistingpeer(), req_ack(), more_pkt(), flush_pkt()
    Test that an error is sent back if the requested peer is not a refclock, or if it doesn't exist.
  • fill_info_if_stats(): more_pkt()
    Simply puts some stats in the packet.
  • get_if_stats(): prepare_pkt(), interface_enumerate(), flush_pkt()
    Wrap
  • do_if_reload(): prepare_pkt(), interface_update(), flush_pkt()
    Wrapper.

ntp_restrict.c

  • init_restrict(): LINK_SLIST macros.
    Adds base entries matching all entries.
  • alloc_res4():
    alloc_res6(): UNLINK_HEAD_SLIST, LINK_SLIST.
    Should return a free structure if available, otherwise allocate new memory and append to the free list.
  • free_res(): UNLINK_SLIST, LINK_SLIST
    Should reset a structure, and put it in the list of free structures.
  • inc_res_limited(): mon_start()
    Should call mon_start() if ref. count is > 0.
  • dec_res_limited(): mon_stop()
    Should call mon_stop if ref. count is 0.
  • match_restrict4_addr(): match_restrict6_addr(): free_res()
    Should return the closest matching mask, test with IPv4 and IPv6 adresses. Check that every addresses gets a match, there shall be a 0.0.0.0 that are the default restrictions.
  • match_restrict_entry():
    Should only return an exact match (in terms of addr, mask and flags). Test that equal items are found and returned, and that NULL is returned otherwise.
  • res_sorts_before4():
  • res_sorts_before6(): ADDR6_CMP (for IPv6 version)
    Returns true if r1 should be before r2 in a sorted list. Test with IPv4 and IPv6 addresses, and verify that sorting is done correctly (compare first addresses, if equal compare their masks, and last flags).
  • restrictions(): match_restrict4_addr(), match_restrict6_addr()
    Test that default restrictions apply, that stored rules are matched, and that multicast sources are ignored.
  • hack_restrict(): match_restrict_entry(), alloc_res6(), alloc_res4(), LINK_SORT_SLIST(), inc_res_limited(), dec_res_limited(), free_res()
    Test adding flags to already existing entries, and adding new entries. Test remove flags from existing entries (both in case where flag is set, and when it's not set). Also test removal of an entry completely.
  • restrict_source(): hack_restrict(), match_restrict{4,6}_addr(), free_res()
    Test by sending in a real address, and check that restrictions apply, and then remove it again.

ntp_signd.c

  • ux_socket_connect(): socket(), connect(), close()
    Connects to socket given a name, returns file descriptor. Does not know how to test.
  • write_all(): write()
    Writes data with write(), until write() fails or has sent everything. Test that the the total amount of data written is correct when everything should be correct...
  • read_all(): read()
    Reads until the given length is read, or when a failure occurs.

  • send_packet(): write_all()
    Returns 0 if a packet was sent, -1 otherwise. Only call write_all really..
  • recv_packet(): read_all()
    Calls read_all to read from socket.

  • send_via_ntp_signd(): ux_socket_connect(), send_packet(), recv_packet(), sendpkt(), close()
    Sends a package to Samba, test that the send in package is sent to the socket, and that the reply is received and stored.

ntp_timer.c

  • reinit_timer(): timer_gettime(), timer_settime(), getitimer(), setitimer().
  • init_timer(): timer_create(), timer_settime(), setitimer(), lib$emul(), sys$gettim(), lib$addx(), sys$setimr(), CreateWaitableTimer(), SetWaitableTimer()
    init functions that initializes the timers, calls different init functions depending on platform. Don't know how to test.
  • get_timer_handle():
    Only on Windows, just returns a handle.
  • timer(): adj_host_clock(), refclock_timer(), refclock_transmit(), transmit(), step_systime(), report_event(), huffpuff(), auth_agekeys(), timer_interfacetimeout(), interface_update(), write_stats(), get_systime()
  • alarming(): lib$addx(), sys$setimr()
    Sets the alarm_flag variable, check so that it's set after calling it (and still set when calling it again).
  • timer_interfacetimeout():
    Just sets a variable.
  • timer_clr_stats():
    Sets a couple of variables to defaults.

ntp_util.c

  • init_util(): filegen_register()
    Check that variables are initialized correctly (peerstats, and similar).
  • write_stats(): getpriority(), setpriority(), getclock(), ntp_set_tod(), record_sys_stats(), fopen(), _unlink(), rename(), lib$delete_file()
    Writes the drift file
  • stats_config(): ExpandEnvironmentStrings(), fopen(), fclose()
    Test the different cases, read from drift file, change of stat directory (test with/without trailing dir. separator), read from {PID,leapsecond} file.
  • record_peer_stats():
    record_loop_stats():
    record_clock_stats():
    record_raw_stats():
    record_sys_stats():
    record_proto_stats():
    record_crypto_stats():
    record_timing_stats(): get_systime(), filegen_setup()
    Test that file is written with some fake data, also test that no file is written when stats_control is false.
  • leap_file(): fgets()
    Reads from file, test that comment lines are ignored. Test that function returns non-zero if file is invalid (does not contain any leapsecs)
  • leap_month():
    Testable! Test both in leap year, and in non-leap year.
  • getauthkeys(): ExpandEnvironmentStrings(), authreadkeys()
    Only a wrapper for authreadkeys() which should be tested in libntp.
  • rereadkeys(): authreadkeys()
    Calls authreadkeys(), if filename is not empty.
  • fstostr(): gmtime()
    Test that a given timestamp is formatted correctly (function uses UTC)
  • ntpd_time_stepped(): mon_stop(), mon_start(), win_time_stepped()
    Check that the MRU list are emptied.

ntp_worker.c

This, just like ntp_intres.c, has to do with threading. I'm not sure how to test any of this.

  • queue_blocking_request(): send_blocking_req_internal()
  • queue_blocking_response(): send_blocking_resp_internal()
  • process_blocking_response(): receive_blocking_resp_internal()
  • blocking_child_common(): receive_blocking_req_internal(), blocking_getaddrinfo(), blocking_getnameinfo()

work_fork.c

  • exit_worker(): fflush()
  • worker_sighup():
    Just a setter. Sets variable if argument is equal to SIGHUP.
  • worker_sleep(): sleep()
    Test that sleep continues the required time, even if a interrupt is received. The only exception is for sighup, then function should return non-zero.
  • interrupt_worker_sleep(): kill()
  • send_worker_home_atexit(): close()
    Closes a couple of pipes.
  • send_blocking_req_internal(): fork_blocking_child(), write()
    Don't know
  • receive_blocking_req_internal(): read()
    Don't know
  • send_blocking_resp_internal(): write()
    Writes to a pipe..
  • receive_blocking_resp_internal(): read()
    Don't know
  • fork_deferred_worker(): fork_blocking_child()
  • fork_blocking_child(): pipe(), move_fd(), atexit(), fflush(), signal_no_reset(), fork(), update_resp_pipe_fd(), kill_asyncio(), close_all_beyond(), setup_logfile(), init_logging(), exit_worker()
    Test that fork is not done when in root (ifdef HAV_DROPROOT)
  • worker_idle_timer_fired(): close(), update_resp_pipe_fd()
    Zeroes out a couple of variables, check that pipes are closed.

work_thread.c

Is this whole file Windows specific? Yes... Methods without comments are just wrappers.

  • exit_worker(): _endthreadex()
    Just a wrapper, just a single call
  • worker_sleep(): WaitForSingleObject()
    Calls WaitForSingleObject() and check if a timeout occured.
  • interrupt_worker_sleep(): Single call to SetEvent()
  • queue_req_point(): WaitForSingleObject()
  • send_blocking_req_internal(): start_blocking_thread(), queue_req_pointer()
    Not much to test.
  • receive_blocking_req_internal(): SetEvent(), WaitForSingleObject(), ResetEvent()
    Test that items are processed in order, and that thread waits when no work is in the queue.
  • send_blocking_resp_internal(): SetEvent()
  • receive_blocking_resp_internal():
  • start_blocking_thread(): CreateEvent(), ResetEvent(), _beginthreadex(), SetThreadPriority(), ResumeThread()
    Initialization routine; creates and resumes a thread.
  • blocking_thread(): blocking_child_common()
    Just a wrapper.
  • working_idle_timer_fired(): queue_req_pointer()

ntpd

cmd_args.c

  • getCmdOpts(): proto_config(), stats_config(), OPT_ARG(), authtrust(), HAVE_OPT(), set_sys_var(), optionUsage()
    Tests could be written for every command line option, or to test specific conditions. For example test that ntpd exists if neither IPv4 or IPv6 are found.

ntp_config.c

  • free_auth_node():
    Frees and nulls.
  • init_syntax_tree(): create_queue()
    Creates a lot of queues.
  • free_all_config_trees(): free_config_tree()
    Could check that all queues are set to NULL.
  • free_config_tree(): free_config_*(), DESTROY_QUEUE(), free_auth_node()
    Frees..
  • dump_all_config_trees(): dump_config_tree()
    Calls dump_config_tree() on all the trees. The returns values are or'ed together, this will always end up beeing zero because dump_config_tree always returns zero though.
  • dump_config_tree(): queue_head(), next_node(), token_name(), keyword(), quote_if_needed()
    Writes all configs to the supplied FILE pointer.
  • enqueue_in_new_queue(): create_queue(), enqueue()
    Tests that the node is added to a queue as the only element there.
  • create_attr_dval(): get_node()
    create_attr_ival(): get_node()
    create_attr_shorts(): get_node()
    create_attr_sval(): get_node(), estrdup()
    create_attr_pval(): get_node()
    All these functions add a attr-value pair. Test that the attribute is returned with the correct attr,value and type set.
  • create_ival(): get_node()
    create_dval(): get_node()
    create_pval(): get_node()
  • create_address_node(): get_node()
    These functions gets memory for a variable of the corresponding type. Test that the value(s) is set.
  • destroy_address_node(): free_node()
    Calls free_node(). Should fail if address is NULL.
  • create_peer_node(): get_node(), dequeue(), enqueue(), token_name(), free_node(), DESTROY_QUEUE()
    Not sure what this does.
  • create_unpeer_node(): get_node(), destroy_address_node()
    Test that node is destroyed only if the address is a 16-bit number less than ASSOCID_MAX. Otherwise the associd should be zero, and the address data left unchanged.
  • create_filegen_node(): get_node()
    create_restrict_node(): get_node()
    Calls get_node() and saves the supplied data into a new structure.
  • destroy_restrict_node(): destroy_address_node(), DESTROY_QUEUE(), free_node()
    Only calls these destructors.
  • create_setvar_node(): get_node()
    Test that variable names with '=' is rejected.
  • create_nic_rule_node(): get_node()
    create_addr_opts_node(): get_node()
    Calls get_node() and saves the supplied data into a new structure.
  • create_sim_script_info(): get_node(), queue_head()
    I don't see why this doesn't causes an infinity loop...
  • get_next_address(): getaddrinfo(), freeaddrinfo()
  • create_sim_server(): get_node(), get_next_address(), dequeue()
    create_sim_node(): get_node() Calls get_node() and saves the supplied data into a new structure.
  • config_other_modes(): proto_config(), queue_head(), getnetnum(), next_node(), queue_head()
    Not sure.
  • free_config_other_modes(): dequeue(), destroy_address_node()
    Dequeues and destroys all nodes in manycast- and multicase server queues. Check that they are empty afterwards.
  • config_auth(): queue_head(), crypto_config(), next_node(), estrdup(), crypto_setup(), getauthkeys(), authtrust()
    Don't know.
  • free_config_auth(): dequeue(), free_node(), DESTROY_QUEUE()
    Dequeues and destroys all values in crypto- and trustedkey queues.
  • config_tos(): queue_head(), proto_config(), next_node()
    Just a wrapper for proto_config to map between protocol and C-constant.
  • free_config_tos(): dequeue(), free_node()
    Dequeues all orphan commands.
  • config_monitor(): stats_config(), queue_head(), keyword(), filegen_get(), next_node(), filegen_config()
    Converts packet attributes to filegen_config constants.
  • free_config_monitor(): free_node(), dequeue()
    Dequeues and frees stats and filegen options.
  • config_access(): queue_head(), keyword(), next_node(), hack_restrict(), getnetnum(), getaddrinfo(), freeaddrinfo()
    Not sure how to test.
  • free_config_access(): dequeue(), free_node(), DESTROY_QUEUE(), destroy_restrict_node()
    Dequeues and frees mru- discard- and restrict options.
  • config_tinker(): queue_head(), loop_config(), next_node()
    Converts packet attributes to loop_config flags.
  • free_config_tinker(): dequeue(), free_node()
    Dequeue and free..
  • config_nic_rules(): queue_head(), next_node(), estrdup(), is_ip_address(), add_nic_rule(), timer_interfacetimeout()
    Don't know.
  • free_config_nic_rules(): dequeue(), free_node(), DESTROY_QUEUE()
    Dequeue and destroy.
  • apply_enable_disable(): queue_Head(), next_node(), proto_config()
    Convert packet options to proto_config arguments.
  • config_system_opts(): apply_enable_disable()
    Wrapper
  • free_config_system_opts(): dequeue(), free_node()
    Dequeue and destroy.
  • config_logconfig(): queue_head(), next_node(), get_logmask()
    Don't know.
  • free_config_logconfig(): dequeue(), free_node()
    Dequeue and destroy.
  • config_phone(): queue_head(), next_node()
  • free_config_phone(): dequeue(), free_node()
    D & D
  • config_qos(): queue_head(), next_node()
    Converts string option to constant. Check specifically the overlapping option name (flash)
  • free_config_qos(): dequeue(), free_node()
    D & D
  • config_setvar(): queue_head(), set_sys_var(), next_node()
    Test the string sent to set_sys_var is ok.
  • free_config_setvar(): dequeue(), free_node()
    D & D
  • config_ttl(): queue_head(), next_node()
    Test that the TTL is added to the list (sys_ttl)
  • free_config_ttl(): Empty
  • config_trap(): queue_head(), next_node(), getnetnum(), findinterface(), getaddrinfo_sometime(), ctlsettrap(), latoa(), stoa()
    Don't know
  • trap_name_resolved(): findinterface(), ctlsettrap(), stoa(), latoa(), gai_strerror()
    Logic depends on the result of findinterface().
  • =free_config_trap(): dequeue(), destroy_addres_node(), free_node(), DESTROY_QUEUE()
    D & D
  • config_fudge(): queue_head(), getnetnum(), stoa(), token_name(), refclock_control(), next_node()
    Ensure that an incorrect refclock address is refused.
  • free_config_fudge(): dequeue(), free_node(), DESTROY_QUEUE()
    D & D
  • config_vars(): queue_head(), proto_config(), stats_config(), change_logfile(), estrdup(), next_node()
    Yet another "convert from attribute -> function arguments"
  • free_config_vars(): dequeue(), free_node()
    D & D
  • is_sane_resolved_address(): stoa()
    Test that refclock addresses are accepted. Test that a multicast address can't be the address of a server.
  • get_correct_host_mode():
    Constant to other constant..
  • peerflag_bits(): queue_head(), next_node()
    Converts network attributes to bits.
  • config_peers(): is_ip_address(), is_sane_resolved_address(), peer_config(), getaddrinfo_sometime(), queue_head(), next_node(), get_correct_host_mode()
    Don't know.
  • peer_name_resolved(): getaddrinfo_sometime(), is_sane_resolved_address(), stoa(), peer_config()
    Don't know.
  • free_config_peers(): dequeue(), destroy_address_node(), DESTROY_QUEUE(), free_node()
    D & D
  • config_unpeers(): queue_head(), next_node(), findpeerbyassoc(), peer_clear(), unpeer(), getnetnum(), findexistingpeer(), getaddrinfo_sometime()
    Test unpeers both with assocId, and with name/address.
  • unpeer_name_resolved(): gai_strerror(), stoa(), findexistingpeer(), peer_clear(), unpeer()
    Don't know.
  • free_config_unpeers(): dequeue(), destroy_address_node(), free_node()
    D & D
  • config_sim(): queue_head(), next_node(), get_no_of_elements(), create_server_associations()
    Don't know.
  • free_config_sim(): DESTROY_QUEUE(), free_node()
    D & D
  • config_ntpd(): config_*(), io_open_sockets(), getaddrinfo_sometime()
    Calls every config_*() function.
  • config_ntpdsim(): config_tos(), config_monitor(), config_tinker(), config_system_opts(), config_logconfig(), config_vars(), config_sim()
    Initialization function for simulator.
  • config_remotely(): init_syntax_tree(), yyparse(), save_and_apply_config_tree()
    Not sure what to test.
  • getconfig(): atexit(), ExpandEnvironmentStrings (), set_sys_var(), loop_config(), getCmdOpts(), init_syntax_tree(), FindConfig (), get_netinfo_config(), io_open_sockets(), yyparse(), save_and_apply_config_tree(), free_netinfo_config()
    Calls the setup functions..
  • save_and_apply_config_tree(): LINK_TAIL_SLIST(), strerror(), dump_all_config_trees(), config_ntpd(), config_ntpdsim(), UNLINK_SLIST(), free_config_tree()
    Another initialization function. Could test fopen failure, if faking fopen call.
  • ntpd_set_tod_using(): set_sys_var()
    Wrapper.
  • get_pfxmatch():
    Not sure what this does.
  • get_match():
    Test that function returns the matching char* if there is any match in the masks struct.
  • get_logmask(): get_pfxmatch(), get_match()
    Not sure what this does.
  • get_netinfo_config(): ni_open(), ni_pathsearch(), ni_free()
    Don't know what NetInfo is
  • free_netinfo_config(): ni_free()
    Destructor.
  • gettokens_netinfo(): ni_lookupprop(), ni_namelist_free()
    Not sure what NetInfo is.
  • getnetnum(): is_ip_address(), stoa()
    Test with IPv4 and IPv6 addresses, also with invalid addresses.

ntp_io.c

  • maintain_activefds(): FD_SET(), FD_CLR()
    Test that ntpd exits when FD_SETSIZE is exceeded.
  • update_resp_pipe_fd(): maintain_activefds()
    Wrapper
  • move_fd(): fcntl(), close()
    If the calls to fcntl() and close() was faked, tests could be written to exercise the conditions in the function comment. Test the cases where FOPEN_MAX > FD_SETSIZE
  • close_all_beyond(): closefrom(), fcntl()
    Should test the result, i.e that all file descriptors after keep_fd is closed. (Don't know if this is possible?)
  • collect_timing(): lfptoa(), stoa(), record_timing_stats()
    Don't know (ifdef'd as DEBUG_TIMING)
  • init_io(): init_recvbuff(), init_io_completion_port(), set_signal()
    Init function.
  • io_open_sockets(): BLOCK_IO(), UNBLOCK_IO(), create_sockets(), init_async_notifications()
    Init function.
  • interface_dump(): sockaddr_dump()
    Debug function, prints to console.
  • sockaddr_dump():
    Debug function, prints sockaddr_u as hex. Can be tested, but not sure if it should be.
  • print_interface(): stoa(), interface_dump()
    Debug function, should these be tested?
  • new_asyncio_reader():
    Allocates some new memory. Check that INVALID_SOCKET is set.
  • delete_asyncio_read():
    Wrapper
  • add_asyncio_reader(): LINK_SLIST(), add_fd_to_list()
    Test that the fd is added to the list
  • remove_asyncio_reader(): UNLINK_SLIST(), close_and_delete_fd_from_list()
    Test that the reader is removed from the asyncoio_reader_list, and that any current socket is closed and set to INVALID_SOCKET.
  • is_ip_address(): isc_netaddr_fromin(), isc_netaddr_fromin6()
    Test that valid IPv4/6 addresses are accepted. Also check that ISC_FALSE is returned if invalid addresses are found.
  • interface_enumerate():
    Test that the receiver-callback is called once for every item in interface list.
  • init_interface():
    Init function.
  • new_interface(): init_interface()
    Test that a copy of an already existing interface is made if a non-null pointer is sent into the function. This test should be merged with tests for init_interface()
  • delete_interface():
    Wrapper
  • add_interface(): LINK_TAIL_SLIST(), addr2refid()
    Test that the interface is added to the end of the interface list, and that the interface count is incresed.
  • remove_interface(): UNLNK_SLIST(), delete_interface_from_list(), stoa(), close_and_delete_fd_from_list(), mon_clearinterface(), hack_restrict()
    The interface should be removed from the lists, together with file descriptors. The interface count should be decreased too.
  • list_if_listening():
    Wrapper for msyslog.
  • create_wildcards(): isc_netaddr_fromin(), interface_action(), new_interface(), open_socket(), add_addr_to_list(), list_if_listening(), stoa(), add_interface()
    Test that the wildcard interface is added to the list. If IPv6 is available, both IPv4 and IPv6 wildcard interfaces should be added.
  • add_nic_rule(): is_ip_address(), LINK_SLIST()
    Test that an invalid IP-address is refused, if match_type is MATCH_IFADDR.
  • action_text():
    Debug function, returns some text. (Returning a pointer to a local also feels dangerous, is this correct?)
  • interface_action(): is_wildcard_netaddr(), action_text(), isc_netaddr_eqprefix(), isc_netaddr_equal()
    Don't know.
  • convert_isc_if(): isc_netaddr_getzone()
    Test that the conversion converts all data, ports, masks, flags, IPv4/IPv6 addresses.
  • refresh_interface(): close_and_delete_fd_from_list(), open_socket()
    Platform dependent.
  • interface_update(): BLOCKIO(), UNBLOCKIO(), update_interfaces(), interrupt_worker_sleep()
    Test that no update is done if disable_dynamic_updates is set to true
  • sau_from_netaddr():
    Test that address, port and family is copied from the isc_netaddr_t to the sockaddr.
  • is_wildcard_addr():
    Test both IPv4 and IPv6 wildcard addresses are matched.
  • is_wildcard_netaddr(): sau_from_netaddr(), is_wildcard_addr()
    Wrapper
  • set_wildcard_reuse(): setsockopt(), stoa()
    Don't know
  • update_interfaces(): isc_interfaceiter_create(), isc_interfaceiter_first(), isc_interfaceiter_next(), isc_interfaceiter_current(), init_interface(), convert_isc_if(), interface_action(), stoa(), is_wildcard_addr(), getinterface(), refresh_interface(), create_interface(), isc_interfaceiter_destroy(), remove_interface(), set_peerdstadr(), delete_interface(), refresh_all_peerinterfaces()
    If the isc_interfaceiter_*() functions could be faked, to supply new interfaces for testing.
  • create_sockets(): create_wildcards(), update_interfaces(), set_reuseaddr()
    Don't know.
  • create_interface(): new_interface(), stoa(), open_socket(), list_if_listening(), delete_interface(), hack_restrict(), add_addr_to_list(), add_interface()
    Check that it is added to the list, otherwise i'm not sure what the code does.
  • set_excladdruse(): setsockopt(), GetLastError (), isc_win32os_versioncheck(), SetLastError ()
    Don't know.
  • set_reuseaddr(): stoa(), setsockopt()
    If possible, test that SE_REUSEADDR is set on every socket in interface list.
  • enable_broadcast(): socket_broadcast_enable()
    Wrapper
  • socket_broadcast_enable(): setsockopt()
    socket_broadcast_disable(): setsockopt()
    SO_BROADCAST should be enabled/disabled on the socket afterwards.
  • get_broadcastclient_flag():
    Getter, returns a variable.
  • addr_ismulticast():
    Test with both IPv6 and IPv4 addresses, should return true if address is multicast.
  • enable_multicast_if(): setsockopt(), stoa()
    Don't know.
  • socket_multicast_enable(): find_addr_in_list(), setsockopt(), stoa(), add_addr_to_list()
    Test that adding an already existing address returns ISC_TRUE (but no duplicate added). Test with IPv4 and IPv6 (if INCLUDE_IPV6_MULTICAST_SUPPORT).
  • socket_multicast_disable(): find_addr_in_list(), stoa(), setsockopt()
    Test that function returns true even if the interface is not found. (only false on a failure)
  • io_setbclient(): open_socket(), socket_broadcast_enable(), addr2refid(), set_reuseaddr()
    Don't know.
  • io_unsetbclient(): socket_broadcast_disable()
    Test that only interfaces without INT_WILDCARD and with INT_BCASTOPEN are send to broadcast_disable().
  • io_multicast_add(): addr_ismulticast(), find_flagged_addr_in_list(), stoa(), new_interface(), findlocalcastinterface(), open_socket(), add_interface(), list_if_listening(), delete_interface(), socket_multicast_enable()
    Test that addition of a duplicate doesn't add a duplicate to the list.
  • io_multicast_del(): addr_ismulticast(), find_flagged_addr_in_list(), socket_multicast_disable(), delete_addr_from_list(), stoa()
    Test that an existing addr is removed.
  • init_nonblocking_io(): fcntl(), ioctl()
    Initialization function.
  • open_socket(): socket(), WSAGetLastError (), connection_reset_fix(), move_fd(), isc_win32os_versioncheck(), setsockopt(), closesocket(), set_excladdruse(), socket_broadcast_enable(), is_wildcard_addr(), set_wildcard_reuse(), bind(), stoa(), init_nonblocking_io(), init_socket_sig(), add_fd_to_list(), io_completion_port_add_socket(), closesocket()
    Not sure how to test when there are so many #ifdef's.
  • sendpkt(): stoa(), setsockopt(), simulate_server(), sendto(), io_completion_port_sendto()

  • fdbits():
    Test with some different fd_set's
  • read_refclock_packet(): get_free_recv_buffer(), freerecvbuf(), add_full_recv_buffer()
    Should read from a file descriptor, don't know how to test.
  • fetch_timestamp(): collect_timing()
    Don't know.
  • read_network_packet(): get_free_recv_buffer(), freerecvbuf(), recvfrom(), free_recvbuffs(), stoa(), fetch_timestamp(), add_full_recv_buffer()
    I'm not sure how to test receiving a packet from the network.
  • input_handler(): fdbits(), read_refclock_packet(), read_network_packet(), process_blocking_response(), get_systime(), collect_timing()
    Still don't know how to handle network packets.
  • findinterface(): findlocalinterface(), stoa()
    Test that the wildcard interface is returned if no matching address is found.
  • findlocalinterface(): socket(), setsockopt(), closesocket(), getsockname(), stoa(), getinterface(), getsamenetinterface()
    Don't know.
  • getinterface(): find_addr_in_list()
    Test that only interfaces with the given flags are matched, and that NULL are returned if no interface is found.
  • getsamenetinterface(): find_samenet_addr_in_list()
    Test that only interfaces with the given flags are matched, and that NULL are returned if no interface is found.
  • findlocalcastinterface(): findlocalinterface(), addr_ismulticast(), stoa()
    Test that program dies if addr is not a multicast address. Test that loopback interfaces and wildcards are ignored.
  • findbcastinter(): findlocalinterface(), addr_ismulticast()
    Don't know.
  • io_clr_stats():
    Zeroes out some variables
  • io_addclock(): BLOCKIO(), init_clock_sig(), io_completion_port(), UNBLOCKIO(), add_fd_to_list()
    Don't know.
  • io_closeclock(): BLOCKIO(), UNBLOCKIO(), close_and_delete_fd_from_list()
    Test that the refclockio is removed from the list.
  • kill_asyncio(): BLOCKIO(), UNBLOCKIO(), close_and_delete_fd_from_list()
    Closes and deletes everything in the fd_list.
  • add_fd_to_list(): LINK_SLIST(), maintain_activefds()
    Test that a new vsock_t is added to the fd_list.
  • close_and_delete_fd_from_list(): UNLINK_EXPR_SLIST(), UNLINK_EXPR_SLIST_CURRENT(), closesocket(), maintain_activefds()
    Test (if possible) that a socket/file is closed, and also that it's removed from the list if it exists.
  • add_addr_to_list(): find_addr_in_list(), LINK_SLIST()
    Check that the given addr is added tp the remoteaddr_list.
  • delete_addr_from_list(): UNLINK_EXPR_SLIST(), UNLINK_EXPR_SLIST_CURRENT()
    Should remove the given addr from the remoteaddr_list
  • delete_interface_from_list(): UNLINK_EXPR_SLIST(), UNLINK_EXPR_SLIST_CURRENT(), stoa(), addr_ismulticast(), io_multicast_add()
    Don't know
  • find_addr_in_list():
    Test that the interface with the given addr is returned, and if no such item exists: NULL.
  • same_network_v4():
    same_network_v6():
    same_network():
    Test with addresses both in the same network and different networks. Test with different masks. Test through same_network().
  • =find_samenet_addr_in_list(): same_network()
    Test both with interface address equal to addr, in the same network as addr, and no match at all.
  • find_flagged_addr_in_list(): stoa()
    Test that only interfaces with the exact address and flag are returned.
  • localaddrtoa(): stoa()
    Wrapper
  • process_routing_msgs(): remove_asyncio_reader(), delete_asyncio_reader(), timter_interfacetimeout()
    Don't know.
  • init_async_notifications(): socket(), move_fd(), bind(), init_nonblocking_io(), init_socket_sig(), new_asyncio_reader(), add_asyncio_reader()
    Initialization function.

ntp_scanner.c

  • keyword():
    Returns a text message.

  • F_OPEN(): fopen()
  • FGETC(): fgetc()
  • UNGETC(): ungetc()
  • FCLOSE(): fclose()
    All these are wrapper functions of their C-calls. Test that the extra info is correct (e.g current line and col)

  • get_next_char(): FGETC()
  • push_back_char(): UNGETC()
    Test that both of these can read/write both from char-arrays and from file.

  • is_keyword():
  • is_integer():
  • is_double():
  • is_special():
  • is_EOC():
    Test that these return true/false depending on what the current token is.

  • quote_if_needed():
    Test that a special string is quoted with backslashes, IF there are no surrounding quotes
  • create_string_token():
    Don't know.
  • yylex(): FCLOSE(), push_back_char(), get_next_char(), is_EOC(), is_*()
    Parses a file or string for something i'm not sure about...

ntpd.c

  • init_logging(): openlog(), setlogmask()
    Initialization function, nothing to test.
  • change_logfile(): fopen(), fileno()
  • setup_logfile(): change_logfile()
    Invokes change_logfile()
  • parse_cmdline_opts(): optionProcess()
    Makes sure optionProcess is only called once.
  • set_process_priority(): sched_get_priority_max(), sched_get_priority_min(), sched_set_scheduler(), rtprio(), setpriority()
    Calls various setpriority functions depending on platform..
  • ntpdmain(): Calls pretty much everything...
  • assertion_failed(): isc_assertion_setcallback(), isc_assertion_typetotext()
    Logs errors messages with msyslog.
  • library_fatal_error(): isc_error_setfatal()
    Logs error messages with msyslog.
  • library_unexpected_error():
    Logs error messages with msyslog.

-- LinusKarlsson - 2010-07-09

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r4 < r3 < r2 < r1 | More topic actions
 
SSL security by CAcert
Get the CAcert Root Certificate
This site is powered by the TWiki collaboration platform
IPv6 Ready
Copyright & 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding the site? Send feedback