mirror of
https://github.com/espressif/openthread.git
synced 2026-08-18 08:29:52 +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:
@@ -92,7 +92,7 @@ void TestEcdsaVector(void)
|
||||
|
||||
DumpBuffer("KeyPair", keyPair.GetDerBytes(), keyPair.GetDerLength());
|
||||
|
||||
SuccessOrQuit(keyPair.GetPublicKey(publicKey), "KeyPair::GetPublicKey() failed");
|
||||
SuccessOrQuit(keyPair.GetPublicKey(publicKey));
|
||||
DumpBuffer("PublicKey", publicKey.GetBytes(), Ecdsa::P256::PublicKey::kSize);
|
||||
|
||||
VerifyOrQuit(sizeof(kPublicKey) == Ecdsa::P256::PublicKey::kSize, "Example public key is invalid");
|
||||
@@ -107,20 +107,19 @@ void TestEcdsaVector(void)
|
||||
DumpBuffer("Hash", hash.GetBytes(), sizeof(hash));
|
||||
|
||||
printf("\nSign the message ----------------------------------------------------------\n");
|
||||
SuccessOrQuit(keyPair.Sign(hash, signature), "KeyPair::Sign() failed");
|
||||
SuccessOrQuit(keyPair.Sign(hash, signature));
|
||||
DumpBuffer("Signature", signature.GetBytes(), sizeof(signature));
|
||||
|
||||
printf("\nCheck signature against expected sequence----------------------------------\n");
|
||||
DumpBuffer("Expected signature", kExpectedSignature, sizeof(kExpectedSignature));
|
||||
|
||||
VerifyOrQuit(sizeof(kExpectedSignature) == sizeof(signature), "Signature length does not match expected size");
|
||||
VerifyOrQuit(memcmp(signature.GetBytes(), kExpectedSignature, sizeof(kExpectedSignature)) == 0,
|
||||
"Signature does not match expected value");
|
||||
VerifyOrQuit(sizeof(kExpectedSignature) == sizeof(signature));
|
||||
VerifyOrQuit(memcmp(signature.GetBytes(), kExpectedSignature, sizeof(kExpectedSignature)) == 0);
|
||||
|
||||
printf("Signature matches expected sequence.\n");
|
||||
|
||||
printf("\nVerify the signature ------------------------------------------------------\n");
|
||||
SuccessOrQuit(publicKey.Verify(hash, signature), "PublicKey::Verify() failed");
|
||||
SuccessOrQuit(publicKey.Verify(hash, signature));
|
||||
printf("\nSignature was verified successfully.\n\n");
|
||||
|
||||
testFreeInstance(instance);
|
||||
@@ -144,11 +143,11 @@ void TestEdsaKeyGenerationSignAndVerify(void)
|
||||
printf("Test ECDA key generation, signing and verification\n");
|
||||
|
||||
printf("\nGenerating key-pair -------------------------------------------------------\n");
|
||||
SuccessOrQuit(keyPair.Generate(), "KeyPair::Generate() failed");
|
||||
SuccessOrQuit(keyPair.Generate());
|
||||
|
||||
DumpBuffer("KeyPair", keyPair.GetDerBytes(), keyPair.GetDerLength());
|
||||
|
||||
SuccessOrQuit(keyPair.GetPublicKey(publicKey), "KeyPair::GetPublicKey() failed");
|
||||
SuccessOrQuit(keyPair.GetPublicKey(publicKey));
|
||||
DumpBuffer("PublicKey", publicKey.GetBytes(), Ecdsa::P256::PublicKey::kSize);
|
||||
|
||||
printf("\nHash the message ----------------------------------------------------------\n");
|
||||
@@ -159,11 +158,11 @@ void TestEdsaKeyGenerationSignAndVerify(void)
|
||||
DumpBuffer("Hash", hash.GetBytes(), sizeof(hash));
|
||||
|
||||
printf("\nSign the message ----------------------------------------------------------\n");
|
||||
SuccessOrQuit(keyPair.Sign(hash, signature), "KeyPair::Sign() failed");
|
||||
SuccessOrQuit(keyPair.Sign(hash, signature));
|
||||
DumpBuffer("Signature", signature.GetBytes(), sizeof(signature));
|
||||
|
||||
printf("\nVerify the signature ------------------------------------------------------\n");
|
||||
SuccessOrQuit(publicKey.Verify(hash, signature), "PublicKey::Verify() failed");
|
||||
SuccessOrQuit(publicKey.Verify(hash, signature));
|
||||
printf("\nSignature was verified successfully.");
|
||||
|
||||
sha256.Start();
|
||||
|
||||
Reference in New Issue
Block a user