diff options
Diffstat (limited to 'pceplib/test')
| -rw-r--r-- | pceplib/test/pcep_msg_messages_test.c | 18 | ||||
| -rw-r--r-- | pceplib/test/pcep_msg_tlvs_test.c | 20 | ||||
| -rw-r--r-- | pceplib/test/pcep_msg_tools_test.c | 49 | ||||
| -rw-r--r-- | pceplib/test/pcep_session_logic_loop_test.c | 20 | ||||
| -rw-r--r-- | pceplib/test/pcep_timers_event_loop_test.c | 2 |
5 files changed, 105 insertions, 4 deletions
diff --git a/pceplib/test/pcep_msg_messages_test.c b/pceplib/test/pcep_msg_messages_test.c index 10b678bcec..b8984a42bc 100644 --- a/pceplib/test/pcep_msg_messages_test.c +++ b/pceplib/test/pcep_msg_messages_test.c @@ -111,7 +111,7 @@ void test_pcep_msg_create_request() /* Test IPv4 */ struct pcep_object_rp *rp_obj = pcep_obj_create_rp(0, false, false, false, false, 10, NULL); - struct in_addr src_addr, dst_addr; + struct in_addr src_addr={}, dst_addr={}; struct pcep_object_endpoints_ipv4 *ipv4_obj = pcep_obj_create_endpoint_ipv4(&src_addr, &dst_addr); message = pcep_msg_create_request(rp_obj, ipv4_obj, NULL); @@ -375,6 +375,10 @@ void test_pcep_msg_create_update() /* Should return NULL if obj_list is empty */ message = pcep_msg_create_update(obj_list); CU_ASSERT_PTR_NULL(message); + if (message != NULL) { + pcep_msg_free_message(message); + message = NULL; + } struct pcep_object_srp *srp = pcep_obj_create_srp(false, 100, NULL); struct pcep_object_lsp *lsp = @@ -390,6 +394,10 @@ void test_pcep_msg_create_update() CU_ASSERT_PTR_NULL(message); dll_append(obj_list, ero); + if (message != NULL) { + pcep_msg_free_message(message); + message = NULL; + } message = pcep_msg_create_update(obj_list); CU_ASSERT_PTR_NOT_NULL(message); pcep_encode_message(message, versioning); @@ -416,6 +424,10 @@ void test_pcep_msg_create_initiate() /* Should return NULL if obj_list is empty */ struct pcep_message *message = pcep_msg_create_initiate(NULL); CU_ASSERT_PTR_NULL(message); + if (message != NULL) { + pcep_msg_free_message(message); + message = NULL; + } struct pcep_object_srp *srp = pcep_obj_create_srp(false, 100, NULL); struct pcep_object_lsp *lsp = @@ -428,6 +440,10 @@ void test_pcep_msg_create_initiate() dll_append(obj_list, srp); message = pcep_msg_create_initiate(obj_list); CU_ASSERT_PTR_NULL(message); + if (message != NULL) { + pcep_msg_free_message(message); + message = NULL; + } dll_append(obj_list, lsp); dll_append(obj_list, ero); diff --git a/pceplib/test/pcep_msg_tlvs_test.c b/pceplib/test/pcep_msg_tlvs_test.c index 878e4d62af..6b650f6823 100644 --- a/pceplib/test/pcep_msg_tlvs_test.c +++ b/pceplib/test/pcep_msg_tlvs_test.c @@ -106,6 +106,10 @@ void test_pcep_tlv_create_speaker_entity_id() double_linked_list *list = dll_initialize(); tlv = pcep_tlv_create_speaker_entity_id(list); CU_ASSERT_PTR_NULL(tlv); + if (tlv != NULL) { + pceplib_free(PCEPLIB_INFRA, tlv); + tlv = NULL; + } uint32_t *speaker_entity = pceplib_malloc(PCEPLIB_MESSAGES, sizeof(uint32_t)); @@ -172,16 +176,28 @@ void test_pcep_tlv_create_path_setup_type_capability() double_linked_list *pst_list = dll_initialize(); tlv = pcep_tlv_create_path_setup_type_capability(pst_list, NULL); CU_ASSERT_PTR_NULL(tlv); + if (tlv != NULL) { + pcep_obj_free_tlv(&tlv->header); + tlv = NULL; + } /* Should still return NULL if pst_list is NULL */ double_linked_list *sub_tlv_list = dll_initialize(); tlv = pcep_tlv_create_path_setup_type_capability(NULL, sub_tlv_list); CU_ASSERT_PTR_NULL(tlv); + if (tlv != NULL) { + pcep_obj_free_tlv(&tlv->header); + tlv = NULL; + } /* Should still return NULL if pst_list is empty */ tlv = pcep_tlv_create_path_setup_type_capability(pst_list, sub_tlv_list); CU_ASSERT_PTR_NULL(tlv); + if (tlv != NULL) { + pcep_obj_free_tlv(&tlv->header); + tlv = NULL; + } /* Test only populating the pst list */ uint8_t *pst1 = pceplib_malloc(PCEPLIB_MESSAGES, 1); @@ -196,6 +212,10 @@ void test_pcep_tlv_create_path_setup_type_capability() tlv = pcep_tlv_create_path_setup_type_capability(pst_list, sub_tlv_list); CU_ASSERT_PTR_NOT_NULL(tlv); + if (tlv == NULL) { + CU_ASSERT_TRUE(tlv != NULL); + return; + } pcep_encode_tlv(&tlv->header, versioning, tlv_buf); CU_ASSERT_EQUAL(tlv->header.type, diff --git a/pceplib/test/pcep_msg_tools_test.c b/pceplib/test/pcep_msg_tools_test.c index a1260b1186..ff5fc62390 100644 --- a/pceplib/test/pcep_msg_tools_test.c +++ b/pceplib/test/pcep_msg_tools_test.c @@ -24,6 +24,9 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + #include <CUnit/CUnit.h> @@ -164,7 +167,15 @@ void pcep_tools_test_teardown(void) int convert_hexstrs_to_binary(const char *hexbyte_strs[], uint16_t hexbyte_strs_length) { - int fd = fileno(tmpfile()); + mode_t oldumask; + oldumask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH); + /* Set umask before anything for security */ + umask(0027); + char tmpfile[] = "/tmp/pceplib_XXXXXX"; + int fd = mkstemp(tmpfile); + umask(oldumask); + if (fd == -1) + return -1; int i = 0; for (; i < hexbyte_strs_length; i++) { @@ -192,6 +203,10 @@ void test_pcep_msg_read_pcep_initiate() { int fd = convert_hexstrs_to_binary(pcep_initiate_hexbyte_strs, pcep_initiate_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -287,6 +302,10 @@ void test_pcep_msg_read_pcep_initiate2() { int fd = convert_hexstrs_to_binary(pcep_initiate2_hexbyte_strs, pcep_initiate2_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -370,6 +389,10 @@ void test_pcep_msg_read_pcep_open() { int fd = convert_hexstrs_to_binary(pcep_open_odl_hexbyte_strs, pcep_open_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -410,6 +433,10 @@ void test_pcep_msg_read_pcep_update() { int fd = convert_hexstrs_to_binary(pcep_update_hexbyte_strs, pcep_update_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -488,6 +515,10 @@ void test_pcep_msg_read_pcep_open_initiate() int fd = convert_hexstrs_to_binary( pcep_open_initiate_odl_hexbyte_strs, pcep_open_initiate_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 2); @@ -513,6 +544,10 @@ void test_pcep_msg_read_pcep_open_cisco_pce() int fd = convert_hexstrs_to_binary( pcep_open_cisco_pce_hexbyte_strs, pcep_open_cisco_pce_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -571,6 +606,10 @@ void test_pcep_msg_read_pcep_update_cisco_pce() int fd = convert_hexstrs_to_binary( pcep_update_cisco_pce_hexbyte_strs, pcep_update_cisco_pce_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -708,6 +747,10 @@ void test_pcep_msg_read_pcep_report_cisco_pcc() int fd = convert_hexstrs_to_binary( pcep_report_cisco_pcc_hexbyte_strs, pcep_report_cisco_pcc_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); @@ -863,6 +906,10 @@ void test_pcep_msg_read_pcep_initiate_cisco_pcc() int fd = convert_hexstrs_to_binary( pcep_initiate_cisco_pcc_hexbyte_strs, pcep_initiate_cisco_pcc_hexbyte_strs_length); + if(fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } double_linked_list *msg_list = pcep_msg_read(fd); CU_ASSERT_PTR_NOT_NULL(msg_list); CU_ASSERT_EQUAL(msg_list->num_entries, 1); diff --git a/pceplib/test/pcep_session_logic_loop_test.c b/pceplib/test/pcep_session_logic_loop_test.c index 38fabd4ccd..3a40f59bb9 100644 --- a/pceplib/test/pcep_session_logic_loop_test.c +++ b/pceplib/test/pcep_session_logic_loop_test.c @@ -25,6 +25,8 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> #include <CUnit/CUnit.h> @@ -70,7 +72,6 @@ void pcep_session_logic_loop_test_setup() PCEPLIB_INFRA, sizeof(pcep_session_logic_handle)); memset(session_logic_handle_, 0, sizeof(pcep_session_logic_handle)); session_logic_handle_->active = true; - session_logic_handle_->session_logic_condition = false; session_logic_handle_->session_list = ordered_list_initialize(pointer_compare_function); session_logic_handle_->session_event_queue = queue_initialize(); @@ -79,6 +80,11 @@ void pcep_session_logic_loop_test_setup() pthread_mutex_init(&(session_logic_handle_->session_logic_mutex), NULL); pthread_mutex_init(&(session_logic_handle_->session_list_mutex), NULL); + pthread_mutex_lock(&(session_logic_handle_->session_logic_mutex)); + session_logic_handle_->session_logic_condition = true; + pthread_cond_signal(&(session_logic_handle_->session_logic_cond_var)); + pthread_mutex_unlock(&(session_logic_handle_->session_logic_mutex)); + session_logic_event_queue_ = pceplib_malloc(PCEPLIB_INFRA, sizeof(pcep_event_queue)); memset(session_logic_event_queue_, 0, sizeof(pcep_event_queue)); @@ -128,7 +134,17 @@ void test_session_logic_msg_ready_handler() /* Read from an empty file should return 0, thus * session_logic_msg_ready_handler returns -1 */ - int fd = fileno(tmpfile()); + mode_t oldumask; + oldumask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH); + /* Set umask before anything for security */ + umask(0027); + char tmpfile[] = "/tmp/pceplib_XXXXXX"; + int fd = mkstemp(tmpfile); + umask(oldumask); + if (fd == -1){ + CU_ASSERT_TRUE(fd>=0); + return; + } pcep_session session; memset(&session, 0, sizeof(pcep_session)); session.session_id = 100; diff --git a/pceplib/test/pcep_timers_event_loop_test.c b/pceplib/test/pcep_timers_event_loop_test.c index 9fcacaf0f2..ae63601df2 100644 --- a/pceplib/test/pcep_timers_event_loop_test.c +++ b/pceplib/test/pcep_timers_event_loop_test.c @@ -130,7 +130,9 @@ void test_walk_and_process_timers_timer_expired() timer->data = timer; // Set the timer to expire 10 seconds ago timer->expire_time = time(NULL) - 10; + pthread_mutex_lock(&test_timers_context->timer_list_lock); timer->timer_id = TEST_EVENT_LOOP_TIMER_ID; + pthread_mutex_unlock(&test_timers_context->timer_list_lock); ordered_list_add_node(test_timers_context->timer_list, timer); walk_and_process_timers(test_timers_context); |
