Merge "Include the failing stats in stats failure assertions." am: 27979bd116 am: db33b9ea65 am: 06fe60cef1 am: 90427f67b0

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1883772

Change-Id: I1aec89d6e43ca111e5621276521ad1b77c3b0eeb
This commit is contained in:
Treehugger Robot
2021-11-08 07:28:28 +00:00
committed by Automerger Merge Worker

View File

@@ -413,20 +413,26 @@ public class IpSecManagerTest extends IpSecBaseTest {
// Check that iface stats are within an acceptable range; data might be sent
// on the local interface by other apps.
assertApproxEquals(
ifaceTxBytes, newIfaceTxBytes, expectedTxByteDelta, ERROR_MARGIN_BYTES);
assertApproxEquals(
ifaceRxBytes, newIfaceRxBytes, expectedRxByteDelta, ERROR_MARGIN_BYTES);
assertApproxEquals(
ifaceTxPackets, newIfaceTxPackets, expectedTxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals(
ifaceRxPackets, newIfaceRxPackets, expectedRxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals("TX bytes", ifaceTxBytes, newIfaceTxBytes, expectedTxByteDelta,
ERROR_MARGIN_BYTES);
assertApproxEquals("RX bytes", ifaceRxBytes, newIfaceRxBytes, expectedRxByteDelta,
ERROR_MARGIN_BYTES);
assertApproxEquals("TX packets", ifaceTxPackets, newIfaceTxPackets,
expectedTxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals("RX packets", ifaceRxPackets, newIfaceRxPackets,
expectedRxPacketDelta, ERROR_MARGIN_PKTS);
}
private static void assertApproxEquals(
long oldStats, long newStats, int expectedDelta, double errorMargin) {
assertTrue(expectedDelta <= newStats - oldStats);
assertTrue((expectedDelta * errorMargin) > newStats - oldStats);
String what, long oldStats, long newStats, int expectedDelta, double errorMargin) {
assertTrue(
"Expected at least " + expectedDelta + " " + what
+ ", got " + (newStats - oldStats),
newStats - oldStats >= expectedDelta);
assertTrue(
"Expected at most " + errorMargin + " * " + expectedDelta + " " + what
+ ", got " + (newStats - oldStats),
newStats - oldStats < (expectedDelta * errorMargin));
}
private static void initStatsChecker() throws Exception {