@@ -60,6 +60,7 @@ std::string GenerateModule(const std::string& src) {
60
60
%uint_4 = OpConstant %uint 4
61
61
%float_1 = OpConstant %float 1.0
62
62
%int8tensor = OpTypeTensorARM %int8 %uint_4
63
+ %int8r3tensor = OpTypeTensorARM %int8 %uint_3
63
64
%int32tensor = OpTypeTensorARM %int32 %uint_4
64
65
%int8tensor_array3 = OpTypeArray %int8tensor %uint_3
65
66
%int32tensor_array3 = OpTypeArray %int32tensor %uint_3
@@ -209,6 +210,61 @@ TEST_F(ValidateGraph, ValidGraphConstantOusideGraph) {
209
210
EXPECT_EQ (SPV_SUCCESS, ValidateInstructions (SPVENV));
210
211
}
211
212
213
+ TEST_F (ValidateGraph, ValidGraphWithNoInputsNoBody) {
214
+ const std::string src = R"(
215
+ %cst = OpGraphConstantARM %int8tensor 1
216
+ %graph_type = OpTypeGraphARM 0 %int8tensor
217
+ OpGraphEntryPointARM %graph "longname" %var_int8tensor
218
+ %graph = OpGraphARM %graph_type
219
+ OpGraphSetOutputARM %cst %uint_0
220
+ OpGraphEndARM
221
+ )" ;
222
+ std::string spvasm = GenerateModule (src);
223
+
224
+ CompileSuccessfully (spvasm, SPVENV);
225
+ EXPECT_EQ (SPV_SUCCESS, ValidateInstructions (SPVENV));
226
+ }
227
+
228
+ TEST_F (ValidateGraph, InvalidGraphWithDisallowedBodyInstructions) {
229
+ const std::string src = R"(
230
+ %graph_type = OpTypeGraphARM 1 %int8tensor %int8tensor
231
+ OpGraphEntryPointARM %graph "longname" %var_int8tensor %var_int8tensor
232
+ %graph = OpGraphARM %graph_type
233
+ %in = OpGraphInputARM %int8tensor %uint_0
234
+ %val = OpCompositeExtract %int8r3tensor %in 0
235
+ %out = OpCompositeInsert %int8tensor %val %in 0
236
+ OpGraphSetOutputARM %out %uint_0
237
+ OpGraphEndARM
238
+ )" ;
239
+ std::string spvasm = GenerateModule (src);
240
+
241
+ CompileSuccessfully (spvasm, SPVENV);
242
+ EXPECT_EQ (SPV_ERROR_INVALID_LAYOUT, ValidateInstructions (SPVENV));
243
+ EXPECT_THAT (
244
+ getDiagnosticString (),
245
+ HasSubstr (
246
+ " OpCompositeInsert cannot appear in the graph definitions section" ));
247
+ }
248
+
249
+ TEST_F (ValidateGraph, InvalidInstructionOutsideGraphAfterGraph) {
250
+ const std::string src = R"(
251
+ %graph_type = OpTypeGraphARM 1 %int8tensor %int8tensor
252
+ %cst = OpGraphConstantARM %int8tensor 1
253
+ OpGraphEntryPointARM %graph "longname" %var_int8tensor %var_int8tensor
254
+ %graph = OpGraphARM %graph_type
255
+ %in = OpGraphInputARM %int8tensor %uint_0
256
+ OpGraphSetOutputARM %in %uint_0
257
+ OpGraphEndARM
258
+ %val = OpCompositeExtract %int8r3tensor %cst 0
259
+ )" ;
260
+ std::string spvasm = GenerateModule (src);
261
+
262
+ CompileSuccessfully (spvasm, SPVENV);
263
+ EXPECT_EQ (SPV_ERROR_INVALID_LAYOUT, ValidateInstructions (SPVENV));
264
+ EXPECT_THAT (getDiagnosticString (),
265
+ HasSubstr (" OpCompositeExtract must appear in a graph body" ));
266
+ }
267
+
212
268
//
213
269
// Type tests
214
270
//
0 commit comments