Skip to content

Commit

Permalink
Fix errors in the CI pipeline introduced by ns-3.41 (#158)
Browse files Browse the repository at this point in the history
+ CI: only skip tests if they were successful on a past run with same ccache contents
+ Tests: compare packets with uid instead of each serialized byte
  • Loading branch information
non-det-alle authored Mar 22, 2024
1 parent 69cb2e3 commit 7c0ca67
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 32 deletions.
24 changes: 24 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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"
Expand Down
32 changes: 26 additions & 6 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 14 additions & 26 deletions test/lorawan-test-suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,16 @@ class PhyConnectivityTest : public TestCase
void NoMoreDemodulators(Ptr<const Packet> packet, uint32_t node);
void WrongFrequency(Ptr<const Packet> packet, uint32_t node);
void WrongSf(Ptr<const Packet> packet, uint32_t node);
bool HaveSamePacketContents(Ptr<Packet> packet1, Ptr<Packet> 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<Packet> packet1, Ptr<Packet> packet2);

private:
void DoRun() override;
Expand Down Expand Up @@ -1162,30 +1171,9 @@ PhyConnectivityTest::WrongFrequency(Ptr<const Packet> packet, uint32_t node)
}

bool
PhyConnectivityTest::HaveSamePacketContents(Ptr<Packet> packet1, Ptr<Packet> packet2)
PhyConnectivityTest::IsSamePacket(Ptr<Packet> packet1, Ptr<Packet> 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
Expand Down Expand Up @@ -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> packet = Create<Packet>(buffer, 10);

// Testing
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 7c0ca67

Please sign in to comment.