diff --git a/tests/gtest/fake_platform.cpp b/tests/gtest/fake_platform.cpp index 9ba765040..9514eeaf7 100644 --- a/tests/gtest/fake_platform.cpp +++ b/tests/gtest/fake_platform.cpp @@ -345,7 +345,7 @@ otError otPlatRadioDisable(otInstance *) { return OT_ERROR_NONE; } otError otPlatRadioSleep(otInstance *) { return OT_ERROR_NONE; } -otError otPlatRadioReceive(otInstance *, uint8_t) { return OT_ERROR_NONE; } +otError otPlatRadioReceive(otInstance *, uint8_t aChannel) { return FakePlatform::CurrentPlatform().Receive(aChannel); } otError otPlatRadioTransmit(otInstance *, otRadioFrame *aFrame) { diff --git a/tests/gtest/fake_platform.hpp b/tests/gtest/fake_platform.hpp index 99559578d..4423ae823 100644 --- a/tests/gtest/fake_platform.hpp +++ b/tests/gtest/fake_platform.hpp @@ -36,6 +36,7 @@ #include +#include #include #include #include @@ -71,8 +72,14 @@ public: virtual void StartMicroAlarm(uint32_t aT0, uint32_t aDt); virtual void StopMicroAlarm(); + uint8_t GetReceiveChannel(void) const { return mChannel; } virtual otRadioFrame *GetTransmitBuffer() { return &mTransmitFrame; } virtual otError Transmit(otRadioFrame *aFrame); + virtual otError Receive(uint8_t aChannel) + { + mChannel = aChannel; + return OT_ERROR_NONE; + } virtual otError SettingsGet(uint16_t aKey, uint16_t aIndex, uint8_t *aValue, uint16_t *aValueLength) const; virtual otError SettingsSet(uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength); @@ -106,6 +113,7 @@ protected: otRadioFrame mTransmitFrame; uint8_t mTransmitBuffer[OT_RADIO_FRAME_MAX_SIZE]; + uint8_t mChannel = 0; uint8_t mFlash[kFlashSwapSize * kFlashSwapNum]; diff --git a/tests/gtest/radio_spinel_rcp_test.cpp b/tests/gtest/radio_spinel_rcp_test.cpp index a299a3fb3..5c7b83438 100644 --- a/tests/gtest/radio_spinel_rcp_test.cpp +++ b/tests/gtest/radio_spinel_rcp_test.cpp @@ -92,3 +92,43 @@ TEST(RadioSpinelTransmit, shouldPassDesiredTxPowerToRadioPlatform) platform.GoInMs(1000); } + +TEST(RadioSpinelTransmit, shouldCauseSwitchingToRxChannelAfterTxDone) +{ + FakeCoprocessorPlatform platform; + + constexpr Mac::PanId kSrcPanId = 0x1234; + constexpr Mac::PanId kDstPanId = 0x4321; + constexpr uint8_t kDstAddr[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; + constexpr uint16_t kSrcAddr = 0xac00; + constexpr int8_t kTxPower = 100; + + uint8_t frameBuffer[OT_RADIO_FRAME_MAX_SIZE]; + Mac::TxFrame txFrame; + + txFrame.mPsdu = frameBuffer; + + { + Mac::TxFrame::Info frameInfo; + + frameInfo.mType = Mac::Frame::kTypeData; + frameInfo.mVersion = Mac::Frame::kVersion2006; + frameInfo.mAddrs.mSource.SetShort(kSrcAddr); + frameInfo.mAddrs.mDestination.SetExtended(kDstAddr); + frameInfo.mPanIds.SetSource(kSrcPanId); + frameInfo.mPanIds.SetDestination(kDstPanId); + frameInfo.mSecurityLevel = Mac::Frame::kSecurityEncMic32; + + frameInfo.PrepareHeadersIn(txFrame); + } + + txFrame.mInfo.mTxInfo.mTxPower = kTxPower; + txFrame.mChannel = 11; + txFrame.mInfo.mTxInfo.mRxChannelAfterTxDone = 25; + + ASSERT_EQ(platform.mRadioSpinel.Enable(FakePlatform::CurrentInstance()), kErrorNone); + ASSERT_EQ(platform.mRadioSpinel.Receive(11), kErrorNone); + ASSERT_EQ(platform.mRadioSpinel.Transmit(txFrame), kErrorNone); + platform.GoInMs(1000); + EXPECT_EQ(platform.GetReceiveChannel(), 25); +}