mirror of
https://github.com/espressif/openthread.git
synced 2026-09-10 19:20:06 +00:00
[test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to include the failed condition in the error message that is printed on a failure (in addition to function name and line number where the error happened). This commit also changes the second parameter (`aMessage`) to in these macros to be optional. This commit also updates unit tests to remove the second `aMessage` string in cases where the failure can be inferred from the condition itself.
This commit is contained in:
@@ -65,22 +65,22 @@ void TestMacBeaconFrame(void)
|
||||
0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x02,
|
||||
};
|
||||
|
||||
VerifyOrQuit(instance != nullptr, "Null OpenThread instance");
|
||||
VerifyOrQuit(instance != nullptr);
|
||||
|
||||
aesCcm.SetKey(key, sizeof(key));
|
||||
aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, headerLength);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength, "AesCcm::GetTagLength() failed");
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength);
|
||||
aesCcm.Finalize(test + headerLength);
|
||||
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0, "TestMacBeaconFrame encrypt failed");
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0);
|
||||
|
||||
aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, headerLength);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength, "AesCcm::GetTagLength() failed");
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength);
|
||||
aesCcm.Finalize(test + headerLength);
|
||||
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0, "TestMacBeaconFrame decrypt failed");
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0);
|
||||
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
@@ -124,17 +124,17 @@ void TestMacCommandFrame()
|
||||
aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, headerLength);
|
||||
aesCcm.Payload(test + headerLength, test + headerLength, payloadLength, ot::Crypto::AesCcm::kEncrypt);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength, "AesCcm::GetTagLength() failed");
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength);
|
||||
aesCcm.Finalize(test + headerLength + payloadLength);
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0, "TestMacCommandFrame encrypt failed");
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0);
|
||||
|
||||
aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, headerLength);
|
||||
aesCcm.Payload(test + headerLength, test + headerLength, payloadLength, ot::Crypto::AesCcm::kDecrypt);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength, "AesCcm::GetTagLength() failed");
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == tagLength);
|
||||
aesCcm.Finalize(test + headerLength + payloadLength);
|
||||
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0, "TestMacCommandFrame decrypt failed");
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
Reference in New Issue
Block a user