Edit tests to reference temporary variables

The shader translator is intended to prune unreferenced variables in
the future. To maintain test coverage when this is done, most tests
that used to have unreferenced GLSL locals and globals are edited to
use built-ins or reference the necessary variables instead.

BUG=angleproject:2166
TEST=angle_unittests, angle_end2end_tests

Change-Id: I3964e7a80d52fc04a95f57e73da6095e433095e8
Reviewed-on: https://chromium-review.googlesource.com/768740
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/tests/compiler_tests/BufferVariables_test.cpp b/src/tests/compiler_tests/BufferVariables_test.cpp
index 319eab0..373ce6e 100644
--- a/src/tests/compiler_tests/BufferVariables_test.cpp
+++ b/src/tests/compiler_tests/BufferVariables_test.cpp
@@ -252,7 +252,7 @@
         "} instanceBuffer;\n"
         "void main()\n"
         "{\n"
-        "    float test = instanceBuffer.f;\n"
+        "    gl_Position.x = instanceBuffer.f;\n"
         "}\n";
     if (!compile(source))
     {
diff --git a/src/tests/compiler_tests/CollectVariables_test.cpp b/src/tests/compiler_tests/CollectVariables_test.cpp
index 3730962..1b42c9e 100644
--- a/src/tests/compiler_tests/CollectVariables_test.cpp
+++ b/src/tests/compiler_tests/CollectVariables_test.cpp
@@ -940,19 +940,23 @@
 TEST_F(CollectGeometryVariablesTest, CollectGLInFields)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "void main()\n"
-        "{\n"
-        "    vec4 value = gl_in[0].gl_Position;\n"
-        "    vec4 value2 = gl_in[0].gl_Position;\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+
+        layout (points) in;
+        layout (points, max_vertices = 2) out;
+
+        void main()
+        {
+            vec4 value = gl_in[0].gl_Position;
+            vec4 value2 = gl_in[0].gl_Position;
+            gl_Position = value + value2;
+            EmitVertex();
+        })";
 
     compile(shaderString);
 
-    EXPECT_TRUE(mTranslator->getOutputVaryings().empty());
+    EXPECT_EQ(1u, mTranslator->getOutputVaryings().size());
     EXPECT_TRUE(mTranslator->getInputVaryings().empty());
 
     const auto &inBlocks = mTranslator->getInBlocks();
@@ -985,10 +989,10 @@
     const GLuint kArraySizeForInputPrimitives[] = {1u, 2u, 4u, 3u, 6u};
 
     const std::string &functionBody =
-        "void main()\n"
-        "{\n"
-        "    vec4 value = gl_in[0].gl_Position;\n"
-        "}\n";
+        R"(void main()
+        {
+            gl_Position = gl_in[0].gl_Position;
+        })";
 
     for (size_t i = 0; i < kInputPrimitives.size(); ++i)
     {
@@ -1007,18 +1011,19 @@
 TEST_F(CollectGeometryVariablesTest, CollectPrimitiveIDIn)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "void main()\n"
-        "{\n"
-        "    int value = gl_PrimitiveIDIn;\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (points) in;
+        layout (points, max_vertices = 2) out;
+        void main()
+        {
+            gl_Position = vec4(gl_PrimitiveIDIn);
+            EmitVertex();
+        })";
 
     compile(shaderString);
 
-    ASSERT_TRUE(mTranslator->getOutputVaryings().empty());
+    EXPECT_EQ(1u, mTranslator->getOutputVaryings().size());
     ASSERT_TRUE(mTranslator->getInBlocks().empty());
 
     const auto &inputVaryings = mTranslator->getInputVaryings();
@@ -1038,18 +1043,19 @@
 TEST_F(CollectGeometryVariablesTest, CollectInvocationID)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points, invocations = 2) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "void main()\n"
-        "{\n"
-        "    int value = gl_InvocationID;\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (points, invocations = 2) in;
+        layout (points, max_vertices = 2) out;
+        void main()
+        {
+            gl_Position = vec4(gl_InvocationID);
+            EmitVertex();
+        })";
 
     compile(shaderString);
 
-    ASSERT_TRUE(mTranslator->getOutputVaryings().empty());
+    EXPECT_EQ(1u, mTranslator->getOutputVaryings().size());
     ASSERT_TRUE(mTranslator->getInBlocks().empty());
 
     const auto &inputVaryings = mTranslator->getInputVaryings();
@@ -1069,18 +1075,19 @@
 TEST_F(CollectGeometryVariablesTest, CollectGLInIndexedByExpression)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (triangles, invocations = 2) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "void main()\n"
-        "{\n"
-        "    vec4 value = gl_in[gl_InvocationID + 1].gl_Position;\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (triangles, invocations = 2) in;
+        layout (points, max_vertices = 2) out;
+        void main()
+        {
+            gl_Position = gl_in[gl_InvocationID + 1].gl_Position;
+            EmitVertex();
+        })";
 
     compile(shaderString);
 
-    ASSERT_TRUE(mTranslator->getOutputVaryings().empty());
+    EXPECT_EQ(1u, mTranslator->getOutputVaryings().size());
 
     const auto &inBlocks = mTranslator->getInBlocks();
     ASSERT_EQ(1u, inBlocks.size());
@@ -1191,12 +1198,15 @@
 TEST_F(CollectFragmentVariablesOESGeometryShaderTest, CollectPrimitiveID)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "void main()\n"
-        "{\n"
-        "    int value = gl_PrimitiveID;\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+
+        out int my_out;
+
+        void main()
+        {
+            my_out = gl_PrimitiveID;
+        })";
 
     compile(shaderString);
 
@@ -1219,12 +1229,15 @@
 TEST_F(CollectFragmentVariablesOESGeometryShaderTest, CollectLayer)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "void main()\n"
-        "{\n"
-        "    int value = gl_Layer;\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+
+        out int my_out;
+
+        void main()
+        {
+            my_out = gl_Layer;
+        })";
 
     compile(shaderString);
 
@@ -1300,21 +1313,22 @@
 TEST_F(CollectGeometryVariablesTest, CollectInputs)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "in vec4 texcoord1[];\n"
-        "in vec4 texcoord2[1];\n"
-        "void main()\n"
-        "{\n"
-        "    vec4 coord1 = texcoord1[0];\n"
-        "    vec4 coord2 = texcoord2[0];\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (points) in;
+        layout (points, max_vertices = 2) out;
+        in vec4 texcoord1[];
+        in vec4 texcoord2[1];
+        void main()
+        {
+            gl_Position = texcoord1[0];
+            gl_Position += texcoord2[0];
+            EmitVertex();
+        })";
 
     compile(shaderString);
 
-    ASSERT_TRUE(mTranslator->getOutputVaryings().empty());
+    EXPECT_EQ(1u, mTranslator->getOutputVaryings().size());
 
     const auto &inputVaryings = mTranslator->getInputVaryings();
     ASSERT_EQ(2u, inputVaryings.size());
@@ -1347,10 +1361,10 @@
 
     const std::string &kVariableDeclaration = "in vec4 texcoord[];\n";
     const std::string &kFunctionBody =
-        "void main()\n"
-        "{\n"
-        "    vec4 value = texcoord[0];\n"
-        "}\n";
+        R"(void main()
+        {
+            gl_Position = texcoord[0];
+        })";
 
     for (size_t i = 0; i < kInputPrimitives.size(); ++i)
     {
@@ -1382,10 +1396,11 @@
         {INTERPOLATION_FLAT, INTERPOLATION_SMOOTH, INTERPOLATION_CENTROID}};
 
     const std::string &kFunctionBody =
-        "void main()\n"
-        "{\n"
-        "    vec4 value = texcoord[0];\n"
-        "}\n";
+        R"(void main()
+        {
+            gl_Position = texcoord[0];
+            EmitVertex();
+        })";
 
     for (size_t i = 0; i < kInterpolationQualifiers.size(); ++i)
     {
diff --git a/src/tests/compiler_tests/EXT_YUV_target_test.cpp b/src/tests/compiler_tests/EXT_YUV_target_test.cpp
index 35557fd..6b247b1 100644
--- a/src/tests/compiler_tests/EXT_YUV_target_test.cpp
+++ b/src/tests/compiler_tests/EXT_YUV_target_test.cpp
@@ -99,28 +99,49 @@
 
 // Shader that specifies yuvCscStandartEXT type and associated values.
 const char ESSL300_YuvCscStandardEXTShader[] =
-    "precision mediump float;\n"
-    "yuvCscStandardEXT;\n"
-    "yuvCscStandardEXT conv;\n"
-    "yuvCscStandardEXT conv1 = itu_601;\n"
-    "yuvCscStandardEXT conv2 = itu_601_full_range;\n"
-    "yuvCscStandardEXT conv3 = itu_709;\n"
-    "const yuvCscStandardEXT conv4 = itu_709;\n"
-    "yuvCscStandardEXT conv_standard() {\n"
-    "    return itu_601;\n"
-    "}\n"
-    "bool is_itu_601(inout yuvCscStandardEXT csc) {\n"
-    "    csc = itu_601;\n"
-    "    return csc == itu_601;\n"
-    "}\n"
-    "bool is_itu_709(yuvCscStandardEXT csc) {\n"
-    "    return csc == itu_709;\n"
-    "}\n"
-    "void main() { \n"
-    "    yuvCscStandardEXT conv = conv_standard();\n"
-    "    bool csc_check1 = is_itu_601(conv);\n"
-    "    bool csc_check2 = is_itu_709(itu_709);\n"
-    "}\n";
+    R"(precision mediump float;
+    yuvCscStandardEXT;
+    yuvCscStandardEXT conv;
+    yuvCscStandardEXT conv1 = itu_601;
+    yuvCscStandardEXT conv2 = itu_601_full_range;
+    yuvCscStandardEXT conv3 = itu_709;
+    const yuvCscStandardEXT conv4 = itu_709;
+
+    uniform int u;
+    out vec4 my_color;
+
+    yuvCscStandardEXT conv_standard()
+    {
+        switch(u)
+        {
+            case 1:
+                return conv1;
+            case 2:
+                return conv2;
+            case 3:
+                return conv3;
+            default:
+                return conv;
+        }
+    }
+    bool is_itu_601(inout yuvCscStandardEXT csc)
+    {
+        csc = itu_601;
+        return csc == itu_601;
+    }
+    bool is_itu_709(yuvCscStandardEXT csc)
+    {
+        return csc == itu_709;
+    }
+    void main()
+    {
+        yuvCscStandardEXT conv = conv_standard();
+        bool csc_check1 = is_itu_601(conv);
+        bool csc_check2 = is_itu_709(itu_709);
+        if (csc_check1 && csc_check2) {
+            my_color = vec4(0, 1, 0, 1);
+        }
+    })";
 
 // Shader that specifies yuvCscStandartEXT type constructor fails to compile.
 const char ESSL300_YuvCscStandartdEXTConstructFailureShader1[] =
@@ -187,12 +208,17 @@
 
 // Shader that specifies yuv_to_rgb() and rgb_to_yuv() built-in functions.
 const char ESSL300_BuiltInFunctionsShader[] =
-    "precision mediump float;\n"
-    "yuvCscStandardEXT conv = itu_601;\n"
-    "void main() { \n"
-    "    vec3 yuv = rgb_2_yuv(vec3(0.0f), conv);\n"
-    "    vec3 rgb = yuv_2_rgb(yuv, itu_601);\n"
-    "}\n";
+    R"(precision mediump float;
+    yuvCscStandardEXT conv = itu_601;
+
+    out vec4 my_color;
+
+    void main()
+    {
+        vec3 yuv = rgb_2_yuv(vec3(0.0f), conv);
+        vec3 rgb = yuv_2_rgb(yuv, itu_601);
+        my_color = vec4(rgb, 1.0);
+    })";
 
 class EXTYUVTargetTest : public testing::TestWithParam<testing::tuple<const char *, const char *>>
 {
diff --git a/src/tests/compiler_tests/GeometryShader_test.cpp b/src/tests/compiler_tests/GeometryShader_test.cpp
index a5e8cbc..ad8512c 100644
--- a/src/tests/compiler_tests/GeometryShader_test.cpp
+++ b/src/tests/compiler_tests/GeometryShader_test.cpp
@@ -119,7 +119,6 @@
         out vec4 o_color;
         void main()
         {
-            int maxValue = gl_MaxGeometryInputComponents;
             for (int i = 0; i < i_color.length(); i++)
             {
                 gl_Position = gl_in[i].gl_Position;
@@ -995,14 +994,15 @@
 TEST_F(GeometryShaderTest, UseGLInLengthWithInputPrimitive)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "void main()\n"
-        "{\n"
-        "    int length = gl_in.length();\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (points) in;
+        layout (points, max_vertices = 2) out;
+        void main()
+        {
+            gl_Position = vec4(gl_in.length());
+            EmitVertex();
+        })";
 
     if (!compile(shaderString))
     {
@@ -1135,13 +1135,13 @@
 TEST_F(GeometryShaderTest, GeometryShaderBuiltInConstants)
 {
     const std::string &kShaderHeader =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points) in;\n"
-        "layout (points, max_vertices = 2) out;\n"
-        "void main()\n"
-        "{\n"
-        "    int val = ";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (points) in;
+        layout (points, max_vertices = 2) out;
+        void main()
+        {
+            gl_Position.x = float()";
 
     const std::array<std::string, 9> kGeometryShaderBuiltinConstants = {{
         "gl_MaxGeometryInputComponents", "gl_MaxGeometryOutputComponents",
@@ -1152,8 +1152,9 @@
     }};
 
     const std::string &kShaderTail =
-        ";\n"
-        "}\n";
+        R"();
+            EmitVertex();
+        })";
 
     for (const std::string &kGSBuiltinConstant : kGeometryShaderBuiltinConstants)
     {
@@ -1295,7 +1296,8 @@
         in vec4[] texcoord3, texcoord4;
         void main()
         {
-            vec4 coord = texcoord[0] + texcoord2[0] + texcoord3[0] + texcoord4[0];
+            gl_Position = texcoord[0] + texcoord2[0] + texcoord3[0] + texcoord4[0];
+            EmitVertex();
         })";
 
     if (!compile(shaderString))
@@ -1309,15 +1311,16 @@
 TEST_F(GeometryShaderTest, CallingLengthOnUnsizedInputDeclaredAfterInputPrimitive)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (points) in;\n"
-        "layout (points, max_vertices = 1) out;\n"
-        "in vec4 texcoord[];\n"
-        "void main()\n"
-        "{\n"
-        "    int length = texcoord.length();\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (points) in;
+        layout (points, max_vertices = 1) out;
+        in vec4 texcoord[];
+        void main()
+        {
+            gl_Position = vec4(texcoord.length());
+            EmitVertex();
+        })";
 
     if (!compile(shaderString))
     {
@@ -1349,18 +1352,19 @@
 TEST_F(GeometryShaderTest, InputWithLocations)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "layout (triangles) in;\n"
-        "layout (points, max_vertices = 1) out;\n"
-        "layout (location = 0) in vec4 texcoord1[];\n"
-        "layout (location = 1) in vec4 texcoord2[];\n"
-        "void main()\n"
-        "{\n"
-        "    int index = 0;\n"
-        "    vec4 coord1 = texcoord1[0];\n"
-        "    vec4 coord2 = texcoord2[index];\n"
-        "}\n";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        layout (triangles) in;
+        layout (points, max_vertices = 1) out;
+        layout (location = 0) in vec4 texcoord1[];
+        layout (location = 1) in vec4 texcoord2[];
+        void main()
+        {
+            int index = 0;
+            vec4 coord1 = texcoord1[0];
+            vec4 coord2 = texcoord2[index];
+            gl_Position = coord1 + coord2;
+        })";
 
     if (!compile(shaderString))
     {
diff --git a/src/tests/compiler_tests/Pack_Unpack_test.cpp b/src/tests/compiler_tests/Pack_Unpack_test.cpp
index 2f14380..bc87e95 100644
--- a/src/tests/compiler_tests/Pack_Unpack_test.cpp
+++ b/src/tests/compiler_tests/Pack_Unpack_test.cpp
@@ -27,14 +27,15 @@
 TEST_F(PackUnpackTest, PackSnorm2x16Emulation)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;"
-        "void main() {\n"
-        "   vec2 v;\n"
-        "   uint u = packSnorm2x16(v);\n"
-        "   fragColor = vec4(0.0);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main()
+        {
+           vec2 v;
+           uint u = packSnorm2x16(v);
+           fragColor = vec4(u);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("uint packSnorm2x16_emu(vec2 v)"));
 }
@@ -43,14 +44,15 @@
 TEST_F(PackUnpackTest, UnpackSnorm2x16Emulation)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;"
-        "void main() {\n"
-        "   uint u;\n"
-        "   vec2 v=unpackSnorm2x16(u);\n"
-        "   fragColor = vec4(0.0);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main()
+        {
+           uint u;
+           vec2 v = unpackSnorm2x16(u);
+           fragColor = vec4(v, 0.0, 0.0);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("vec2 unpackSnorm2x16_emu(uint u)"));
 }
@@ -59,14 +61,15 @@
 TEST_F(PackUnpackTest, PackUnorm2x16Emulation)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;"
-        "void main() {\n"
-        "   vec2 v;\n"
-        "   uint u = packUnorm2x16(v);\n"
-        "   fragColor = vec4(0.0);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main()
+        {
+           vec2 v;
+           uint u = packUnorm2x16(v);
+           fragColor = vec4(u);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("uint packUnorm2x16_emu(vec2 v)"));
 }
@@ -75,14 +78,15 @@
 TEST_F(PackUnpackTest, UnpackUnorm2x16Emulation)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;"
-        "void main() {\n"
-        "   uint u;\n"
-        "   vec2 v=unpackUnorm2x16(u);\n"
-        "   fragColor = vec4(0.0);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main()
+        {
+           uint u;
+           vec2 v = unpackUnorm2x16(u);
+           fragColor = vec4(v, 0.0, 0.0);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("vec2 unpackUnorm2x16_emu(uint u)"));
 }
@@ -91,14 +95,15 @@
 TEST_F(PackUnpackTest, PackHalf2x16Emulation)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;"
-        "void main() {\n"
-        "   vec2 v;\n"
-        "   uint u=packHalf2x16(v);\n"
-        "   fragColor = vec4(0.0);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main()
+        {
+            vec2 v;
+            uint u = packHalf2x16(v);
+            fragColor = vec4(u);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("uint packHalf2x16_emu(vec2 v)"));
 }
@@ -107,14 +112,15 @@
 TEST_F(PackUnpackTest, UnpackHalf2x16Emulation)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;"
-        "void main() {\n"
-        "   uint u;\n"
-        "   vec2 v=unpackHalf2x16(u);\n"
-        "   fragColor = vec4(0.0);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main()
+        {
+            uint u;
+            vec2 v = unpackHalf2x16(u);
+            fragColor = vec4(v, 0.0, 0.0);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("vec2 unpackHalf2x16_emu(uint u)"));
 }
diff --git a/src/tests/compiler_tests/PrunePureLiteralStatements_test.cpp b/src/tests/compiler_tests/PrunePureLiteralStatements_test.cpp
index d1a61cc..70a975f 100644
--- a/src/tests/compiler_tests/PrunePureLiteralStatements_test.cpp
+++ b/src/tests/compiler_tests/PrunePureLiteralStatements_test.cpp
@@ -27,12 +27,13 @@
 TEST_F(PrunePureLiteralStatementsTest, FloatLiteralStatement)
 {
     const std::string shaderString =
-        "precision mediump float;\n"
-        "void main()\n"
-        "{\n"
-        "   float f = 41.0;\n"
-        "   42.0;\n"
-        "}\n";
+        R"(precision mediump float;
+        void main()
+        {
+           float f = 41.0;
+           42.0;
+           gl_FragColor = vec4(f);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("41"));
     ASSERT_TRUE(notFoundInCode("42"));
@@ -42,12 +43,13 @@
 TEST_F(PrunePureLiteralStatementsTest, ConstructorLiteralStatement)
 {
     const std::string shaderString =
-        "precision mediump float;\n"
-        "void main()\n"
-        "{\n"
-        "   vec2 f = vec2(41.0, 41.0);\n"
-        "   vec2(42.0, 42.0);\n"
-        "}\n";
+        R"(precision mediump float;
+        void main()
+        {
+            vec2 f = vec2(41.0, 41.0);
+            vec2(42.0, 42.0);
+            gl_FragColor = vec4(f, 0.0, 0.0);
+        })";
     compile(shaderString);
     ASSERT_TRUE(foundInCode("41"));
     ASSERT_TRUE(notFoundInCode("42"));
diff --git a/src/tests/compiler_tests/ShaderValidation_test.cpp b/src/tests/compiler_tests/ShaderValidation_test.cpp
index 6760dc9..b581a40 100644
--- a/src/tests/compiler_tests/ShaderValidation_test.cpp
+++ b/src/tests/compiler_tests/ShaderValidation_test.cpp
@@ -2339,17 +2339,19 @@
 TEST_F(ComputeShaderValidationTest, CorrectUsageOfComputeBuiltins)
 {
     const std::string &shaderString =
-        "#version 310 es\n"
-        "layout(local_size_x = 12) in;\n"
-        "void main()\n"
-        "{\n"
-        "   uvec3 NumWorkGroups = gl_NumWorkGroups;\n"
-        "   uvec3 WorkGroupSize = gl_WorkGroupSize;\n"
-        "   uvec3 WorkGroupID = gl_WorkGroupID;\n"
-        "   uvec3 GlobalInvocationID = gl_GlobalInvocationID;\n"
-        "   uvec3 LocalInvocationID = gl_LocalInvocationID;\n"
-        "   uint LocalInvocationIndex = gl_LocalInvocationIndex;\n"
-        "}\n";
+        R"(#version 310 es
+        layout(local_size_x=4, local_size_y=3, local_size_z=2) in;
+        layout(rgba32ui) uniform highp writeonly uimage2D imageOut;
+        void main()
+        {
+            uvec3 temp1 = gl_NumWorkGroups;
+            uvec3 temp2 = gl_WorkGroupSize;
+            uvec3 temp3 = gl_WorkGroupID;
+            uvec3 temp4 = gl_LocalInvocationID;
+            uvec3 temp5 = gl_GlobalInvocationID;
+            uint  temp6 = gl_LocalInvocationIndex;
+            imageStore(imageOut, ivec2(0), uvec4(temp1 + temp2 + temp3 + temp4 + temp5, temp6));
+        })";
     if (!compile(shaderString))
     {
         FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
@@ -2589,11 +2591,12 @@
 TEST_F(FragmentShaderValidationTest, ShiftBy32)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "void main() {\n"
-        "   uint u = 1u << 32u;\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        out uint my_out;
+        void main() {
+           my_out = 1u << 32u;
+        })";
     if (compile(shaderString))
     {
         if (!hasWarning())
@@ -2614,11 +2617,12 @@
 TEST_F(FragmentShaderValidationTest, ShiftByNegative)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "void main() {\n"
-        "   uint u = 1u << (-1);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        out uint my_out;
+        void main() {
+           my_out = 1u << (-1);
+        })";
     if (compile(shaderString))
     {
         if (!hasWarning())
@@ -4017,12 +4021,15 @@
 TEST_F(FragmentShaderValidationTest, BufferAndSharedAsIdentifierOnES3)
 {
     const std::string &shaderString =
-        "#version 300 es\n"
-        "void main()\n"
-        "{\n"
-        "    int buffer;\n"
-        "    int shared;\n"
-        "}\n";
+        R"(#version 300 es
+        precision highp float;
+        out vec4 my_out;
+        void main()
+        {
+            int buffer = 1;
+            int shared = 2;
+            my_out = vec4(buffer + shared);
+        })";
 
     if (!compile(shaderString))
     {
@@ -4558,13 +4565,13 @@
 TEST_F(FragmentShaderOESGeometryShaderValidationTest, GeometryShaderBuiltInConstants)
 {
     const std::string &kShaderHeader =
-        "#version 310 es\n"
-        "#extension GL_OES_geometry_shader : require\n"
-        "precision mediump float;\n"
-        "layout(location = 0) out mediump vec4 fragColor;\n"
-        "void main(void)\n"
-        "{\n"
-        "    int val = ";
+        R"(#version 310 es
+        #extension GL_OES_geometry_shader : require
+        precision mediump float;
+        layout(location = 0) out mediump vec4 fragColor;
+        void main(void)
+        {
+            int val = )";
 
     const std::array<std::string, 9> kGeometryShaderBuiltinConstants = {{
         "gl_MaxGeometryInputComponents", "gl_MaxGeometryOutputComponents",
@@ -4575,9 +4582,9 @@
     }};
 
     const std::string &kShaderTail =
-        ";\n"
-        "    fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
-        "}\n";
+        R"(;
+            fragColor = vec4(val, 0, 0, 1);
+        })";
 
     for (const std::string &kGSBuiltinConstant : kGeometryShaderBuiltinConstants)
     {
diff --git a/src/tests/compiler_tests/ShaderVariable_test.cpp b/src/tests/compiler_tests/ShaderVariable_test.cpp
index 9389788..5a77ea2 100644
--- a/src/tests/compiler_tests/ShaderVariable_test.cpp
+++ b/src/tests/compiler_tests/ShaderVariable_test.cpp
@@ -254,18 +254,17 @@
                                               SH_GLSL_COMPATIBILITY_OUTPUT, &resources);
     EXPECT_NE(static_cast<ShHandle>(0), compiler);
 
-    const char *program1[] =
-    {
-        "void foo() {\n"
-        "  vec4 v;\n"
-        "}\n"
-        "varying vec4 v_varying;\n"
-        "invariant v_varying;\n"
-        "void main() {\n"
-        "  foo();\n"
-        "  gl_Position = v_varying;\n"
-        "}"
-    };
+    const char *program1[] = {
+        R"(void foo()
+        {
+        }
+        varying vec4 v_varying;
+        invariant v_varying;
+        void main()
+        {
+           foo();
+           gl_Position = v_varying;
+        })"};
     const char *program2[] =
     {
         "varying vec4 v_varying;\n"
diff --git a/src/tests/compiler_tests/TypeTracking_test.cpp b/src/tests/compiler_tests/TypeTracking_test.cpp
index 8e3f95f..b2913c6 100644
--- a/src/tests/compiler_tests/TypeTracking_test.cpp
+++ b/src/tests/compiler_tests/TypeTracking_test.cpp
@@ -387,7 +387,7 @@
         "void main() {\n"
         "   float fval2 = abs(fval1);\n"
         "   float fval3 = sign(fval1);\n"
-        "   gl_FragColor = vec4(fval1, 0.0, 0.0, 1.0); \n"
+        "   gl_FragColor = vec4(fval1, fval2, fval3, 1.0); \n"
         "}\n";
     compile(shaderString);
     ASSERT_FALSE(foundErrorInIntermediateTree());
@@ -406,7 +406,7 @@
         "void main() {\n"
         "   int ival2 = abs(ival1);\n"
         "   int ival3 = sign(ival1);\n"
-        "   my_FragColor = vec4(0.0, 0.0, 0.0, 1.0); \n"
+        "   my_FragColor = vec4(ival2, ival3, 0, 1); \n"
         "}\n";
     compile(shaderString);
     ASSERT_FALSE(foundErrorInIntermediateTree());
@@ -426,7 +426,7 @@
         "void main() {\n"
         "   int i = floatBitsToInt(f);\n"
         "   uint u = floatBitsToUint(f);\n"
-        "   my_FragColor = vec4(0.0, 0.0, 0.0, 1.0); \n"
+        "   my_FragColor = vec4(i, int(u), 0, 1); \n"
         "}\n";
     compile(shaderString);
     ASSERT_FALSE(foundErrorInIntermediateTree());
diff --git a/src/tests/gl_tests/ComputeShaderTest.cpp b/src/tests/gl_tests/ComputeShaderTest.cpp
index a8ba25f..9e1f4fb 100644
--- a/src/tests/gl_tests/ComputeShaderTest.cpp
+++ b/src/tests/gl_tests/ComputeShaderTest.cpp
@@ -64,26 +64,26 @@
 TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms)
 {
     const std::string csSource =
-        "#version 310 es\n"
-        "precision mediump sampler2D;\n"
-        "layout(local_size_x=1) in;\n"
-        "uniform int myUniformInt;\n"
-        "uniform sampler2D myUniformSampler;\n"
-        "void main()\n"
-        "{\n"
-        "int q = myUniformInt;\n"
-        "texture(myUniformSampler, vec2(0.0));\n"
-        "}\n";
+        R"(#version 310 es
+        precision mediump sampler2D;
+        layout(local_size_x=1) in;
+        uniform int myUniformInt;
+        uniform sampler2D myUniformSampler;
+        layout(rgba32i) uniform highp writeonly iimage2D imageOut;
+        void main()
+        {
+            int q = myUniformInt;
+            vec4 v = textureLod(myUniformSampler, vec2(0.0), 0.0);
+            imageStore(imageOut, ivec2(0), ivec4(v) * q);
+        })";
 
     ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
 
-    // It's not possible to validate uniforms are present since they are unreferenced.
-    // TODO(jmadill): Make uniforms referenced.
-    // GLint uniformLoc = glGetUniformLocation(program.get(), "myUniformInt");
-    // EXPECT_NE(-1, uniformLoc);
+    GLint uniformLoc = glGetUniformLocation(program.get(), "myUniformInt");
+    EXPECT_NE(-1, uniformLoc);
 
-    // uniformLoc = glGetUniformLocation(program.get(), "myUniformSampler");
-    // EXPECT_NE(-1, uniformLoc);
+    uniformLoc = glGetUniformLocation(program.get(), "myUniformSampler");
+    EXPECT_NE(-1, uniformLoc);
 
     EXPECT_GL_NO_ERROR();
 }
@@ -238,17 +238,19 @@
 TEST_P(ComputeShaderTest, AccessAllSpecialVariables)
 {
     const std::string csSource =
-        "#version 310 es\n"
-        "layout(local_size_x=4, local_size_y=3, local_size_z=2) in;\n"
-        "void main()\n"
-        "{\n"
-        "    uvec3 temp1 = gl_NumWorkGroups;\n"
-        "    uvec3 temp2 = gl_WorkGroupSize;\n"
-        "    uvec3 temp3 = gl_WorkGroupID;\n"
-        "    uvec3 temp4 = gl_LocalInvocationID;\n"
-        "    uvec3 temp5 = gl_GlobalInvocationID;\n"
-        "    uint  temp6 = gl_LocalInvocationIndex;\n"
-        "}\n";
+        R"(#version 310 es
+        layout(local_size_x=4, local_size_y=3, local_size_z=2) in;
+        layout(rgba32ui) uniform highp writeonly uimage2D imageOut;
+        void main()
+        {
+            uvec3 temp1 = gl_NumWorkGroups;
+            uvec3 temp2 = gl_WorkGroupSize;
+            uvec3 temp3 = gl_WorkGroupID;
+            uvec3 temp4 = gl_LocalInvocationID;
+            uvec3 temp5 = gl_GlobalInvocationID;
+            uint  temp6 = gl_LocalInvocationIndex;
+            imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), uvec4(temp1 + temp2 + temp3 + temp4 + temp5, temp6));
+        })";
 
     ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
 }
@@ -257,14 +259,16 @@
 TEST_P(ComputeShaderTest, AccessPartSpecialVariables)
 {
     const std::string csSource =
-        "#version 310 es\n"
-        "layout(local_size_x=4, local_size_y=3, local_size_z=2) in;\n"
-        "void main()\n"
-        "{\n"
-        "    uvec3 temp1 = gl_WorkGroupSize;\n"
-        "    uvec3 temp2 = gl_WorkGroupID;\n"
-        "    uint  temp3 = gl_LocalInvocationIndex;\n"
-        "}\n";
+        R"(#version 310 es
+        layout(local_size_x=4, local_size_y=3, local_size_z=2) in;
+        layout(rgba32ui) uniform highp writeonly uimage2D imageOut;
+        void main()
+        {
+            uvec3 temp1 = gl_WorkGroupSize;
+            uvec3 temp2 = gl_WorkGroupID;
+            uint  temp3 = gl_LocalInvocationIndex;
+            imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), uvec4(temp1 + temp2, temp3));
+        })";
 
     ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
 }
@@ -273,12 +277,14 @@
 TEST_P(ComputeShaderTest, DispatchCompute)
 {
     const std::string csSource =
-        "#version 310 es\n"
-        "layout(local_size_x=4, local_size_y=3, local_size_z=2) in;\n"
-        "void main()\n"
-        "{\n"
-        "    uvec3 temp = gl_NumWorkGroups;\n"
-        "}\n";
+        R"(#version 310 es
+        layout(local_size_x=4, local_size_y=3, local_size_z=2) in;
+        layout(rgba32ui) uniform highp writeonly uimage2D imageOut;
+        void main()
+        {
+            uvec3 temp = gl_NumWorkGroups;
+            imageStore(imageOut, ivec2(0), uvec4(temp, 0u));
+        })";
 
     ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
 
@@ -412,17 +418,19 @@
 TEST_P(ComputeShaderTest, ImageLoad)
 {
     const std::string csSource =
-        "#version 310 es\n"
-        "layout(local_size_x=8) in;\n"
-        "layout(rgba8) uniform highp readonly image2D mImage2DInput;\n"
-        "layout(rgba16i) uniform highp readonly iimageCube mImageCubeInput;\n"
-        "layout(rgba32ui) uniform highp readonly uimage3D mImage3DInput;\n"
-        "void main()\n"
-        "{\n"
-        "    vec4 result2d = imageLoad(mImage2DInput, ivec2(gl_LocalInvocationID.xy));\n"
-        "    ivec4 resultCube = imageLoad(mImageCubeInput, ivec3(gl_LocalInvocationID.xyz));\n"
-        "    uvec4 result3d = imageLoad(mImage3DInput, ivec3(gl_LocalInvocationID.xyz));\n"
-        "}\n";
+        R"(#version 310 es
+        layout(local_size_x=8) in;
+        layout(rgba8) uniform highp readonly image2D mImage2DInput;
+        layout(rgba16i) uniform highp readonly iimageCube mImageCubeInput;
+        layout(rgba32ui) uniform highp readonly uimage3D mImage3DInput;
+        layout(r32i) uniform highp writeonly iimage2D imageOut;
+        void main()
+        {
+            vec4 result2d = imageLoad(mImage2DInput, ivec2(gl_LocalInvocationID.xy));
+            ivec4 resultCube = imageLoad(mImageCubeInput, ivec3(gl_LocalInvocationID.xyz));
+            uvec4 result3d = imageLoad(mImage3DInput, ivec3(gl_LocalInvocationID.xyz));
+            imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), ivec4(result2d) + resultCube + ivec4(result3d));
+        })";
 
     ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
     EXPECT_GL_NO_ERROR();
@@ -452,17 +460,19 @@
 TEST_P(ComputeShaderTest, ImageSize)
 {
     const std::string csSource =
-        "#version 310 es\n"
-        "layout(local_size_x=8) in;\n"
-        "layout(rgba8) uniform highp readonly imageCube mImageCubeInput;\n"
-        "layout(r32i) uniform highp readonly iimage2D mImage2DInput;\n"
-        "layout(rgba16ui) uniform highp readonly uimage2DArray mImage2DArrayInput;\n"
-        "void main()\n"
-        "{\n"
-        "    ivec2 sizeCube = imageSize(mImageCubeInput);\n"
-        "    ivec2 size2D = imageSize(mImage2DInput);\n"
-        "    ivec3 size2DArray = imageSize(mImage2DArrayInput);\n"
-        "}\n";
+        R"(#version 310 es
+        layout(local_size_x=8) in;
+        layout(rgba8) uniform highp readonly imageCube mImageCubeInput;
+        layout(r32i) uniform highp readonly iimage2D mImage2DInput;
+        layout(rgba16ui) uniform highp readonly uimage2DArray mImage2DArrayInput;
+        layout(r32i) uniform highp writeonly iimage2D imageOut;
+        void main()
+        {
+            ivec2 sizeCube = imageSize(mImageCubeInput);
+            ivec2 size2D = imageSize(mImage2DInput);
+            ivec3 size2DArray = imageSize(mImage2DArrayInput);
+            imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), ivec4(sizeCube, size2D.x, size2DArray.x));
+        })";
 
     ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
     EXPECT_GL_NO_ERROR();
diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp
index 88db5bd..d130d63 100644
--- a/src/tests/gl_tests/GLSLTest.cpp
+++ b/src/tests/gl_tests/GLSLTest.cpp
@@ -2474,14 +2474,23 @@
 TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperator)
 {
     const std::string &fragmentShader =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "out vec4 color;\n"
-        "void main(void)\n"
-        "{\n"
-        " float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0);\n"
-        " color = vec4(b);\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        out vec4 color;
+
+        uniform float u;
+        float c = 0.0;
+        float sideEffect()
+        {
+            c = u;
+            return c;
+        }
+
+        void main(void)
+        {
+            float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : sideEffect()), a);
+            color = vec4(b + c);
+        })";
 
     ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
 }
@@ -2491,17 +2500,26 @@
 TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperatorInForLoop)
 {
     const std::string &fragmentShader =
-        "#version 300 es\n"
-        "precision mediump float;\n"
-        "out vec4 color;\n"
-        "void main(void)\n"
-        "{\n"
-        " for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0); a < 10.0; a++)\n"
-        " {\n"
-        "  b += 1.0;\n"
-        "  color = vec4(b);\n"
-        " }\n"
-        "}\n";
+        R"(#version 300 es
+        precision mediump float;
+        out vec4 color;
+
+        uniform float u;
+        float c = 0.0;
+        float sideEffect()
+        {
+            c = u;
+            return c;
+        }
+
+        void main(void)
+        {
+            for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : sideEffect()), a); a < 10.0; a++)
+            {
+                b += 1.0;
+                color = vec4(b);
+            }
+        })";
 
     ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
 }