diff --git a/lib/test/common/CMakeLists.txt b/lib/test/common/CMakeLists.txt index bc7c0173c..5a44305e4 100644 --- a/lib/test/common/CMakeLists.txt +++ b/lib/test/common/CMakeLists.txt @@ -46,6 +46,7 @@ add_executable(timeout_test timeout_test.cc) target_link_libraries(timeout_test srslte_phy ${CMAKE_THREAD_LIBS_INIT}) add_executable(bcd_helpers_test bcd_helpers_test.cc) +target_link_libraries(bcd_helpers_test srslte_common) add_executable(stack_procedure_test stack_procedure_test.cc) add_test(stack_procedure_test stack_procedure_test) diff --git a/lib/test/common/bcd_helpers_test.cc b/lib/test/common/bcd_helpers_test.cc index 194dcf43a..206c1b46f 100644 --- a/lib/test/common/bcd_helpers_test.cc +++ b/lib/test/common/bcd_helpers_test.cc @@ -11,7 +11,7 @@ */ #include "srslte/common/bcd_helpers.h" -#include +#include "srslte/common/test_common.h" using namespace srslte; @@ -24,15 +24,15 @@ int main(int argc, char** argv) // String to code - assert(string_to_mcc(mcc_str, &mcc)); - assert(mcc == 0xF001); + TESTASSERT(string_to_mcc(mcc_str, &mcc)); + TESTASSERT(mcc == 0xF001); - assert(string_to_mnc(mnc_str, &mnc)); - assert(mnc == 0xF001); + TESTASSERT(string_to_mnc(mnc_str, &mnc)); + TESTASSERT(mnc == 0xF001); mnc_str = "01"; - assert(string_to_mnc(mnc_str, &mnc)); - assert(mnc == 0xFF01); + TESTASSERT(string_to_mnc(mnc_str, &mnc)); + TESTASSERT(mnc == 0xFF01); // Code to string @@ -41,13 +41,14 @@ int main(int argc, char** argv) mcc = 0xF001; mnc = 0xF001; - assert(mcc_to_string(mcc, &mcc_str)); - assert(mcc_str.compare("001") == 0); + TESTASSERT(mcc_to_string(mcc, &mcc_str)); + TESTASSERT(mcc_str.compare("001") == 0); - assert(mnc_to_string(mnc, &mnc_str)); - assert(mnc_str.compare("001") == 0); + TESTASSERT(mnc_to_string(mnc, &mnc_str)); + TESTASSERT(mnc_str.compare("001") == 0); mnc = 0xFF01; - assert(mnc_to_string(mnc, &mnc_str)); - assert(mnc_str.compare("01") == 0); + TESTASSERT(mnc_to_string(mnc, &mnc_str)); + TESTASSERT(mnc_str.compare("01") == 0); + return SRSLTE_SUCCESS; } diff --git a/lib/test/common/test_eea1.cc b/lib/test/common/test_eea1.cc index 5e745542b..34a171901 100644 --- a/lib/test/common/test_eea1.cc +++ b/lib/test/common/test_eea1.cc @@ -10,12 +10,12 @@ * */ -#include #include #include #include #include "srslte/common/liblte_security.h" +#include "srslte/common/test_common.h" #include "srslte/srslte.h" /* @@ -42,7 +42,7 @@ int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) * Integrity Algorithms UEA2 & UIA2 D4 v1.0 */ -void test_set_1() +int test_set_1() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -61,24 +61,25 @@ void test_set_1() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_2() +int test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -105,24 +106,25 @@ void test_set_2() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_3() +int test_set_3() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -143,24 +145,25 @@ void test_set_3() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_4() +int test_set_4() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -191,24 +194,25 @@ void test_set_4() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_5() +int test_set_5() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -243,24 +247,25 @@ void test_set_5() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_6() +int test_set_6() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -336,11 +341,11 @@ void test_set_6() get_time_interval(t); printf( "encryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int)t[0].tv_usec, (float)len_bits / t[0].tv_usec); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption gettimeofday(&t[1], NULL); @@ -349,17 +354,18 @@ void test_set_6() get_time_interval(t); printf( "decryption: %u bits, t=%d us, rate=%.1f Mbps/s\n", len_bits, (int)t[0].tv_usec, (float)len_bits / t[0].tv_usec); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } // set len_bitsgth to multiple of 8 respectively 128 -void test_set_1_block_size() +int test_set_1_block_size() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -378,25 +384,26 @@ void test_set_1_block_size() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } // inserted bit flip in msg[0] -void test_set_1_invalid() +int test_set_1_invalid() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -415,21 +422,22 @@ void test_set_1_invalid() // encryption err_lte = liblte_security_encryption_eea1(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp != 0); + TESTASSERT(err_cmp != 0); // decryption err_lte = liblte_security_decryption_eea1(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp != 0); + TESTASSERT(err_cmp != 0); free(out); + return SRSLTE_SUCCESS; } /* @@ -438,12 +446,13 @@ void test_set_1_invalid() int main(int argc, char* argv[]) { - test_set_1(); - test_set_2(); - test_set_3(); - test_set_4(); - test_set_5(); - test_set_6(); - test_set_1_block_size(); - test_set_1_invalid(); + TESTASSERT(test_set_1() == SRSLTE_SUCCESS); + TESTASSERT(test_set_2() == SRSLTE_SUCCESS); + TESTASSERT(test_set_3() == SRSLTE_SUCCESS); + TESTASSERT(test_set_4() == SRSLTE_SUCCESS); + TESTASSERT(test_set_5() == SRSLTE_SUCCESS); + TESTASSERT(test_set_6() == SRSLTE_SUCCESS); + TESTASSERT(test_set_1_block_size() == SRSLTE_SUCCESS); + TESTASSERT(test_set_1_invalid() == SRSLTE_SUCCESS); + return SRSLTE_SUCCESS; } diff --git a/lib/test/common/test_eea2.cc b/lib/test/common/test_eea2.cc index d367e3481..3e55c2023 100644 --- a/lib/test/common/test_eea2.cc +++ b/lib/test/common/test_eea2.cc @@ -15,6 +15,7 @@ #include #include "srslte/common/liblte_security.h" +#include "srslte/common/test_common.h" #include "srslte/srslte.h" /* @@ -39,7 +40,7 @@ int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) * Document Reference: 33.401 V13.1.0 Annex C.1 */ -void test_set_1() +int test_set_1() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -58,24 +59,25 @@ void test_set_1() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_2() +int test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -102,24 +104,25 @@ void test_set_2() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_3() +int test_set_3() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -140,24 +143,25 @@ void test_set_3() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_4() +int test_set_4() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -188,24 +192,25 @@ void test_set_4() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_5() +int test_set_5() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -240,24 +245,25 @@ void test_set_5() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } -void test_set_6() +int test_set_6() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -337,11 +343,11 @@ void test_set_6() len_bits, (int)t[0].tv_usec / 100, (float)100 * len_bits / t[0].tv_usec); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption gettimeofday(&t[1], NULL); @@ -354,17 +360,18 @@ void test_set_6() len_bits, (int)t[0].tv_usec / 100, (float)100 * len_bits / t[0].tv_usec); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } // set len_bitsgth to multiple of 8 respectively 128 -void test_set_1_block_size() +int test_set_1_block_size() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -383,25 +390,26 @@ void test_set_1_block_size() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); free(out); + return SRSLTE_SUCCESS; } // inserted bit flip in msg[0] -void test_set_1_invalid() +int test_set_1_invalid() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -420,21 +428,22 @@ void test_set_1_invalid() // encryption err_lte = liblte_security_encryption_eea2(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); - assert(err_cmp != 0); + TESTASSERT(err_cmp != 0); // decryption err_lte = liblte_security_decryption_eea2(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp != 0); + TESTASSERT(err_cmp != 0); free(out); + return SRSLTE_SUCCESS; } /* @@ -443,12 +452,12 @@ void test_set_1_invalid() int main(int argc, char* argv[]) { - test_set_1(); - test_set_2(); - test_set_3(); - test_set_4(); - test_set_5(); - test_set_6(); - test_set_1_block_size(); - test_set_1_invalid(); + TESTASSERT(test_set_1() == SRSLTE_SUCCESS); + TESTASSERT(test_set_2() == SRSLTE_SUCCESS); + TESTASSERT(test_set_3() == SRSLTE_SUCCESS); + TESTASSERT(test_set_4() == SRSLTE_SUCCESS); + TESTASSERT(test_set_5() == SRSLTE_SUCCESS); + TESTASSERT(test_set_6() == SRSLTE_SUCCESS); + TESTASSERT(test_set_1_block_size() == SRSLTE_SUCCESS); + TESTASSERT(test_set_1_invalid() == SRSLTE_SUCCESS); } diff --git a/lib/test/common/test_eea3.cc b/lib/test/common/test_eea3.cc index 3f717727a..8cfb62066 100644 --- a/lib/test/common/test_eea3.cc +++ b/lib/test/common/test_eea3.cc @@ -10,11 +10,11 @@ * */ -#include #include #include #include "srslte/common/liblte_security.h" +#include "srslte/common/test_common.h" #include "srslte/srslte.h" int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) @@ -37,7 +37,7 @@ int32 arrcmp(uint8_t const* const a, uint8_t const* const b, uint32 len) * */ -void test_set_1() +int test_set_1() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -59,7 +59,7 @@ void test_set_1() // encryption err_lte = liblte_security_encryption_eea3(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); @@ -70,15 +70,15 @@ void test_set_1() printf("Test Set 1 Encryption: Failed\n"); } - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea3(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); if (err_cmp == 0) { printf("Test Set 1 Decryption: Success\n"); @@ -87,9 +87,10 @@ void test_set_1() } free(out); + return SRSLTE_SUCCESS; } -void test_set_2() +int test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -119,7 +120,7 @@ void test_set_2() // encryption err_lte = liblte_security_encryption_eea3(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); @@ -129,15 +130,15 @@ void test_set_2() printf("Test Set 2 Encryption: Failed\n"); } - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea3(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); if (err_cmp == 0) { printf("Test Set 2 Decryption: Success\n"); @@ -146,9 +147,10 @@ void test_set_2() } free(out); + return SRSLTE_SUCCESS; } -void test_set_3() +int test_set_3() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -190,7 +192,7 @@ void test_set_3() // encryption err_lte = liblte_security_encryption_eea3(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); int i; // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); @@ -201,15 +203,15 @@ void test_set_3() printf("Test Set 3 Encryption: Failed\n"); } - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea3(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); if (err_cmp == 0) { printf("Test Set 3 Decryption: Success\n"); @@ -218,9 +220,10 @@ void test_set_3() } free(out); + return SRSLTE_SUCCESS; } -void test_set_4() +int test_set_4() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -278,7 +281,7 @@ void test_set_4() // encryption err_lte = liblte_security_encryption_eea3(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); int i; // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); @@ -289,15 +292,15 @@ void test_set_4() printf("Test Set 4 Encryption: Failed\n"); } - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea3(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); if (err_cmp == 0) { printf("Test Set 4 Decryption: Success\n"); @@ -306,9 +309,10 @@ void test_set_4() } free(out); + return SRSLTE_SUCCESS; } -void test_set_5() +int test_set_5() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -382,7 +386,7 @@ void test_set_5() // encryption err_lte = liblte_security_encryption_eea3(key, count, bearer, direction, msg, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); int i; // compare cipher text err_cmp = arrcmp(ct, out, len_bytes); @@ -393,15 +397,15 @@ void test_set_5() printf("Test Set 5 Encryption: Failed\n"); } - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // decryption err_lte = liblte_security_decryption_eea3(key, count, bearer, direction, ct, len_bits, out); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); // compare cipher text err_cmp = arrcmp(msg, out, len_bytes); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); if (err_cmp == 0) { printf("Test Set 5 Decryption: Success\n"); @@ -410,13 +414,14 @@ void test_set_5() } free(out); + return SRSLTE_SUCCESS; } int main(int argc, char* argv[]) { - test_set_1(); - test_set_2(); - test_set_3(); - test_set_4(); - test_set_5(); + TESTASSERT(test_set_1() == SRSLTE_SUCCESS); + TESTASSERT(test_set_2() == SRSLTE_SUCCESS); + TESTASSERT(test_set_3() == SRSLTE_SUCCESS); + TESTASSERT(test_set_4() == SRSLTE_SUCCESS); + TESTASSERT(test_set_5() == SRSLTE_SUCCESS); } diff --git a/lib/test/common/test_eia1.cc b/lib/test/common/test_eia1.cc index fe6f251af..85045aa59 100644 --- a/lib/test/common/test_eia1.cc +++ b/lib/test/common/test_eia1.cc @@ -16,6 +16,7 @@ #include #include "srslte/common/security.h" +#include "srslte/common/test_common.h" #include "srslte/srslte.h" /* @@ -25,7 +26,7 @@ * */ -void test_set_1() +int test_set_1() { uint8_t key[] = {0x2b, 0xd6, 0x45, 0x9f, 0x82, 0xc5, 0xb3, 0x00, 0x95, 0x2c, 0x49, 0x10, 0x48, 0x81, 0xff, 0x48}; uint32_t count = 0x38a6f056; @@ -41,11 +42,12 @@ void test_set_1() srslte::security_128_eia1(key, count, bearer, direction, msg, len_bytes, mac); for (int i = 0; i < 4; i++) { - assert(mac[i] == mt[i]); + TESTASSERT(mac[i] == mt[i]); } + return SRSLTE_SUCCESS; } -void test_set_4() +int test_set_4() { uint8_t key[] = {0x83, 0xfd, 0x23, 0xa2, 0x44, 0xa7, 0x4c, 0xf3, 0x58, 0xda, 0x30, 0x19, 0xf1, 0x72, 0x26, 0x35}; uint32_t count = 0x36af6144; @@ -66,11 +68,12 @@ void test_set_4() srslte::security_128_eia1(key, count, bearer, direction, msg, len_bytes, mac); for (int i = 0; i < 4; i++) { - assert(mac[i] == mt[i]); + TESTASSERT(mac[i] == mt[i]); } + return SRSLTE_SUCCESS; } -void test_set_7() +int test_set_7() { uint8_t key[] = {0xb3, 0x12, 0x0f, 0xfd, 0xb2, 0xcf, 0x6a, 0xf4, 0xe7, 0x3e, 0xaf, 0x2e, 0xf4, 0xeb, 0xec, 0x69}; uint32_t count = 0x296f393c; @@ -197,8 +200,9 @@ void test_set_7() srslte::security_128_eia1(key, count, bearer, direction, msg, len_bytes, mac); for (int i = 0; i < 4; i++) { - assert(mac[i] == mt[i]); + TESTASSERT(mac[i] == mt[i]); } + return SRSLTE_SUCCESS; } /* * Functions @@ -206,7 +210,8 @@ void test_set_7() int main(int argc, char* argv[]) { - test_set_1(); - test_set_4(); - test_set_7(); + TESTASSERT(test_set_1() == SRSLTE_SUCCESS); + TESTASSERT(test_set_4() == SRSLTE_SUCCESS); + TESTASSERT(test_set_7() == SRSLTE_SUCCESS); + return SRSLTE_SUCCESS; } diff --git a/lib/test/common/test_eia3.cc b/lib/test/common/test_eia3.cc index 10862ef59..0d864e9b9 100644 --- a/lib/test/common/test_eia3.cc +++ b/lib/test/common/test_eia3.cc @@ -10,13 +10,13 @@ * */ -#include #include #include #include #include "srslte/common/liblte_security.h" #include "srslte/common/security.h" +#include "srslte/common/test_common.h" #include "srslte/srslte.h" /* @@ -27,7 +27,7 @@ * */ -void test_set_1() +int test_set_1() { uint8_t key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint32_t count = 0x0; @@ -48,16 +48,17 @@ void test_set_1() if (mac[i] != expected_mac[i]) { failed = true; } - assert(mac[i] == expected_mac[i]); + TESTASSERT(mac[i] == expected_mac[i]); } if (failed == true) { printf("Test Set 1: Failed\n"); } else { printf("Test Set 1: Success\n"); } + return SRSLTE_SUCCESS; } -void test_set_2() +int test_set_2() { uint8_t key[] = {0x47, 0x05, 0x41, 0x25, 0x56, 0x1e, 0xb2, 0xdd, 0xa9, 0x40, 0x59, 0xda, 0x05, 0x09, 0x78, 0x50}; uint32_t count = 0x561eb2dd; @@ -78,16 +79,17 @@ void test_set_2() if (mac[i] != expected_mac[i]) { failed = true; } - assert(mac[i] == expected_mac[i]); + TESTASSERT(mac[i] == expected_mac[i]); } if (failed == true) { printf("Test Set 2: Failed\n"); } else { printf("Test Set 2: Success\n"); } + return SRSLTE_SUCCESS; } -void test_set_3() +int test_set_3() { uint8_t key[] = {0xc9, 0xe6, 0xce, 0xc4, 0x60, 0x7c, 0x72, 0xdb, 0x00, 0x0a, 0xef, 0xa8, 0x83, 0x85, 0xab, 0x0a}; uint32_t count = 0xa94059da; @@ -112,16 +114,17 @@ void test_set_3() if (mac[i] != expected_mac[i]) { failed = true; } - assert(mac[i] == expected_mac[i]); + TESTASSERT(mac[i] == expected_mac[i]); } if (failed == true) { printf("Test Set 3: Failed\n"); } else { printf("Test Set 3: Success\n"); } + return SRSLTE_SUCCESS; } -void test_set_4() +int test_set_4() { uint8_t key[] = {0xc8, 0xa4, 0x82, 0x62, 0xd0, 0xc2, 0xe2, 0xba, 0xc4, 0xb9, 0x6e, 0xf7, 0x7e, 0x80, 0xca, 0x59}; uint32_t count = 0x05097850; @@ -156,16 +159,17 @@ void test_set_4() if (mac[i] != expected_mac[i]) { failed = true; } - assert(mac[i] == expected_mac[i]); + TESTASSERT(mac[i] == expected_mac[i]); } if (failed == true) { printf("Test Set 4: Failed\n"); } else { printf("Test Set 4: Success\n"); } + return SRSLTE_SUCCESS; } -void test_set_5() +int test_set_5() { uint8_t key[] = {0x6b, 0x8b, 0x08, 0xee, 0x79, 0xe0, 0xb5, 0x98, 0x2d, 0x6d, 0x12, 0x8e, 0xa9, 0xf2, 0x20, 0xcb}; uint32_t count = 0x561eb2dd; @@ -225,20 +229,22 @@ void test_set_5() if (mac[i] != expected_mac[i]) { failed = true; } - assert(mac[i] == expected_mac[i]); + TESTASSERT(mac[i] == expected_mac[i]); } if (failed == true) { printf("Test Set 5: Failed\n"); } else { printf("Test Set 5: Success\n"); } + return SRSLTE_SUCCESS; } int main(int argc, char* argv[]) { - test_set_1(); - test_set_2(); - test_set_3(); - test_set_4(); - test_set_5(); + TESTASSERT(test_set_1() == SRSLTE_SUCCESS); + TESTASSERT(test_set_2() == SRSLTE_SUCCESS); + TESTASSERT(test_set_3() == SRSLTE_SUCCESS); + TESTASSERT(test_set_4() == SRSLTE_SUCCESS); + TESTASSERT(test_set_5() == SRSLTE_SUCCESS); + return SRSLTE_SUCCESS; } \ No newline at end of file diff --git a/lib/test/common/test_f12345.cc b/lib/test/common/test_f12345.cc index 345b010e6..54102656a 100644 --- a/lib/test/common/test_f12345.cc +++ b/lib/test/common/test_f12345.cc @@ -10,12 +10,11 @@ * */ -#include #include #include #include "srslte/common/liblte_security.h" - +#include "srslte/common/test_common.h" /* * Prototypes */ @@ -55,7 +54,7 @@ void arrprint(uint8_t const* const a, uint32 len) * Functions */ -void test_set_2() +int test_set_2() { LIBLTE_ERROR_ENUM err_lte = LIBLTE_ERROR_INVALID_INPUTS; int32 err_cmp = 0; @@ -69,17 +68,17 @@ void test_set_2() uint8_t opc_o[16]; err_lte = liblte_compute_opc(k, op, opc_o); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); arrprint(opc_o, sizeof(opc_o)); uint8_t opc_a[] = {0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e, 0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf}; err_cmp = arrcmp(opc_o, opc_a, sizeof(opc_o)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); uint8_t mac_o[8]; err_lte = liblte_security_milenage_f1(k, opc_o, rand, sqn, amf, mac_o); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); arrprint(mac_o, sizeof(mac_o)); @@ -87,21 +86,21 @@ void test_set_2() // compare mac a err_cmp = arrcmp(mac_o, mac_a, sizeof(mac_a)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // f1 star uint8_t mac_so[8]; err_lte = liblte_security_milenage_f1_star(k, opc_o, rand, sqn, amf, mac_so); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); uint8_t mac_s[] = {0x01, 0xcf, 0xaf, 0x9e, 0xc4, 0xe8, 0x71, 0xe9}; arrprint(mac_so, sizeof(mac_so)); err_cmp = arrcmp(mac_so, mac_s, sizeof(mac_s)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // f2345 uint8_t res_o[8]; @@ -111,7 +110,7 @@ void test_set_2() err_lte = liblte_security_milenage_f2345(k, opc_o, rand, res_o, ck_o, ik_o, ak_o); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); uint8_t res[] = {0xa5, 0x42, 0x11, 0xd5, 0xe3, 0xba, 0x50, 0xbf}; uint8_t ck[] = {0xb4, 0x0b, 0xa9, 0xa3, 0xc5, 0x8b, 0x2a, 0x05, 0xbb, 0xf0, 0xd9, 0x87, 0xb2, 0x1b, 0xf8, 0xcb}; @@ -122,35 +121,36 @@ void test_set_2() arrprint(res_o, sizeof(res_o)); err_cmp = arrcmp(res_o, res, sizeof(res)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // CK arrprint(ck_o, sizeof(ck_o)); err_cmp = arrcmp(ck_o, ck, sizeof(ck)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // IK arrprint(ik_o, sizeof(ik_o)); err_cmp = arrcmp(ik_o, ik, sizeof(ik)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // AK arrprint(ak_o, sizeof(ak_o)); err_cmp = arrcmp(ak_o, ak, sizeof(ak)); - assert(err_cmp == 0); + TESTASSERT(err_cmp == 0); // f star uint8_t ak_star_o[6]; err_lte = liblte_security_milenage_f5_star(k, opc_o, rand, ak_star_o); - assert(err_lte == LIBLTE_SUCCESS); + TESTASSERT(err_lte == LIBLTE_SUCCESS); arrprint(ak_star_o, sizeof(ak_star_o)); uint8_t ak_star[] = {0x45, 0x1e, 0x8b, 0xec, 0xa4, 0x3b}; err_cmp = arrcmp(ak_star_o, ak_star, sizeof(ak_star)); - assert(err_cmp == 0); - return; + TESTASSERT(err_cmp == 0); + return SRSLTE_SUCCESS; + ; } /* @@ -160,11 +160,6 @@ void test_set_2() int main(int argc, char* argv[]) { - test_set_2(); - /* - test_set_3(); - test_set_4(); - test_set_5(); - test_set_6(); - */ + TESTASSERT(test_set_2() == SRSLTE_SUCCESS); + return SRSLTE_SUCCESS; } diff --git a/lib/test/upper/rlc_am_data_test.cc b/lib/test/upper/rlc_am_data_test.cc index 0b3e819eb..d3b1da428 100644 --- a/lib/test/upper/rlc_am_data_test.cc +++ b/lib/test/upper/rlc_am_data_test.cc @@ -10,8 +10,8 @@ * */ +#include "srslte/common/test_common.h" #include "srslte/upper/rlc_am_lte.h" -#include #include // Fixed header only @@ -42,7 +42,7 @@ uint32_t PDU4_LEN = 5; using namespace srslte; -void test1() +int test1() { srslte::rlc_amd_pdu_header_t h; srslte::byte_buffer_t b1, b2; @@ -50,21 +50,22 @@ void test1() memcpy(b1.msg, &pdu1[0], PDU1_LEN); b1.N_bytes = PDU1_LEN; rlc_am_read_data_pdu_header(&b1, &h); - assert(RLC_DC_FIELD_DATA_PDU == h.dc); - assert(0x01 == h.fi); - assert(0 == h.N_li); - assert(0 == h.lsf); - assert(0 == h.p); - assert(0 == h.rf); - assert(0 == h.so); - assert(6 == h.sn); + TESTASSERT(RLC_DC_FIELD_DATA_PDU == h.dc); + TESTASSERT(0x01 == h.fi); + TESTASSERT(0 == h.N_li); + TESTASSERT(0 == h.lsf); + TESTASSERT(0 == h.p); + TESTASSERT(0 == h.rf); + TESTASSERT(0 == h.so); + TESTASSERT(6 == h.sn); rlc_am_write_data_pdu_header(&h, &b2); - assert(b2.N_bytes == PDU1_LEN); + TESTASSERT(b2.N_bytes == PDU1_LEN); for (uint32_t i = 0; i < b2.N_bytes; i++) - assert(b2.msg[i] == b1.msg[i]); + TESTASSERT(b2.msg[i] == b1.msg[i]); + return SRSLTE_SUCCESS; } -void test2() +int test2() { srslte::rlc_amd_pdu_header_t h; srslte::byte_buffer_t b1, b2; @@ -72,23 +73,24 @@ void test2() memcpy(b1.msg, &pdu2[0], PDU2_LEN); b1.N_bytes = PDU2_LEN; rlc_am_read_data_pdu_header(&b1, &h); - assert(RLC_DC_FIELD_DATA_PDU == h.dc); - assert(0x01 == h.fi); - assert(2 == h.N_li); - assert(1500 == h.li[0]); - assert(1500 == h.li[1]); - assert(0 == h.lsf); - assert(0 == h.p); - assert(0 == h.rf); - assert(0 == h.so); - assert(0 == h.sn); + TESTASSERT(RLC_DC_FIELD_DATA_PDU == h.dc); + TESTASSERT(0x01 == h.fi); + TESTASSERT(2 == h.N_li); + TESTASSERT(1500 == h.li[0]); + TESTASSERT(1500 == h.li[1]); + TESTASSERT(0 == h.lsf); + TESTASSERT(0 == h.p); + TESTASSERT(0 == h.rf); + TESTASSERT(0 == h.so); + TESTASSERT(0 == h.sn); rlc_am_write_data_pdu_header(&h, &b2); - assert(b2.N_bytes == PDU2_LEN); + TESTASSERT(b2.N_bytes == PDU2_LEN); for (uint32_t i = 0; i < b2.N_bytes; i++) - assert(b2.msg[i] == b1.msg[i]); + TESTASSERT(b2.msg[i] == b1.msg[i]); + return SRSLTE_SUCCESS; } -void test3() +int test3() { srslte::rlc_amd_pdu_header_t h; srslte::byte_buffer_t b1, b2; @@ -96,24 +98,25 @@ void test3() memcpy(b1.msg, &pdu3[0], PDU3_LEN); b1.N_bytes = PDU3_LEN; rlc_am_read_data_pdu_header(&b1, &h); - assert(RLC_DC_FIELD_DATA_PDU == h.dc); - assert(0x01 == h.fi); - assert(3 == h.N_li); - assert(1500 == h.li[0]); - assert(1500 == h.li[1]); - assert(1500 == h.li[2]); - assert(0 == h.lsf); - assert(0 == h.p); - assert(0 == h.rf); - assert(0 == h.so); - assert(0 == h.sn); + TESTASSERT(RLC_DC_FIELD_DATA_PDU == h.dc); + TESTASSERT(0x01 == h.fi); + TESTASSERT(3 == h.N_li); + TESTASSERT(1500 == h.li[0]); + TESTASSERT(1500 == h.li[1]); + TESTASSERT(1500 == h.li[2]); + TESTASSERT(0 == h.lsf); + TESTASSERT(0 == h.p); + TESTASSERT(0 == h.rf); + TESTASSERT(0 == h.so); + TESTASSERT(0 == h.sn); rlc_am_write_data_pdu_header(&h, &b2); - assert(b2.N_bytes == PDU3_LEN); + TESTASSERT(b2.N_bytes == PDU3_LEN); for (uint32_t i = 0; i < b2.N_bytes; i++) - assert(b2.msg[i] == b1.msg[i]); + TESTASSERT(b2.msg[i] == b1.msg[i]); + return SRSLTE_SUCCESS; } -void test4() +int test4() { srslte::rlc_amd_pdu_header_t h; srslte::byte_buffer_t b1, b2; @@ -121,26 +124,28 @@ void test4() memcpy(b1.msg, &pdu4[0], PDU4_LEN); b1.N_bytes = PDU4_LEN; rlc_am_read_data_pdu_header(&b1, &h); - assert(RLC_DC_FIELD_DATA_PDU == h.dc); - assert(0x03 == h.fi); - assert(2 == h.N_li); - assert(1342 == h.li[0]); - assert(1500 == h.li[1]); - assert(0 == h.lsf); - assert(0 == h.p); - assert(0 == h.rf); - assert(0 == h.so); - assert(2 == h.sn); + TESTASSERT(RLC_DC_FIELD_DATA_PDU == h.dc); + TESTASSERT(0x03 == h.fi); + TESTASSERT(2 == h.N_li); + TESTASSERT(1342 == h.li[0]); + TESTASSERT(1500 == h.li[1]); + TESTASSERT(0 == h.lsf); + TESTASSERT(0 == h.p); + TESTASSERT(0 == h.rf); + TESTASSERT(0 == h.so); + TESTASSERT(2 == h.sn); rlc_am_write_data_pdu_header(&h, &b2); - assert(b2.N_bytes == PDU4_LEN); + TESTASSERT(b2.N_bytes == PDU4_LEN); for (uint32_t i = 0; i < b2.N_bytes; i++) - assert(b2.msg[i] == b1.msg[i]); + TESTASSERT(b2.msg[i] == b1.msg[i]); + return SRSLTE_SUCCESS; } int main(int argc, char** argv) { - test1(); - test2(); - test3(); - test4(); + TESTASSERT(test1() == SRSLTE_SUCCESS); + TESTASSERT(test2() == SRSLTE_SUCCESS); + TESTASSERT(test3() == SRSLTE_SUCCESS); + TESTASSERT(test4() == SRSLTE_SUCCESS); + return SRSLTE_SUCCESS; } diff --git a/lib/test/upper/rlc_am_test.cc b/lib/test/upper/rlc_am_test.cc index be2362153..2b7c3c560 100644 --- a/lib/test/upper/rlc_am_test.cc +++ b/lib/test/upper/rlc_am_test.cc @@ -15,7 +15,6 @@ #include "srslte/common/test_common.h" #include "srslte/common/threads.h" #include "srslte/upper/rlc_am_lte.h" -#include #include #define NBUFS 5 #define HAVE_PCAP 0 @@ -112,7 +111,7 @@ private: bool running; }; -void basic_test_tx(rlc_am_lte* rlc, byte_buffer_t pdu_bufs[NBUFS]) +int basic_test_tx(rlc_am_lte* rlc, byte_buffer_t pdu_bufs[NBUFS]) { // Push 5 SDUs into RLC1 @@ -125,19 +124,20 @@ void basic_test_tx(rlc_am_lte* rlc, byte_buffer_t pdu_bufs[NBUFS]) rlc->write_sdu(std::move(sdu_bufs[i])); } - assert(13 == rlc->get_buffer_state()); // 2 Bytes for fixed header + 6 for LIs + 5 for payload + TESTASSERT(13 == rlc->get_buffer_state()); // 2 Bytes for fixed header + 6 for LIs + 5 for payload // Read 5 PDUs from RLC1 (1 byte each) for (int i = 0; i < NBUFS; i++) { uint32_t len = rlc->read_pdu(pdu_bufs[i].msg, 3); // 2 bytes for header + 1 byte payload pdu_bufs[i].N_bytes = len; - assert(3 == len); + TESTASSERT(3 == len); } - assert(0 == rlc->get_buffer_state()); + TESTASSERT(0 == rlc->get_buffer_state()); + return SRSLTE_SUCCESS; } -bool basic_test() +int basic_test() { rlc_am_tester tester; timer_handler timers(8); @@ -147,7 +147,7 @@ bool basic_test() rlc_am_lte rlc2(rrc_log2, 1, &tester, &tester, &timers); // before configuring entity - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); if (not rlc1.configure(rlc_config_t::default_rlc_am_config())) { return -1; @@ -164,14 +164,14 @@ bool basic_test() rlc2.write_pdu(pdu_bufs[i].msg, pdu_bufs[i].N_bytes); } - assert(2 == rlc2.get_buffer_state()); + TESTASSERT(2 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; int len = rlc2.read_pdu(status_buf.msg, 2); status_buf.N_bytes = len; - assert(0 == rlc2.get_buffer_state()); + TESTASSERT(0 == rlc2.get_buffer_state()); // Assert status is correct rlc_status_pdu_t status_check = {}; @@ -182,8 +182,8 @@ bool basic_test() rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); for (int i = 0; i < tester.n_sdus; i++) { - assert(tester.sdus[i]->N_bytes == 1); - assert(*(tester.sdus[i]->msg) == i); + TESTASSERT(tester.sdus[i]->N_bytes == 1); + TESTASSERT(*(tester.sdus[i]->msg) == i); } // Check statistics @@ -192,7 +192,7 @@ bool basic_test() return SRSLTE_SUCCESS; } -bool concat_test() +int concat_test() { rlc_am_tester tester; srslte::timer_handler timers(8); @@ -218,14 +218,14 @@ bool concat_test() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(13 == rlc1.get_buffer_state()); // 2 Bytes for fixed header + 6 for LIs + 5 for payload + TESTASSERT(13 == rlc1.get_buffer_state()); // 2 Bytes for fixed header + 6 for LIs + 5 for payload // Read 1 PDUs from RLC1 containing all 5 SDUs byte_buffer_t pdu_buf; int len = rlc1.read_pdu(pdu_buf.msg, 13); // 8 bytes for header + payload pdu_buf.N_bytes = len; - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDU into RLC2 rlc2.write_pdu(pdu_buf.msg, pdu_buf.N_bytes); @@ -246,10 +246,10 @@ bool concat_test() // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { - assert(tester.sdus[i]->N_bytes == 1); - assert(*(tester.sdus[i]->msg) == i); + TESTASSERT(tester.sdus[i]->N_bytes == 1); + TESTASSERT(*(tester.sdus[i]->msg) == i); } // Check statistics @@ -258,7 +258,7 @@ bool concat_test() return SRSLTE_SUCCESS; } -bool segment_test(bool in_seq_rx) +int segment_test(bool in_seq_rx) { rlc_am_tester tester; srslte::timer_handler timers(8); @@ -286,7 +286,7 @@ bool segment_test(bool in_seq_rx) rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(58 == rlc1.get_buffer_state()); // 2 bytes for header + 6 bytes for LI + 50 bytes for payload + TESTASSERT(58 == rlc1.get_buffer_state()); // 2 bytes for header + 6 bytes for LI + 50 bytes for payload // Read PDUs from RLC1 (force segmentation) byte_buffer_t pdu_bufs[20]; @@ -296,7 +296,7 @@ bool segment_test(bool in_seq_rx) pdu_bufs[n_pdus++].N_bytes = len; } - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 if (in_seq_rx) { @@ -314,7 +314,7 @@ bool segment_test(bool in_seq_rx) // Receiver will only generate status PDU if they arrive in order // If SN=7 arrives first, but the Rx expects SN=0, status reporting will be delayed, see TS 36.322 v10 Section 5.2.3 if (in_seq_rx) { - assert(2 == rlc2.get_buffer_state()); + TESTASSERT(2 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -330,13 +330,13 @@ bool segment_test(bool in_seq_rx) rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); } - assert(0 == rlc2.get_buffer_state()); + TESTASSERT(0 == rlc2.get_buffer_state()); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { - assert(tester.sdus[i]->N_bytes == 10); + TESTASSERT(tester.sdus[i]->N_bytes == 10); for (int j = 0; j < 10; j++) - assert(tester.sdus[i]->msg[j] == j); + TESTASSERT(tester.sdus[i]->msg[j] == j); } // Check statistics @@ -345,7 +345,7 @@ bool segment_test(bool in_seq_rx) return SRSLTE_SUCCESS; } -bool retx_test() +int retx_test() { rlc_am_tester tester; timer_handler timers(8); @@ -372,7 +372,7 @@ bool retx_test() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(13 == rlc1.get_buffer_state()); + TESTASSERT(13 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (1 byte each) byte_buffer_t pdu_bufs[NBUFS]; @@ -381,7 +381,7 @@ bool retx_test() pdu_bufs[i].N_bytes = len; } - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 1) for (int i = 0; i < NBUFS; i++) { @@ -391,7 +391,7 @@ bool retx_test() // check buffered bytes at receiver, 3 PDUs with one 1 B each (SN=0 has been delivered already) rlc_bearer_metrics_t metrics = rlc2.get_metrics(); - assert(metrics.rx_buffered_bytes == 3); + TESTASSERT(metrics.rx_buffered_bytes == 3); // Step timers until reordering timeout expires for (int cnt = 0; cnt < 5; cnt++) { @@ -399,7 +399,7 @@ bool retx_test() } uint32_t buffer_state = rlc2.get_buffer_state(); - assert(4 == buffer_state); + TESTASSERT(4 == buffer_state); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -419,7 +419,7 @@ bool retx_test() // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); - assert(3 == rlc1.get_buffer_state()); // 2 byte header + 1 byte payload + TESTASSERT(3 == rlc1.get_buffer_state()); // 2 byte header + 1 byte payload // Read the retx PDU from RLC1 byte_buffer_t retx; @@ -429,7 +429,7 @@ bool retx_test() // Write the retx PDU to RLC2 rlc2.write_pdu(retx.msg, retx.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 1) return -1; @@ -441,7 +441,7 @@ bool retx_test() } // Purpose: test correct retx of lost segment and pollRetx timer expiration -bool segment_retx_test() +int segment_retx_test() { rlc_am_tester tester; timer_handler timers(8); @@ -544,7 +544,7 @@ bool segment_retx_test() return SRSLTE_SUCCESS; } -bool resegment_test_1() +int resegment_test_1() { // SDUs: | 10 | 10 | 10 | 10 | 10 | // PDUs: | 10 | 10 | 10 | 10 | 10 | @@ -576,7 +576,7 @@ bool resegment_test_1() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(58 == rlc1.get_buffer_state()); // 2 bytes for fixed header, 6 bytes for LIs, 50 bytes for data + TESTASSERT(58 == rlc1.get_buffer_state()); // 2 bytes for fixed header, 6 bytes for LIs, 50 bytes for data // Read 5 PDUs from RLC1 (10 bytes each) byte_buffer_t pdu_bufs[NBUFS]; @@ -585,7 +585,7 @@ bool resegment_test_1() pdu_bufs[i].N_bytes = len; } - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 1) for (int i = 0; i < NBUFS; i++) { @@ -599,7 +599,7 @@ bool resegment_test_1() timers.step_all(); } - assert(4 == rlc2.get_buffer_state()); + TESTASSERT(4 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -609,7 +609,7 @@ bool resegment_test_1() // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); - assert(12 == rlc1.get_buffer_state()); // 2 byte header + 10 data + TESTASSERT(12 == rlc1.get_buffer_state()); // 2 byte header + 10 data // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; @@ -619,7 +619,7 @@ bool resegment_test_1() // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(9 == rlc1.get_buffer_state()); + TESTASSERT(9 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; @@ -629,7 +629,7 @@ bool resegment_test_1() // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 10) return -1; @@ -641,7 +641,7 @@ bool resegment_test_1() return 0; } -bool resegment_test_2() +int resegment_test_2() { // SDUs: | 10 | 10 | 10 | 10 | 10 | @@ -674,7 +674,7 @@ bool resegment_test_2() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(58 == rlc1.get_buffer_state()); + TESTASSERT(58 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (5 bytes, 10 bytes, 20 bytes, 10 bytes, 5 bytes) byte_buffer_t pdu_bufs[NBUFS]; @@ -684,7 +684,7 @@ bool resegment_test_2() pdu_bufs[3].N_bytes = rlc1.read_pdu(pdu_bufs[3].msg, 14); // 4 byte header + 10 byte payload pdu_bufs[4].N_bytes = rlc1.read_pdu(pdu_bufs[4].msg, 7); // 2 byte header + 5 byte payload - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) for (int i = 0; i < NBUFS; i++) { @@ -698,7 +698,7 @@ bool resegment_test_2() timers.step_all(); } - assert(4 == rlc2.get_buffer_state()); + TESTASSERT(4 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -707,7 +707,7 @@ bool resegment_test_2() // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); - assert(25 == rlc1.get_buffer_state()); // 4 byte header + 20 data + TESTASSERT(25 == rlc1.get_buffer_state()); // 4 byte header + 20 data // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; @@ -716,7 +716,7 @@ bool resegment_test_2() // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(18 == rlc1.get_buffer_state()); + TESTASSERT(18 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; @@ -725,7 +725,7 @@ bool resegment_test_2() // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 10) return -1; @@ -737,7 +737,7 @@ bool resegment_test_2() return 0; } -bool resegment_test_3() +int resegment_test_3() { // SDUs: | 10 | 10 | 10 | 10 | 10 | @@ -769,7 +769,7 @@ bool resegment_test_3() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(58 == rlc1.get_buffer_state()); + TESTASSERT(58 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (5 bytes, 5 bytes, 20 bytes, 10 bytes, 10 bytes) byte_buffer_t pdu_bufs[NBUFS]; @@ -779,7 +779,7 @@ bool resegment_test_3() pdu_bufs[3].N_bytes = rlc1.read_pdu(pdu_bufs[3].msg, 12); // 2 byte header + 10 byte payload pdu_bufs[4].N_bytes = rlc1.read_pdu(pdu_bufs[4].msg, 12); // 2 byte header + 10 byte payload - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) for (int i = 0; i < NBUFS; i++) { @@ -793,7 +793,7 @@ bool resegment_test_3() timers.step_all(); } - assert(4 == rlc2.get_buffer_state()); + TESTASSERT(4 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -816,7 +816,7 @@ bool resegment_test_3() // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 10) return -1; @@ -828,7 +828,7 @@ bool resegment_test_3() return 0; } -bool resegment_test_4() +int resegment_test_4() { // SDUs: | 10 | 10 | 10 | 10 | 10 | // PDUs: | 5 | 5| 30 | 5 | 5| @@ -859,7 +859,7 @@ bool resegment_test_4() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(58 == rlc1.get_buffer_state()); + TESTASSERT(58 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (5 bytes, 5 bytes, 30 bytes, 5 bytes, 5 bytes) byte_buffer_t pdu_bufs[NBUFS]; @@ -869,7 +869,7 @@ bool resegment_test_4() pdu_bufs[3].N_bytes = rlc1.read_pdu(pdu_bufs[3].msg, 7); // 2 byte header + 5 byte payload pdu_bufs[4].N_bytes = rlc1.read_pdu(pdu_bufs[4].msg, 7); // 2 byte header + 5 byte payload - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) for (int i = 0; i < NBUFS; i++) { @@ -883,7 +883,7 @@ bool resegment_test_4() timers.step_all(); } - assert(4 == rlc2.get_buffer_state()); + TESTASSERT(4 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -899,7 +899,7 @@ bool resegment_test_4() // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(23 == rlc1.get_buffer_state()); + TESTASSERT(23 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; @@ -908,7 +908,7 @@ bool resegment_test_4() // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 10) return -1; @@ -920,7 +920,7 @@ bool resegment_test_4() return 0; } -bool resegment_test_5() +int resegment_test_5() { // SDUs: | 10 | 10 | 10 | 10 | 10 | // PDUs: |2|3| 40 |3|2| @@ -951,7 +951,7 @@ bool resegment_test_5() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(58 == rlc1.get_buffer_state()); + TESTASSERT(58 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (2 bytes, 3 bytes, 40 bytes, 3 bytes, 2 bytes) byte_buffer_t pdu_bufs[NBUFS]; @@ -961,7 +961,7 @@ bool resegment_test_5() pdu_bufs[3].N_bytes = rlc1.read_pdu(pdu_bufs[3].msg, 5); // 2 byte header + 3 byte payload pdu_bufs[4].N_bytes = rlc1.read_pdu(pdu_bufs[4].msg, 4); // 2 byte header + 2 byte payload - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 2) for (int i = 0; i < NBUFS; i++) { @@ -975,7 +975,7 @@ bool resegment_test_5() timers.step_all(); } - assert(4 == rlc2.get_buffer_state()); + TESTASSERT(4 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -991,7 +991,7 @@ bool resegment_test_5() // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(31 == rlc1.get_buffer_state()); + TESTASSERT(31 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; @@ -1000,7 +1000,7 @@ bool resegment_test_5() // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); - assert(tester.n_sdus == 5); + TESTASSERT(tester.n_sdus == 5); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 10) return -1; @@ -1012,7 +1012,7 @@ bool resegment_test_5() return 0; } -bool resegment_test_6() +int resegment_test_6() { // SDUs: |10|10|10| 54 | 54 | 54 | 54 | 54 | 54 | // PDUs: |10|10|10| 270 | 54 | @@ -1051,7 +1051,7 @@ bool resegment_test_6() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(368 == rlc1.get_buffer_state()); + TESTASSERT(368 == rlc1.get_buffer_state()); // Read PDUs from RLC1 (10, 10, 10, 270, 54) byte_buffer_t pdu_bufs[5]; @@ -1064,7 +1064,7 @@ bool resegment_test_6() len = rlc1.read_pdu(pdu_bufs[4].msg, 56); pdu_bufs[4].N_bytes = len; - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Write PDUs into RLC2 (skip SN 3) for (int i = 0; i < 5; i++) { @@ -1078,7 +1078,7 @@ bool resegment_test_6() timers.step_all(); } - assert(4 == rlc2.get_buffer_state()); + TESTASSERT(4 == rlc2.get_buffer_state()); // Read status PDU from RLC2 byte_buffer_t status_buf; @@ -1088,7 +1088,7 @@ bool resegment_test_6() // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); - assert(278 == rlc1.get_buffer_state()); + TESTASSERT(278 == rlc1.get_buffer_state()); // Read the retx PDU from RLC1 and force resegmentation byte_buffer_t retx1; @@ -1098,7 +1098,7 @@ bool resegment_test_6() // Write the retx PDU to RLC2 rlc2.write_pdu(retx1.msg, retx1.N_bytes); - assert(159 == rlc1.get_buffer_state()); + TESTASSERT(159 == rlc1.get_buffer_state()); // Read the remaining segment byte_buffer_t retx2; @@ -1108,11 +1108,11 @@ bool resegment_test_6() // Write the retx PDU to RLC2 rlc2.write_pdu(retx2.msg, retx2.N_bytes); - assert(tester.n_sdus == 9); + TESTASSERT(tester.n_sdus == 9); for (int i = 0; i < 3; i++) { - assert(tester.sdus[i]->N_bytes == 10); + TESTASSERT(tester.sdus[i]->N_bytes == 10); for (int j = 0; j < 10; j++) - assert(tester.sdus[i]->msg[j] == j); + TESTASSERT(tester.sdus[i]->msg[j] == j); } for (int i = 3; i < 9; i++) { if (i >= tester.n_sdus) @@ -1129,7 +1129,7 @@ bool resegment_test_6() } // Retransmission of PDU segments of the same size -bool resegment_test_7() +int resegment_test_7() { // SDUs: | 30 | 30 | // PDUs: | 13 | 13 | 11 | 13 | 10 | @@ -1172,13 +1172,13 @@ bool resegment_test_7() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(64 == rlc1.get_buffer_state()); + TESTASSERT(64 == rlc1.get_buffer_state()); // Read PDUs from RLC1 (15 bytes each) byte_buffer_t pdu_bufs[N_PDU_BUFS]; for (uint32_t i = 0; i < N_PDU_BUFS; i++) { pdu_bufs[i].N_bytes = rlc1.read_pdu(pdu_bufs[i].msg, 15); // 2 bytes for header + 12 B payload - assert(pdu_bufs[i].N_bytes); + TESTASSERT(pdu_bufs[i].N_bytes); } // Step timers until poll_retx timeout expires @@ -1188,7 +1188,7 @@ bool resegment_test_7() } // RLC should try to retx a random PDU because it needs to request a status from the receiver - assert(0 != rlc1.get_buffer_state()); + TESTASSERT(0 != rlc1.get_buffer_state()); // Skip PDU with SN 2 for (uint32_t i = 0; i < N_PDU_BUFS; i++) { @@ -1207,14 +1207,14 @@ bool resegment_test_7() } // RLC should try to retransmit a random PDU because it needs to re-request a status PDU from the receiver - assert(0 != rlc1.get_buffer_state()); + TESTASSERT(0 != rlc1.get_buffer_state()); // first round of retx, forcing resegmentation byte_buffer_t retx[4]; for (uint32_t i = 0; i < 4; i++) { - assert(0 != rlc1.get_buffer_state()); + TESTASSERT(0 != rlc1.get_buffer_state()); retx[i].N_bytes = rlc1.read_pdu(retx[i].msg, 7); - assert(retx[i].N_bytes); + TESTASSERT(retx[i].N_bytes); // Write the last two segments to RLC2 if (i > 1) { @@ -1226,7 +1226,7 @@ bool resegment_test_7() } // Read status PDU from RLC2 - assert(rlc2.get_buffer_state()); + TESTASSERT(rlc2.get_buffer_state()); byte_buffer_t status_buf; status_buf.N_bytes = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status @@ -1236,14 +1236,14 @@ bool resegment_test_7() pcap.write_ul_am_ccch(status_buf.msg, status_buf.N_bytes); #endif - assert(15 == rlc1.get_buffer_state()); + TESTASSERT(15 == rlc1.get_buffer_state()); // second round of retx, forcing resegmentation byte_buffer_t retx2[4]; for (uint32_t i = 0; i < 4; i++) { - assert(rlc1.get_buffer_state() != 0); + TESTASSERT(rlc1.get_buffer_state() != 0); retx2[i].N_bytes = rlc1.read_pdu(retx2[i].msg, 9); - assert(retx2[i].N_bytes != 0); + TESTASSERT(retx2[i].N_bytes != 0); rlc2.write_pdu(retx2[i].msg, retx2[i].N_bytes); #if HAVE_PCAP @@ -1252,7 +1252,7 @@ bool resegment_test_7() } // check buffer states - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Step timers until poll_retx timeout expires cnt = 5; @@ -1261,7 +1261,7 @@ bool resegment_test_7() } // Read status PDU from RLC2 - assert(rlc2.get_buffer_state()); + TESTASSERT(rlc2.get_buffer_state()); status_buf.N_bytes = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status // Write status PDU to RLC1 @@ -1271,11 +1271,11 @@ bool resegment_test_7() #endif // check status again - assert(0 == rlc1.get_buffer_state()); - assert(0 == rlc2.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc2.get_buffer_state()); // Check number of SDUs and their content - assert(tester.n_sdus == N_SDU_BUFS); + TESTASSERT(tester.n_sdus == N_SDU_BUFS); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != sdu_size) return -1; @@ -1293,7 +1293,7 @@ bool resegment_test_7() } // Retransmission of PDU segments with different size -bool resegment_test_8() +int resegment_test_8() { // SDUs: | 30 | 30 | // PDUs: | 15 | 15 | 15 | 15 | 15 | @@ -1336,16 +1336,16 @@ bool resegment_test_8() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(64 == rlc1.get_buffer_state()); + TESTASSERT(64 == rlc1.get_buffer_state()); // Read PDUs from RLC1 (15 bytes each) byte_buffer_t pdu_bufs[N_PDU_BUFS]; for (uint32_t i = 0; i < N_PDU_BUFS; i++) { pdu_bufs[i].N_bytes = rlc1.read_pdu(pdu_bufs[i].msg, 15); // 12 bytes for header + payload - assert(pdu_bufs[i].N_bytes); + TESTASSERT(pdu_bufs[i].N_bytes); } - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Skip PDU one and two for (uint32_t i = 0; i < N_PDU_BUFS; i++) { @@ -1364,14 +1364,14 @@ bool resegment_test_8() } // what PDU to retransmit is random but it must not be zero - assert(0 != rlc1.get_buffer_state()); + TESTASSERT(0 != rlc1.get_buffer_state()); // first round of retx, forcing resegmentation byte_buffer_t retx[4]; for (uint32_t i = 0; i < 3; i++) { - assert(rlc1.get_buffer_state()); + TESTASSERT(rlc1.get_buffer_state()); retx[i].N_bytes = rlc1.read_pdu(retx[i].msg, 8); - assert(retx[i].N_bytes); + TESTASSERT(retx[i].N_bytes); // Write the last two segments to RLC2 if (i > 1) { @@ -1389,7 +1389,7 @@ bool resegment_test_8() } // Read status PDU from RLC2 - assert(rlc2.get_buffer_state()); + TESTASSERT(rlc2.get_buffer_state()); byte_buffer_t status_buf; status_buf.N_bytes = rlc2.read_pdu(status_buf.msg, 10); // 10 bytes is enough to hold the status @@ -1399,14 +1399,14 @@ bool resegment_test_8() pcap.write_ul_am_ccch(status_buf.msg, status_buf.N_bytes); #endif - assert(15 == rlc1.get_buffer_state()); + TESTASSERT(15 == rlc1.get_buffer_state()); // second round of retx, reduce grant size to force different segment sizes byte_buffer_t retx2[20]; for (uint32_t i = 0; i < 7; i++) { - assert(rlc1.get_buffer_state() != 0); + TESTASSERT(rlc1.get_buffer_state() != 0); retx2[i].N_bytes = rlc1.read_pdu(retx2[i].msg, 9); - assert(retx2[i].N_bytes != 0); + TESTASSERT(retx2[i].N_bytes != 0); rlc2.write_pdu(retx2[i].msg, retx2[i].N_bytes); #if HAVE_PCAP pcap.write_dl_am_ccch(retx[i].msg, retx[i].N_bytes); @@ -1431,7 +1431,7 @@ bool resegment_test_8() }; // Check number of SDUs and their content - assert(tester.n_sdus == N_SDU_BUFS); + TESTASSERT(tester.n_sdus == N_SDU_BUFS); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != sdu_size) return -1; @@ -1585,7 +1585,7 @@ bool status_pdu_test() rlc1.write_sdu(std::move(sdu_bufs[i])); } - assert(13 == rlc1.get_buffer_state()); + TESTASSERT(13 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (1 byte each) byte_buffer_t pdu_bufs[NBUFS]; @@ -1594,7 +1594,7 @@ bool status_pdu_test() pdu_bufs[i].N_bytes = len; } - assert(0 == rlc1.get_buffer_state()); + TESTASSERT(0 == rlc1.get_buffer_state()); // Only pass last PDUs to RLC2 for (int i = 0; i < NBUFS; i++) { @@ -1610,14 +1610,14 @@ bool status_pdu_test() } uint32_t buffer_state = rlc2.get_buffer_state(); - assert(8 == buffer_state); + TESTASSERT(8 == buffer_state); // Read status PDU from RLC2 byte_buffer_t status_buf; len = rlc2.read_pdu(status_buf.msg, 5); // provide only small grant status_buf.N_bytes = len; - assert(status_buf.N_bytes != 0); + TESTASSERT(status_buf.N_bytes != 0); // check status PDU doesn't contain ACK_SN in NACK list rlc_status_pdu_t status_pdu = {}; @@ -1629,7 +1629,7 @@ bool status_pdu_test() // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); - assert(3 == rlc1.get_buffer_state()); // 2 byte header + 1 byte payload + TESTASSERT(3 == rlc1.get_buffer_state()); // 2 byte header + 1 byte payload // Read the retx PDU from RLC1 byte_buffer_t retx; @@ -1649,7 +1649,7 @@ bool status_pdu_test() status_buf.clear(); len = rlc2.read_pdu(status_buf.msg, 10); // big enough grant to fit full status PDU status_buf.N_bytes = len; - assert(status_buf.N_bytes != 0); + TESTASSERT(status_buf.N_bytes != 0); // Write status PDU to RLC1 rlc1.write_pdu(status_buf.msg, status_buf.N_bytes); @@ -1664,7 +1664,7 @@ bool status_pdu_test() rlc2.write_pdu(retx.msg, retx.N_bytes); } - assert(tester.n_sdus == NBUFS); + TESTASSERT(tester.n_sdus == NBUFS); for (int i = 0; i < tester.n_sdus; i++) { if (tester.sdus[i]->N_bytes != 1) return -1; diff --git a/lib/test/upper/rlc_stress_test.cc b/lib/test/upper/rlc_stress_test.cc index 93ff18bdd..324f126f8 100644 --- a/lib/test/upper/rlc_stress_test.cc +++ b/lib/test/upper/rlc_stress_test.cc @@ -13,6 +13,7 @@ #include "srslte/common/crash_handler.h" #include "srslte/common/log_filter.h" #include "srslte/common/rlc_pcap.h" +#include "srslte/common/test_common.h" #include "srslte/common/threads.h" #include "srslte/upper/rlc.h" #include diff --git a/lib/test/upper/rlc_um_data_test.cc b/lib/test/upper/rlc_um_data_test.cc index 0ab4fc965..03d9f0462 100644 --- a/lib/test/upper/rlc_um_data_test.cc +++ b/lib/test/upper/rlc_um_data_test.cc @@ -10,8 +10,8 @@ * */ +#include "srslte/common/test_common.h" #include "srslte/upper/rlc_um_lte.h" -#include #include // Fixed header only @@ -30,13 +30,13 @@ int main(int argc, char** argv) memcpy(b1.msg, &pdu1[0], PDU1_LEN); b1.N_bytes = PDU1_LEN; rlc_um_read_data_pdu_header(&b1, srslte::rlc_umd_sn_size_t::size10bits, &h); - assert(0x03 == h.fi); - assert(0 == h.N_li); - assert(226 == h.sn); + TESTASSERT(0x03 == h.fi); + TESTASSERT(0 == h.N_li); + TESTASSERT(226 == h.sn); rlc_um_write_data_pdu_header(&h, &b2); - assert(b2.N_bytes == PDU1_LEN); + TESTASSERT(b2.N_bytes == PDU1_LEN); for (uint32_t i = 0; i < b2.N_bytes; i++) - assert(b2.msg[i] == b1.msg[i]); + TESTASSERT(b2.msg[i] == b1.msg[i]); b1.clear(); b2.clear(); @@ -45,12 +45,12 @@ int main(int argc, char** argv) memcpy(b1.msg, &pdu2[0], PDU2_LEN); b1.N_bytes = PDU2_LEN; rlc_um_read_data_pdu_header(&b1, srslte::rlc_umd_sn_size_t::size10bits, &h); - assert(0x03 == h.fi); - assert(225 == h.sn); - assert(1 == h.N_li); - assert(104 == h.li[0]); + TESTASSERT(0x03 == h.fi); + TESTASSERT(225 == h.sn); + TESTASSERT(1 == h.N_li); + TESTASSERT(104 == h.li[0]); rlc_um_write_data_pdu_header(&h, &b2); - assert(b2.N_bytes == PDU2_LEN); + TESTASSERT(b2.N_bytes == PDU2_LEN); for (uint32_t i = 0; i < b2.N_bytes; i++) - assert(b2.msg[i] == b1.msg[i]); + TESTASSERT(b2.msg[i] == b1.msg[i]); } diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index 30823a5a1..9a737a941 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -19,7 +19,6 @@ #include "srslte/test/ue_test_interfaces.h" #include "srsue/hdr/stack/mac/mac.h" #include "srsue/hdr/stack/mac/mux.h" -#include #include #include diff --git a/srsue/test/ttcn3/test/CMakeLists.txt b/srsue/test/ttcn3/test/CMakeLists.txt index cc908b42d..f4dea0dc2 100644 --- a/srsue/test/ttcn3/test/CMakeLists.txt +++ b/srsue/test/ttcn3/test/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories(${PROJECT_SOURCE_DIR}/srsue/test/ttcn3/hdr) add_executable(rapidjson_test rapidjson_test.cc) +target_link_libraries(rapidjson_test srslte_common) add_test(rapidjson_test rapidjson_test) add_executable(ttcn3_if_handler_test ttcn3_if_handler_test.cc) diff --git a/srsue/test/ttcn3/test/rapidjson_test.cc b/srsue/test/ttcn3/test/rapidjson_test.cc index 2a5eafb41..f3ed4bbcd 100644 --- a/srsue/test/ttcn3/test/rapidjson_test.cc +++ b/srsue/test/ttcn3/test/rapidjson_test.cc @@ -10,8 +10,8 @@ * */ +#include "srslte/common/test_common.h" #include "ttcn3_helpers.h" -#include #include #include #include @@ -64,20 +64,21 @@ int SYSTEM_CTRL_CNF_test() return 0; } -void pretty_print(std::string json) +int pretty_print(std::string json) { Document document; if (document.Parse((char*)json.c_str()).HasParseError()) { fprintf(stderr, "Error parsing incoming data. Exiting\n"); exit(-1); } - assert(document.IsObject()); + TESTASSERT(document.IsObject() == true); // Pretty-print StringBuffer buffer; PrettyWriter writer(buffer); document.Accept(writer); printf("%s\n", (char*)buffer.GetString()); + return SRSLTE_SUCCESS; } // UDP v4 test diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index 4ffa9b8af..9831d32cd 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -14,6 +14,7 @@ #include "srslte/common/log_filter.h" #include "srslte/common/logger_srslog_wrapper.h" #include "srslte/common/logmap.h" +#include "srslte/common/test_common.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/srslog/srslog.h" #include "srslte/test/ue_test_interfaces.h" @@ -26,7 +27,6 @@ #include "srsue/hdr/stack/upper/nas.h" #include "srsue/hdr/stack/upper/usim.h" #include "srsue/hdr/stack/upper/usim_base.h" -#include #include using namespace srsue; @@ -34,14 +34,6 @@ using namespace asn1::rrc; #define LCID 1 -#define TESTASSERT(cond) \ - { \ - if (!(cond)) { \ - std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \ - return -1; \ - } \ - } - uint8_t auth_request_pdu[] = {0x07, 0x52, 0x01, 0x0c, 0x63, 0xa8, 0x54, 0x13, 0xe6, 0xa4, 0xce, 0xd9, 0x86, 0xfb, 0xe5, 0xce, 0x9b, 0x62, 0x5e, 0x10, 0x67, 0x57, 0xb3, 0xc2, 0xb9, 0x70, 0x90, 0x01, 0x0c, 0x72, 0x8a, 0x67, 0x57, 0x92, 0x52, 0xb8}; diff --git a/srsue/test/upper/usim_test.cc b/srsue/test/upper/usim_test.cc index 0c8c7d912..4c0a23ebe 100644 --- a/srsue/test/upper/usim_test.cc +++ b/srsue/test/upper/usim_test.cc @@ -11,8 +11,8 @@ */ #include "srslte/common/log_filter.h" +#include "srslte/common/test_common.h" #include "srsue/hdr/stack/upper/usim.h" -#include #include using namespace srsue; @@ -69,5 +69,5 @@ int main(int argc, char** argv) srsue::usim usim(&usim_log); usim.init(&args); - assert(usim.generate_authentication_response(rand_enb, autn_enb, mcc, mnc, res, &res_len, k_asme) == AUTH_OK); + TESTASSERT(usim.generate_authentication_response(rand_enb, autn_enb, mcc, mnc, res, &res_len, k_asme) == AUTH_OK); }