Add addWrite32() to write 4-byte arrays to the buffer
Introduced the addWrite32() method to enable appending 4-byte arrays to
the end of a write buffer.
Test: TH
Change-Id: Icc8f63733f3f24fdc9e57fe87d48fbf0b6c827cf
diff --git a/tests/unit/src/android/net/apf/ApfV5Test.kt b/tests/unit/src/android/net/apf/ApfV5Test.kt
index c370d3d..bcc59dc 100644
--- a/tests/unit/src/android/net/apf/ApfV5Test.kt
+++ b/tests/unit/src/android/net/apf/ApfV5Test.kt
@@ -241,6 +241,9 @@
assertFailsWith<IllegalArgumentException> {
gen.addCountAndPassIfR0LessThan(3, DROPPED_ETH_BROADCAST)
}
+ assertFailsWith<IllegalArgumentException> {
+ gen.addWrite32(byteArrayOf())
+ }
val v4gen = ApfV4Generator(APF_VERSION_4)
assertFailsWith<IllegalArgumentException> { v4gen.addCountAndDrop(PASSED_ARP) }
@@ -439,6 +442,7 @@
gen.addWriteU32(0x00000000)
gen.addWriteU32(0x80000000)
gen.addWrite32(-2)
+ gen.addWrite32(byteArrayOf(0xff.toByte(), 0xfe.toByte(), 0xfd.toByte(), 0xfc.toByte()))
program = gen.generate()
assertContentEquals(byteArrayOf(
encodeInstruction(24, 1, 0), 0x01,
@@ -451,7 +455,9 @@
encodeInstruction(24, 4, 0), 0x00, 0x00, 0x00, 0x00,
encodeInstruction(24, 4, 0), 0x80.toByte(), 0x00, 0x00, 0x00,
encodeInstruction(24, 4, 0), 0xff.toByte(), 0xff.toByte(),
- 0xff.toByte(), 0xfe.toByte()), program)
+ 0xff.toByte(), 0xfe.toByte(),
+ encodeInstruction(24, 4, 0), 0xff.toByte(), 0xfe.toByte(),
+ 0xfd.toByte(), 0xfc.toByte()), program)
assertContentEquals(listOf(
"0: write 0x01",
"2: write 0x0102",
@@ -462,7 +468,8 @@
"17: write 0x8000",
"20: write 0x00000000",
"25: write 0x80000000",
- "30: write 0xfffffffe"
+ "30: write 0xfffffffe",
+ "35: write 0xfffefdfc"
), ApfJniUtils.disassembleApf(program).map { it.trim() })
gen = ApfV6Generator()
@@ -605,6 +612,7 @@
.addWriteU16(0x0203)
.addWriteU32(0x04050607)
.addWrite32(-2)
+ .addWrite32(byteArrayOf(0xff.toByte(), 0xfe.toByte(), 0xfd.toByte(), 0xfc.toByte()))
.addLoadImmediate(R0, 1)
.addWriteU8(R0)
.addLoadImmediate(R0, 0x0203)
@@ -614,9 +622,13 @@
.addTransmitWithoutChecksum()
.generate()
assertPass(MIN_APF_VERSION_IN_DEV, program, ByteArray(MIN_PKT_SIZE))
- assertContentEquals(byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff.toByte(),
- 0xff.toByte(), 0xff.toByte(), 0xfe.toByte(), 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
- 0x07), ApfJniUtils.getTransmittedPacket())
+ assertContentEquals(
+ byteArrayOf(
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff.toByte(),
+ 0xff.toByte(), 0xff.toByte(), 0xfe.toByte(), 0xff.toByte(), 0xfe.toByte(),
+ 0xfd.toByte(), 0xfc.toByte(), 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07),
+ ApfJniUtils.getTransmittedPacket()
+ )
}
@Test