diff --git a/srsue/test/mac_test.cc b/srsue/test/mac_test.cc index 57185e91a..2cf6708ac 100644 --- a/srsue/test/mac_test.cc +++ b/srsue/test/mac_test.cc @@ -699,6 +699,180 @@ int mac_ul_sch_pdu_with_padding_bsr_test() return SRSLTE_SUCCESS; } +// Single byte MAC PDU +int mac_ul_sch_pdu_one_byte_test() +{ + const uint8_t tv[] = {0x1f}; + + srslte::log_filter mac_log("MAC"); + mac_log.set_level(srslte::LOG_LEVEL_DEBUG); + mac_log.set_hex_limit(100000); + + srslte::log_filter rlc_log("RLC"); + rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); + rlc_log.set_hex_limit(100000); + + // dummy layers + phy_dummy phy; + rlc_dummy rlc(&rlc_log); + rrc_dummy rrc; + + // the actual MAC + mac mac; + mac.init(&phy, &rlc, &rrc, &mac_log); + const uint16_t crnti = 0x1001; + mac.set_ho_rnti(crnti, 0); + + // write dummy data + rlc.write_sdu(0, 10); + + // create UL action and grant and push MAC PDU + { + mac_interface_phy_lte::tb_action_ul_t ul_action = {}; + mac_interface_phy_lte::mac_grant_ul_t mac_grant = {}; + + mac_grant.rnti = crnti; // make sure MAC picks it up as valid UL grant + mac_grant.tb.ndi_present = true; + mac_grant.tb.ndi = true; + mac_grant.tb.tbs = 1; + int cc_idx = 0; + + // Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC + mac.new_grant_ul(cc_idx, mac_grant, &ul_action); + + // print generated PDU + mac_log.info_hex(ul_action.tb.payload, mac_grant.tb.tbs, "Generated PDU (%d B)\n", mac_grant.tb.tbs); +#if HAVE_PCAP + pcap_handle->write_ul_crnti(ul_action.tb.payload, mac_grant.tb.tbs, 0x1001, true, 1); +#endif + + TESTASSERT(memcmp(ul_action.tb.payload, tv, sizeof(tv)) == 0); + } + + // make sure MAC PDU thread picks up before stopping + sleep(1); + mac.run_tti(0); + mac.stop(); + + return SRSLTE_SUCCESS; +} + +// Two byte MAC PDU +int mac_ul_sch_pdu_two_byte_test() +{ + const uint8_t tv[] = {0x01, 0x01}; + + srslte::log_filter mac_log("MAC"); + mac_log.set_level(srslte::LOG_LEVEL_DEBUG); + mac_log.set_hex_limit(100000); + + srslte::log_filter rlc_log("RLC"); + rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); + rlc_log.set_hex_limit(100000); + + // dummy layers + phy_dummy phy; + rlc_dummy rlc(&rlc_log); + rrc_dummy rrc; + + // the actual MAC + mac mac; + mac.init(&phy, &rlc, &rrc, &mac_log); + const uint16_t crnti = 0x1001; + mac.set_ho_rnti(crnti, 0); + + // write dummy data + rlc.write_sdu(1, 10); + + // create UL action and grant and push MAC PDU + { + mac_interface_phy_lte::tb_action_ul_t ul_action = {}; + mac_interface_phy_lte::mac_grant_ul_t mac_grant = {}; + + mac_grant.rnti = crnti; // make sure MAC picks it up as valid UL grant + mac_grant.tb.ndi_present = true; + mac_grant.tb.ndi = true; + mac_grant.tb.tbs = 2; + int cc_idx = 0; + + // Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC + mac.new_grant_ul(cc_idx, mac_grant, &ul_action); + + // print generated PDU + mac_log.info_hex(ul_action.tb.payload, mac_grant.tb.tbs, "Generated PDU (%d B)\n", mac_grant.tb.tbs); +#if HAVE_PCAP + pcap_handle->write_ul_crnti(ul_action.tb.payload, mac_grant.tb.tbs, 0x1001, true, 1); +#endif + + TESTASSERT(memcmp(ul_action.tb.payload, tv, sizeof(tv)) == 0); + } + + // make sure MAC PDU thread picks up before stopping + sleep(1); + mac.run_tti(0); + mac.stop(); + + return SRSLTE_SUCCESS; +} + +// Three byte MAC PDU (Single byte padding, SDU header, 1 B SDU) +int mac_ul_sch_pdu_three_byte_test() +{ + const uint8_t tv[] = {0x3f, 0x01, 0x01}; + + srslte::log_filter mac_log("MAC"); + mac_log.set_level(srslte::LOG_LEVEL_DEBUG); + mac_log.set_hex_limit(100000); + + srslte::log_filter rlc_log("RLC"); + rlc_log.set_level(srslte::LOG_LEVEL_DEBUG); + rlc_log.set_hex_limit(100000); + + // dummy layers + phy_dummy phy; + rlc_dummy rlc(&rlc_log); + rrc_dummy rrc; + + // the actual MAC + mac mac; + mac.init(&phy, &rlc, &rrc, &mac_log); + const uint16_t crnti = 0x1001; + mac.set_ho_rnti(crnti, 0); + + // write dummy data + rlc.write_sdu(1, 1); + + // create UL action and grant and push MAC PDU + { + mac_interface_phy_lte::tb_action_ul_t ul_action = {}; + mac_interface_phy_lte::mac_grant_ul_t mac_grant = {}; + + mac_grant.rnti = crnti; // make sure MAC picks it up as valid UL grant + mac_grant.tb.ndi_present = true; + mac_grant.tb.ndi = true; + mac_grant.tb.tbs = 3; + int cc_idx = 0; + + // Send grant to MAC and get action for this TB, then call tb_decoded to unlock MAC + mac.new_grant_ul(cc_idx, mac_grant, &ul_action); + + // print generated PDU + mac_log.info_hex(ul_action.tb.payload, mac_grant.tb.tbs, "Generated PDU (%d B)\n", mac_grant.tb.tbs); +#if HAVE_PCAP + pcap_handle->write_ul_crnti(ul_action.tb.payload, mac_grant.tb.tbs, 0x1001, true, 1); +#endif + + TESTASSERT(memcmp(ul_action.tb.payload, tv, sizeof(tv)) == 0); + } + + // make sure MAC PDU thread picks up before stopping + sleep(1); + mac.run_tti(0); + mac.stop(); + + return SRSLTE_SUCCESS; +} + int main(int argc, char** argv) { #if HAVE_PCAP @@ -741,5 +915,20 @@ int main(int argc, char** argv) return -1; } + if (mac_ul_sch_pdu_one_byte_test()) { + printf("mac_ul_sch_pdu_one_byte_test() test failed.\n"); + return -1; + } + + if (mac_ul_sch_pdu_two_byte_test()) { + printf("mac_ul_sch_pdu_two_byte_test() test failed.\n"); + return -1; + } + + if (mac_ul_sch_pdu_three_byte_test()) { + printf("mac_ul_sch_pdu_three_byte_test() test failed.\n"); + return -1; + } + return 0; }