diff --git a/lib/test/pdcp/pdcp_nr_test_tx.cc b/lib/test/pdcp/pdcp_nr_test_tx.cc index 99dec8e1e..60fd0377a 100644 --- a/lib/test/pdcp/pdcp_nr_test_tx.cc +++ b/lib/test/pdcp/pdcp_nr_test_tx.cc @@ -15,44 +15,55 @@ /* * Genric function to test transmission of in-sequence packets */ -int test_tx(uint32_t n_packets, - const pdcp_initial_state& init_state, - uint8_t pdcp_sn_len, - uint64_t n_pdus_exp, - srsran::unique_byte_buffer_t pdu_exp, - srslog::basic_logger& logger) +class test_tx_helper { - srsran::pdcp_config_t cfg = {1, - srsran::PDCP_RB_IS_DRB, - srsran::SECURITY_DIRECTION_UPLINK, - srsran::SECURITY_DIRECTION_DOWNLINK, - pdcp_sn_len, - srsran::pdcp_t_reordering_t::ms500, - srsran::pdcp_discard_timer_t::infinity, - false, - srsran::srsran_rat_t::nr}; +public: + pdcp_nr_test_helper pdcp_hlp_tx; + srsran::pdcp_entity_nr& pdcp_tx; + rlc_dummy& rlc_tx; + srsue::stack_test_dummy& stack; + srslog::basic_logger& logger; - pdcp_nr_test_helper pdcp_hlp(cfg, sec_cfg, logger); - srsran::pdcp_entity_nr* pdcp = &pdcp_hlp.pdcp; - rlc_dummy* rlc = &pdcp_hlp.rlc; - - pdcp_hlp.set_pdcp_initial_state(init_state); + test_tx_helper(uint8_t pdcp_sn_len, srslog::basic_logger& logger) : + pdcp_hlp_tx({1, + srsran::PDCP_RB_IS_DRB, + srsran::SECURITY_DIRECTION_UPLINK, + srsran::SECURITY_DIRECTION_DOWNLINK, + pdcp_sn_len, + srsran::pdcp_t_reordering_t::ms500, + srsran::pdcp_discard_timer_t::ms500, + false, + srsran::srsran_rat_t::nr}, + sec_cfg, + logger), + pdcp_tx(pdcp_hlp_tx.pdcp), + rlc_tx(pdcp_hlp_tx.rlc), + stack(pdcp_hlp_tx.stack), + logger(logger) + {} + int test_tx(uint32_t n_packets, + const pdcp_initial_state& init_state, + uint64_t n_pdus_exp, + srsran::unique_byte_buffer_t pdu_exp) + { + pdcp_hlp_tx.set_pdcp_initial_state(init_state); - // Run test - for (uint32_t i = 0; i < n_packets; ++i) { - // Test SDU - srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer(); - sdu->append_bytes(sdu1, sizeof(sdu1)); - pdcp->write_sdu(std::move(sdu)); - } + // Run test + for (uint32_t i = 0; i < n_packets; ++i) { + // Test SDU + srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer(); + sdu->append_bytes(sdu1, sizeof(sdu1)); + pdcp_hlp_tx.pdcp.write_sdu(std::move(sdu)); + } - srsran::unique_byte_buffer_t pdu_act = srsran::make_byte_buffer(); - rlc->get_last_sdu(pdu_act); + srsran::unique_byte_buffer_t pdu_act = srsran::make_byte_buffer(); + pdcp_hlp_tx.rlc.get_last_sdu(pdu_act); - TESTASSERT(rlc->rx_count == n_pdus_exp); - TESTASSERT(compare_two_packets(pdu_act, pdu_exp) == 0); - return 0; -} + TESTASSERT(pdcp_hlp_tx.rlc.rx_count == n_pdus_exp); + TESTASSERT(compare_two_packets(pdu_act, pdu_exp) == 0); + return 0; + } +}; /* * TX Test: PDCP Entity with SN LEN = 12 and 18. @@ -70,13 +81,11 @@ int test_tx_all(srslog::basic_logger& logger) { auto& test_logger = srslog::fetch_basic_logger("TESTER "); srsran::test_delimit_logger delimiter("TX COUNT 0, 12 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_12, logger); n_packets = 1; srsran::unique_byte_buffer_t pdu_exp_count0_len12 = srsran::make_byte_buffer(); pdu_exp_count0_len12->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12)); - TESTASSERT( - test_tx( - n_packets, normal_init_state, srsran::PDCP_SN_LEN_12, n_packets, std::move(pdu_exp_count0_len12), logger) == - 0); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_count0_len12)) == 0); } /* * TX Test 2: PDCP Entity with SN LEN = 12 @@ -87,15 +96,11 @@ int test_tx_all(srslog::basic_logger& logger) { auto& test_logger = srslog::fetch_basic_logger("TESTER "); srsran::test_delimit_logger delimiter("TX COUNT 2048, 12 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_12, logger); n_packets = 2049; srsran::unique_byte_buffer_t pdu_exp_count2048_len12 = srsran::make_byte_buffer(); pdu_exp_count2048_len12->append_bytes(pdu1_count2048_snlen12, sizeof(pdu1_count2048_snlen12)); - TESTASSERT(test_tx(n_packets, - normal_init_state, - srsran::PDCP_SN_LEN_12, - n_packets, - std::move(pdu_exp_count2048_len12), - logger) == 0); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_count2048_len12)) == 0); } /* * TX Test 3: PDCP Entity with SN LEN = 12 @@ -106,15 +111,12 @@ int test_tx_all(srslog::basic_logger& logger) { auto& test_logger = srslog::fetch_basic_logger("TESTER "); srsran::test_delimit_logger delimiter("TX COUNT 4096, 12 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_12, logger); + n_packets = 2049; n_packets = 4097; srsran::unique_byte_buffer_t pdu_exp_count4096_len12 = srsran::make_byte_buffer(); pdu_exp_count4096_len12->append_bytes(pdu1_count4096_snlen12, sizeof(pdu1_count4096_snlen12)); - TESTASSERT(test_tx(n_packets, - normal_init_state, - srsran::PDCP_SN_LEN_12, - n_packets, - std::move(pdu_exp_count4096_len12), - logger) == 0); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_count4096_len12)) == 0); } /* * TX Test 4: PDCP Entity with SN LEN = 18 @@ -125,13 +127,11 @@ int test_tx_all(srslog::basic_logger& logger) { auto& test_logger = srslog::fetch_basic_logger("TESTER "); srsran::test_delimit_logger delimiter("TX COUNT 0, 18 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_18, logger); n_packets = 1; srsran::unique_byte_buffer_t pdu_exp_count0_len18 = srsran::make_byte_buffer(); pdu_exp_count0_len18->append_bytes(pdu1_count0_snlen18, sizeof(pdu1_count0_snlen18)); - TESTASSERT( - test_tx( - n_packets, normal_init_state, srsran::PDCP_SN_LEN_18, n_packets, std::move(pdu_exp_count0_len18), logger) == - 0); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_count0_len18)) == 0); } /* @@ -143,15 +143,11 @@ int test_tx_all(srslog::basic_logger& logger) { auto& test_logger = srslog::fetch_basic_logger("TESTER "); srsran::test_delimit_logger delimiter("TX COUNT 131072, 18 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_18, logger); n_packets = 131073; srsran::unique_byte_buffer_t pdu_exp_sn131072_len18 = srsran::make_byte_buffer(); pdu_exp_sn131072_len18->append_bytes(pdu1_count131072_snlen18, sizeof(pdu1_count131072_snlen18)); - TESTASSERT(test_tx(n_packets, - normal_init_state, - srsran::PDCP_SN_LEN_18, - n_packets, - std::move(pdu_exp_sn131072_len18), - logger) == 0); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_sn131072_len18)) == 0); } /* @@ -163,15 +159,11 @@ int test_tx_all(srslog::basic_logger& logger) { auto& test_logger = srslog::fetch_basic_logger("TESTER "); srsran::test_delimit_logger delimiter("TX COUNT 262144, 18 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_18, logger); n_packets = 262145; srsran::unique_byte_buffer_t pdu_exp_count262144_len18 = srsran::make_byte_buffer(); pdu_exp_count262144_len18->append_bytes(pdu1_count262144_snlen18, sizeof(pdu1_count262144_snlen18)); - TESTASSERT(test_tx(n_packets, - normal_init_state, - srsran::PDCP_SN_LEN_18, - n_packets, - std::move(pdu_exp_count262144_len18), - logger) == 0); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_count262144_len18)) == 0); } /* * TX Test 7: PDCP Entity with SN LEN = 12 @@ -180,16 +172,13 @@ int test_tx_all(srslog::basic_logger& logger) */ { auto& test_logger = srslog::fetch_basic_logger("TESTER "); - srsran::test_delimit_logger delimiter("TX COUNT wrap arround, 12 bit SN"); + srsran::test_delimit_logger delimiter("TX COUNT wrap around, 12 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_12, logger); n_packets = 5; srsran::unique_byte_buffer_t pdu_exp_count4294967295_len12 = srsran::make_byte_buffer(); pdu_exp_count4294967295_len12->append_bytes(pdu1_count4294967295_snlen12, sizeof(pdu1_count4294967295_snlen12)); - TESTASSERT(test_tx(n_packets, - near_wraparound_init_state, - srsran::PDCP_SN_LEN_12, - 1, - std::move(pdu_exp_count4294967295_len12), - logger) == 0); + TESTASSERT(tx_helper.test_tx(n_packets, near_wraparound_init_state, 1, std::move(pdu_exp_count4294967295_len12)) == + 0); } /* @@ -199,16 +188,30 @@ int test_tx_all(srslog::basic_logger& logger) */ { auto& test_logger = srslog::fetch_basic_logger("TESTER "); - srsran::test_delimit_logger delimiter("TX COUNT wrap arround, 12 bit SN"); + srsran::test_delimit_logger delimiter("TX COUNT wrap around, 12 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_18, logger); n_packets = 5; srsran::unique_byte_buffer_t pdu_exp_count4294967295_len18 = srsran::make_byte_buffer(); pdu_exp_count4294967295_len18->append_bytes(pdu1_count4294967295_snlen18, sizeof(pdu1_count4294967295_snlen18)); - TESTASSERT(test_tx(n_packets, - near_wraparound_init_state, - srsran::PDCP_SN_LEN_18, - 1, - std::move(pdu_exp_count4294967295_len18), - logger) == 0); + TESTASSERT(tx_helper.test_tx(n_packets, near_wraparound_init_state, 1, std::move(pdu_exp_count4294967295_len18)) == + 0); + } + + /* + * TX Test 9: PDCP Entity with SN LEN = 12 + * Test whether discard timers are correctly stopped after receiving a notification from the RLC + */ + { + auto& test_logger = srslog::fetch_basic_logger("TESTER "); + srsran::test_delimit_logger delimiter("TX COUNT 0, 12 bit SN"); + test_tx_helper tx_helper(srsran::PDCP_SN_LEN_12, logger); + n_packets = 1; + srsran::unique_byte_buffer_t pdu_exp_count0_len12 = srsran::make_byte_buffer(); + pdu_exp_count0_len12->append_bytes(pdu1_count0_snlen12, sizeof(pdu1_count0_snlen12)); + TESTASSERT(tx_helper.test_tx(n_packets, normal_init_state, n_packets, std::move(pdu_exp_count0_len12)) == 0); + TESTASSERT(tx_helper.pdcp_tx.nof_discard_timers() == 1); + tx_helper.pdcp_tx.notify_delivery({0}); + TESTASSERT(tx_helper.pdcp_tx.nof_discard_timers() == 0); } return SRSRAN_SUCCESS; }