spirv-fuzz: Added extra tests for AddTypeFloat and AddTypeInt transformations (#4292)

Tests some edge cases of these transformations more thoroughly.
This commit is contained in:
EGJ1996 2021-05-27 09:36:39 +02:00 коммит произвёл GitHub
Родитель 94f570d7aa
Коммит ec1bc3e2e5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 38 добавлений и 1 удалений

Просмотреть файл

@ -61,7 +61,8 @@ TEST(TransformationAddTypeFloatTest, IsApplicable) {
ASSERT_FALSE(
transformation.IsApplicable(context.get(), transformation_context));
// Tests existing 16-bit float type.
// The transformation is not applicable because there is already a 16-bit
// float type declared in the module.
transformation = TransformationAddTypeFloat(7, 16);
ASSERT_FALSE(
transformation.IsApplicable(context.get(), transformation_context));
@ -70,6 +71,19 @@ TEST(TransformationAddTypeFloatTest, IsApplicable) {
transformation = TransformationAddTypeFloat(7, 32);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
// By default, SPIR-V does not support 64-bit float types.
// Below we add such capability, so the test should now pass.
context.get()->get_feature_mgr()->AddCapability(SpvCapabilityFloat64);
ASSERT_TRUE(TransformationAddTypeFloat(7, 64).IsApplicable(
context.get(), transformation_context));
#ifndef NDEBUG
// Should not be able to add float type of width different from 16/32/64
ASSERT_DEATH(TransformationAddTypeFloat(7, 20).IsApplicable(
context.get(), transformation_context),
"Unexpected float type width");
#endif
}
TEST(TransformationAddTypeFloatTest, Apply) {

Просмотреть файл

@ -85,6 +85,29 @@ TEST(TransformationAddTypeIntTest, IsApplicable) {
transformation = TransformationAddTypeInt(7, 32, true);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
// By default SPIR-V does not support 16-bit integers.
// Below we add such capability, so the test should now be succesful.
context.get()->get_feature_mgr()->AddCapability(SpvCapabilityInt16);
ASSERT_TRUE(TransformationAddTypeInt(7, 16, true)
.IsApplicable(context.get(), transformation_context));
// By default SPIR-V does not support 64-bit integers.
// Below we add such capability, so the test should now pass.
context.get()->get_feature_mgr()->AddCapability(SpvCapabilityInt64);
ASSERT_TRUE(TransformationAddTypeInt(7, 64, true)
.IsApplicable(context.get(), transformation_context));
#ifndef NDEBUG
// Should not be able to add signed/unsigned integers of width different from
// 16/32/64 bits.
ASSERT_DEATH(TransformationAddTypeInt(7, 20, false)
.IsApplicable(context.get(), transformation_context),
"Unexpected integer type width");
ASSERT_DEATH(TransformationAddTypeInt(12, 15, false)
.IsApplicable(context.get(), transformation_context),
"Unexpected integer type width");
#endif
}
TEST(TransformationAddTypeIntTest, Apply) {