spirv-fuzz: Fix to TransformationInlineFunction (#3913)

This fixes a problem where TransformationInlineFunction could lead to
distinct instructions having identical unique ids. It adds a validity
check to detect this problem in general.

Fixes #3911.
This commit is contained in:
Alastair Donaldson 2020-10-16 22:58:09 +01:00 committed by GitHub
parent bf1a11dab7
commit 502e982956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
116 changed files with 2386 additions and 1488 deletions

View File

@ -15,6 +15,8 @@
#ifndef SOURCE_FUZZ_EQUIVALENCE_RELATION_H_
#define SOURCE_FUZZ_EQUIVALENCE_RELATION_H_
#include <algorithm>
#include <cassert>
#include <memory>
#include <unordered_map>
#include <unordered_set>

View File

@ -158,42 +158,11 @@ void Fuzzer::MaybeAddFinalPass(std::vector<std::unique_ptr<FuzzerPass>>* passes,
}
}
bool Fuzzer::ApplyPassAndCheckValidity(
FuzzerPass* pass, const spvtools::SpirvTools& tools) const {
bool Fuzzer::ApplyPassAndCheckValidity(FuzzerPass* pass) const {
pass->Apply();
if (validate_after_each_fuzzer_pass_) {
std::vector<uint32_t> binary_to_validate;
ir_context_->module()->ToBinary(&binary_to_validate, false);
if (!tools.Validate(&binary_to_validate[0], binary_to_validate.size(),
validator_options_)) {
consumer_(SPV_MSG_INFO, nullptr, {},
"Binary became invalid during fuzzing (set a breakpoint to "
"inspect); stopping.");
return false;
}
// Check that all blocks in the module have appropriate parent functions.
for (auto& function : *ir_context_->module()) {
for (auto& block : function) {
if (block.GetParent() == nullptr) {
std::stringstream ss;
ss << "Block " << block.id()
<< " has no parent; its parent should be " << function.result_id()
<< ".";
consumer_(SPV_MSG_INFO, nullptr, {}, ss.str().c_str());
return false;
}
if (block.GetParent() != &function) {
std::stringstream ss;
ss << "Block " << block.id() << " should have parent "
<< function.result_id() << " but instead has parent "
<< block.GetParent() << ".";
consumer_(SPV_MSG_INFO, nullptr, {}, ss.str().c_str());
return false;
}
}
}
}
return true;
return !validate_after_each_fuzzer_pass_ ||
fuzzerutil::IsValidAndWellFormed(ir_context_.get(), validator_options_,
consumer_);
}
Fuzzer::FuzzerResult Fuzzer::Run() {
@ -352,8 +321,7 @@ Fuzzer::FuzzerResult Fuzzer::Run() {
do {
if (!ApplyPassAndCheckValidity(
repeated_pass_manager->ChoosePass(transformation_sequence_out_),
tools)) {
repeated_pass_manager->ChoosePass(transformation_sequence_out_))) {
return {Fuzzer::FuzzerResultStatus::kFuzzerPassLedToInvalidModule,
std::vector<uint32_t>(), protobufs::TransformationSequence()};
}
@ -375,7 +343,7 @@ Fuzzer::FuzzerResult Fuzzer::Run() {
MaybeAddFinalPass<FuzzerPassSwapCommutableOperands>(&final_passes);
MaybeAddFinalPass<FuzzerPassToggleAccessChainInstruction>(&final_passes);
for (auto& pass : final_passes) {
if (!ApplyPassAndCheckValidity(pass.get(), tools)) {
if (!ApplyPassAndCheckValidity(pass.get())) {
return {Fuzzer::FuzzerResultStatus::kFuzzerPassLedToInvalidModule,
std::vector<uint32_t>(), protobufs::TransformationSequence()};
}

View File

@ -124,10 +124,9 @@ class Fuzzer {
// Applies |pass|, which must be a pass constructed with |ir_context|.
// If |validate_after_each_fuzzer_pass_| is not set, true is always returned.
// Otherwise, true is returned if and only if |ir_context| passes validation,
// and if every block has its enclosing function as its parent. |tools| is
// used for checking validity.
bool ApplyPassAndCheckValidity(FuzzerPass* pass,
const spvtools::SpirvTools& tools) const;
// every block has its enclosing function as its parent, and every
// instruction has a distinct unique id.
bool ApplyPassAndCheckValidity(FuzzerPass* pass) const;
// Target environment.
const spv_target_env target_env_;

View File

@ -65,10 +65,11 @@ void FuzzerPassDonateModules::Apply() {
std::unique_ptr<opt::IRContext> donor_ir_context = donor_suppliers_.at(
GetFuzzerContext()->RandomIndex(donor_suppliers_))();
assert(donor_ir_context != nullptr && "Supplying of donor failed");
assert(fuzzerutil::IsValid(
donor_ir_context.get(),
GetTransformationContext()->GetValidatorOptions()) &&
"The donor module must be valid");
assert(
fuzzerutil::IsValid(donor_ir_context.get(),
GetTransformationContext()->GetValidatorOptions(),
fuzzerutil::kSilentMessageConsumer) &&
"The donor module must be valid");
// Donate the supplied module.
//
// Randomly decide whether to make the module livesafe (see

View File

@ -43,6 +43,10 @@ uint32_t MaybeGetOpConstant(opt::IRContext* ir_context,
} // namespace
const spvtools::MessageConsumer kSilentMessageConsumer =
[](spv_message_level_t, const char*, const spv_position_t&,
const char*) -> void {};
bool IsFreshId(opt::IRContext* context, uint32_t id) {
return !context->get_def_use_mgr()->GetDef(id);
}
@ -400,13 +404,64 @@ uint32_t GetBoundForCompositeIndex(const opt::Instruction& composite_type_inst,
}
}
bool IsValid(opt::IRContext* context, spv_validator_options validator_options) {
bool IsValid(const opt::IRContext* context,
spv_validator_options validator_options,
MessageConsumer consumer) {
std::vector<uint32_t> binary;
context->module()->ToBinary(&binary, false);
SpirvTools tools(context->grammar().target_env());
tools.SetMessageConsumer(consumer);
return tools.Validate(binary.data(), binary.size(), validator_options);
}
bool IsValidAndWellFormed(const opt::IRContext* ir_context,
spv_validator_options validator_options,
MessageConsumer consumer) {
if (!IsValid(ir_context, validator_options, consumer)) {
consumer(SPV_MSG_INFO, nullptr, {},
"Module is invalid (set a breakpoint to inspect).");
return false;
}
// Check that all blocks in the module have appropriate parent functions.
for (auto& function : *ir_context->module()) {
for (auto& block : function) {
if (block.GetParent() == nullptr) {
std::stringstream ss;
ss << "Block " << block.id() << " has no parent; its parent should be "
<< function.result_id() << " (set a breakpoint to inspect).";
consumer(SPV_MSG_INFO, nullptr, {}, ss.str().c_str());
return false;
}
if (block.GetParent() != &function) {
std::stringstream ss;
ss << "Block " << block.id() << " should have parent "
<< function.result_id() << " but instead has parent "
<< block.GetParent() << " (set a breakpoint to inspect).";
consumer(SPV_MSG_INFO, nullptr, {}, ss.str().c_str());
return false;
}
}
}
// Check that all instructions have distinct unique ids. We map each unique
// id to the first instruction it is observed to be associated with so that
// if we encounter a duplicate we have access to the previous instruction -
// this is a useful aid to debugging.
std::unordered_map<uint32_t, opt::Instruction*> unique_ids;
bool found_duplicate = false;
ir_context->module()->ForEachInst([&consumer, &found_duplicate,
&unique_ids](opt::Instruction* inst) {
if (unique_ids.count(inst->unique_id()) != 0) {
consumer(SPV_MSG_INFO, nullptr, {},
"Two instructions have the same unique id (set a breakpoint to "
"inspect).");
found_duplicate = true;
}
unique_ids.insert({inst->unique_id(), inst});
});
return !found_duplicate;
}
std::unique_ptr<opt::IRContext> CloneIRContext(opt::IRContext* context) {
std::vector<uint32_t> binary;
context->module()->ToBinary(&binary, false);

View File

@ -15,6 +15,7 @@
#ifndef SOURCE_FUZZ_FUZZER_UTIL_H_
#define SOURCE_FUZZ_FUZZER_UTIL_H_
#include <iostream>
#include <map>
#include <vector>
@ -23,6 +24,7 @@
#include "source/opt/basic_block.h"
#include "source/opt/instruction.h"
#include "source/opt/ir_context.h"
#include "spirv-tools/libspirv.hpp"
namespace spvtools {
namespace fuzz {
@ -30,6 +32,9 @@ namespace fuzz {
// Provides types and global utility methods for use by the fuzzer
namespace fuzzerutil {
// A silent message consumer.
extern const spvtools::MessageConsumer kSilentMessageConsumer;
// Function type that produces a SPIR-V module.
using ModuleSupplier = std::function<std::unique_ptr<opt::IRContext>()>;
@ -150,8 +155,18 @@ uint32_t GetBoundForCompositeIndex(const opt::Instruction& composite_type_inst,
opt::IRContext* ir_context);
// Returns true if and only if |context| is valid, according to the validator
// instantiated with |validator_options|.
bool IsValid(opt::IRContext* context, spv_validator_options validator_options);
// instantiated with |validator_options|. |consumer| is used for error
// reporting.
bool IsValid(const opt::IRContext* context,
spv_validator_options validator_options, MessageConsumer consumer);
// Returns true if and only if IsValid(|context|, |validator_options|) holds,
// and furthermore every basic block in |context| has its enclosing function as
// its parent, and every instruction in |context| has a distinct unique id.
// |consumer| is used for error reporting.
bool IsValidAndWellFormed(const opt::IRContext* context,
spv_validator_options validator_options,
MessageConsumer consumer);
// Returns a clone of |context|, by writing |context| to a binary and then
// parsing it again.

View File

@ -182,7 +182,8 @@ bool TransformationAddDeadBreak::IsApplicable(
auto cloned_context = fuzzerutil::CloneIRContext(ir_context);
ApplyImpl(cloned_context.get(), transformation_context);
return fuzzerutil::IsValid(cloned_context.get(),
transformation_context.GetValidatorOptions());
transformation_context.GetValidatorOptions(),
fuzzerutil::kSilentMessageConsumer);
}
void TransformationAddDeadBreak::Apply(

View File

@ -122,7 +122,8 @@ bool TransformationAddDeadContinue::IsApplicable(
auto cloned_context = fuzzerutil::CloneIRContext(ir_context);
ApplyImpl(cloned_context.get(), transformation_context);
return fuzzerutil::IsValid(cloned_context.get(),
transformation_context.GetValidatorOptions());
transformation_context.GetValidatorOptions(),
fuzzerutil::kSilentMessageConsumer);
}
void TransformationAddDeadContinue::Apply(

View File

@ -135,7 +135,8 @@ bool TransformationAddFunction::IsApplicable(
// Check whether the cloned module is still valid after adding the function.
// If it is not, the transformation is not applicable.
if (!fuzzerutil::IsValid(cloned_module.get(),
transformation_context.GetValidatorOptions())) {
transformation_context.GetValidatorOptions(),
fuzzerutil::kSilentMessageConsumer)) {
return false;
}
@ -151,7 +152,8 @@ bool TransformationAddFunction::IsApplicable(
// It is simpler to rely on the validator to guard against this than to
// consider all scenarios when making a function livesafe.
if (!fuzzerutil::IsValid(cloned_module.get(),
transformation_context.GetValidatorOptions())) {
transformation_context.GetValidatorOptions(),
fuzzerutil::kSilentMessageConsumer)) {
return false;
}
}

View File

@ -46,7 +46,8 @@ bool TransformationAddSpecConstantOp::IsApplicable(
auto clone = fuzzerutil::CloneIRContext(ir_context);
ApplyImpl(clone.get());
return fuzzerutil::IsValid(clone.get(),
transformation_context.GetValidatorOptions());
transformation_context.GetValidatorOptions(),
fuzzerutil::kSilentMessageConsumer);
}
void TransformationAddSpecConstantOp::Apply(

View File

@ -141,16 +141,18 @@ void TransformationInlineFunction::Apply(
// Inline the |called_function| entry block.
for (auto& entry_block_instruction : *called_function->entry()) {
opt::Instruction* inlined_instruction = nullptr;
opt::Instruction* inlined_instruction;
if (entry_block_instruction.opcode() == SpvOpVariable) {
// All OpVariable instructions in a function must be in the first block
// in the function.
inlined_instruction = caller_function->begin()->begin()->InsertBefore(
MakeUnique<opt::Instruction>(entry_block_instruction));
std::unique_ptr<opt::Instruction>(
entry_block_instruction.Clone(ir_context)));
} else {
inlined_instruction = function_call_instruction->InsertBefore(
MakeUnique<opt::Instruction>(entry_block_instruction));
std::unique_ptr<opt::Instruction>(
entry_block_instruction.Clone(ir_context)));
}
AdaptInlinedInstruction(result_id_map, ir_context, inlined_instruction);

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/call_graph.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -274,7 +277,9 @@ TEST(CallGraphTest, FunctionInDegree) {
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const auto graph = CallGraph(context.get());
@ -292,7 +297,9 @@ TEST(CallGraphTest, DirectCallees) {
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const auto graph = CallGraph(context.get());
@ -309,7 +316,9 @@ TEST(CallGraphTest, IndirectCallees) {
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const auto graph = CallGraph(context.get());
@ -326,7 +335,9 @@ TEST(CallGraphTest, TopologicalOrder) {
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const auto graph = CallGraph(context.get());
@ -347,7 +358,9 @@ TEST(CallGraphTest, LoopNestingDepth) {
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const auto graph = CallGraph(context.get());

View File

@ -13,7 +13,10 @@
// limitations under the License.
#include "source/fuzz/comparator_deep_blocks_first.h"
#include "gtest/gtest.h"
#include "source/fuzz/fact_manager/fact_manager.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "source/fuzz/transformation_context.h"
#include "test/fuzz/fuzz_test_util.h"
@ -73,9 +76,9 @@ TEST(ComparatorDeepBlocksFirstTest, Compare) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto is_deeper = ComparatorDeepBlocksFirst(context.get());
@ -105,9 +108,9 @@ TEST(ComparatorDeepBlocksFirstTest, Sort) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Check that, sorting using the comparator, the blocks are ordered from more

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/data_descriptor.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/id_use_descriptor.h"
#include "source/fuzz/instruction_descriptor.h"
#include "source/fuzz/transformation_composite_extract.h"
@ -120,9 +123,9 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -159,7 +162,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_TRUE(
replacement_1.IsApplicable(context.get(), transformation_context));
replacement_1.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %13 with %100[1] in 'OpStore %15 %13'
auto instruction_descriptor_2 = MakeInstructionDescriptor(100, SpvOpStore, 0);
@ -174,7 +178,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_TRUE(
replacement_2.IsApplicable(context.get(), transformation_context));
replacement_2.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %22 with %100[2] in '%23 = OpConvertSToF %16 %22'
auto instruction_descriptor_3 =
@ -194,7 +199,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_FALSE(
bad_replacement_3.IsApplicable(context.get(), transformation_context));
replacement_3.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %28 with %101[0] in 'OpStore %33 %28'
auto instruction_descriptor_4 = MakeInstructionDescriptor(33, SpvOpStore, 0);
@ -213,7 +219,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_TRUE(
replacement_4.IsApplicable(context.get(), transformation_context));
replacement_4.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %23 with %101[1] in '%50 = OpCopyObject %16 %23'
auto instruction_descriptor_5 =
@ -233,7 +240,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_FALSE(
bad_replacement_5.IsApplicable(context.get(), transformation_context));
replacement_5.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %32 with %101[2] in 'OpStore %33 %32'
auto instruction_descriptor_6 = MakeInstructionDescriptor(33, SpvOpStore, 1);
@ -252,7 +260,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_TRUE(
replacement_6.IsApplicable(context.get(), transformation_context));
replacement_6.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %23 with %101[3] in '%51 = OpCopyObject %16 %23'
auto instruction_descriptor_7 =
@ -272,7 +281,8 @@ TEST(DataSynonymTransformationTest, ArrayCompositeSynonyms) {
ASSERT_FALSE(
bad_replacement_7.IsApplicable(context.get(), transformation_context));
replacement_7.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -407,9 +417,9 @@ TEST(DataSynonymTransformationTest, MatrixCompositeSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -431,7 +441,8 @@ TEST(DataSynonymTransformationTest, MatrixCompositeSynonyms) {
ASSERT_TRUE(
replacement_1.IsApplicable(context.get(), transformation_context));
replacement_1.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %25 with %100[1] in '%26 = OpFAdd %7 %23 %25'
auto instruction_descriptor_2 = MakeInstructionDescriptor(26, SpvOpFAdd, 0);
@ -444,7 +455,8 @@ TEST(DataSynonymTransformationTest, MatrixCompositeSynonyms) {
ASSERT_TRUE(
replacement_2.IsApplicable(context.get(), transformation_context));
replacement_2.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -576,9 +588,9 @@ TEST(DataSynonymTransformationTest, StructCompositeSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -609,7 +621,8 @@ TEST(DataSynonymTransformationTest, StructCompositeSynonyms) {
ASSERT_TRUE(
replacement_1.IsApplicable(context.get(), transformation_context));
replacement_1.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace second occurrence of %27 with %101[0] in '%28 =
// OpCompositeConstruct %8 %27 %27'
@ -624,7 +637,8 @@ TEST(DataSynonymTransformationTest, StructCompositeSynonyms) {
ASSERT_TRUE(
replacement_2.IsApplicable(context.get(), transformation_context));
replacement_2.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %36 with %101[1] in '%45 = OpCompositeConstruct %31 %36 %41 %44'
auto instruction_descriptor_3 =
@ -638,7 +652,8 @@ TEST(DataSynonymTransformationTest, StructCompositeSynonyms) {
ASSERT_TRUE(
replacement_3.IsApplicable(context.get(), transformation_context));
replacement_3.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace first occurrence of %27 with %101[2] in '%28 = OpCompositeConstruct
// %8 %27 %27'
@ -653,7 +668,8 @@ TEST(DataSynonymTransformationTest, StructCompositeSynonyms) {
ASSERT_TRUE(
replacement_4.IsApplicable(context.get(), transformation_context));
replacement_4.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %22 with %102[0] in 'OpStore %23 %22'
auto instruction_descriptor_5 = MakeInstructionDescriptor(23, SpvOpStore, 0);
@ -666,7 +682,8 @@ TEST(DataSynonymTransformationTest, StructCompositeSynonyms) {
ASSERT_TRUE(
replacement_5.IsApplicable(context.get(), transformation_context));
replacement_5.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -865,9 +882,9 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -926,7 +943,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_1.IsApplicable(context.get(), transformation_context));
replacement_1.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %54 with %100[3] in '%56 = OpFOrdNotEqual %30 %54 %55'
auto instruction_descriptor_2 =
@ -941,7 +959,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_2.IsApplicable(context.get(), transformation_context));
replacement_2.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %15 with %101[0:1] in 'OpStore %12 %15'
auto instruction_descriptor_3 = MakeInstructionDescriptor(64, SpvOpStore, 0);
@ -956,7 +975,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_3.IsApplicable(context.get(), transformation_context));
replacement_3.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %19 with %101[2:3] in '%81 = OpVectorShuffle %16 %19 %19 0 0 1'
auto instruction_descriptor_4 =
@ -972,7 +992,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_4.IsApplicable(context.get(), transformation_context));
replacement_4.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %27 with %102[0] in '%82 = OpCompositeConstruct %21 %26 %27 %28
// %25'
@ -988,7 +1009,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_5.IsApplicable(context.get(), transformation_context));
replacement_5.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %15 with %102[1:2] in '%83 = OpCopyObject %10 %15'
auto instruction_descriptor_6 =
@ -1004,7 +1026,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_6.IsApplicable(context.get(), transformation_context));
replacement_6.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %33 with %103[0] in '%86 = OpCopyObject %30 %33'
auto instruction_descriptor_7 =
@ -1018,7 +1041,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_7.IsApplicable(context.get(), transformation_context));
replacement_7.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %47 with %103[1:3] in '%84 = OpCopyObject %39 %47'
auto instruction_descriptor_8 =
@ -1034,7 +1058,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_8.IsApplicable(context.get(), transformation_context));
replacement_8.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %42 with %104[0] in '%85 = OpCopyObject %30 %42'
auto instruction_descriptor_9 =
@ -1048,7 +1073,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_9.IsApplicable(context.get(), transformation_context));
replacement_9.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %45 with %104[1] in '%63 = OpLogicalOr %30 %45 %46'
auto instruction_descriptor_10 =
@ -1062,7 +1088,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_10.IsApplicable(context.get(), transformation_context));
replacement_10.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %38 with %105[0:1] in 'OpStore %36 %38'
auto instruction_descriptor_11 = MakeInstructionDescriptor(85, SpvOpStore, 0);
@ -1077,7 +1104,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_11.IsApplicable(context.get(), transformation_context));
replacement_11.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %46 with %105[2] in '%62 = OpLogicalAnd %30 %45 %46'
auto instruction_descriptor_12 =
@ -1091,7 +1119,8 @@ TEST(DataSynonymTransformationTest, VectorCompositeSynonyms) {
ASSERT_TRUE(
replacement_12.IsApplicable(context.get(), transformation_context));
replacement_12.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,9 +14,10 @@
#include <set>
#include "source/fuzz/equivalence_relation.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "source/fuzz/equivalence_relation.h"
namespace spvtools {
namespace fuzz {

View File

@ -15,6 +15,9 @@
#include <limits>
#include "source/fuzz/fact_manager/fact_manager.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/uniform_buffer_element_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -202,7 +205,9 @@ TEST(ConstantUniformFactsTest, ConstantsAvailableViaUniforms) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
uint32_t buffer_int32_min[1];
uint32_t buffer_int64_1[2];
@ -531,7 +536,9 @@ TEST(ConstantUniformFactsTest, TwoConstantsWithSameValue) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -596,7 +603,9 @@ TEST(ConstantUniformFactsTest, NonFiniteFactsAreNotValid) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
auto uniform_buffer_element_descriptor_f =
@ -711,7 +720,9 @@ TEST(ConstantUniformFactsTest, AmbiguousFact) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
auto uniform_buffer_element_descriptor =
@ -757,7 +768,9 @@ TEST(ConstantUniformFactsTest, CheckingFactsDoesNotAddConstants) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/fact_manager/fact_manager.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/transformation_merge_blocks.h"
#include "test/fuzz/fuzz_test_util.h"
@ -62,7 +65,9 @@ TEST(DataSynonymAndIdEquationFactsTest, RecursiveAdditionOfFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -124,7 +129,9 @@ TEST(DataSynonymAndIdEquationFactsTest, CorollaryConversionFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -197,9 +204,9 @@ TEST(DataSynonymAndIdEquationFactsTest, HandlesCorollariesWithInvalidIds) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -216,7 +223,8 @@ TEST(DataSynonymAndIdEquationFactsTest, HandlesCorollariesWithInvalidIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
transformation.Apply(context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
CheckConsistencyOfSynonymFacts(context.get(), transformation_context);
@ -276,7 +284,9 @@ TEST(DataSynonymAndIdEquationFactsTest, LogicalNotEquationFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -320,7 +330,9 @@ TEST(DataSynonymAndIdEquationFactsTest, SignedNegateEquationFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -362,7 +374,9 @@ TEST(DataSynonymAndIdEquationFactsTest, AddSubNegateFacts1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -418,7 +432,9 @@ TEST(DataSynonymAndIdEquationFactsTest, AddSubNegateFacts2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -494,7 +510,9 @@ TEST(DataSynonymAndIdEquationFactsTest, ConversionEquations) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -579,7 +597,9 @@ TEST(DataSynonymAndIdEquationFactsTest, BitcastEquationFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -625,7 +645,9 @@ TEST(DataSynonymAndIdEquationFactsTest, EquationAndEquivalenceFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/fact_manager/fact_manager.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -49,7 +52,9 @@ TEST(DeadBlockFactsTest, BlockIsDead) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/fact_manager/fact_manager.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -41,7 +44,9 @@ TEST(IrrelevantValueFactsTest, IdIsIrrelevant) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -77,7 +82,9 @@ TEST(IrrelevantValueFactsTest, GetIrrelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());
@ -135,7 +142,9 @@ TEST(IrrelevantValueFactsTest, IdsFromDeadBlocksAreIrrelevant) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
FactManager fact_manager(context.get());

View File

@ -14,6 +14,8 @@
#include "test/fuzz/fuzz_test_util.h"
#include "gtest/gtest.h"
#include <fstream>
#include <iostream>
@ -23,6 +25,29 @@
namespace spvtools {
namespace fuzz {
const spvtools::MessageConsumer kConsoleMessageConsumer =
[](spv_message_level_t level, const char*, const spv_position_t& position,
const char* message) -> void {
switch (level) {
case SPV_MSG_FATAL:
case SPV_MSG_INTERNAL_ERROR:
case SPV_MSG_ERROR:
std::cerr << "error: line " << position.index << ": " << message
<< std::endl;
break;
case SPV_MSG_WARNING:
std::cout << "warning: line " << position.index << ": " << message
<< std::endl;
break;
case SPV_MSG_INFO:
std::cout << "info: line " << position.index << ": " << message
<< std::endl;
break;
default:
break;
}
};
bool IsEqual(const spv_target_env env,
const std::vector<uint32_t>& expected_binary,
const std::vector<uint32_t>& actual_binary) {
@ -80,42 +105,6 @@ bool IsEqual(const spv_target_env env, const std::vector<uint32_t>& binary_1,
return IsEqual(env, binary_1, binary_2);
}
bool IsValid(spv_target_env env, const opt::IRContext* ir) {
MessageConsumer consumer = kConsoleMessageConsumer;
// First, run the validator.
std::vector<uint32_t> binary;
ir->module()->ToBinary(&binary, false);
SpirvTools t(env);
t.SetMessageConsumer(consumer);
if (!t.Validate(binary)) {
return false;
}
// Now check that every block in the module has the appropriate parent
// function.
for (auto& function : *ir->module()) {
for (auto& block : function) {
if (block.GetParent() == nullptr) {
std::stringstream ss;
ss << "Block " << block.id() << " has no parent; its parent should be "
<< function.result_id() << ".";
consumer(SPV_MSG_INFO, nullptr, {}, ss.str().c_str());
return false;
}
if (block.GetParent() != &function) {
std::stringstream ss;
ss << "Block " << block.id() << " should have parent "
<< function.result_id() << " but instead has parent "
<< block.GetParent() << ".";
consumer(SPV_MSG_INFO, nullptr, {}, ss.str().c_str());
return false;
}
}
}
return true;
}
std::string ToString(spv_target_env env, const opt::IRContext* ir) {
std::vector<uint32_t> binary;
ir->module()->ToBinary(&binary, false);
@ -143,6 +132,15 @@ void DumpShader(const std::vector<uint32_t>& binary, const char* filename) {
}
}
void DumpTransformationsBinary(
const protobufs::TransformationSequence& transformations,
const char* filename) {
std::ofstream transformations_file;
transformations_file.open(filename, std::ios::out | std::ios::binary);
transformations.SerializeToOstream(&transformations_file);
transformations_file.close();
}
void DumpTransformationsJson(
const protobufs::TransformationSequence& transformations,
const char* filename) {

View File

@ -17,7 +17,6 @@
#include <vector>
#include "gtest/gtest.h"
#include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
#include "source/fuzz/transformation.h"
#include "source/fuzz/transformation_context.h"
@ -28,6 +27,8 @@
namespace spvtools {
namespace fuzz {
extern const spvtools::MessageConsumer kConsoleMessageConsumer;
// Returns true if and only if the given binaries are bit-wise equal.
bool IsEqual(spv_target_env env, const std::vector<uint32_t>& expected_binary,
const std::vector<uint32_t>& actual_binary);
@ -52,11 +53,6 @@ bool IsEqual(spv_target_env env, const opt::IRContext* ir_1,
bool IsEqual(spv_target_env env, const std::vector<uint32_t>& binary_1,
const opt::IRContext* ir_2);
// Assembles the given IR context and returns true if and only if
// the resulting binary is valid and every basic block has its enclosing
// function as its parent.
bool IsValid(spv_target_env env, const opt::IRContext* ir);
// Assembles the given IR context, then returns its disassembly as a string.
// Useful for debugging.
std::string ToString(spv_target_env env, const opt::IRContext* ir);
@ -73,34 +69,6 @@ const uint32_t kFuzzAssembleOption =
const uint32_t kFuzzDisassembleOption =
SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | SPV_BINARY_TO_TEXT_OPTION_INDENT;
// A silent message consumer.
const spvtools::MessageConsumer kSilentConsumer =
[](spv_message_level_t, const char*, const spv_position_t&,
const char*) -> void {};
const spvtools::MessageConsumer kConsoleMessageConsumer =
[](spv_message_level_t level, const char*, const spv_position_t& position,
const char* message) -> void {
switch (level) {
case SPV_MSG_FATAL:
case SPV_MSG_INTERNAL_ERROR:
case SPV_MSG_ERROR:
std::cerr << "error: line " << position.index << ": " << message
<< std::endl;
break;
case SPV_MSG_WARNING:
std::cout << "warning: line " << position.index << ": " << message
<< std::endl;
break;
case SPV_MSG_INFO:
std::cout << "info: line " << position.index << ": " << message
<< std::endl;
break;
default:
break;
}
};
// Dumps the SPIRV-V module in |context| to file |filename|. Useful for
// interactive debugging.
void DumpShader(opt::IRContext* context, const char* filename);
@ -108,6 +76,12 @@ void DumpShader(opt::IRContext* context, const char* filename);
// Dumps |binary| to file |filename|. Useful for interactive debugging.
void DumpShader(const std::vector<uint32_t>& binary, const char* filename);
// Dumps |transformations| to file |filename| in binary format. Useful for
// interactive debugging.
void DumpTransformationsBinary(
const protobufs::TransformationSequence& transformations,
const char* filename);
// Dumps |transformations| to file |filename| in JSON format. Useful for
// interactive debugging.
void DumpTransformationsJson(

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/fuzzer_pass_add_opphi_synonyms.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "test/fuzz/fuzz_test_util.h"
@ -120,9 +123,9 @@ TEST(FuzzerPassAddOpPhiSynonymsTest, HelperFunctions) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
PseudoRandomGenerator prng(0);

View File

@ -14,6 +14,8 @@
#include "source/fuzz/fuzzer_pass_construct_composites.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "test/fuzz/fuzz_test_util.h"
@ -80,9 +82,9 @@ TEST(FuzzerPassConstructCompositesTest, IsomorphicStructs) {
for (uint32_t i = 0; i < 10; i++) {
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
FuzzerContext fuzzer_context(prng.get(), 100);
@ -95,7 +97,8 @@ TEST(FuzzerPassConstructCompositesTest, IsomorphicStructs) {
fuzzer_pass.Apply();
// We just check that the result is valid.
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
}
@ -160,9 +163,9 @@ TEST(FuzzerPassConstructCompositesTest, IsomorphicArrays) {
for (uint32_t i = 0; i < 10; i++) {
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
FuzzerContext fuzzer_context(prng.get(), 100);
@ -175,7 +178,8 @@ TEST(FuzzerPassConstructCompositesTest, IsomorphicArrays) {
fuzzer_pass.Apply();
// We just check that the result is valid.
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
}

View File

@ -16,6 +16,7 @@
#include <algorithm>
#include "gtest/gtest.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "test/fuzz/fuzz_test_util.h"
@ -188,15 +189,18 @@ TEST(FuzzerPassDonateModulesTest, BasicDonation) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -212,7 +216,8 @@ TEST(FuzzerPassDonateModulesTest, BasicDonation) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonationWithUniforms) {
@ -265,15 +270,18 @@ TEST(FuzzerPassDonateModulesTest, DonationWithUniforms) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context = BuildModule(
env, consumer, recipient_and_donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context = BuildModule(
env, consumer, recipient_and_donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -287,7 +295,8 @@ TEST(FuzzerPassDonateModulesTest, DonationWithUniforms) {
fuzzer_pass.DonateSingleModule(donor_context.get(), false);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -392,15 +401,18 @@ TEST(FuzzerPassDonateModulesTest, DonationWithInputAndOutputVariables) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context = BuildModule(
env, consumer, recipient_and_donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context = BuildModule(
env, consumer, recipient_and_donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -414,7 +426,8 @@ TEST(FuzzerPassDonateModulesTest, DonationWithInputAndOutputVariables) {
fuzzer_pass.DonateSingleModule(donor_context.get(), false);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -483,15 +496,18 @@ TEST(FuzzerPassDonateModulesTest, DonateFunctionTypeWithDifferentPointers) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context = BuildModule(
env, consumer, recipient_and_donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context = BuildModule(
env, consumer, recipient_and_donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -507,7 +523,8 @@ TEST(FuzzerPassDonateModulesTest, DonateFunctionTypeWithDifferentPointers) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateOpConstantNull) {
@ -549,15 +566,18 @@ TEST(FuzzerPassDonateModulesTest, DonateOpConstantNull) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -573,7 +593,8 @@ TEST(FuzzerPassDonateModulesTest, DonateOpConstantNull) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImages) {
@ -673,15 +694,18 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImages) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -697,7 +721,8 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImages) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesSampler) {
@ -765,15 +790,18 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesSampler) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -789,7 +817,8 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesSampler) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImageStructField) {
@ -893,15 +922,18 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImageStructField) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -917,7 +949,8 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImageStructField) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImageFunctionParameter) {
@ -1025,15 +1058,18 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImageFunctionParameter) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1049,7 +1085,8 @@ TEST(FuzzerPassDonateModulesTest, DonateCodeThatUsesImageFunctionParameter) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateShaderWithImageStorageClass) {
@ -1103,15 +1140,18 @@ TEST(FuzzerPassDonateModulesTest, DonateShaderWithImageStorageClass) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1127,7 +1167,8 @@ TEST(FuzzerPassDonateModulesTest, DonateShaderWithImageStorageClass) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithRuntimeArray) {
@ -1186,15 +1227,18 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithRuntimeArray) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1210,7 +1254,8 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithRuntimeArray) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithRuntimeArrayLivesafe) {
@ -1286,15 +1331,18 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithRuntimeArrayLivesafe) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1310,7 +1358,8 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithRuntimeArrayLivesafe) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithWorkgroupVariables) {
@ -1354,15 +1403,18 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithWorkgroupVariables) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1378,7 +1430,8 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithWorkgroupVariables) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithAtomics) {
@ -1460,15 +1513,18 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithAtomics) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1484,7 +1540,8 @@ TEST(FuzzerPassDonateModulesTest, DonateComputeShaderWithAtomics) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, Miscellaneous1) {
@ -1640,15 +1697,18 @@ TEST(FuzzerPassDonateModulesTest, Miscellaneous1) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1664,7 +1724,8 @@ TEST(FuzzerPassDonateModulesTest, Miscellaneous1) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, OpSpecConstantInstructions) {
@ -1708,15 +1769,18 @@ TEST(FuzzerPassDonateModulesTest, OpSpecConstantInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1731,7 +1795,8 @@ TEST(FuzzerPassDonateModulesTest, OpSpecConstantInstructions) {
fuzzer_pass.DonateSingleModule(donor_context.get(), false);
// Check that the module is valid first.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1861,15 +1926,18 @@ TEST(FuzzerPassDonateModulesTest, DonationSupportsOpTypeRuntimeArray) {
const auto env = SPV_ENV_UNIVERSAL_1_0;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1883,7 +1951,8 @@ TEST(FuzzerPassDonateModulesTest, DonationSupportsOpTypeRuntimeArray) {
fuzzer_pass.DonateSingleModule(donor_context.get(), false);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
TEST(FuzzerPassDonateModulesTest, HandlesCapabilities) {
@ -1930,15 +1999,18 @@ TEST(FuzzerPassDonateModulesTest, HandlesCapabilities) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -1976,7 +2048,8 @@ TEST(FuzzerPassDonateModulesTest, HandlesCapabilities) {
fuzzer_pass.DonateSingleModule(donor_context.get(), false);
// Check that donation was successful.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -2159,15 +2232,18 @@ TEST(FuzzerPassDonateModulesTest, HandlesOpPhisInMergeBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
spvtools::ValidatorOptions validator_options;
const auto recipient_context =
BuildModule(env, consumer, recipient_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_context =
BuildModule(env, consumer, donor_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(recipient_context.get()), validator_options);
@ -2183,7 +2259,8 @@ TEST(FuzzerPassDonateModulesTest, HandlesOpPhisInMergeBlock) {
// We just check that the result is valid. Checking to what it should be
// exactly equal to would be very fragile.
ASSERT_TRUE(IsValid(env, recipient_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
recipient_context.get(), validator_options, kConsoleMessageConsumer));
}
} // namespace

View File

@ -14,6 +14,8 @@
#include "source/fuzz/fuzzer_pass_outline_functions.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "test/fuzz/fuzz_test_util.h"
@ -117,9 +119,9 @@ TEST(FuzzerPassOutlineFunctionsTest, EntryIsAlreadySuitable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
PseudoRandomGenerator prng(0);
@ -160,9 +162,9 @@ TEST(FuzzerPassOutlineFunctionsTest, EntryHasOpVariable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
PseudoRandomGenerator prng(0);
@ -284,9 +286,9 @@ TEST(FuzzerPassOutlineFunctionsTest, EntryBlockIsHeader) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
PseudoRandomGenerator prng(0);
@ -451,9 +453,9 @@ TEST(FuzzerPassOutlineFunctionsTest, ExitBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
PseudoRandomGenerator prng(0);

View File

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_pass_add_opphi_synonyms.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "test/fuzz/fuzz_test_util.h"
@ -74,9 +76,9 @@ TEST(FuzzerPassTest, ForEachInstructionWithInstructionDescriptor) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Check that %5 is reachable and %8 is unreachable as expected.

View File

@ -13,9 +13,11 @@
// limitations under the License.
#include "source/fuzz/fuzzer.h"
#include "source/fuzz/replayer.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "source/fuzz/replayer.h"
#include "source/fuzz/uniform_buffer_element_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"

View File

@ -12,13 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "source/fuzz/fuzzer.h"
#include "source/fuzz/shrinker.h"
#include <functional>
#include <vector>
#include "source/fuzz/fuzzer.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "source/fuzz/shrinker.h"
#include "source/fuzz/uniform_buffer_element_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -992,7 +994,7 @@ void RunAndCheckShrinker(
spv_validator_options validator_options) {
// Run the shrinker.
auto shrinker_result =
Shrinker(target_env, kSilentConsumer, binary_in, initial_facts,
Shrinker(target_env, kConsoleMessageConsumer, binary_in, initial_facts,
transformation_sequence_in, interestingness_function, step_limit,
false, validator_options)
.Run();
@ -1054,9 +1056,9 @@ void RunFuzzerAndShrinker(const std::string& shader,
}
auto fuzzer_result =
Fuzzer(env, kSilentConsumer, binary_in, initial_facts, donor_suppliers,
MakeUnique<PseudoRandomGenerator>(seed), enable_all_passes,
repeated_pass_strategy, true, validator_options)
Fuzzer(env, kConsoleMessageConsumer, binary_in, initial_facts,
donor_suppliers, MakeUnique<PseudoRandomGenerator>(seed),
enable_all_passes, repeated_pass_strategy, true, validator_options)
.Run();
ASSERT_EQ(Fuzzer::FuzzerResultStatus::kComplete, fuzzer_result.status);
ASSERT_TRUE(t.Validate(fuzzer_result.transformed_binary));

View File

@ -14,6 +14,8 @@
#include "source/fuzz/instruction_descriptor.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -52,7 +54,9 @@ TEST(InstructionDescriptorTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
for (auto& function : *context->module()) {
for (auto& block : function) {

View File

@ -14,7 +14,9 @@
#include "source/fuzz/replayer.h"
#include "gtest/gtest.h"
#include "source/fuzz/data_descriptor.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "source/fuzz/transformation_add_constant_scalar.h"
#include "source/fuzz/transformation_add_global_variable.h"
@ -80,7 +82,7 @@ TEST(ReplayerTest, PartialReplay) {
std::vector<uint32_t> binary_in;
SpirvTools t(env);
t.SetMessageConsumer(kSilentConsumer);
t.SetMessageConsumer(kConsoleMessageConsumer);
ASSERT_TRUE(t.Assemble(kTestShader, &binary_in, kFuzzAssembleOption));
ASSERT_TRUE(t.Validate(binary_in));
@ -96,8 +98,8 @@ TEST(ReplayerTest, PartialReplay) {
// Full replay
protobufs::FactSequence empty_facts;
auto replayer_result =
Replayer(env, kSilentConsumer, binary_in, empty_facts, transformations,
11, true, validator_options)
Replayer(env, kConsoleMessageConsumer, binary_in, empty_facts,
transformations, 11, true, validator_options)
.Run();
// Replay should succeed.
ASSERT_EQ(Replayer::ReplayerResultStatus::kComplete,
@ -182,8 +184,8 @@ TEST(ReplayerTest, PartialReplay) {
// Half replay
protobufs::FactSequence empty_facts;
auto replayer_result =
Replayer(env, kSilentConsumer, binary_in, empty_facts, transformations,
5, true, validator_options)
Replayer(env, kConsoleMessageConsumer, binary_in, empty_facts,
transformations, 5, true, validator_options)
.Run();
// Replay should succeed.
ASSERT_EQ(Replayer::ReplayerResultStatus::kComplete,
@ -260,8 +262,8 @@ TEST(ReplayerTest, PartialReplay) {
// Empty replay
protobufs::FactSequence empty_facts;
auto replayer_result =
Replayer(env, kSilentConsumer, binary_in, empty_facts, transformations,
0, true, validator_options)
Replayer(env, kConsoleMessageConsumer, binary_in, empty_facts,
transformations, 0, true, validator_options)
.Run();
// Replay should succeed.
ASSERT_EQ(Replayer::ReplayerResultStatus::kComplete,
@ -278,8 +280,8 @@ TEST(ReplayerTest, PartialReplay) {
// The number of transformations requested to be applied exceeds the number
// of transformations
auto replayer_result =
Replayer(env, kSilentConsumer, binary_in, empty_facts, transformations,
12, true, validator_options)
Replayer(env, kConsoleMessageConsumer, binary_in, empty_facts,
transformations, 12, true, validator_options)
.Run();
// Replay should not succeed.
@ -324,7 +326,7 @@ TEST(ReplayerTest, CheckFactsAfterReplay) {
std::vector<uint32_t> binary_in;
SpirvTools t(env);
t.SetMessageConsumer(kSilentConsumer);
t.SetMessageConsumer(kConsoleMessageConsumer);
ASSERT_TRUE(t.Assemble(kTestShader, &binary_in, kFuzzAssembleOption));
ASSERT_TRUE(t.Validate(binary_in));
@ -348,8 +350,9 @@ TEST(ReplayerTest, CheckFactsAfterReplay) {
// Full replay
protobufs::FactSequence empty_facts;
auto replayer_result =
Replayer(env, kSilentConsumer, binary_in, empty_facts, transformations,
transformations.transformation_size(), true, validator_options)
Replayer(env, kConsoleMessageConsumer, binary_in, empty_facts,
transformations, transformations.transformation_size(), true,
validator_options)
.Run();
// Replay should succeed.
ASSERT_EQ(Replayer::ReplayerResultStatus::kComplete, replayer_result.status);

View File

@ -14,9 +14,11 @@
#include "source/fuzz/shrinker.h"
#include "gtest/gtest.h"
#include "source/fuzz/fact_manager/fact_manager.h"
#include "source/fuzz/fuzzer_context.h"
#include "source/fuzz/fuzzer_pass_donate_modules.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "source/fuzz/transformation_context.h"
#include "source/opt/ir_context.h"
@ -142,24 +144,27 @@ TEST(ShrinkerTest, ReduceAddedFunctions) {
// compilers are kept happy. See:
// https://developercommunity.visualstudio.com/content/problem/367326/problems-with-capturing-constexpr-in-lambda.html
spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = kSilentConsumer;
const auto consumer = kConsoleMessageConsumer;
SpirvTools tools(env);
std::vector<uint32_t> reference_binary;
ASSERT_TRUE(
tools.Assemble(kReferenceModule, &reference_binary, kFuzzAssembleOption));
spvtools::ValidatorOptions validator_options;
const auto variant_ir_context =
BuildModule(env, consumer, kReferenceModule, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, variant_ir_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
variant_ir_context.get(), validator_options, kConsoleMessageConsumer));
const auto donor_ir_context =
BuildModule(env, consumer, kDonorModule, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, donor_ir_context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
donor_ir_context.get(), validator_options, kConsoleMessageConsumer));
PseudoRandomGenerator random_generator(0);
FuzzerContext fuzzer_context(&random_generator, 100);
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(variant_ir_context.get()), validator_options);

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/transformation_access_chain.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -101,7 +104,9 @@ TEST(TransformationAccessChainTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Types:
// Ptr | Pointee | Storage class | GLSL for pointee | Ids of this type
@ -117,7 +122,6 @@ TEST(TransformationAccessChainTest, BasicTest) {
// Indices 0-5 are in ids 80-85
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(
@ -217,7 +221,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(100));
}
@ -229,7 +234,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(101));
}
@ -241,7 +247,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(103));
}
@ -253,7 +260,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(104));
}
@ -265,7 +273,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(105));
}
@ -277,7 +286,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(106));
}
@ -289,7 +299,8 @@ TEST(TransformationAccessChainTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(107));
}
@ -406,9 +417,9 @@ TEST(TransformationAccessChainTest, IsomorphicStructs) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
{
@ -418,7 +429,8 @@ TEST(TransformationAccessChainTest, IsomorphicStructs) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationAccessChain transformation(
@ -427,7 +439,8 @@ TEST(TransformationAccessChainTest, IsomorphicStructs) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -514,9 +527,9 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: no ids given for clamping
@ -570,7 +583,8 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -581,7 +595,8 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -592,7 +607,8 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -603,7 +619,8 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -614,7 +631,8 @@ TEST(TransformationAccessChainTest, ClampingVariables) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_bit_instruction_synonym.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -79,9 +81,9 @@ TEST(TransformationAddBitInstructionSynonymTest, IsApplicable) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests undefined bit instruction.
@ -218,9 +220,9 @@ TEST(TransformationAddBitInstructionSynonymTest, AddOpBitwiseOrSynonym) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -454,7 +456,8 @@ TEST(TransformationAddBitInstructionSynonymTest, AddOpBitwiseOrSynonym) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -516,9 +519,9 @@ TEST(TransformationAddBitInstructionSynonymTest, AddOpNotSynonym) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -717,7 +720,8 @@ TEST(TransformationAddBitInstructionSynonymTest, AddOpNotSynonym) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -779,9 +783,9 @@ TEST(TransformationAddBitInstructionSynonymTest, NoSynonymWhenIdIsIrrelevant) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -803,7 +807,8 @@ TEST(TransformationAddBitInstructionSynonymTest, NoSynonymWhenIdIsIrrelevant) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// No synonym should have been created, since the bit instruction is
// irrelevant.
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous(
@ -868,9 +873,9 @@ TEST(TransformationAddBitInstructionSynonymTest, NoSynonymWhenBlockIsDead) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -892,7 +897,8 @@ TEST(TransformationAddBitInstructionSynonymTest, NoSynonymWhenBlockIsDead) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// No synonym should have been created, since the bit instruction is
// irrelevant.
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_constant_boolean.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -41,9 +43,9 @@ TEST(TransformationAddConstantBooleanTest, NeitherPresentInitiallyAddBoth) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// True and false can both be added as neither is present.
@ -67,7 +69,8 @@ TEST(TransformationAddConstantBooleanTest, NeitherPresentInitiallyAddBoth) {
ASSERT_TRUE(add_true.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(add_true, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Having added true, we cannot add it again with the same id.
ASSERT_FALSE(add_true.IsApplicable(context.get(), transformation_context));
@ -76,11 +79,13 @@ TEST(TransformationAddConstantBooleanTest, NeitherPresentInitiallyAddBoth) {
ASSERT_TRUE(
add_true_again.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(add_true_again, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(add_false.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(add_false, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Having added false, we cannot add it again with the same id.
ASSERT_FALSE(add_false.IsApplicable(context.get(), transformation_context));
@ -90,7 +95,8 @@ TEST(TransformationAddConstantBooleanTest, NeitherPresentInitiallyAddBoth) {
add_false_again.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(add_false_again, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// We can create an irrelevant OpConstantTrue.
TransformationAddConstantBoolean irrelevant_true(102, true, true);
@ -98,7 +104,8 @@ TEST(TransformationAddConstantBooleanTest, NeitherPresentInitiallyAddBoth) {
irrelevant_true.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(irrelevant_true, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// We can create an irrelevant OpConstantFalse.
TransformationAddConstantBoolean irrelevant_false(103, false, true);
@ -106,7 +113,8 @@ TEST(TransformationAddConstantBooleanTest, NeitherPresentInitiallyAddBoth) {
irrelevant_false.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(irrelevant_false, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(100));
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(101));
@ -159,9 +167,9 @@ TEST(TransformationAddConstantBooleanTest, NoOpTypeBoolPresent) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Neither true nor false can be added as OpTypeBool is not present.

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_constant_composite.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -62,9 +64,9 @@ TEST(TransformationAddConstantCompositeTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Too few ids
@ -131,7 +133,8 @@ TEST(TransformationAddConstantCompositeTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
for (uint32_t id = 100; id <= 106; ++id) {
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(id));
@ -229,9 +232,9 @@ TEST(TransformationAddConstantCompositeTest, DisallowBufferBlockDecoration) {
const auto env = SPV_ENV_UNIVERSAL_1_0;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationAddConstantComposite(100, 7, {10, 10}, false)
@ -272,9 +275,9 @@ TEST(TransformationAddConstantCompositeTest, DisallowBlockDecoration) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationAddConstantComposite(100, 7, {10, 10}, false)

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_constant_null.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -48,9 +50,9 @@ TEST(TransformationAddConstantNullTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -101,7 +103,8 @@ TEST(TransformationAddConstantNullTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_constant_scalar.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -68,9 +70,9 @@ TEST(TransformationAddConstantScalarTest, IsApplicable) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests |fresh_id| being non-fresh.
@ -162,9 +164,9 @@ TEST(TransformationAddConstantScalarTest, Apply) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Adds 32-bit unsigned integer (1 logical operand with 1 word).
@ -173,7 +175,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
auto* constant_instruction = context->get_def_use_mgr()->GetDef(19);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 1);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds 32-bit signed integer (1 logical operand with 1 word).
transformation = TransformationAddConstantScalar(20, 3, {5}, false);
@ -181,7 +184,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(20);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 1);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds 32-bit float (1 logical operand with 1 word).
transformation = TransformationAddConstantScalar(
@ -190,7 +194,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(21);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 1);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds 64-bit unsigned integer (1 logical operand with 2 words).
transformation = TransformationAddConstantScalar(22, 5, {7, 0}, false);
@ -198,7 +203,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(22);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 2);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds 64-bit signed integer (1 logical operand with 2 words).
transformation = TransformationAddConstantScalar(23, 6, {8, 0}, false);
@ -206,7 +212,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(23);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 2);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds 64-bit float (1 logical operand with 2 words).
transformation = TransformationAddConstantScalar(
@ -215,7 +222,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(24);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 2);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds irrelevant 32-bit unsigned integer (1 logical operand with 1 word).
transformation = TransformationAddConstantScalar(25, 2, {10}, true);
@ -223,7 +231,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(25);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 1);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds irrelevant 32-bit signed integer (1 logical operand with 1 word).
transformation = TransformationAddConstantScalar(26, 3, {11}, true);
@ -231,7 +240,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(26);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 1);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds irrelevant 32-bit float (1 logical operand with 1 word).
transformation = TransformationAddConstantScalar(
@ -240,7 +250,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(27);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 1);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds irrelevant 64-bit unsigned integer (1 logical operand with 2 words).
transformation = TransformationAddConstantScalar(28, 5, {13, 0}, true);
@ -248,7 +259,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(28);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 2);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds irrelevant 64-bit signed integer (1 logical operand with 2 words).
transformation = TransformationAddConstantScalar(29, 6, {14, 0}, true);
@ -256,7 +268,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(29);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 2);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Adds irrelevant 64-bit float (1 logical operand with 2 words).
transformation = TransformationAddConstantScalar(
@ -265,7 +278,8 @@ TEST(TransformationAddConstantScalarTest, Apply) {
constant_instruction = context->get_def_use_mgr()->GetDef(30);
EXPECT_EQ(constant_instruction->NumInOperands(), 1);
EXPECT_EQ(constant_instruction->NumInOperandWords(), 2);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
for (uint32_t result_id = 19; result_id <= 24; ++result_id) {
ASSERT_FALSE(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_copy_memory.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -138,9 +140,9 @@ TEST(TransformationAddCopyMemoryTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Target id is not fresh (59).
@ -242,7 +244,8 @@ TEST(TransformationAddCopyMemoryTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(
fresh_id));
@ -416,9 +419,9 @@ TEST(TransformationAddCopyMemoryTest, DisallowBufferBlockDecoration) {
const auto env = SPV_ENV_UNIVERSAL_1_0;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(
@ -462,9 +465,9 @@ TEST(TransformationAddCopyMemoryTest, DisallowBlockDecoration) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_dead_block.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -60,9 +62,9 @@ TEST(TransformationAddDeadBlockTest, BasicTest) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id 4 is already in use
@ -135,7 +137,8 @@ TEST(TransformationAddDeadBlockTest, BasicTest) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -168,9 +171,9 @@ TEST(TransformationAddDeadBlockTest, TargetBlockMustNotBeSelectionMerge) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationAddDeadBlock(100, 9, true)
@ -214,9 +217,9 @@ TEST(TransformationAddDeadBlockTest, TargetBlockMustNotBeLoopMergeOrContinue) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad because 9's successor is the loop continue target.
@ -258,9 +261,9 @@ TEST(TransformationAddDeadBlockTest, SourceBlockMustNotBeLoopHead) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad because 8 is a loop head.
@ -296,16 +299,17 @@ TEST(TransformationAddDeadBlockTest, OpPhiInTarget) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationAddDeadBlock transformation(100, 5, true);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->BlockIsDead(100));
@ -367,9 +371,9 @@ TEST(TransformationAddDeadBlockTest, BackEdge) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// 9 is a back edge block, so it would not be OK to add a dead block here,

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_dead_break.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -98,8 +100,9 @@ TEST(TransformationAddDeadBreakTest, BreaksOutOfSimpleIf) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
const uint32_t merge_block = 16;
@ -152,37 +155,43 @@ TEST(TransformationAddDeadBreakTest, BreaksOutOfSimpleIf) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation6.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -343,9 +352,9 @@ TEST(TransformationAddDeadBreakTest, BreakOutOfNestedIfs) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// The header and merge blocks
@ -437,49 +446,57 @@ TEST(TransformationAddDeadBreakTest, BreakOutOfNestedIfs) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation6.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation7.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation7, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation8.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation8, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -712,9 +729,9 @@ TEST(TransformationAddDeadBreakTest, BreakOutOfNestedSwitches) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// The header and merge blocks
@ -829,61 +846,71 @@ TEST(TransformationAddDeadBreakTest, BreakOutOfNestedSwitches) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation6.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation7.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation7, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation8.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation8, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation9.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation9, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation10.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation10, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1142,9 +1169,9 @@ TEST(TransformationAddDeadBreakTest, BreakOutOfLoopNest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// The header and merge blocks
@ -1264,43 +1291,50 @@ TEST(TransformationAddDeadBreakTest, BreakOutOfLoopNest) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation6.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation7.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation7, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1484,9 +1518,9 @@ TEST(TransformationAddDeadBreakTest, NoBreakFromContinueConstruct) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Not OK to break loop from its continue construct, except from the back-edge
@ -1545,9 +1579,9 @@ TEST(TransformationAddDeadBreakTest, BreakFromBackEdgeBlock) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation = TransformationAddDeadBreak(18, 21, true, {});
@ -1596,7 +1630,8 @@ TEST(TransformationAddDeadBreakTest, BreakFromBackEdgeBlock) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -1677,9 +1712,9 @@ TEST(TransformationAddDeadBreakTest, SelectionInContinueConstruct) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
const uint32_t loop_merge = 12;
@ -1715,25 +1750,29 @@ TEST(TransformationAddDeadBreakTest, SelectionInContinueConstruct) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1897,9 +1936,9 @@ TEST(TransformationAddDeadBreakTest, LoopInContinueConstruct) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
const uint32_t outer_loop_merge = 34;
@ -1924,13 +1963,15 @@ TEST(TransformationAddDeadBreakTest, LoopInContinueConstruct) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -2118,9 +2159,9 @@ TEST(TransformationAddDeadBreakTest, PhiInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Some inapplicable transformations
@ -2163,31 +2204,36 @@ TEST(TransformationAddDeadBreakTest, PhiInstructions) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -2312,9 +2358,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadBreak(100, 101, false, {});
@ -2367,9 +2413,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadBreak(102, 101, false, {});
@ -2416,9 +2462,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules3) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto good_transformation = TransformationAddDeadBreak(100, 101, false, {11});
@ -2427,7 +2473,8 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules3) {
ApplyAndCheckFreshIds(good_transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -2507,9 +2554,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules4) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto good_transformation = TransformationAddDeadBreak(102, 101, false, {11});
@ -2518,7 +2565,8 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules4) {
ApplyAndCheckFreshIds(good_transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -2592,9 +2640,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules5) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadBreak(100, 101, false, {});
@ -2651,9 +2699,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules6) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadBreak(102, 101, false, {});
@ -2712,9 +2760,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules7) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadBreak(102, 101, false, {});
@ -2760,9 +2808,9 @@ TEST(TransformationAddDeadBreakTest, RespectDominanceRules8) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadBreak(102, 101, false, {});
@ -2808,9 +2856,9 @@ TEST(TransformationAddDeadBreakTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad because 14 comes before 12 in the module, and 14 has no predecessors.

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_dead_continue.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -96,8 +98,9 @@ TEST(TransformationAddDeadContinueTest, SimpleExample) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// These are all possibilities.
@ -144,19 +147,22 @@ TEST(TransformationAddDeadContinueTest, SimpleExample) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -370,9 +376,9 @@ TEST(TransformationAddDeadContinueTest, LoopNest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
std::vector<uint32_t> good = {6, 7, 18, 20, 34, 40, 45, 46, 47, 56, 57};
@ -609,9 +615,9 @@ TEST(TransformationAddDeadConditionalTest, LoopInContinueConstruct) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
std::vector<uint32_t> good = {32, 33, 46, 52, 101};
@ -819,9 +825,9 @@ TEST(TransformationAddDeadContinueTest, PhiInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
std::vector<uint32_t> bad = {5, 19, 20, 23, 31, 32, 33, 70};
@ -995,9 +1001,9 @@ TEST(TransformationAddDeadContinueTest, RespectDominanceRules1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// This transformation is not applicable because the dead continue from the
@ -1112,9 +1118,9 @@ TEST(TransformationAddDeadContinueTest, RespectDominanceRules2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// This transformation would shortcut the part of the loop body that defines
@ -1162,9 +1168,9 @@ TEST(TransformationAddDeadContinueTest, RespectDominanceRules3) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// This transformation would shortcut the part of the loop body that defines
@ -1303,9 +1309,9 @@ TEST(TransformationAddDeadContinueTest, Miscellaneous1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// This transformation would shortcut the part of the loop body that defines
@ -1371,9 +1377,9 @@ TEST(TransformationAddDeadContinueTest, Miscellaneous2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// This transformation would introduce a branch from a continue target to
@ -1431,9 +1437,9 @@ TEST(TransformationAddDeadContinueTest, Miscellaneous3) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadContinue(299, false, {});
@ -1493,9 +1499,9 @@ TEST(TransformationAddDeadContinueTest, Miscellaneous4) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadContinue(10, false, {});
@ -1547,9 +1553,9 @@ TEST(TransformationAddDeadContinueTest, Miscellaneous5) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadContinue(110, true, {});
@ -1594,9 +1600,9 @@ TEST(TransformationAddDeadContinueTest, Miscellaneous6) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_transformation = TransformationAddDeadContinue(10, true, {});

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_early_terminator_wrapper.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -32,9 +34,9 @@ TEST(TransformationAddEarlyTerminatorWrapperTest, NoVoidType) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -55,9 +57,9 @@ TEST(TransformationAddEarlyTerminatorWrapperTest, NoVoidFunctionType) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -85,9 +87,9 @@ TEST(TransformationAddEarlyTerminatorWrapperTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -123,7 +125,8 @@ TEST(TransformationAddEarlyTerminatorWrapperTest, BasicTest) {
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include "source/fuzz/transformation_add_function.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_message.h"
#include "test/fuzz/fuzz_test_util.h"
@ -39,7 +42,10 @@ std::vector<protobufs::Instruction> GetInstructionsForFunction(
std::vector<protobufs::Instruction> result;
const auto donor_context =
BuildModule(env, consumer, donor, kFuzzAssembleOption);
assert(IsValid(env, donor_context.get()) && "The given donor must be valid.");
spvtools::ValidatorOptions validator_options;
assert(fuzzerutil::IsValidAndWellFormed(
donor_context.get(), validator_options, kConsoleMessageConsumer) &&
"The given donor must be valid.");
for (auto& function : *donor_context->module()) {
if (function.result_id() == function_id) {
function.ForEachInst([&result](opt::Instruction* inst) {
@ -142,9 +148,9 @@ TEST(TransformationAddFunctionTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationAddFunction transformation1(std::vector<protobufs::Instruction>(
@ -220,7 +226,8 @@ TEST(TransformationAddFunctionTest, BasicTest) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation1 = R"(
OpCapability Shader
@ -342,7 +349,8 @@ TEST(TransformationAddFunctionTest, BasicTest) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation2 = R"(
OpCapability Shader
@ -491,9 +499,9 @@ TEST(TransformationAddFunctionTest, InapplicableTransformations) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// No instructions
@ -629,11 +637,13 @@ TEST(TransformationAddFunctionTest, LoopLimiters) {
instructions.push_back(MakeInstructionMessage(SpvOpReturn, 0, 0, {}));
instructions.push_back(MakeInstructionMessage(SpvOpFunctionEnd, 0, 0, {}));
spvtools::ValidatorOptions validator_options;
const auto context1 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
const auto context2 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context1(
MakeUnique<FactManager>(context1.get()), validator_options);
TransformationContext transformation_context2(
@ -644,7 +654,8 @@ TEST(TransformationAddFunctionTest, LoopLimiters) {
add_dead_function.IsApplicable(context1.get(), transformation_context1));
ApplyAndCheckFreshIds(add_dead_function, context1.get(),
&transformation_context1);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
// The added function should not be deemed livesafe.
ASSERT_FALSE(
transformation_context1.GetFactManager()->FunctionIsLivesafe(30));
@ -730,7 +741,8 @@ TEST(TransformationAddFunctionTest, LoopLimiters) {
transformation_context2));
ApplyAndCheckFreshIds(add_livesafe_function, context2.get(),
&transformation_context2);
ASSERT_TRUE(IsValid(env, context2.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context2.get(), validator_options, kConsoleMessageConsumer));
// The added function should indeed be deemed livesafe.
ASSERT_TRUE(transformation_context2.GetFactManager()->FunctionIsLivesafe(30));
// All variables/parameters in the function should be deemed irrelevant,
@ -851,11 +863,13 @@ TEST(TransformationAddFunctionTest, KillAndUnreachableInVoidFunction) {
instructions.push_back(MakeInstructionMessage(SpvOpKill, 0, 0, {}));
instructions.push_back(MakeInstructionMessage(SpvOpFunctionEnd, 0, 0, {}));
spvtools::ValidatorOptions validator_options;
const auto context1 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
const auto context2 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context1(
MakeUnique<FactManager>(context1.get()), validator_options);
TransformationContext transformation_context2(
@ -866,7 +880,8 @@ TEST(TransformationAddFunctionTest, KillAndUnreachableInVoidFunction) {
add_dead_function.IsApplicable(context1.get(), transformation_context1));
ApplyAndCheckFreshIds(add_dead_function, context1.get(),
&transformation_context1);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
// The added function should not be deemed livesafe.
ASSERT_FALSE(
transformation_context1.GetFactManager()->FunctionIsLivesafe(10));
@ -913,7 +928,8 @@ TEST(TransformationAddFunctionTest, KillAndUnreachableInVoidFunction) {
transformation_context2));
ApplyAndCheckFreshIds(add_livesafe_function, context2.get(),
&transformation_context2);
ASSERT_TRUE(IsValid(env, context2.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context2.get(), validator_options, kConsoleMessageConsumer));
// The added function should indeed be deemed livesafe.
ASSERT_TRUE(transformation_context2.GetFactManager()->FunctionIsLivesafe(10));
// All variables/parameters in the function should be deemed irrelevant.
@ -1006,11 +1022,13 @@ TEST(TransformationAddFunctionTest, KillAndUnreachableInNonVoidFunction) {
instructions.push_back(MakeInstructionMessage(SpvOpKill, 0, 0, {}));
instructions.push_back(MakeInstructionMessage(SpvOpFunctionEnd, 0, 0, {}));
spvtools::ValidatorOptions validator_options;
const auto context1 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
const auto context2 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context1(
MakeUnique<FactManager>(context1.get()), validator_options);
TransformationContext transformation_context2(
@ -1021,7 +1039,8 @@ TEST(TransformationAddFunctionTest, KillAndUnreachableInNonVoidFunction) {
add_dead_function.IsApplicable(context1.get(), transformation_context1));
ApplyAndCheckFreshIds(add_dead_function, context1.get(),
&transformation_context1);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
// The added function should not be deemed livesafe.
ASSERT_FALSE(
transformation_context1.GetFactManager()->FunctionIsLivesafe(10));
@ -1069,7 +1088,8 @@ TEST(TransformationAddFunctionTest, KillAndUnreachableInNonVoidFunction) {
transformation_context2));
ApplyAndCheckFreshIds(add_livesafe_function, context2.get(),
&transformation_context2);
ASSERT_TRUE(IsValid(env, context2.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context2.get(), validator_options, kConsoleMessageConsumer));
// The added function should indeed be deemed livesafe.
ASSERT_TRUE(transformation_context2.GetFactManager()->FunctionIsLivesafe(10));
// All variables/parameters in the function should be deemed irrelevant.
@ -1293,11 +1313,13 @@ TEST(TransformationAddFunctionTest, ClampedAccessChains) {
instructions.push_back(MakeInstructionMessage(SpvOpReturn, 0, 0, {}));
instructions.push_back(MakeInstructionMessage(SpvOpFunctionEnd, 0, 0, {}));
spvtools::ValidatorOptions validator_options;
const auto context1 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
const auto context2 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context1(
MakeUnique<FactManager>(context1.get()), validator_options);
TransformationContext transformation_context2(
@ -1308,7 +1330,8 @@ TEST(TransformationAddFunctionTest, ClampedAccessChains) {
add_dead_function.IsApplicable(context1.get(), transformation_context1));
ApplyAndCheckFreshIds(add_dead_function, context1.get(),
&transformation_context1);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
// The function should not be deemed livesafe
ASSERT_FALSE(
transformation_context1.GetFactManager()->FunctionIsLivesafe(12));
@ -1449,7 +1472,8 @@ TEST(TransformationAddFunctionTest, ClampedAccessChains) {
transformation_context2));
ApplyAndCheckFreshIds(add_livesafe_function, context2.get(),
&transformation_context2);
ASSERT_TRUE(IsValid(env, context2.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context2.get(), validator_options, kConsoleMessageConsumer));
// The function should be deemed livesafe
ASSERT_TRUE(transformation_context2.GetFactManager()->FunctionIsLivesafe(12));
// All variables/parameters in the function should be deemed irrelevant.
@ -1620,11 +1644,13 @@ TEST(TransformationAddFunctionTest, LivesafeCanCallLivesafe) {
instructions.push_back(MakeInstructionMessage(SpvOpReturn, 0, 0, {}));
instructions.push_back(MakeInstructionMessage(SpvOpFunctionEnd, 0, 0, {}));
spvtools::ValidatorOptions validator_options;
const auto context1 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
const auto context2 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context1(
MakeUnique<FactManager>(context1.get()), validator_options);
TransformationContext transformation_context2(
@ -1638,7 +1664,8 @@ TEST(TransformationAddFunctionTest, LivesafeCanCallLivesafe) {
add_dead_function.IsApplicable(context1.get(), transformation_context1));
ApplyAndCheckFreshIds(add_dead_function, context1.get(),
&transformation_context1);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
// The function should not be deemed livesafe
ASSERT_FALSE(transformation_context1.GetFactManager()->FunctionIsLivesafe(8));
// All variables/parameters in the function should be deemed irrelevant.
@ -1676,7 +1703,8 @@ TEST(TransformationAddFunctionTest, LivesafeCanCallLivesafe) {
transformation_context2));
ApplyAndCheckFreshIds(add_livesafe_function, context2.get(),
&transformation_context2);
ASSERT_TRUE(IsValid(env, context2.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context2.get(), validator_options, kConsoleMessageConsumer));
// The function should be deemed livesafe
ASSERT_TRUE(transformation_context2.GetFactManager()->FunctionIsLivesafe(8));
// All variables/parameters in the function should be deemed irrelevant.
@ -1720,11 +1748,13 @@ TEST(TransformationAddFunctionTest, LivesafeOnlyCallsLivesafe) {
instructions.push_back(MakeInstructionMessage(SpvOpReturn, 0, 0, {}));
instructions.push_back(MakeInstructionMessage(SpvOpFunctionEnd, 0, 0, {}));
spvtools::ValidatorOptions validator_options;
const auto context1 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
const auto context2 = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context1(
MakeUnique<FactManager>(context1.get()), validator_options);
TransformationContext transformation_context2(
@ -1735,7 +1765,8 @@ TEST(TransformationAddFunctionTest, LivesafeOnlyCallsLivesafe) {
add_dead_function.IsApplicable(context1.get(), transformation_context1));
ApplyAndCheckFreshIds(add_dead_function, context1.get(),
&transformation_context1);
ASSERT_TRUE(IsValid(env, context1.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context1.get(), validator_options, kConsoleMessageConsumer));
// The function should not be deemed livesafe
ASSERT_FALSE(transformation_context1.GetFactManager()->FunctionIsLivesafe(8));
// All variables/parameters in the function should be deemed irrelevant.
@ -1851,9 +1882,9 @@ TEST(TransformationAddFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %6 in
@ -1873,7 +1904,8 @@ TEST(TransformationAddFunctionTest,
transformation_context));
ApplyAndCheckFreshIds(add_livesafe_function, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -2007,9 +2039,9 @@ TEST(TransformationAddFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %6 in
@ -2029,7 +2061,8 @@ TEST(TransformationAddFunctionTest,
transformation_context));
ApplyAndCheckFreshIds(add_livesafe_function, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -2161,9 +2194,9 @@ TEST(TransformationAddFunctionTest, LoopLimitersHeaderIsBackEdgeBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %6 in
@ -2183,7 +2216,8 @@ TEST(TransformationAddFunctionTest, LoopLimitersHeaderIsBackEdgeBlock) {
transformation_context));
ApplyAndCheckFreshIds(add_livesafe_function, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -2307,9 +2341,9 @@ TEST(TransformationAddFunctionTest, InfiniteLoop) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %6 in
@ -2419,9 +2453,9 @@ TEST(TransformationAddFunctionTest, UnreachableContinueConstruct) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %6 in
@ -2441,7 +2475,8 @@ TEST(TransformationAddFunctionTest, UnreachableContinueConstruct) {
transformation_context));
ApplyAndCheckFreshIds(add_livesafe_function, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -2583,9 +2618,9 @@ TEST(TransformationAddFunctionTest, LoopLimitersAndOpPhi1) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %8 in
@ -2616,7 +2651,8 @@ TEST(TransformationAddFunctionTest, LoopLimitersAndOpPhi1) {
with_op_phi_data.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(with_op_phi_data, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -2774,9 +2810,9 @@ TEST(TransformationAddFunctionTest, LoopLimitersAndOpPhi2) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %8 in
@ -2796,7 +2832,8 @@ TEST(TransformationAddFunctionTest, LoopLimitersAndOpPhi2) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -2922,9 +2959,9 @@ TEST(TransformationAddFunctionTest, StaticallyOutOfBoundsArrayAccess) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a sequence of instruction messages corresponding to function %6 in
@ -2938,7 +2975,8 @@ TEST(TransformationAddFunctionTest, StaticallyOutOfBoundsArrayAccess) {
transformation_context));
ApplyAndCheckFreshIds(add_livesafe_function, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_global_undef.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -45,9 +47,9 @@ TEST(TransformationAddGlobalUndefTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -86,7 +88,8 @@ TEST(TransformationAddGlobalUndefTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_global_variable.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -58,9 +60,9 @@ TEST(TransformationAddGlobalVariableTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -160,7 +162,8 @@ TEST(TransformationAddGlobalVariableTest, BasicTest) {
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(105));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -246,9 +249,9 @@ TEST(TransformationAddGlobalVariableTest, TestEntryPointInterfaceEnlargement) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationAddGlobalVariable transformations[] = {
@ -276,7 +279,8 @@ TEST(TransformationAddGlobalVariableTest, TestEntryPointInterfaceEnlargement) {
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(102));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(101));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -342,9 +346,9 @@ TEST(TransformationAddGlobalVariableTest, TestAddingWorkgroupGlobals) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
#ifndef NDEBUG
@ -373,7 +377,8 @@ TEST(TransformationAddGlobalVariableTest, TestAddingWorkgroupGlobals) {
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(8));
ASSERT_FALSE(
transformation_context.GetFactManager()->PointeeValueIsIrrelevant(10));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_image_sample_unused_components.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -64,9 +66,9 @@ TEST(TransformationAddImageSampleUnusedComponentsTest, IsApplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests applicable image instruction.
@ -190,9 +192,9 @@ TEST(TransformationAddImageSampleUnusedComponentsTest, Apply) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_local_variable.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -77,9 +79,9 @@ TEST(TransformationAddLocalVariableTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// A few cases of inapplicable transformations:

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_loop_preheader.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -70,7 +72,8 @@ TEST(TransformationAddLoopPreheaderTest, SimpleTest) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %9 is not a loop header
ASSERT_FALSE(TransformationAddLoopPreheader(9, 15, {}).IsApplicable(
@ -97,7 +100,8 @@ TEST(TransformationAddLoopPreheaderTest, SimpleTest) {
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -201,7 +205,8 @@ TEST(TransformationAddLoopPreheaderTest, OpPhi) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation1 = TransformationAddLoopPreheader(8, 40, {});
ASSERT_TRUE(
@ -231,7 +236,8 @@ TEST(TransformationAddLoopPreheaderTest, OpPhi) {
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_loop_to_create_int_constant_synonym.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -74,9 +76,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Reminder: the first four parameters of the constructor are the constants
@ -183,9 +185,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationAddLoopToCreateIntConstantSynonym(
@ -222,9 +224,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationAddLoopToCreateIntConstantSynonym(
@ -261,9 +263,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationAddLoopToCreateIntConstantSynonym(
@ -327,9 +329,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Simple) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Block %14 has no predecessors.
@ -393,7 +395,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Simple) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {}), MakeDataDescriptor(100, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// This transformation will create a synonym of constant %12 from a 2-block
// loop.
@ -405,7 +408,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Simple) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {}), MakeDataDescriptor(107, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// This transformation will create a synonym of constant %12 from a 2-block
// loop.
@ -417,7 +421,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Simple) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {}), MakeDataDescriptor(115, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -552,9 +557,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// These tests check that the transformation is applicable and is applied
@ -569,7 +574,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {}), MakeDataDescriptor(100, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %12 and %11 are signed integers, %18 is an unsigned integer.
auto transformation2 = TransformationAddLoopToCreateIntConstantSynonym(
@ -580,7 +586,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {}), MakeDataDescriptor(108, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %17, %18 and %16 are all signed integers.
auto transformation3 = TransformationAddLoopToCreateIntConstantSynonym(
@ -591,7 +598,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(17, {}), MakeDataDescriptor(115, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %22 is an unsigned integer vector, %23 and %24 are signed integer vectors.
auto transformation4 = TransformationAddLoopToCreateIntConstantSynonym(
@ -602,7 +610,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(22, {}), MakeDataDescriptor(122, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %21, %23 and %24 are all signed integer vectors.
auto transformation5 = TransformationAddLoopToCreateIntConstantSynonym(
@ -613,7 +622,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(21, {}), MakeDataDescriptor(129, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -746,9 +756,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, 64BitConstants) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// These tests check that the transformation can be applied, and is applied
@ -763,7 +773,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, 64BitConstants) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(13, {}), MakeDataDescriptor(100, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// 64-bit vector integers.
auto transformation2 = TransformationAddLoopToCreateIntConstantSynonym(
@ -774,7 +785,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, 64BitConstants) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(16, {}), MakeDataDescriptor(107, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -865,9 +877,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Underflow) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// These tests check that underflows are taken into consideration when
@ -883,7 +895,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Underflow) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {}), MakeDataDescriptor(100, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Subtracting 20 twice from 0 underflows and gives the unsigned integer
// 4294967256.
@ -895,7 +908,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, Underflow) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(15, {}), MakeDataDescriptor(107, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -988,9 +1002,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactBlockIsDead(15);
@ -1054,9 +1068,9 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, InserBeforeOpSwitch) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1068,7 +1082,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, InserBeforeOpSwitch) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(20, {}), MakeDataDescriptor(100, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationAddLoopToCreateIntConstantSynonym(
20, 21, 20, 20, 8, 200, 201, 202, 203, 204, 205, 206, 0);
@ -1078,7 +1093,8 @@ TEST(TransformationAddLoopToCreateIntConstantSynonymTest, InserBeforeOpSwitch) {
&transformation_context);
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(20, {}), MakeDataDescriptor(200, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_no_contraction_decoration.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -93,8 +95,9 @@ TEST(TransformationAddNoContractionDecorationTest, BasicScenarios) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Invalid: 200 is not an id
@ -115,7 +118,8 @@ TEST(TransformationAddNoContractionDecorationTest, BasicScenarios) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_opphi_synonym.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -83,9 +85,9 @@ TEST(TransformationAddOpPhiSynonymTest, Inapplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
SetUpIdSynonyms(transformation_context.GetFactManager());
@ -204,9 +206,9 @@ TEST(TransformationAddOpPhiSynonymTest, Apply) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
SetUpIdSynonyms(transformation_context.GetFactManager());
@ -249,7 +251,8 @@ TEST(TransformationAddOpPhiSynonymTest, Apply) {
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(103, {}), MakeDataDescriptor(9, {})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -351,9 +354,9 @@ TEST(TransformationAddOpPhiSynonymTest, VariablePointers) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Declare synonyms
@ -461,9 +464,9 @@ TEST(TransformationAddOpPhiSynonymTest, DeadBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Dead blocks

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_parameter.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -100,9 +102,9 @@ TEST(TransformationAddParameterTest, NonPointerBasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Can't modify entry point function.
@ -134,28 +136,32 @@ TEST(TransformationAddParameterTest, NonPointerBasicTest) {
TransformationAddParameter correct(9, 60, 11, {{{13, 8}}}, 61);
ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(60));
}
{
TransformationAddParameter correct(17, 62, 7, {{}}, 63);
ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(62));
}
{
TransformationAddParameter correct(29, 64, 31, {{}}, 65);
ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(64));
}
{
TransformationAddParameter correct(34, 66, 7, {{}}, 67);
ASSERT_TRUE(correct.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(correct, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(66));
}
@ -318,9 +324,9 @@ TEST(TransformationAddParameterTest, NonPointerNotApplicableTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: Id 19 is not available in the caller that has id 34.
@ -443,9 +449,9 @@ TEST(TransformationAddParameterTest, PointerFunctionTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: Pointer of id 61 has storage class Output, which is not supported.
@ -462,7 +468,8 @@ TEST(TransformationAddParameterTest, PointerFunctionTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: Local variable of id 34 is defined in the caller (main).
TransformationAddParameter transformation_good_2(14, 52, 9, {{{43, 34}}}, 53);
@ -470,7 +477,8 @@ TEST(TransformationAddParameterTest, PointerFunctionTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: Local variable of id 39 is defined in the caller (main).
TransformationAddParameter transformation_good_3(6, 54, 9, {{{33, 39}}}, 55);
@ -478,7 +486,8 @@ TEST(TransformationAddParameterTest, PointerFunctionTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: This adds another pointer parameter to the function of id 6.
TransformationAddParameter transformation_good_4(6, 56, 30, {{{33, 31}}}, 57);
@ -486,7 +495,8 @@ TEST(TransformationAddParameterTest, PointerFunctionTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -664,9 +674,9 @@ TEST(TransformationAddParameterTest, PointerPrivateWorkgroupTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Good: Global variable of id 28 (storage class Private) is defined in the
@ -677,7 +687,8 @@ TEST(TransformationAddParameterTest, PointerPrivateWorkgroupTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: Global variable of id 61 is (storage class Workgroup) is defined in
// the caller (main).
@ -695,7 +706,8 @@ TEST(TransformationAddParameterTest, PointerPrivateWorkgroupTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: Global variable of id 61 is (storage class Workgroup) is defined in
// the caller (main).
@ -713,7 +725,8 @@ TEST(TransformationAddParameterTest, PointerPrivateWorkgroupTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: Global variable of id 61 is (storage class Workgroup) is defined in
// the caller (main).
@ -723,7 +736,8 @@ TEST(TransformationAddParameterTest, PointerPrivateWorkgroupTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -881,9 +895,9 @@ TEST(TransformationAddParameterTest, PointerMoreEntriesInMapTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Good: Local variable of id 21 is defined in every caller (id 27 and id 31).
@ -893,7 +907,8 @@ TEST(TransformationAddParameterTest, PointerMoreEntriesInMapTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Good: Local variable of id 28 is defined in every caller (id 27 and id 31).
TransformationAddParameter transformation_good_2(
@ -902,7 +917,8 @@ TEST(TransformationAddParameterTest, PointerMoreEntriesInMapTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1037,9 +1053,9 @@ TEST(TransformationAddParameterTest, PointeeValueIsIrrelevantTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationAddParameter transformation_good_1(10, 70, 7,
@ -1048,7 +1064,8 @@ TEST(TransformationAddParameterTest, PointeeValueIsIrrelevantTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Check if the fact PointeeValueIsIrrelevant is set for the new parameter
// (storage class Function).
@ -1061,7 +1078,8 @@ TEST(TransformationAddParameterTest, PointeeValueIsIrrelevantTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Check if the fact PointeeValueIsIrrelevant is set for the new parameter
// (storage class Private).
@ -1074,7 +1092,8 @@ TEST(TransformationAddParameterTest, PointeeValueIsIrrelevantTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Check if the fact PointeeValueIsIrrelevant is set for the new parameter
// (storage class Workgroup).

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_relaxed_decoration.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -65,9 +67,9 @@ TEST(TransformationAddRelaxedDecorationTest, BasicScenarios) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactBlockIsDead(100);
@ -92,7 +94,8 @@ TEST(TransformationAddRelaxedDecorationTest, BasicScenarios) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_synonym.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -68,9 +70,9 @@ TEST(TransformationAddSynonymTest, NotApplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(24);
@ -204,9 +206,9 @@ TEST(TransformationAddSynonymTest, AddZeroSubZeroMulOne) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(5, SpvOpReturn, 0);
@ -340,9 +342,9 @@ TEST(TransformationAddSynonymTest, LogicalAndLogicalOr) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(5, SpvOpReturn, 0);
@ -433,9 +435,9 @@ TEST(TransformationAddSynonymTest, LogicalAndConstantIsNotPresent) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(5, SpvOpReturn, 0);
@ -471,9 +473,9 @@ TEST(TransformationAddSynonymTest, LogicalOrConstantIsNotPresent) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(5, SpvOpReturn, 0);
@ -529,9 +531,9 @@ TEST(TransformationAddSynonymTest, CopyObject) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(5, SpvOpReturn, 0);
@ -625,9 +627,9 @@ TEST(TransformationAddSynonymTest, CopyBooleanConstants) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_EQ(0, transformation_context.GetFactManager()
@ -933,9 +935,9 @@ TEST(TransformationAddSynonymTest, CheckIllegalCases) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Inapplicable because %18 is decorated.
@ -1126,9 +1128,9 @@ TEST(TransformationAddSynonymTest, MiscellaneousCopies) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
std::vector<TransformationAddSynonym> transformations = {
@ -1161,7 +1163,8 @@ TEST(TransformationAddSynonymTest, MiscellaneousCopies) {
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1235,9 +1238,9 @@ TEST(TransformationAddSynonymTest, DoNotCopyNullOrUndefPointers) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Illegal to copy null.
@ -1279,9 +1282,9 @@ TEST(TransformationAddSynonymTest, PropagateIrrelevantPointeeFact) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(8);

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_array.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -52,9 +54,9 @@ TEST(TransformationAddTypeArrayTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -101,7 +103,8 @@ TEST(TransformationAddTypeArrayTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_boolean.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -40,9 +42,9 @@ TEST(TransformationAddTypeBooleanTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Not applicable because id 1 is already in use.
@ -53,7 +55,8 @@ TEST(TransformationAddTypeBooleanTest, BasicTest) {
ASSERT_TRUE(
add_type_bool.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(add_type_bool, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Not applicable as we already have this type now.
ASSERT_FALSE(TransformationAddTypeBoolean(101).IsApplicable(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_float.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -44,9 +46,9 @@ TEST(TransformationAddTypeFloatTest, IsApplicable) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests non-fresh id.
@ -94,9 +96,9 @@ TEST(TransformationAddTypeFloatTest, Apply) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Adds 16-bit float type.
@ -133,7 +135,8 @@ TEST(TransformationAddTypeFloatTest, Apply) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_function.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -57,9 +59,9 @@ TEST(TransformationAddTypeFunctionTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -93,7 +95,8 @@ TEST(TransformationAddTypeFunctionTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_int.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -44,9 +46,9 @@ TEST(TransformationAddTypeIntTest, IsApplicable) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests non-fresh id.
@ -110,9 +112,9 @@ TEST(TransformationAddTypeIntTest, Apply) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Adds signed 8-bit integer type.
@ -175,7 +177,8 @@ TEST(TransformationAddTypeIntTest, Apply) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_matrix.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -45,9 +47,9 @@ TEST(TransformationAddTypeMatrixTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -95,7 +97,8 @@ TEST(TransformationAddTypeMatrixTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_pointer.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -95,9 +97,9 @@ TEST(TransformationAddTypePointerTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto bad_type_id_does_not_exist =
@ -142,7 +144,8 @@ TEST(TransformationAddTypePointerTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_struct.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -45,9 +47,9 @@ TEST(TransformationAddTypeStructTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -80,7 +82,8 @@ TEST(TransformationAddTypeStructTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -136,9 +139,9 @@ TEST(TransformationAddTypeStructTest, HandlesBuiltInMembers) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// From the spec for the BuiltIn decoration:

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_add_type_vector.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -43,9 +45,9 @@ TEST(TransformationAddTypeVectorTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Id already in use
@ -74,7 +76,8 @@ TEST(TransformationAddTypeVectorTest, BasicTest) {
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_adjust_branch_weights.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -99,9 +101,9 @@ TEST(TransformationAdjustBranchWeightsTest, IsApplicableTest) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests OpBranchConditional instruction with weigths.
@ -247,9 +249,9 @@ TEST(TransformationAdjustBranchWeightsTest, ApplyTest) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_composite_construct.h"
#include "gtest/gtest.h"
#include "source/fuzz/data_descriptor.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -127,9 +129,9 @@ TEST(TransformationCompositeConstructTest, ConstructArrays) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Make a vec2[3]
@ -146,7 +148,8 @@ TEST(TransformationCompositeConstructTest, ConstructArrays) {
context.get(), transformation_context));
ApplyAndCheckFreshIds(make_vec2_array_length_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(41, {}), MakeDataDescriptor(200, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -166,7 +169,8 @@ TEST(TransformationCompositeConstructTest, ConstructArrays) {
context.get(), transformation_context));
ApplyAndCheckFreshIds(make_float_array_length_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(24, {}), MakeDataDescriptor(201, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -186,7 +190,8 @@ TEST(TransformationCompositeConstructTest, ConstructArrays) {
context.get(), transformation_context));
ApplyAndCheckFreshIds(make_bool_array_length_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(33, {}), MakeDataDescriptor(202, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -206,7 +211,8 @@ TEST(TransformationCompositeConstructTest, ConstructArrays) {
context.get(), transformation_context));
ApplyAndCheckFreshIds(make_uvec3_array_length_2_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(69, {}), MakeDataDescriptor(203, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -395,9 +401,9 @@ TEST(TransformationCompositeConstructTest, ConstructMatrices) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// make a mat3x4
@ -410,7 +416,8 @@ TEST(TransformationCompositeConstructTest, ConstructMatrices) {
ASSERT_FALSE(
make_mat34_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_mat34, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(25, {}), MakeDataDescriptor(200, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -428,7 +435,8 @@ TEST(TransformationCompositeConstructTest, ConstructMatrices) {
ASSERT_FALSE(
make_mat43_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_mat43, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(11, {}), MakeDataDescriptor(201, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -606,9 +614,9 @@ TEST(TransformationCompositeConstructTest, ConstructStructs) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// make an Inner
@ -621,7 +629,8 @@ TEST(TransformationCompositeConstructTest, ConstructStructs) {
ASSERT_FALSE(
make_inner_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_inner, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(25, {}), MakeDataDescriptor(200, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -639,7 +648,8 @@ TEST(TransformationCompositeConstructTest, ConstructStructs) {
ASSERT_FALSE(
make_outer_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_outer, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(46, {}), MakeDataDescriptor(201, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -928,9 +938,9 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationCompositeConstruct make_vec2(
@ -942,7 +952,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_vec2_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_vec2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(17, {}), MakeDataDescriptor(200, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -959,7 +970,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_vec3_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_vec3, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(12, {0}), MakeDataDescriptor(201, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -978,7 +990,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_vec4_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_vec4, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(32, {}), MakeDataDescriptor(202, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -997,7 +1010,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_ivec2_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_ivec2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(126, {}), MakeDataDescriptor(203, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1014,7 +1028,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_ivec3_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_ivec3, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(56, {}), MakeDataDescriptor(204, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1033,7 +1048,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_ivec4_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_ivec4, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(56, {}), MakeDataDescriptor(205, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1051,7 +1067,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_uvec2_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_uvec2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(18, {}), MakeDataDescriptor(206, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1066,7 +1083,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_uvec3_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_uvec3, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(14, {}), MakeDataDescriptor(207, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1085,7 +1103,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_uvec4_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_uvec4, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(14, {}), MakeDataDescriptor(208, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1114,7 +1133,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_bvec2_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_bvec2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(111, {}), MakeDataDescriptor(209, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1129,7 +1149,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_bvec3_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_bvec3, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(108, {0}), MakeDataDescriptor(210, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1146,7 +1167,8 @@ TEST(TransformationCompositeConstructTest, ConstructVectors) {
ASSERT_FALSE(
make_bvec4_bad.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(make_bvec4, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(108, {0}), MakeDataDescriptor(211, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1420,9 +1442,9 @@ TEST(TransformationCompositeConstructTest, AddSynonymsForRelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationCompositeConstruct transformation(
@ -1430,7 +1452,8 @@ TEST(TransformationCompositeConstructTest, AddSynonymsForRelevantIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(25, {}), MakeDataDescriptor(200, {0})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -1502,9 +1525,9 @@ TEST(TransformationCompositeConstructTest, DontAddSynonymsForIrrelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(25);
@ -1514,7 +1537,8 @@ TEST(TransformationCompositeConstructTest, DontAddSynonymsForIrrelevantIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(25, {}), MakeDataDescriptor(200, {0})));
// Even though %28 is not irrelevant, we do not create a synonym because part
@ -1557,9 +1581,9 @@ TEST(TransformationCompositeConstructTest, DontAddSynonymsInDeadBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactBlockIsDead(15);

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_composite_extract.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -94,9 +96,9 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Instruction does not exist.
@ -144,7 +146,8 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
transformation_1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationCompositeExtract transformation_2(
MakeInstructionDescriptor(37, SpvOpAccessChain, 0), 202, 104, {0, 2});
@ -152,7 +155,8 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
transformation_2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationCompositeExtract transformation_3(
MakeInstructionDescriptor(29, SpvOpAccessChain, 0), 203, 104, {0});
@ -160,7 +164,8 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
transformation_3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationCompositeExtract transformation_4(
MakeInstructionDescriptor(24, SpvOpStore, 0), 204, 101, {0});
@ -168,7 +173,8 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
transformation_4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation_4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationCompositeExtract transformation_5(
MakeInstructionDescriptor(29, SpvOpBranch, 0), 205, 102, {2});
@ -176,7 +182,8 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
transformation_5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation_5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationCompositeExtract transformation_6(
MakeInstructionDescriptor(37, SpvOpReturn, 0), 206, 103, {1});
@ -184,7 +191,8 @@ TEST(TransformationCompositeExtractTest, BasicTest) {
transformation_6.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation_6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(201, {}), MakeDataDescriptor(100, {2})));
@ -353,9 +361,9 @@ TEST(TransformationCompositeExtractTest, IllegalInsertionPoints) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Cannot insert before the OpVariables of a function.
@ -475,9 +483,9 @@ TEST(TransformationCompositeExtractTest, AddSynonymsForRelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationCompositeExtract transformation(
@ -562,9 +570,9 @@ TEST(TransformationCompositeExtractTest, DontAddSynonymsForIrrelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(100);
@ -611,9 +619,9 @@ TEST(TransformationCompositeExtractTest, DontAddSynonymInDeadBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactBlockIsDead(15);

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_composite_insert.h"
#include "gtest/gtest.h"
#include "source/fuzz/data_descriptor.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -94,9 +96,9 @@ TEST(TransformationCompositeInsertTest, NotApplicableScenarios) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: |fresh_id| is not fresh.
@ -213,9 +215,9 @@ TEST(TransformationCompositeInsertTest, EmptyCompositeScenarios) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: The composite with |composite_id| cannot be empty.
@ -232,7 +234,8 @@ TEST(TransformationCompositeInsertTest, EmptyCompositeScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -356,8 +359,9 @@ TEST(TransformationCompositeInsertTest, IrrelevantCompositeNoSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add fact that the composite is irrelevant.
@ -369,7 +373,8 @@ TEST(TransformationCompositeInsertTest, IrrelevantCompositeNoSynonyms) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// No synonyms that involve the original object - %30 - should have been
// added.
@ -459,8 +464,9 @@ TEST(TransformationCompositeInsertTest, IrrelevantObjectNoSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add fact that the object is irrelevant.
@ -472,7 +478,8 @@ TEST(TransformationCompositeInsertTest, IrrelevantObjectNoSynonyms) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Since %30 and %50 are not irrelevant, they should be synonymous at all
// indices unaffected by the insertion.
@ -567,8 +574,9 @@ TEST(TransformationCompositeInsertTest, ApplicableCreatedSynonyms) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation_good_1 = TransformationCompositeInsert(
@ -577,7 +585,8 @@ TEST(TransformationCompositeInsertTest, ApplicableCreatedSynonyms) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// These synonyms should have been added.
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -605,7 +614,8 @@ TEST(TransformationCompositeInsertTest, ApplicableCreatedSynonyms) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// These synonyms should have been added.
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -769,9 +779,9 @@ TEST(TransformationCompositeInsertTest, IdNotAvailableScenarios) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: The object with |object_id| is not available at
@ -841,9 +851,9 @@ TEST(TransformationCompositeInsertTest, CompositeInsertionWithIrrelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -901,7 +911,8 @@ TEST(TransformationCompositeInsertTest, CompositeInsertionWithIrrelevantIds) {
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(103, {1}), MakeDataDescriptor(9, {1})));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
}
} // namespace

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_compute_data_synonym_fact_closure.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -121,9 +123,9 @@ TEST(TransformationComputeDataSynonymFactClosureTest, DataSynonymFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(TransformationComputeDataSynonymFactClosure(100).IsApplicable(
@ -404,9 +406,10 @@ TEST(TransformationComputeDataSynonymFactClosureTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_duplicate_region_with_selection.h"
#include "gtest/gtest.h"
#include "source/fuzz/counter_overflow_id_source.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -77,9 +79,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, BasicUseTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationDuplicateRegionWithSelection transformation_good_1 =
@ -92,7 +94,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest, BasicUseTest) {
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
OpCapability VariablePointers
@ -208,9 +211,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, BasicExitBlockTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationDuplicateRegionWithSelection transformation_good_1 =
@ -223,7 +226,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest, BasicExitBlockTest) {
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -346,9 +350,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, NotApplicableCFGTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: |entry_block_id| refers to the entry block of the function (this
@ -442,9 +446,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, NotApplicableIdTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: A value in the |original_label_to_duplicate_label| is not a fresh id.
@ -615,9 +619,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, NotApplicableCFGTest2) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: The exit block cannot be a header of a loop, because the region won't
@ -697,9 +701,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, NotApplicableCFGTest3) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: The block with id 7, which is not an exit block, has two successors:
@ -781,9 +785,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, MultipleBlocksLoopTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationDuplicateRegionWithSelection transformation_good_1 =
@ -808,7 +812,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest, MultipleBlocksLoopTest) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -969,12 +974,13 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationDuplicateRegionWithSelection transformation_good_1 =
TransformationDuplicateRegionWithSelection(
@ -985,7 +991,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1123,9 +1130,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest, NotApplicableEarlyReturn) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: The block with id 50, which is the entry block, has two successors:
@ -1200,12 +1207,13 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationDuplicateRegionWithSelection transformation_good_1 =
TransformationDuplicateRegionWithSelection(
@ -1214,7 +1222,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1336,9 +1345,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Bad: There is no required capability CapabilityVariablePointers
@ -1396,12 +1405,13 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationDuplicateRegionWithSelection transformation_good_1 =
TransformationDuplicateRegionWithSelection(
@ -1411,7 +1421,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1515,12 +1526,13 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationDuplicateRegionWithSelection transformation_good_1 =
TransformationDuplicateRegionWithSelection(
@ -1530,7 +1542,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1653,9 +1666,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationDuplicateRegionWithSelection transformation_bad =
@ -1731,9 +1744,9 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1792,15 +1805,16 @@ TEST(TransformationDuplicateRegionWithSelectionTest, OverflowIds) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto overflow_ids_unique_ptr = MakeUnique<CounterOverflowIdSource>(1000);
auto overflow_ids_ptr = overflow_ids_unique_ptr.get();
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options,
std::move(overflow_ids_unique_ptr));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// The mappings do not provide sufficient ids, thus overflow ids are required.
TransformationDuplicateRegionWithSelection transformation_good_1 =
@ -1811,7 +1825,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest, OverflowIds) {
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context,
overflow_ids_ptr->GetIssuedOverflowIds());
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1921,12 +1936,13 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationDuplicateRegionWithSelection transformation_good_1 =
TransformationDuplicateRegionWithSelection(
@ -1936,7 +1952,8 @@ TEST(TransformationDuplicateRegionWithSelectionTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_equation_instruction.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -46,9 +48,9 @@ TEST(TransformationEquationInstructionTest, SignedNegate) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -102,7 +104,8 @@ TEST(TransformationEquationInstructionTest, SignedNegate) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationEquationInstruction(
15, SpvOpSNegate, {14}, return_instruction);
@ -110,7 +113,8 @@ TEST(TransformationEquationInstructionTest, SignedNegate) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(15, {}), MakeDataDescriptor(7, {})));
@ -164,9 +168,9 @@ TEST(TransformationEquationInstructionTest, LogicalNot) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -193,7 +197,8 @@ TEST(TransformationEquationInstructionTest, LogicalNot) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationEquationInstruction(
15, SpvOpLogicalNot, {14}, return_instruction);
@ -201,7 +206,8 @@ TEST(TransformationEquationInstructionTest, LogicalNot) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(15, {}), MakeDataDescriptor(7, {})));
@ -256,9 +262,9 @@ TEST(TransformationEquationInstructionTest, AddSubNegate1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -291,7 +297,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate1) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationEquationInstruction(
19, SpvOpISub, {14, 16}, return_instruction);
@ -299,7 +306,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate1) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(15, {}), MakeDataDescriptor(19, {})));
@ -309,7 +317,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate1) {
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(20, {}), MakeDataDescriptor(16, {})));
@ -319,7 +328,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate1) {
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation5 = TransformationEquationInstruction(
24, SpvOpSNegate, {22}, return_instruction);
@ -327,7 +337,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate1) {
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(24, {}), MakeDataDescriptor(15, {})));
@ -383,9 +394,9 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -397,7 +408,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationEquationInstruction(
17, SpvOpIAdd, {14, 16}, return_instruction);
@ -405,7 +417,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(17, {}), MakeDataDescriptor(15, {})));
@ -415,7 +428,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(17, {}), MakeDataDescriptor(18, {})));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
@ -427,7 +441,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation5 = TransformationEquationInstruction(
20, SpvOpSNegate, {19}, return_instruction);
@ -435,7 +450,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation5.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(20, {}), MakeDataDescriptor(16, {})));
@ -445,7 +461,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation6.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(21, {}), MakeDataDescriptor(15, {})));
@ -455,7 +472,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation7.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation7, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation8 = TransformationEquationInstruction(
23, SpvOpSNegate, {22}, return_instruction);
@ -463,7 +481,8 @@ TEST(TransformationEquationInstructionTest, AddSubNegate2) {
transformation8.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation8, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(23, {}), MakeDataDescriptor(16, {})));
@ -531,9 +550,9 @@ TEST(TransformationEquationInstructionTest, Bitcast) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -655,9 +674,9 @@ TEST(TransformationEquationInstructionTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -702,9 +721,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -745,9 +764,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -820,9 +839,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist3) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -894,9 +913,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist4) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -914,7 +933,8 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist4) {
TransformationEquationInstruction(51, SpvOpBitcast, {20}, insert_before)
.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -964,9 +984,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist5) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -984,7 +1004,8 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist5) {
TransformationEquationInstruction(51, SpvOpBitcast, {20}, insert_before)
.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1036,9 +1057,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist6) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -1060,7 +1081,8 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist6) {
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1115,9 +1137,9 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist7) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto insert_before = MakeInstructionDescriptor(13, SpvOpReturn, 0);
@ -1139,7 +1161,8 @@ TEST(TransformationEquationInstructionTest, BitcastResultTypeIntDoesNotExist7) {
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string expected_shader = R"(
OpCapability Shader
@ -1189,9 +1212,9 @@ TEST(TransformationEquationInstructionTest, Miscellaneous1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -1203,7 +1226,8 @@ TEST(TransformationEquationInstructionTest, Miscellaneous1) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationEquationInstruction(
570, SpvOpIAdd, {522, 113}, return_instruction);
@ -1211,7 +1235,8 @@ TEST(TransformationEquationInstructionTest, Miscellaneous1) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1259,9 +1284,9 @@ TEST(TransformationEquationInstructionTest, Miscellaneous2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -1273,7 +1298,8 @@ TEST(TransformationEquationInstructionTest, Miscellaneous2) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation2 = TransformationEquationInstruction(
570, SpvOpIAdd, {522, 113}, return_instruction);
@ -1281,7 +1307,8 @@ TEST(TransformationEquationInstructionTest, Miscellaneous2) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1343,9 +1370,9 @@ TEST(TransformationEquationInstructionTest, ConversionInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -1446,7 +1473,8 @@ TEST(TransformationEquationInstructionTest, ConversionInstructions) {
&transformation_context);
}
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -1517,9 +1545,9 @@ TEST(TransformationEquationInstructionTest, FloatResultTypeDoesNotExist) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::InstructionDescriptor return_instruction =
@ -1568,9 +1596,9 @@ TEST(TransformationEquationInstructionTest, HandlesIrrelevantIds) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto return_instruction = MakeInstructionDescriptor(13, SpvOpReturn, 0);

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_flatten_conditional_branch.h"
#include "gtest/gtest.h"
#include "source/fuzz/counter_overflow_id_source.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -137,9 +139,9 @@ TEST(TransformationFlattenConditionalBranchTest, Inapplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Block %15 does not end with OpBranchConditional.
@ -243,9 +245,9 @@ TEST(TransformationFlattenConditionalBranchTest, Simple) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation1 = TransformationFlattenConditionalBranch(7, true, {});
@ -272,7 +274,8 @@ TEST(TransformationFlattenConditionalBranchTest, Simple) {
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -417,9 +420,9 @@ TEST(TransformationFlattenConditionalBranchTest, LoadStoreFunctionCall) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
#ifndef NDEBUG
@ -515,7 +518,8 @@ TEST(TransformationFlattenConditionalBranchTest, LoadStoreFunctionCall) {
&new_transformation_context,
overflow_ids_ptr->GetIssuedOverflowIds());
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -693,9 +697,9 @@ TEST(TransformationFlattenConditionalBranchTest, EdgeCases) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
#ifndef NDEBUG
@ -735,7 +739,8 @@ TEST(TransformationFlattenConditionalBranchTest, EdgeCases) {
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -826,9 +831,9 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect1) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -836,7 +841,8 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect1) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -891,9 +897,9 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect2) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -901,7 +907,8 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect2) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -958,9 +965,9 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect3) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -968,7 +975,8 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect3) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1027,9 +1035,9 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect4) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1037,7 +1045,8 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect4) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1101,9 +1110,10 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect5) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1116,7 +1126,8 @@ TEST(TransformationFlattenConditionalBranchTest, PhiToSelect5) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1205,9 +1216,9 @@ TEST(TransformationFlattenConditionalBranchTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1218,7 +1229,8 @@ TEST(TransformationFlattenConditionalBranchTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
}
} // namespace

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_function_call.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -132,9 +134,9 @@ TEST(TransformationFunctionCallTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactBlockIsDead(59);
@ -258,7 +260,8 @@ TEST(TransformationFunctionCallTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
// Livesafe called from original live block: fine
@ -268,7 +271,8 @@ TEST(TransformationFunctionCallTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
// Livesafe called from livesafe function: fine
@ -278,7 +282,8 @@ TEST(TransformationFunctionCallTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
// Dead called from dead block in injected function: fine
@ -288,7 +293,8 @@ TEST(TransformationFunctionCallTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
// Non-livesafe called from dead block in livesafe function: OK
@ -298,7 +304,8 @@ TEST(TransformationFunctionCallTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
// Livesafe called from dead block with non-arbitrary parameter
@ -308,7 +315,8 @@ TEST(TransformationFunctionCallTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -449,9 +457,9 @@ TEST(TransformationFunctionCallTest, DoNotInvokeEntryPoint) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactBlockIsDead(11);

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_inline_function.h"
#include "gtest/gtest.h"
#include "source/fuzz/counter_overflow_id_source.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -140,9 +142,9 @@ TEST(TransformationInlineFunctionTest, IsApplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests undefined OpFunctionCall instruction.
@ -270,9 +272,9 @@ TEST(TransformationInlineFunctionTest, Apply) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation = TransformationInlineFunction(43, {{22, 45},
@ -378,7 +380,8 @@ TEST(TransformationInlineFunctionTest, Apply) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -508,9 +511,9 @@ TEST(TransformationInlineFunctionTest, ApplyToMultipleFunctions) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation = TransformationInlineFunction(30, {});
@ -746,7 +749,8 @@ TEST(TransformationInlineFunctionTest, ApplyToMultipleFunctions) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -780,9 +784,9 @@ TEST(TransformationInlineFunctionTest, HandlesOpPhisInTheSecondBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationInlineFunction transformation(6,
@ -790,7 +794,8 @@ TEST(TransformationInlineFunctionTest, HandlesOpPhisInTheSecondBlock) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -897,9 +902,9 @@ TEST(TransformationInlineFunctionTest, OverflowIds) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto overflow_ids_unique_ptr = MakeUnique<CounterOverflowIdSource>(1000);
auto overflow_ids_ptr = overflow_ids_unique_ptr.get();
TransformationContext transformation_context(
@ -1011,7 +1016,8 @@ TEST(TransformationInlineFunctionTest, OverflowIds) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_invert_comparison_operator.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -57,9 +59,9 @@ TEST(TransformationInvertComparisonOperatorTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Operator id is not valid.

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_load.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -83,9 +85,9 @@ TEST(TransformationLoadTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(
@ -190,7 +192,8 @@ TEST(TransformationLoadTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -200,7 +203,8 @@ TEST(TransformationLoadTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -210,7 +214,8 @@ TEST(TransformationLoadTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
@ -220,7 +225,8 @@ TEST(TransformationLoadTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_make_vector_operation_dynamic.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -91,9 +93,9 @@ TEST(TransformationMakeVectorOperationDynamicTest, IsApplicable) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests undefined instruction.
@ -202,9 +204,9 @@ TEST(TransformationMakeVectorOperationDynamicTest, Apply) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation = TransformationMakeVectorOperationDynamic(22, 9);
@ -352,7 +354,8 @@ TEST(TransformationMakeVectorOperationDynamicTest, Apply) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_merge_blocks.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -42,9 +44,9 @@ TEST(TransformationMergeBlocksTest, BlockDoesNotExist) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationMergeBlocks(3).IsApplicable(
@ -82,9 +84,9 @@ TEST(TransformationMergeBlocksTest, DoNotMergeFirstBlockHasMultipleSuccessors) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationMergeBlocks(6).IsApplicable(
@ -121,9 +123,9 @@ TEST(TransformationMergeBlocksTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationMergeBlocks(10).IsApplicable(
@ -161,16 +163,17 @@ TEST(TransformationMergeBlocksTest, MergeWhenSecondBlockIsSelectionMerge) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationMergeBlocks transformation(10);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -233,16 +236,17 @@ TEST(TransformationMergeBlocksTest, MergeWhenSecondBlockIsLoopMerge) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationMergeBlocks transformation(10);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -310,16 +314,17 @@ TEST(TransformationMergeBlocksTest, MergeWhenSecondBlockIsLoopContinue) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationMergeBlocks transformation(11);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -383,16 +388,17 @@ TEST(TransformationMergeBlocksTest, MergeWhenSecondBlockStartsWithOpPhi) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationMergeBlocks transformation(6);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -462,9 +468,9 @@ TEST(TransformationMergeBlocksTest, BasicMerge) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
for (auto& transformation :
@ -474,7 +480,8 @@ TEST(TransformationMergeBlocksTest, BasicMerge) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -553,9 +560,9 @@ TEST(TransformationMergeBlocksTest, MergeWhenSecondBlockIsSelectionHeader) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
for (auto& transformation :
@ -564,7 +571,8 @@ TEST(TransformationMergeBlocksTest, MergeWhenSecondBlockIsSelectionHeader) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -643,16 +651,17 @@ TEST(TransformationMergeBlocksTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationMergeBlocks transformation(101);
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,7 @@
#include "source/fuzz/transformation_merge_function_returns.h"
#include "gtest/gtest.h"
#include "source/fuzz/counter_overflow_id_source.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
@ -139,9 +140,9 @@ TEST(TransformationMergeFunctionReturnsTest, SimpleInapplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -228,9 +229,9 @@ TEST(TransformationMergeFunctionReturnsTest, MissingBooleans) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -280,9 +281,9 @@ TEST(TransformationMergeFunctionReturnsTest, MissingBooleans) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -376,9 +377,9 @@ TEST(TransformationMergeFunctionReturnsTest, InvalidIds) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -551,9 +552,9 @@ TEST(TransformationMergeFunctionReturnsTest, Simple) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -564,7 +565,8 @@ TEST(TransformationMergeFunctionReturnsTest, Simple) {
transformation1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %12 is available at the end of the entry block of %19 (it is a global
// variable).
@ -579,7 +581,8 @@ TEST(TransformationMergeFunctionReturnsTest, Simple) {
transformation2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %27 is available at the end of the entry block of %26 (it is a function
// parameter).
@ -594,7 +597,8 @@ TEST(TransformationMergeFunctionReturnsTest, Simple) {
transformation3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %35 is available at the end of the entry block of %33 (it is in the entry
// block).
@ -609,7 +613,8 @@ TEST(TransformationMergeFunctionReturnsTest, Simple) {
transformation4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -793,9 +798,9 @@ TEST(TransformationMergeFunctionReturnsTest, NestedLoops) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -808,7 +813,8 @@ TEST(TransformationMergeFunctionReturnsTest, NestedLoops) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -976,9 +982,9 @@ TEST(TransformationMergeFunctionReturnsTest, OverflowIds) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1004,7 +1010,8 @@ TEST(TransformationMergeFunctionReturnsTest, OverflowIds) {
ApplyAndCheckFreshIds(transformation1, context.get(),
&transformation_context_with_overflow_ids,
overflow_ids_ptr->GetIssuedOverflowIds());
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// No mapping from merge block %27 to fresh ids is given, so overflow ids are
// needed.
@ -1021,7 +1028,8 @@ TEST(TransformationMergeFunctionReturnsTest, OverflowIds) {
context.get(), transformation_context_with_overflow_ids));
ApplyAndCheckFreshIds(transformation2, context.get(),
&transformation_context_with_overflow_ids, {1002});
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader
@ -1160,9 +1168,9 @@ TEST(TransformationMergeFunctionReturnsTest, MissingIdsForOpPhi) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1176,7 +1184,8 @@ TEST(TransformationMergeFunctionReturnsTest, MissingIdsForOpPhi) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1304,9 +1313,9 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules1) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1326,7 +1335,8 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules1) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1461,9 +1471,9 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules2) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1535,9 +1545,9 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules3) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1550,7 +1560,8 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules3) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1679,9 +1690,9 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules4) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1693,7 +1704,8 @@ TEST(TransformationMergeFunctionReturnsTest, RespectDominanceRules4) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// In function %20, the definition of id %28 will not dominate its use in
// instruction %32 after the transformation is applied, because %28 dominates
@ -1810,9 +1822,10 @@ TEST(TransformationMergeFunctionReturnsTest, OpPhiAfterFirstBlock) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1821,7 +1834,8 @@ TEST(TransformationMergeFunctionReturnsTest, OpPhiAfterFirstBlock) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_move_block_down.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -333,7 +335,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
// Let's bubble 20 all the way down.
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 23 20 21 25 29 32 30 15
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -351,7 +354,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_15.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 23 21 20 25 29 32 30 15
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -369,7 +373,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_15.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 23 21 25 20 29 32 30 15
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -386,7 +391,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_15.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 23 21 25 29 20 32 30 15
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -404,7 +410,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_15.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 23 21 25 29 32 20 30 15
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -422,7 +429,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_15.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 23 21 25 29 32 30 20 15
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -440,7 +448,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_15.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_20, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_bubbling_20_down = R"(
OpCapability Shader
@ -530,7 +539,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_20.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_23, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 21 23 25 29 32 30 15 20
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -548,7 +558,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_20.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_23, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 21 25 23 29 32 30 15 20
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -565,7 +576,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_20.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_21, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Current ordering: 5 14 25 21 23 29 32 30 15 20
ASSERT_FALSE(move_down_5.IsApplicable(context.get(), transformation_context));
@ -581,7 +593,8 @@ TEST(TransformationMoveBlockDownTest, ManyMovesPossible) {
move_down_20.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(move_down_14, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_more_shuffling = R"(
OpCapability Shader
@ -698,9 +711,9 @@ TEST(TransformationMoveBlockDownTest, DoNotMoveUnreachable) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation = TransformationMoveBlockDown(6);

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_move_instruction_down.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -64,9 +66,9 @@ TEST(TransformationMoveInstructionDownTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Instruction descriptor is invalid.
@ -113,7 +115,8 @@ TEST(TransformationMoveInstructionDownTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationMoveInstructionDown transformation(
@ -122,7 +125,8 @@ TEST(TransformationMoveInstructionDownTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -207,9 +211,9 @@ TEST(TransformationMoveInstructionDownTest, HandlesUnsupportedInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Swap memory instruction with an unsupported one.
@ -228,7 +232,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesUnsupportedInstructions) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -310,9 +315,9 @@ TEST(TransformationMoveInstructionDownTest, HandlesBarrierInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Swap two barrier instructions.
@ -336,7 +341,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesBarrierInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationMoveInstructionDown transformation(
@ -345,7 +351,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesBarrierInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
ASSERT_TRUE(IsEqual(env, shader, context.get()));
@ -391,9 +398,9 @@ TEST(TransformationMoveInstructionDownTest, HandlesSimpleInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Swap simple and barrier instructions.
@ -404,7 +411,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesSimpleInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationMoveInstructionDown transformation(
@ -413,7 +421,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesSimpleInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
// Swap simple and memory instructions.
@ -424,7 +433,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesSimpleInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationMoveInstructionDown transformation(
@ -433,7 +443,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesSimpleInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
// Swap two simple instructions.
@ -444,7 +455,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesSimpleInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -601,9 +613,9 @@ TEST(TransformationMoveInstructionDownTest, HandlesMemoryInstructions) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(
@ -696,7 +708,8 @@ TEST(TransformationMoveInstructionDownTest, HandlesMemoryInstructions) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
ASSERT_TRUE(IsEqual(env, shader, context.get()));

View File

@ -14,6 +14,7 @@
#include "source/fuzz/transformation_mutate_pointer.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -77,9 +78,9 @@ TEST(TransformationMutatePointerTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(35);
@ -156,7 +157,8 @@ TEST(TransformationMutatePointerTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -266,9 +268,9 @@ TEST(TransformationMutatePointerTest, HandlesUnreachableBlocks) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(7);
@ -287,7 +289,8 @@ TEST(TransformationMutatePointerTest, HandlesUnreachableBlocks) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_outline_function.h"
#include "gtest/gtest.h"
#include "source/fuzz/counter_overflow_id_source.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -43,9 +45,9 @@ TEST(TransformationOutlineFunctionTest, TrivialOutline) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(5, 5, /* not relevant */ 200,
@ -54,7 +56,8 @@ TEST(TransformationOutlineFunctionTest, TrivialOutline) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -106,9 +109,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(5, 5, /* not relevant */ 200,
@ -161,9 +164,9 @@ TEST(TransformationOutlineFunctionTest, OutlineInterestingControlFlowNoState) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 13, /* not relevant */
@ -172,7 +175,8 @@ TEST(TransformationOutlineFunctionTest, OutlineInterestingControlFlowNoState) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -248,9 +252,9 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatGeneratesUnusedIds) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 6, /* not relevant */ 200,
@ -259,7 +263,8 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatGeneratesUnusedIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -324,9 +329,9 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatGeneratesSingleUsedId) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 6, 99, 100, 101, 102, 103,
@ -334,7 +339,8 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatGeneratesSingleUsedId) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -421,9 +427,9 @@ TEST(TransformationOutlineFunctionTest, OutlineDiamondThatGeneratesSeveralIds) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -432,7 +438,8 @@ TEST(TransformationOutlineFunctionTest, OutlineDiamondThatGeneratesSeveralIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -519,9 +526,9 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesASingleId) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 6, 100, 101, 102, 103, 104,
@ -529,7 +536,8 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesASingleId) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -595,9 +603,9 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesAVariable) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 6, 100, 101, 102, 103, 104,
@ -605,7 +613,8 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesAVariable) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -681,9 +690,9 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesAParameter) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(11, 11, 100, 101, 102, 103, 104,
@ -691,7 +700,8 @@ TEST(TransformationOutlineFunctionTest, OutlineCodeThatUsesAParameter) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -769,9 +779,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 8, 100, 101, 102, 103, 104,
@ -817,9 +827,9 @@ TEST(TransformationOutlineFunctionTest, DoNotOutlineIfRegionInvolvesReturn) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 11, /* not relevant */ 200,
@ -866,9 +876,9 @@ TEST(TransformationOutlineFunctionTest, DoNotOutlineIfRegionInvolvesKill) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 11, /* not relevant */ 200,
@ -916,9 +926,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 11, /* not relevant */ 200,
@ -958,9 +968,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 8, 100, 101, 102, 103, 104,
@ -1000,9 +1010,9 @@ TEST(TransformationOutlineFunctionTest, DoNotOutlineIfLoopHeadIsOutsideRegion) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(7, 8, 100, 101, 102, 103, 104,
@ -1041,9 +1051,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 7, 100, 101, 102, 103, 104,
@ -1084,9 +1094,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(6, 7, 100, 101, 102, 103, 104,
@ -1127,9 +1137,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(8, 11, 100, 101, 102, 103, 104,
@ -1167,9 +1177,9 @@ TEST(TransformationOutlineFunctionTest, OutlineRegionEndingWithReturnVoid) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1187,7 +1197,8 @@ TEST(TransformationOutlineFunctionTest, OutlineRegionEndingWithReturnVoid) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1256,9 +1267,9 @@ TEST(TransformationOutlineFunctionTest, OutlineRegionEndingWithReturnValue) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1276,7 +1287,8 @@ TEST(TransformationOutlineFunctionTest, OutlineRegionEndingWithReturnValue) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1349,9 +1361,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1369,7 +1381,8 @@ TEST(TransformationOutlineFunctionTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1437,9 +1450,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1457,7 +1470,8 @@ TEST(TransformationOutlineFunctionTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1521,9 +1535,9 @@ TEST(TransformationOutlineFunctionTest, DoNotOutlineRegionThatStartsWithOpPhi) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1576,9 +1590,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1631,9 +1645,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1689,9 +1703,9 @@ TEST(TransformationOutlineFunctionTest, DoNotOutlineRegionThatUsesAccessChain) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1749,9 +1763,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1814,9 +1828,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -1834,7 +1848,8 @@ TEST(TransformationOutlineFunctionTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -1968,9 +1983,9 @@ TEST(TransformationOutlineFunctionTest, OutlineLivesafe) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactFunctionIsLivesafe(30);
@ -1994,7 +2009,8 @@ TEST(TransformationOutlineFunctionTest, OutlineLivesafe) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// The original function should still be livesafe.
ASSERT_TRUE(transformation_context.GetFactManager()->FunctionIsLivesafe(30));
@ -2195,9 +2211,9 @@ TEST(TransformationOutlineFunctionTest, OutlineWithDeadBlocks1) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
for (uint32_t block_id : {16u, 23u, 24u, 26u, 27u, 34u, 35u, 50u}) {
@ -2219,7 +2235,8 @@ TEST(TransformationOutlineFunctionTest, OutlineWithDeadBlocks1) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// All the original blocks, plus the new function entry block, should be dead.
for (uint32_t block_id : {16u, 23u, 24u, 26u, 27u, 34u, 35u, 50u, 203u}) {
ASSERT_TRUE(transformation_context.GetFactManager()->BlockIsDead(block_id));
@ -2277,9 +2294,9 @@ TEST(TransformationOutlineFunctionTest, OutlineWithDeadBlocks2) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
for (uint32_t block_id : {32u, 34u, 35u}) {
@ -2301,7 +2318,8 @@ TEST(TransformationOutlineFunctionTest, OutlineWithDeadBlocks2) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// The blocks that were originally dead, but not others, should be dead.
for (uint32_t block_id : {32u, 34u, 35u}) {
ASSERT_TRUE(transformation_context.GetFactManager()->BlockIsDead(block_id));
@ -2360,9 +2378,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactValueOfPointeeIsIrrelevant(9);
@ -2384,7 +2402,8 @@ TEST(TransformationOutlineFunctionTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// The variables that were originally irrelevant, plus input parameters
// corresponding to them, should be irrelevant. The rest should not be.
for (uint32_t variable_id : {9u, 14u, 206u, 208u}) {
@ -2434,9 +2453,9 @@ TEST(TransformationOutlineFunctionTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -2490,9 +2509,9 @@ TEST(TransformationOutlineFunctionTest, ExitBlockHeadsLoop) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -2671,7 +2690,8 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous1) {
{
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -2695,7 +2715,8 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous1) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
std::string variant_shader = R"(
OpCapability Shader
@ -2814,7 +2835,8 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous1) {
{
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
auto overflow_ids_unique_ptr = MakeUnique<CounterOverflowIdSource>(2000);
auto overflow_ids_ptr = overflow_ids_unique_ptr.get();
TransformationContext new_transformation_context(
@ -2829,7 +2851,8 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous1) {
ApplyAndCheckFreshIds(transformation_with_missing_input_and_output_ids,
context.get(), &new_transformation_context,
overflow_ids_ptr->GetIssuedOverflowIds());
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
std::string variant_shader = R"(
OpCapability Shader
@ -2977,9 +3000,9 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous2) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -3034,9 +3057,9 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous3) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -3054,7 +3077,8 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous3) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -3125,9 +3149,9 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous4) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationOutlineFunction transformation(
@ -3145,7 +3169,8 @@ TEST(TransformationOutlineFunctionTest, Miscellaneous4) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_permute_function_parameters.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -251,9 +253,9 @@ TEST(TransformationPermuteFunctionParametersTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Can't permute main function
@ -294,7 +296,8 @@ TEST(TransformationPermuteFunctionParametersTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationPermuteFunctionParameters transformation(28, 106, {1, 0});
@ -302,7 +305,8 @@ TEST(TransformationPermuteFunctionParametersTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationPermuteFunctionParameters transformation(200, 107, {1, 0});
@ -310,7 +314,8 @@ TEST(TransformationPermuteFunctionParametersTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationPermuteFunctionParameters transformation(219, 108, {1, 0});
@ -318,7 +323,8 @@ TEST(TransformationPermuteFunctionParametersTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationPermuteFunctionParameters transformation(229, 109, {1, 0});
@ -326,7 +332,8 @@ TEST(TransformationPermuteFunctionParametersTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_permute_phi_operands.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -66,9 +68,9 @@ TEST(TransformationPermutePhiOperandsTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Result id is invalid.

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_propagate_instruction_down.h"
#include "gtest/gtest.h"
#include "source/fuzz/counter_overflow_id_source.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -105,9 +107,9 @@ TEST(TransformationPropagateInstructionDownTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -177,7 +179,8 @@ TEST(TransformationPropagateInstructionDownTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(201, {}), MakeDataDescriptor(202, {})));
@ -335,9 +338,9 @@ TEST(TransformationPropagateInstructionDownTest, CantCreateOpPhiTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -365,7 +368,8 @@ TEST(TransformationPropagateInstructionDownTest, CantCreateOpPhiTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
// No transformation has introduced an OpPhi instruction.
@ -471,9 +475,9 @@ TEST(TransformationPropagateInstructionDownTest, VariablePointersCapability) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -485,7 +489,8 @@ TEST(TransformationPropagateInstructionDownTest, VariablePointersCapability) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(context->get_def_use_mgr()->GetDef(200));
}
{
@ -505,7 +510,8 @@ TEST(TransformationPropagateInstructionDownTest, VariablePointersCapability) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -582,9 +588,9 @@ TEST(TransformationPropagateInstructionDownTest, UseOverflowIdsTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options,
MakeUnique<CounterOverflowIdSource>(300));
@ -594,7 +600,8 @@ TEST(TransformationPropagateInstructionDownTest, UseOverflowIdsTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context,
{300});
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -671,9 +678,9 @@ TEST(TransformationPropagateInstructionDownTest, TestCreatedFacts) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -690,7 +697,8 @@ TEST(TransformationPropagateInstructionDownTest, TestCreatedFacts) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(201));
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(202));
@ -716,7 +724,8 @@ TEST(TransformationPropagateInstructionDownTest, TestCreatedFacts) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(203));
ASSERT_TRUE(transformation_context.GetFactManager()->IdIsIrrelevant(204));
@ -742,7 +751,8 @@ TEST(TransformationPropagateInstructionDownTest, TestCreatedFacts) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(206));
ASSERT_FALSE(transformation_context.GetFactManager()->IdIsIrrelevant(207));
@ -857,9 +867,9 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -870,7 +880,8 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops1) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
// Can't replace usage of %22 in %26.
@ -966,9 +977,9 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -980,7 +991,8 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops2) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
// Can propagate %201 from %20 into %21.
@ -990,7 +1002,8 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops2) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
// Can't propagate %24 from %21 into %20.
@ -1068,9 +1081,9 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops3) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -1083,7 +1096,8 @@ TEST(TransformationPropagateInstructionDownTest, TestLoops3) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_propagate_instruction_up.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -71,9 +73,9 @@ TEST(TransformationPropagateInstructionUpTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// |block_id| is invalid.
@ -114,7 +116,8 @@ TEST(TransformationPropagateInstructionUpTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
{
TransformationPropagateInstructionUp transformation(19, {{{5, 41}}});
@ -122,7 +125,8 @@ TEST(TransformationPropagateInstructionUpTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(
@ -183,7 +187,8 @@ TEST(TransformationPropagateInstructionUpTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
after_transformation = R"(
@ -246,7 +251,8 @@ TEST(TransformationPropagateInstructionUpTest, BasicTest) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
after_transformation = R"(
@ -357,9 +363,9 @@ TEST(TransformationPropagateInstructionUpTest, BlockDominatesPredecessor1) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationPropagateInstructionUp transformation(
@ -367,7 +373,8 @@ TEST(TransformationPropagateInstructionUpTest, BlockDominatesPredecessor1) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -474,9 +481,9 @@ TEST(TransformationPropagateInstructionUpTest, BlockDominatesPredecessor2) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationPropagateInstructionUp transformation(
@ -484,7 +491,8 @@ TEST(TransformationPropagateInstructionUpTest, BlockDominatesPredecessor2) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -587,9 +595,9 @@ TEST(TransformationPropagateInstructionUpTest, BlockDominatesPredecessor3) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationPropagateInstructionUp transformation(
@ -597,7 +605,8 @@ TEST(TransformationPropagateInstructionUpTest, BlockDominatesPredecessor3) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -680,9 +689,9 @@ TEST(TransformationPropagateInstructionUpTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Required capabilities haven't yet been specified.
@ -695,7 +704,8 @@ TEST(TransformationPropagateInstructionUpTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -759,9 +769,9 @@ TEST(TransformationPropagateInstructionUpTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Required capabilities haven't yet been specified
@ -774,7 +784,8 @@ TEST(TransformationPropagateInstructionUpTest,
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -838,16 +849,17 @@ TEST(TransformationPropagateInstructionUpTest, MultipleIdenticalPredecessors) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationPropagateInstructionUp transformation(9, {{{5, 40}}});
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_push_id_through_variable.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -100,7 +102,8 @@ TEST(TransformationPushIdThroughVariableTest, IsApplicable) {
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests the reference shader validity.
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Tests |value_synonym_id| and |variable_id| are fresh ids.
uint32_t value_id = 21;
@ -573,7 +576,8 @@ TEST(TransformationPushIdThroughVariableTest, AddSynonymsForRelevantIds) {
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests the reference shader validity.
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
uint32_t value_id = 21;
uint32_t value_synonym_id = 62;
@ -588,7 +592,8 @@ TEST(TransformationPushIdThroughVariableTest, AddSynonymsForRelevantIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(21, {}), MakeDataDescriptor(62, {})));
}
@ -672,7 +677,8 @@ TEST(TransformationPushIdThroughVariableTest, DontAddSynonymsForIrrelevantIds) {
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests the reference shader validity.
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(21);
@ -689,7 +695,8 @@ TEST(TransformationPushIdThroughVariableTest, DontAddSynonymsForIrrelevantIds) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(21, {}), MakeDataDescriptor(62, {})));
}
@ -735,7 +742,8 @@ TEST(TransformationPushIdThroughVariableTest, DontAddSynonymsInDeadBlocks) {
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests the reference shader validity.
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
transformation_context.GetFactManager()->AddFactBlockIsDead(15);
auto transformation = TransformationPushIdThroughVariable(
@ -744,7 +752,8 @@ TEST(TransformationPushIdThroughVariableTest, DontAddSynonymsInDeadBlocks) {
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_context.GetFactManager()->IsSynonymous(
MakeDataDescriptor(14, {}), MakeDataDescriptor(100, {})));
}

View File

@ -15,6 +15,8 @@
#include "source/fuzz/transformation_record_synonymous_constants.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -88,7 +90,8 @@ TEST(TransformationRecordSynonymousConstantsTest, IntConstants) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %3 is not a constant declaration
ASSERT_FALSE(TransformationRecordSynonymousConstants(3, 9).IsApplicable(
@ -196,7 +199,8 @@ TEST(TransformationRecordSynonymousConstantsTest, BoolConstants) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %9 and %11 are not equivalent
ASSERT_FALSE(TransformationRecordSynonymousConstants(9, 11).IsApplicable(
@ -287,7 +291,8 @@ TEST(TransformationRecordSynonymousConstantsTest, FloatConstants) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %9 and %13 are not equivalent
ASSERT_FALSE(TransformationRecordSynonymousConstants(9, 13).IsApplicable(
@ -392,7 +397,8 @@ TEST(TransformationRecordSynonymousConstantsTest,
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %25 and %27 are equivalent (25 is zero-like, 27 is null)
ASSERT_TRUE(TransformationRecordSynonymousConstants(25, 27).IsApplicable(
@ -528,7 +534,8 @@ TEST(TransformationRecordSynonymousConstantsTest, StructCompositeConstants) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %29 and %35 are not equivalent (they have different types)
ASSERT_FALSE(TransformationRecordSynonymousConstants(29, 35).IsApplicable(
@ -625,7 +632,8 @@ TEST(TransformationRecordSynonymousConstantsTest, ArrayCompositeConstants) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %25 and %31 are not equivalent (they have different types)
ASSERT_FALSE(TransformationRecordSynonymousConstants(25, 31).IsApplicable(
@ -715,7 +723,8 @@ TEST(TransformationRecordSynonymousConstantsTest, IntVectors) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %15 and %17 are not equivalent (having non-equivalent components)
ASSERT_FALSE(TransformationRecordSynonymousConstants(15, 17).IsApplicable(
@ -789,9 +798,9 @@ TEST(TransformationRecordSynonymousConstantsTest, FirstIrrelevantConstant) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(TransformationRecordSynonymousConstants(7, 8).IsApplicable(
@ -824,9 +833,9 @@ TEST(TransformationRecordSynonymousConstantsTest, SecondIrrelevantConstant) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(TransformationRecordSynonymousConstants(7, 8).IsApplicable(
@ -858,9 +867,9 @@ TEST(TransformationRecordSynonymousConstantsTest, InvalidIds) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationRecordSynonymousConstants(7, 8).IsApplicable(

View File

@ -14,6 +14,7 @@
#include "source/fuzz/transformation_replace_add_sub_mul_with_carrying_extended.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
@ -410,7 +411,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_2 =
TransformationReplaceAddSubMulWithCarryingExtended(81, 18);
@ -418,7 +420,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_3 =
TransformationReplaceAddSubMulWithCarryingExtended(82, 21);
@ -426,7 +429,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_4 =
TransformationReplaceAddSubMulWithCarryingExtended(83, 31);
@ -434,7 +438,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_4, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_5 =
TransformationReplaceAddSubMulWithCarryingExtended(84, 42);
@ -442,7 +447,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_5, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_6 =
TransformationReplaceAddSubMulWithCarryingExtended(85, 45);
@ -450,7 +456,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_6, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_7 =
TransformationReplaceAddSubMulWithCarryingExtended(86, 48);
@ -458,7 +465,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_7, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_8 =
TransformationReplaceAddSubMulWithCarryingExtended(87, 59);
@ -466,7 +474,8 @@ TEST(TransformationReplaceAddSubMulWithCarryingExtendedTest,
transformation_context));
ApplyAndCheckFreshIds(transformation_good_8, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,7 @@
#include "source/fuzz/transformation_replace_boolean_constant_with_constant_binary.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/id_use_descriptor.h"
#include "source/fuzz/instruction_descriptor.h"
@ -160,9 +161,9 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
std::vector<protobufs::IdUseDescriptor> uses_of_true = {
@ -292,22 +293,26 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
context.get(), transformation_context));
ApplyAndCheckFreshIds(replace_true_with_double_comparison, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(replace_true_with_uint32_comparison.IsApplicable(
context.get(), transformation_context));
ApplyAndCheckFreshIds(replace_true_with_uint32_comparison, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(replace_false_with_float_comparison.IsApplicable(
context.get(), transformation_context));
ApplyAndCheckFreshIds(replace_false_with_float_comparison, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(replace_false_with_sint64_comparison.IsApplicable(
context.get(), transformation_context));
ApplyAndCheckFreshIds(replace_false_with_sint64_comparison, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after = R"(
OpCapability Shader
@ -420,7 +425,8 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
context->module()->AddGlobalValue(MakeUnique<opt::Instruction>(
context.get(), SpvOpConstant, 6, 200, operands));
fuzzerutil::UpdateModuleIdBound(context.get(), 200);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
// The transformation is not applicable because %200 is NaN.
ASSERT_FALSE(TransformationReplaceBooleanConstantWithConstantBinary(
uses_of_true[0], 11, 200, SpvOpFOrdLessThan, 300)
@ -436,7 +442,8 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
context->module()->AddGlobalValue(MakeUnique<opt::Instruction>(
context.get(), SpvOpConstant, 6, 201, operands));
fuzzerutil::UpdateModuleIdBound(context.get(), 201);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
// Even though the double constant %11 is less than the infinity %201, the
// transformation is restricted to only apply to finite values.
ASSERT_FALSE(TransformationReplaceBooleanConstantWithConstantBinary(
@ -460,7 +467,8 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
context->module()->AddGlobalValue(MakeUnique<opt::Instruction>(
context.get(), SpvOpConstant, 12, 203, operands));
fuzzerutil::UpdateModuleIdBound(context.get(), 203);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
// Even though the negative infinity at %203 is less than the positive
// infinity %202, the transformation is restricted to only apply to finite
// values.
@ -533,9 +541,9 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto use_of_true_in_if = MakeIdUseDescriptor(
@ -551,12 +559,14 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
ASSERT_TRUE(
replacement_1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement_1, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(
replacement_2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement_2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after = R"(
OpCapability Shader
@ -647,9 +657,9 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest, OpPhi) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor = MakeInstructionDescriptor(14, SpvOpPhi, 0);
@ -692,7 +702,8 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest, OpPhi) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -724,9 +735,9 @@ TEST(TransformationReplaceBooleanConstantWithConstantBinaryTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_FALSE(TransformationReplaceBooleanConstantWithConstantBinary(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_branch_from_dead_block_with_exit.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -64,9 +66,9 @@ TEST(TransformationReplaceBranchFromDeadBlockWithExitTest, BasicTest) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -117,7 +119,8 @@ TEST(TransformationReplaceBranchFromDeadBlockWithExitTest, BasicTest) {
ASSERT_FALSE(
transformation2.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -265,9 +268,9 @@ TEST(TransformationReplaceBranchFromDeadBlockWithExitTest,
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -331,7 +334,8 @@ TEST(TransformationReplaceBranchFromDeadBlockWithExitTest,
ASSERT_FALSE(
transformation1.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -481,9 +485,9 @@ TEST(TransformationReplaceBranchFromDeadBlockWithExitTest, OpPhi) {
const auto env = SPV_ENV_UNIVERSAL_1_4;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
@ -508,7 +512,8 @@ TEST(TransformationReplaceBranchFromDeadBlockWithExitTest, OpPhi) {
ASSERT_FALSE(
transformation2.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_constant_with_uniform.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "source/fuzz/uniform_buffer_element_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -102,9 +104,9 @@ TEST(TransformationReplaceConstantWithUniformTest, BasicReplacements) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_a =
@ -187,7 +189,8 @@ TEST(TransformationReplaceConstantWithUniformTest, BasicReplacements) {
// Apply the use of 9 in a store.
ApplyAndCheckFreshIds(transformation_use_of_9_in_store, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_replacing_use_of_9_in_store = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -242,7 +245,8 @@ TEST(TransformationReplaceConstantWithUniformTest, BasicReplacements) {
// Apply the use of 11 in an add.
ApplyAndCheckFreshIds(transformation_use_of_11_in_add, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_replacing_use_of_11_in_add = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -299,7 +303,8 @@ TEST(TransformationReplaceConstantWithUniformTest, BasicReplacements) {
// Apply the use of 15 in an add.
ApplyAndCheckFreshIds(transformation_use_of_14_in_add, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_replacing_use_of_14_in_add = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
@ -465,9 +470,9 @@ TEST(TransformationReplaceConstantWithUniformTest, NestedStruct) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_1 =
@ -527,7 +532,8 @@ TEST(TransformationReplaceConstantWithUniformTest, NestedStruct) {
ApplyAndCheckFreshIds(transformation_use_of_13_in_store, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_use_of_13_in_store.IsApplicable(
context.get(), transformation_context));
ASSERT_TRUE(transformation_use_of_15_in_add.IsApplicable(
@ -539,7 +545,8 @@ TEST(TransformationReplaceConstantWithUniformTest, NestedStruct) {
ApplyAndCheckFreshIds(transformation_use_of_15_in_add, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_use_of_13_in_store.IsApplicable(
context.get(), transformation_context));
ASSERT_FALSE(transformation_use_of_15_in_add.IsApplicable(
@ -551,7 +558,8 @@ TEST(TransformationReplaceConstantWithUniformTest, NestedStruct) {
ApplyAndCheckFreshIds(transformation_use_of_17_in_add, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_use_of_13_in_store.IsApplicable(
context.get(), transformation_context));
ASSERT_FALSE(transformation_use_of_15_in_add.IsApplicable(
@ -563,7 +571,8 @@ TEST(TransformationReplaceConstantWithUniformTest, NestedStruct) {
ApplyAndCheckFreshIds(transformation_use_of_20_in_store, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_FALSE(transformation_use_of_13_in_store.IsApplicable(
context.get(), transformation_context));
ASSERT_FALSE(transformation_use_of_15_in_add.IsApplicable(
@ -706,9 +715,9 @@ TEST(TransformationReplaceConstantWithUniformTest, NoUniformIntPointerPresent) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_0 =
@ -781,9 +790,9 @@ TEST(TransformationReplaceConstantWithUniformTest, NoConstantPresentForIndex) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_0 =
@ -855,9 +864,9 @@ TEST(TransformationReplaceConstantWithUniformTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_3 =
@ -943,9 +952,9 @@ TEST(TransformationReplaceConstantWithUniformTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_9 =
@ -1158,9 +1167,9 @@ TEST(TransformationReplaceConstantWithUniformTest, ComplexReplacements) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
const float float_array_values[5] = {1.0, 1.5, 1.75, 1.875, 1.9375};
@ -1300,7 +1309,8 @@ TEST(TransformationReplaceConstantWithUniformTest, ComplexReplacements) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after = R"(
@ -1500,9 +1510,9 @@ TEST(TransformationReplaceConstantWithUniformTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
protobufs::UniformBufferElementDescriptor blockname_a =
@ -1558,9 +1568,9 @@ TEST(TransformationReplaceConstantWithUniformTest, ReplaceOpPhiOperand) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto int_descriptor = MakeUniformBufferElementDescriptor(0, 0, {0});
@ -1575,7 +1585,8 @@ TEST(TransformationReplaceConstantWithUniformTest, ReplaceOpPhiOperand) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(
context.get(), validator_options, kConsoleMessageConsumer));
}
std::string after_transformation = R"(

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_copy_memory_with_load_store.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -69,7 +71,8 @@ TEST(TransformationReplaceCopyMemoryWithLoadStoreTest, BasicScenarios) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto instruction_descriptor_invalid_1 =
MakeInstructionDescriptor(5, SpvOpStore, 0);
@ -96,7 +99,8 @@ TEST(TransformationReplaceCopyMemoryWithLoadStoreTest, BasicScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_valid_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_valid_2 = TransformationReplaceCopyMemoryWithLoadStore(
21, instruction_descriptor_valid_2);
@ -104,7 +108,8 @@ TEST(TransformationReplaceCopyMemoryWithLoadStoreTest, BasicScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_valid_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_copy_object_with_store_load.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -81,7 +83,8 @@ TEST(TransformationReplaceCopyObjectWithStoreLoad, BasicScenarios) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Invalid: fresh_variable_id=10 is not fresh.
auto transformation_invalid_1 = TransformationReplaceCopyObjectWithStoreLoad(
@ -127,7 +130,8 @@ TEST(TransformationReplaceCopyObjectWithStoreLoad, BasicScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_valid_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_valid_2 = TransformationReplaceCopyObjectWithStoreLoad(
28, 32, SpvStorageClassPrivate, 15);
@ -135,7 +139,8 @@ TEST(TransformationReplaceCopyObjectWithStoreLoad, BasicScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_valid_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -232,7 +237,8 @@ TEST(TransformationReplaceCopyObjectWithStoreLoad, IrrelevantIdsAndDeadBlocks) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
transformation_context.GetFactManager()->AddFactBlockIsDead(15);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(11);

View File

@ -14,7 +14,9 @@
#include "source/fuzz/transformation_replace_id_with_synonym.h"
#include "gtest/gtest.h"
#include "source/fuzz/data_descriptor.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/id_use_descriptor.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -218,9 +220,9 @@ TEST(TransformationReplaceIdWithSynonymTest, IllegalTransformations) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, kComplexShader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
SetUpIdSynonyms(transformation_context.GetFactManager());
@ -291,9 +293,9 @@ TEST(TransformationReplaceIdWithSynonymTest, LegalTransformations) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, kComplexShader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
SetUpIdSynonyms(transformation_context.GetFactManager());
@ -305,7 +307,8 @@ TEST(TransformationReplaceIdWithSynonymTest, LegalTransformations) {
transformation_context));
ApplyAndCheckFreshIds(global_constant_synonym, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto replace_vector_access_chain_index = TransformationReplaceIdWithSynonym(
MakeIdUseDescriptor(
@ -315,7 +318,8 @@ TEST(TransformationReplaceIdWithSynonymTest, LegalTransformations) {
context.get(), transformation_context));
ApplyAndCheckFreshIds(replace_vector_access_chain_index, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// This is an interesting case because it replaces something that is being
// copied with something that is already a synonym.
@ -327,7 +331,8 @@ TEST(TransformationReplaceIdWithSynonymTest, LegalTransformations) {
regular_replacement.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(regular_replacement, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto regular_replacement2 = TransformationReplaceIdWithSynonym(
MakeIdUseDescriptor(55, MakeInstructionDescriptor(203, SpvOpStore, 0), 0),
@ -336,14 +341,16 @@ TEST(TransformationReplaceIdWithSynonymTest, LegalTransformations) {
regular_replacement2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(regular_replacement2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto good_op_phi = TransformationReplaceIdWithSynonym(
MakeIdUseDescriptor(74, MakeInstructionDescriptor(86, SpvOpPhi, 0), 2),
205);
ASSERT_TRUE(good_op_phi.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(good_op_phi, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -515,9 +522,9 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfVariables) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->MaybeAddFact(
@ -532,7 +539,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfVariables) {
100);
ASSERT_TRUE(replacement1.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement1, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %8 with %101 in:
// OpStore %8 %11
@ -541,7 +549,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfVariables) {
101);
ASSERT_TRUE(replacement2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %8 with %101 in:
// %12 = OpLoad %6 %8
@ -550,7 +559,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfVariables) {
101);
ASSERT_TRUE(replacement3.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement3, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replace %10 with %100 in:
// OpStore %10 %12
@ -559,7 +569,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfVariables) {
100);
ASSERT_TRUE(replacement4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement4, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -647,9 +658,9 @@ TEST(TransformationReplaceIdWithSynonymTest,
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->MaybeAddFact(
@ -811,9 +822,9 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add synonym facts corresponding to the OpCopyObject operations that have
@ -886,7 +897,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
100);
ASSERT_TRUE(replacement4.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement4, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %52 = OpAccessChain %23 %50 %16 *%16*
// Corresponds to i[0].*f*
@ -917,7 +929,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
100);
ASSERT_TRUE(replacement7.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement7, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replacements of the form %21 -> %101
@ -951,7 +964,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement10.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement10, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %44 = OpAccessChain %23 %37 *%21* %21 %43
// Corresponds to h.*g*.b[0]
@ -993,7 +1007,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement14.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement14, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %53 = OpAccessChain %19 %50 %21 *%21* %16 %16
// Corresponds to i[1].*g*.a[0]
@ -1047,7 +1062,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement19.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement19, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %27 = OpAccessChain %26 %15 %17
// Corresponds to d.c
@ -1079,7 +1095,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement22.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement22, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// %58 = OpInBoundsAccessChain %26 %50 %57 %21 %17
// Corresponds to i[3].g.*c*
@ -1103,7 +1120,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement24.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement24, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replacements of the form %32 -> %106
@ -1117,7 +1135,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement25.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement25, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replacements of the form %43 -> %107
@ -1131,7 +1150,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement26.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement26, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replacements of the form %55 -> %108
@ -1145,7 +1165,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement27.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement27, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Replacements of the form %8 -> %109
@ -1159,7 +1180,8 @@ TEST(TransformationReplaceIdWithSynonymTest, SynonymsOfAccessChainIndices) {
ASSERT_TRUE(
replacement28.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement28, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -1310,9 +1332,9 @@ TEST(TransformationReplaceIdWithSynonymTest, RuntimeArrayTest) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add synonym fact relating %50 and %12.
@ -1346,7 +1368,8 @@ TEST(TransformationReplaceIdWithSynonymTest, RuntimeArrayTest) {
ASSERT_TRUE(replacement2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -1421,9 +1444,9 @@ TEST(TransformationReplaceIdWithSynonymTest,
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add synonym fact relating %100 and %9.
@ -1481,9 +1504,9 @@ TEST(TransformationReplaceIdWithSynonymTest, EquivalentIntegerConstants) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add synonym fact relating %10 and %13 (equivalent integer constant with
@ -1544,7 +1567,8 @@ TEST(TransformationReplaceIdWithSynonymTest, EquivalentIntegerConstants) {
13)
.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -1624,9 +1648,9 @@ TEST(TransformationReplaceIdWithSynonymTest, EquivalentIntegerVectorConstants) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Add synonym fact relating %10 and %13 (equivalent integer vectors with
@ -1662,7 +1686,8 @@ TEST(TransformationReplaceIdWithSynonymTest, EquivalentIntegerVectorConstants) {
ASSERT_TRUE(replacement2.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(replacement2, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
const std::string after_transformation = R"(
OpCapability Shader
@ -1728,9 +1753,9 @@ TEST(TransformationReplaceIdWithSynonymTest, IncompatibleTypes) {
const auto env = SPV_ENV_UNIVERSAL_1_3;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto* op_i_add = context->get_def_use_mgr()->GetDef(18);

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_irrelevant_id.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/id_use_descriptor.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -72,9 +74,9 @@ TEST(TransformationReplaceIrrelevantIdTest, Inapplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
SetUpIrrelevantIdFacts(transformation_context.GetFactManager());
@ -123,9 +125,9 @@ TEST(TransformationReplaceIrrelevantIdTest, Apply) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
SetUpIrrelevantIdFacts(transformation_context.GetFactManager());
@ -139,7 +141,8 @@ TEST(TransformationReplaceIrrelevantIdTest, Apply) {
transformation.IsApplicable(context.get(), transformation_context));
ApplyAndCheckFreshIds(transformation, context.get(), &transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader
@ -217,9 +220,9 @@ TEST(TransformationReplaceIrrelevantIdTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
transformation_context.GetFactManager()->AddFactIdIsIrrelevant(13);

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_linear_algebra_instruction.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -68,9 +70,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, IsApplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// Tests linear algebra instructions.
@ -241,9 +243,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, ReplaceOpTranspose) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -457,7 +459,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, ReplaceOpTranspose) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -497,9 +500,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -568,7 +571,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -667,9 +671,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -840,7 +844,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -953,9 +958,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -1173,7 +1178,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -1286,9 +1292,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -1504,7 +1510,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -1671,9 +1678,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -2045,7 +2052,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest,
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -2143,9 +2151,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, ReplaceOpOuterProduct) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor =
@ -2333,7 +2341,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, ReplaceOpOuterProduct) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}
@ -2379,9 +2388,9 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, ReplaceOpDot) {
const auto consumer = nullptr;
const auto context =
BuildModule(env, consumer, reference_shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto instruction_descriptor = MakeInstructionDescriptor(24, SpvOpDot, 0);
@ -2467,7 +2476,8 @@ TEST(TransformationReplaceLinearAlgebraInstructionTest, ReplaceOpDot) {
OpFunctionEnd
)";
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
ASSERT_TRUE(IsEqual(env, variant_shader, context.get()));
}

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_load_store_with_copy_memory.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "source/fuzz/instruction_descriptor.h"
#include "test/fuzz/fuzz_test_util.h"
@ -112,7 +114,8 @@ TEST(TransformationReplaceLoadStoreWithCopyMemoryTest, BasicScenarios) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto bad_instruction_descriptor_1 =
MakeInstructionDescriptor(11, SpvOpConstant, 0);
@ -184,7 +187,8 @@ TEST(TransformationReplaceLoadStoreWithCopyMemoryTest, BasicScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_1, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
auto transformation_good_2 = TransformationReplaceLoadStoreWithCopyMemory(
load_instruction_descriptor_3, store_instruction_descriptor_3);
@ -192,7 +196,8 @@ TEST(TransformationReplaceLoadStoreWithCopyMemoryTest, BasicScenarios) {
transformation_context));
ApplyAndCheckFreshIds(transformation_good_2, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader

View File

@ -14,6 +14,8 @@
#include "source/fuzz/transformation_replace_opphi_id_from_dead_predecessor.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -78,7 +80,8 @@ TEST(TransformationReplaceOpPhiIdFromDeadPredecessorTest, Inapplicable) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Record the fact that blocks 20, 17, 28 are dead.
transformation_context.GetFactManager()->AddFactBlockIsDead(20);
@ -119,7 +122,8 @@ TEST(TransformationReplaceOpPhiIdFromDeadPredecessorTest, Apply) {
spvtools::ValidatorOptions validator_options;
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
// Record the fact that blocks 20, 17, 28 are dead.
transformation_context.GetFactManager()->AddFactBlockIsDead(20);
@ -147,7 +151,8 @@ TEST(TransformationReplaceOpPhiIdFromDeadPredecessorTest, Apply) {
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformations = R"(
OpCapability Shader

View File

@ -14,8 +14,8 @@
#include "source/fuzz/transformation_replace_opselect_with_conditional_branch.h"
#include "source/fuzz/fuzzer_pass_replace_opselects_with_conditional_branches.h"
#include "source/fuzz/pseudo_random_generator.h"
#include "gtest/gtest.h"
#include "source/fuzz/fuzzer_util.h"
#include "test/fuzz/fuzz_test_util.h"
namespace spvtools {
@ -84,9 +84,9 @@ TEST(TransformationReplaceOpSelectWithConditionalBranchTest, Inapplicable) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
// %20 is not an OpSelect instruction.
@ -186,9 +186,9 @@ TEST(TransformationReplaceOpSelectWithConditionalBranchTest, Simple) {
const auto env = SPV_ENV_UNIVERSAL_1_5;
const auto consumer = nullptr;
const auto context = BuildModule(env, consumer, shader, kFuzzAssembleOption);
ASSERT_TRUE(IsValid(env, context.get()));
spvtools::ValidatorOptions validator_options;
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
auto transformation =
@ -211,7 +211,8 @@ TEST(TransformationReplaceOpSelectWithConditionalBranchTest, Simple) {
ApplyAndCheckFreshIds(transformation3, context.get(),
&transformation_context);
ASSERT_TRUE(IsValid(env, context.get()));
ASSERT_TRUE(fuzzerutil::IsValidAndWellFormed(context.get(), validator_options,
kConsoleMessageConsumer));
std::string after_transformation = R"(
OpCapability Shader

Some files were not shown because too many files have changed in this diff Show More