Add test for chm_only desugared jdk libs

Bug: 193010049
Change-Id: I4356e4d755dcb3c7ae76df3161f5110ac8b1bdf9
diff --git a/src/library_desugar/jdk11/chm_only_desugar_jdk_libs.json b/src/library_desugar/jdk11/chm_only_desugar_jdk_libs.json
new file mode 100644
index 0000000..ad27516
--- /dev/null
+++ b/src/library_desugar/jdk11/chm_only_desugar_jdk_libs.json
@@ -0,0 +1,39 @@
+{
+  "configuration_format_version": 3,
+  "group_id" : "com.tools.android",
+  "artifact_id" : "chm_only_desugar_jdk_libs",
+  "version": "1.0.12",
+  "required_compilation_api_level": 26,
+  "synthesized_library_classes_package_prefix": "j$.",
+  "support_all_callbacks_from_library": false,
+  "common_flags": [
+  ],
+  "library_flags": [
+    {
+      "api_level_below_or_equal": 23,
+      "rewrite_prefix": {
+        "java.util.concurrent.Helpers": "j$.util.concurrent.Helpers",
+        "java.util.concurrent.ThreadLocalRandom": "j$.util.concurrent.ThreadLocalRandom",
+        "java.util.concurrent.ConcurrentHashMap": "j$.util.concurrent.ConcurrentHashMap",
+        "sun.misc.Desugar": "j$.sun.misc.Desugar"
+      }
+    }
+  ],
+  "program_flags": [
+    {
+      "api_level_below_or_equal": 23,
+      "rewrite_prefix": {
+        "java.util.concurrent.ThreadLocalRandom": "j$.util.concurrent.ThreadLocalRandom",
+        "java.util.concurrent.ConcurrentHashMap": "j$.util.concurrent.ConcurrentHashMap"
+      }
+    }
+  ],
+  "shrinker_config": [
+    "-keepclassmembers class j$.util.concurrent.ConcurrentHashMap$TreeBin { int lockState; }",
+    "-keepclassmembers class j$.util.concurrent.ConcurrentHashMap { int sizeCtl; int transferIndex; long baseCount; int cellsBusy; }",
+    "-keepclassmembers class j$.util.concurrent.ConcurrentHashMap$CounterCell { long value; }",
+    "-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }",
+    "-keeppackagenames j$",
+    "-dontwarn sun.misc.Unsafe"
+  ]
+}
\ No newline at end of file
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 0a7edb3..f0d2830 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -197,6 +197,10 @@
     return Paths.get(getDesugarLibraryJsonDir(), "desugar_jdk_libs.json");
   }
 
+  public static Path getCHMOnlyDesugarLibJsonForTesting() {
+    return Paths.get(getDesugarLibraryJsonDir(), "chm_only_desugar_jdk_libs.json");
+  }
+
   public static Path getDesugarLibJsonForTestingAlternative3() {
     return Paths.get(getDesugarLibraryJsonDir(), "desugar_jdk_libs_alternative_3.json");
   }
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryCHMOnlyContentTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryCHMOnlyContentTest.java
new file mode 100644
index 0000000..dc995e3
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryCHMOnlyContentTest.java
@@ -0,0 +1,81 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.desugar.desugaredlibrary;
+
+import com.android.tools.r8.StringResource;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.ToolHelper;
+import com.android.tools.r8.ir.desugar.desugaredlibrary.DesugaredLibraryConfiguration;
+import com.android.tools.r8.ir.desugar.desugaredlibrary.DesugaredLibraryConfigurationParser;
+import com.android.tools.r8.utils.InternalOptions;
+import com.android.tools.r8.utils.codeinspector.CodeInspector;
+import java.nio.file.Path;
+import java.util.Collections;
+import org.junit.Assume;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class DesugaredLibraryCHMOnlyContentTest extends DesugaredLibraryTestBase {
+
+  private final TestParameters parameters;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withDexRuntimes().withAllApiLevels().build();
+  }
+
+  public DesugaredLibraryCHMOnlyContentTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testDesugaredLibraryContentCHMOnlyD8() throws Exception {
+    Assume.assumeTrue(requiresEmulatedInterfaceCoreLibDesugaring(parameters));
+    Assume.assumeTrue(isJDK11DesugaredLibrary());
+    Path desugaredLib =
+        buildDesugaredLibrary(
+            parameters.getApiLevel(),
+            "",
+            false,
+            Collections.emptyList(),
+            options -> {
+              options.desugaredLibraryConfiguration =
+                  chmOnlyConfiguration(options, true, parameters);
+            });
+    CodeInspector inspector = new CodeInspector(desugaredLib);
+    assert inspector.clazz("j$.util.concurrent.ConcurrentHashMap").isPresent();
+  }
+
+  @Test
+  public void testDesugaredLibraryContentCHMOnlyR8() throws Exception {
+    Assume.assumeTrue(requiresEmulatedInterfaceCoreLibDesugaring(parameters));
+    Assume.assumeTrue(isJDK11DesugaredLibrary());
+    Path desugaredLib =
+        buildDesugaredLibrary(
+            parameters.getApiLevel(),
+            "-keep class * { *; }",
+            true,
+            Collections.emptyList(),
+            options -> {
+              options.desugaredLibraryConfiguration =
+                  chmOnlyConfiguration(options, true, parameters);
+            });
+    CodeInspector inspector = new CodeInspector(desugaredLib);
+    assert inspector.clazz("j$.util.concurrent.ConcurrentHashMap").isPresent();
+  }
+
+  DesugaredLibraryConfiguration chmOnlyConfiguration(
+      InternalOptions options, boolean libraryCompilation, TestParameters parameters) {
+    return new DesugaredLibraryConfigurationParser(
+            options.dexItemFactory(),
+            options.reporter,
+            libraryCompilation,
+            parameters.getApiLevel().getLevel())
+        .parse(StringResource.fromFile(ToolHelper.getCHMOnlyDesugarLibJsonForTesting()));
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryContentTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryContentTest.java
index 02d036c..c7544d5 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryContentTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryContentTest.java
@@ -41,13 +41,22 @@
   }
 
   @Test
-  public void testDesugaredLibraryContent() throws Exception {
+  public void testDesugaredLibraryContentD8() throws Exception {
     Assume.assumeTrue(requiresAnyCoreLibDesugaring(parameters));
     CodeInspector inspector = new CodeInspector(buildDesugaredLibrary(parameters.getApiLevel()));
     assertCorrect(inspector);
   }
 
   @Test
+  public void testDesugaredLibraryContentR8() throws Exception {
+    Assume.assumeTrue(requiresAnyCoreLibDesugaring(parameters));
+    CodeInspector inspector =
+        new CodeInspector(
+            buildDesugaredLibrary(parameters.getApiLevel(), "-keep class * { *; }", true));
+    assertCorrect(inspector);
+  }
+
+  @Test
   public void testDesugaredLibraryContentWithCoreLambdaStubsAsProgram() throws Exception {
     Assume.assumeTrue(requiresAnyCoreLibDesugaring(parameters));
     ArrayList<Path> coreLambdaStubs = new ArrayList<>();