gn2bp: Change stem for test targets

* Stem should be the name of the target under GN build system as this is the one expected in the source code
as seen here https://source.chromium.org/chromium/chromium/src/+/main:components/cronet/android/test/javatests/src/org/chromium/net/CronetTestRule.java;l=244?q=loadLibrary%5C(%5C%22cronet_tests&ss=chromium%2Fchromium%2Fsrc

Test: None
Change-Id: I758b9b265d0187c93b4fc8ab48491cc5f7a5a750
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 7f13906..b5eae77 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -8293,6 +8293,7 @@
         "-Wl,-wrap,valloc",
         "-Wl,-wrap,vasprintf",
     ],
+    stem: "libcronet_unittests_android__library",
     target: {
         android_arm: {
             cflags: [
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 2760425..a0e719d 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -525,6 +525,12 @@
     else:
       self.shared_libs.add(lib)
 
+  def is_test(self):
+    if gn_utils.TESTING_SUFFIX in self.name:
+      name_without_prefix = self.name[:self.name.find(gn_utils.TESTING_SUFFIX)]
+      return any([name_without_prefix == label_to_module_name(target) for target in DEFAULT_TESTS])
+    return False
+
   def _output_field(self, output, name, sort=True):
     value = getattr(self, name)
     return write_blueprint_key_value(output, name, value, sort)
@@ -1474,6 +1480,11 @@
     # So setting the output name based on the output_name from the desc.json
     module.stem = 'lib' + target.output_name
 
+  if module.is_test():
+    # Tests output should be a shared library in the format of 'lib[module_name]'
+    module.stem = 'lib' + target.get_target_name()[
+                          :target.get_target_name().find(gn_utils.TESTING_SUFFIX)]
+
   # dep_name is an unmangled GN target name (e.g. //foo:bar(toolchain)).
   # Currently, only one module is generated from target even target has multiple toolchains.
   # And module is generated based on the first visited target.
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index bda2754..09a7b80 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -268,6 +268,9 @@
                   'inputs', 'outputs', 'args', 'script', 'response_file_contents', 'ldflags'):
         self._finalize_attribute(key)
 
+    def get_target_name(self):
+      return self.name[self.name.find(":") + 1:]
+
 
   def __init__(self, builtin_deps):
     self.builtin_deps = builtin_deps