From e4e902dcedd9aa65418b93899a49e36fbafb2531 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 7 Nov 2022 12:59:13 -0800 Subject: [PATCH] [flutter_tools] add compilation failure tests for new cases added in impellerc (#114757) --- .../shader_compiler_test.dart | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart b/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart index 3a950068b61a..3dd004c0bf85 100644 --- a/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart +++ b/packages/flutter_tools/test/integration.shard/shader_compiler_test.dart @@ -17,6 +17,26 @@ void main() { logger = BufferLogger.test(); }); + Future testCompileShader(String source) async { + final Directory tmpDir = globals.fs.systemTempDirectory.createTempSync( + 'shader_compiler_test.', + ); + final File file = tmpDir.childFile('test_shader.frag') + ..writeAsStringSync(source); + final ShaderCompiler shaderCompiler = ShaderCompiler( + processManager: globals.processManager, + logger: logger, + fileSystem: globals.fs, + artifacts: globals.artifacts!, + ); + await shaderCompiler.compileShader( + input: file, + outputPath: tmpDir.childFile('test_shader.frag.out').path, + target: ShaderTarget.sksl, + json: false, + ); + } + testUsingContext('impellerc .iplr output has correct permissions', () async { if (globals.platform.isWindows) { return; @@ -54,4 +74,66 @@ void main() { final int expectedMode = int.parse('644', radix: 8); expect(resultFile.statSync().mode & expectedMode, equals(expectedMode)); }); + + testUsingContext('Compilation error with in storage', () async { + const String kShaderWithInput = ''' +in float foo; + +out vec4 fragColor; + +void main() { + fragColor = vec4(1.0, 0.0, 0.0, 1.0); +} +'''; + + expect(() => testCompileShader(kShaderWithInput), throwsA(isA() + .having( + (ShaderCompilerException exception) => exception.message, + 'message', + contains('SkSL does not support inputs'), + ), + )); + }); + + testUsingContext('Compilation error with UBO', () async { + const String kShaderWithInput = ''' +uniform Data { + vec4 foo; +} data; + +out vec4 fragColor; + +void main() { + fragColor = data.foo; +} +'''; + + expect(() => testCompileShader(kShaderWithInput), throwsA(isA() + .having( + (ShaderCompilerException exception) => exception.message, + 'message', + contains('SkSL does not support UBOs or SSBOs'), + ), + )); + }); + + testUsingContext('Compilation error with texture arguments besides position or sampler', () async { + const String kShaderWithInput = ''' +uniform sampler2D tex; + +out vec4 fragColor; + +void main() { + fragColor = texture(tex, vec2(0.5, 0.3), 0.5); +} +'''; + + expect(() => testCompileShader(kShaderWithInput), throwsA(isA() + .having( + (ShaderCompilerException exception) => exception.message, + 'message', + contains('Only sampler and position arguments are supported in texture() calls'), + ), + )); + }); }