[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:
Abtin Keshavarzian
2021-06-28 11:38:10 -07:00
committed by GitHub
parent 2db3ddca33
commit 57d072d352
36 changed files with 1733 additions and 1864 deletions
+9 -9
View File
@@ -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)