Change build info short-length to be based on real length.
[ Cherry-pick of v19 http://go/wvgerrit/219592 ] [ Merge of http://go/wvgerrit/219554 ] The original CheckBuildInformation_OutputLengthAPI17 test was written with the assumption that the estimated length would not be too much larger than the real length of the build info; however this is not true for some vendors. This CL changes the short-buffer length to be based on a real build info length from a successful call to OEMCrypto. Bug: 411308060 Change-Id: I6504288ca59d7d41facaadc45adc76a5236826d9
This commit is contained in:
@@ -399,45 +399,58 @@ TEST_F(OEMCryptoClientTest, CheckBuildInformation_OutputLengthAPI17) {
|
||||
ASSERT_GT(build_info_length, kZero)
|
||||
<< "Signaling ERROR_SHORT_BUFFER should have assigned a length";
|
||||
|
||||
// Try again using the size they provided, ensuring that it
|
||||
// is successful.
|
||||
const size_t initial_estimate_length = build_info_length;
|
||||
build_info.assign(build_info_length, kNullChar);
|
||||
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
||||
ASSERT_EQ(result, OEMCrypto_SUCCESS)
|
||||
<< "initial_estimate_length = " << initial_estimate_length
|
||||
<< ", build_info_length (output) = " << build_info_length;
|
||||
ASSERT_GT(build_info_length, kZero) << "Build info cannot be empty";
|
||||
// Ensure the real length is within the size originally specified.
|
||||
// OK if final length is smaller than estimated length.
|
||||
ASSERT_LE(build_info_length, initial_estimate_length);
|
||||
const size_t expected_length = build_info_length;
|
||||
|
||||
// Force a ERROR_SHORT_BUFFER using a non-zero value.
|
||||
// Note: It is assumed that vendors will provide more than a single
|
||||
// character of info.
|
||||
const size_t second_attempt_length =
|
||||
(build_info_length >= 2) ? build_info_length / 2 : 1;
|
||||
build_info.assign(second_attempt_length, kNullChar);
|
||||
const size_t short_length = (expected_length >= 2) ? expected_length / 2 : 1;
|
||||
build_info.assign(short_length, kNullChar);
|
||||
build_info_length = build_info.size();
|
||||
|
||||
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
||||
ASSERT_EQ(result, OEMCrypto_ERROR_SHORT_BUFFER)
|
||||
<< "second_attempt_length = " << second_attempt_length
|
||||
<< ", build_info_length" << build_info_length;
|
||||
<< "short_length = " << short_length
|
||||
<< ", expected_length = " << expected_length << ", build_info_length"
|
||||
<< build_info_length;
|
||||
// OEM specified build info length should be larger than the
|
||||
// original length if returning ERROR_SHORT_BUFFER.
|
||||
ASSERT_GT(build_info_length, second_attempt_length);
|
||||
ASSERT_GT(build_info_length, short_length);
|
||||
|
||||
// Final attempt with a buffer large enough buffer, padding to
|
||||
// ensure the caller truncates.
|
||||
constexpr size_t kBufferPadSize = 42;
|
||||
const size_t expected_length = build_info_length;
|
||||
const size_t final_attempt_length = expected_length + kBufferPadSize;
|
||||
build_info.assign(final_attempt_length, kNullChar);
|
||||
const size_t oversize_length = expected_length + kBufferPadSize;
|
||||
build_info.assign(oversize_length, kNullChar);
|
||||
build_info_length = build_info.size();
|
||||
|
||||
result = OEMCrypto_BuildInformation(&build_info[0], &build_info_length);
|
||||
|
||||
ASSERT_EQ(result, OEMCrypto_SUCCESS)
|
||||
<< "final_attempt_length = " << final_attempt_length
|
||||
<< "oversize_length = " << oversize_length
|
||||
<< ", expected_length = " << expected_length
|
||||
<< ", build_info_length = " << build_info_length;
|
||||
<< ", build_info_length (output) = " << build_info_length;
|
||||
// Ensure not empty.
|
||||
ASSERT_GT(build_info_length, kZero) << "Build info cannot be empty";
|
||||
// Ensure it was truncated down from the padded length.
|
||||
ASSERT_LT(build_info_length, final_attempt_length)
|
||||
ASSERT_LT(build_info_length, oversize_length)
|
||||
<< "Should have truncated from oversized buffer: expected_length = "
|
||||
<< expected_length;
|
||||
// Ensure the real length is within the size originally specified.
|
||||
// OK if final length is smaller than estimated length.
|
||||
ASSERT_LE(build_info_length, expected_length);
|
||||
// Ensure that length is equal to the length of the previous
|
||||
// successful call.
|
||||
ASSERT_EQ(build_info_length, expected_length);
|
||||
}
|
||||
|
||||
// Verifies that OEMCrypto_BuildInformation() is behaving as expected
|
||||
|
||||
Reference in New Issue
Block a user