Merge "Include the failing stats in stats failure assertions." am: 27979bd116
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1883772 Change-Id: I05c36d9718a07041224dded9e32c755321760acd
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user