diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 8fa7741c0a..43c4f12aa2 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -13,6 +13,8 @@ runs: using: "composite" steps: # Pre-configuration steps + # (skip ccache for --disable-precompiled-headers because it won't use it) + # (skip ccache for optimized because built files are too architecture dependent) - if: env.MODE != 'optimized' && ( ! contains(env.EXTRA_OPTIONS, '--disable-precompiled-headers') ) name: "Restore build cache of this job" uses: hendrikmuhs/ccache-action@v1.2 @@ -30,6 +32,28 @@ runs: - name: "Build ns-3" shell: bash run: ./ns3 build + - name: "Show ccache stats" + shell: bash + run: ccache -s + # Manage inter-run placeholder for tests + - name: "Prepare env and get cache miss rate" + shell: bash + run: | + echo "CACHE_MISS=`./utils/ccache-miss-rate.py`" >> $GITHUB_ENV + echo "REF_NAME=`echo $GITHUB_REF_NAME | sed -r 's/[/]+/-/g'`" >> $GITHUB_ENV + echo "NOW=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV + touch build/tests-base.txt + - if: env.CACHE_MISS != '0' + name: "Create tests placeholder" + shell: bash + run: | + touch build/tests-$BUILD_ID.txt + - if: env.CACHE_MISS != '0' + name: "Store tests placeholder" + uses: actions/cache/save@v4 + with: + key: ${{ format('tests-{0}-{1}-{2}', env.BUILD_ID, env.REF_NAME, env.NOW) }} + path: build/tests-*.txt # Post-build steps - if: inputs.store-artifacts == 'true' name: "Tar files to preserve permissions" diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 77395cb4ff..32429a44fa 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -4,11 +4,31 @@ description: "Defines the central steps in testing ns-3" runs: using: "composite" steps: - # Test steps - - name: "Store ccache miss rate" + - name: "Prepare env" + run: | + echo "REF_NAME=`echo $GITHUB_REF_NAME | sed -r 's/[/]+/-/g'`" >> $GITHUB_ENV + echo "NOW=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV + shell: bash + - name: "Restore tests placeholder" + uses: actions/cache/restore@v4 + with: + key: ${{ format('tests-{0}-{1}-', env.BUILD_ID, env.REF_NAME) }} + restore-keys: ${{ format('tests-{0}-{1}-', env.BUILD_ID, env.REF_NAME) }} + path: build/tests-*.txt + - run: ls -al build/ | grep tests shell: bash - run: echo "CACHE_MISS=`./utils/ccache-miss-rate.py`" >> $GITHUB_ENV - - if: env.CACHE_MISS != '0' && env.MODE != 'debug' - name: "Test ns-3" + # Test steps + - name: "Test ns-3" shell: bash - run: ./test.py -n + run: > + if [[ "$MODE" != "debug" ]] && [[ -f build/tests-$BUILD_ID.txt ]]; + then ./test.py -n; + if [[ $? == 0 ]]; + then `rm build/tests-$BUILD_ID.txt` || true; + fi; + fi + - name: "Update tests placeholder" + uses: actions/cache/save@v4 + with: + key: ${{ format('tests-{0}-{1}-{2}', env.BUILD_ID, env.REF_NAME, env.NOW) }} + path: build/tests-*.txt diff --git a/test/lorawan-test-suite.cc b/test/lorawan-test-suite.cc index 6cb77de91c..e8210570ef 100644 --- a/test/lorawan-test-suite.cc +++ b/test/lorawan-test-suite.cc @@ -1082,7 +1082,16 @@ class PhyConnectivityTest : public TestCase void NoMoreDemodulators(Ptr packet, uint32_t node); void WrongFrequency(Ptr packet, uint32_t node); void WrongSf(Ptr packet, uint32_t node); - bool HaveSamePacketContents(Ptr packet1, Ptr packet2); + + /** + * Compare two packets to check if they are equal. + * + * \param packet1 A first packet. + * \param packet2 A second packet. + * \return True if their unique identifiers are equal, + * \return false otherwise. + */ + bool IsSamePacket(Ptr packet1, Ptr packet2); private: void DoRun() override; @@ -1162,30 +1171,9 @@ PhyConnectivityTest::WrongFrequency(Ptr packet, uint32_t node) } bool -PhyConnectivityTest::HaveSamePacketContents(Ptr packet1, Ptr packet2) +PhyConnectivityTest::IsSamePacket(Ptr packet1, Ptr packet2) { - uint32_t size1 = packet1->GetSerializedSize(); - uint8_t buffer1[size1]; - packet1->Serialize(buffer1, size1); - - uint32_t size2 = packet2->GetSerializedSize(); - uint8_t buffer2[size2]; - packet2->Serialize(buffer2, size2); - - NS_ASSERT(size1 == size2); - - bool foundADifference = false; - for (uint32_t i = 0; i < size1; i++) - { - NS_LOG_DEBUG(unsigned(buffer1[i]) << " " << unsigned(buffer2[i])); - if (buffer1[i] != buffer2[i]) - { - foundADifference = true; - break; - } - } - - return !foundADifference; + return packet1->GetUid() == packet2->GetUid(); } void @@ -1310,7 +1298,7 @@ PhyConnectivityTest::DoRun() LoraTxParameters txParams; txParams.sf = 12; - uint8_t buffer[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint8_t buffer[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Ptr packet = Create(buffer, 10); // Testing @@ -1496,7 +1484,7 @@ PhyConnectivityTest::DoRun() Simulator::Run(); Simulator::Destroy(); - NS_TEST_EXPECT_MSG_EQ(HaveSamePacketContents(packet, m_latestReceivedPacket), + NS_TEST_EXPECT_MSG_EQ(IsSamePacket(packet, m_latestReceivedPacket), true, "Packet changed contents when going through the channel");