@@ -1375,7 +1375,7 @@ the proper file in test/Dialect/SPIRV/.
1375
1375
1376
1376
The generated op will automatically gain the logic for (de)serialization.
1377
1377
However, tests still need to be coupled with the change to make sure no
1378
- surprises. Serialization tests live in test/Dialect/SPIRV/Serialization .
1378
+ surprises (see [ Add a new test] ( #add-a-new-test ) below) .
1379
1379
1380
1380
### Add a new enum
1381
1381
@@ -1416,6 +1416,40 @@ conversion][MlirDialectConversionSignatureConversion] might be needed as well.
1416
1416
operations contained within its region are valid operations in the SPIR-V
1417
1417
dialect.
1418
1418
1419
+ ### Add a new test
1420
+
1421
+ Currently the SPIR-V dialect has three types of tests that should be added or
1422
+ updated accordingly:
1423
+
1424
+ 1 . ** Dialect tests** - Those tests check different aspects of the op in isolation.
1425
+ They should include both positive and negative case, and exercise the verifier,
1426
+ parser and printer. Dialect tests do not have to form a valid SPIR-V code and
1427
+ should be kept as simple as possible. They are run with ` mlir-opt ` ; and are
1428
+ also used to test transformations.
1429
+
1430
+ 2 . ** Target tests** - Those tests are designed to exercise serialization and
1431
+ deserialization, so each module should be a valid SPIR-V module. (De)serialization
1432
+ is tested using the ` mlir-translate --test-spirv-roundtrip ` option.
1433
+
1434
+ To ensure that the SPIR-V MLIR forms and serializes into a valid SPIR-V, the
1435
+ ` spriv-val ` tool should be run on a serialized binary (` --serialize-spirv ` ).
1436
+ This can be automated by adding a conditional validation section to the test:
1437
+
1438
+ ```
1439
+ // RUN: %if spirv-tools %{ rm -rf %t %}
1440
+ // RUN: %if spirv-tools %{ mkdir %t %}
1441
+ // RUN: %if spirv-tools %{ mlir-translate --no-implicit-module --serialize-spirv --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s %}
1442
+ // RUN: %if spirv-tools %{ spirv-val %t %}
1443
+ ```
1444
+
1445
+ This sequence serializes and dumps each MLIR SPIR-V module into a separate
1446
+ SPIR-V binary (MLIR allows multiple modules per files, however the SPIR-V
1447
+ spec restricts each binary to a single module), and then runs `spirv-val`
1448
+ on each of the file.
1449
+
1450
+ 3. **Integration tests** - Those tests execute the MLIR code using the `mlir-runner`
1451
+ to verify its functional correctness.
1452
+
1419
1453
## Operation definitions
1420
1454
1421
1455
[include "Dialects/SPIRVOps.md"]
0 commit comments