Fix runtest --path for package-private frameworks tests.

A recent change to runtest resulted in absolute paths incorrectly
being used for a tests build path. This broke the special logic
for frameworks/base tests, since it assumed relative build paths.
Change build paths back to relative paths.

Bug 5105885

Change-Id: I83a26be25294d501cca73eb1b88a7364131b2caf
diff --git a/testrunner/test_defs/gtest.py b/testrunner/test_defs/gtest.py
index 7de674b..094ceea 100644
--- a/testrunner/test_defs/gtest.py
+++ b/testrunner/test_defs/gtest.py
@@ -59,9 +59,9 @@
 
 class GTestFactory(test_suite.AbstractTestFactory):
 
-  def __init__(self, test_root_path, upstream_build_path=None):
+  def __init__(self, test_root_path, build_path):
     test_suite.AbstractTestFactory.__init__(self, test_root_path,
-        upstream_build_path=upstream_build_path)
+        build_path)
 
   def CreateTests(self, sub_tests_path=None):
     """Create tests found in sub_tests_path.
diff --git a/testrunner/test_defs/instrumentation_test.py b/testrunner/test_defs/instrumentation_test.py
index 6f82456..ede7ceb 100644
--- a/testrunner/test_defs/instrumentation_test.py
+++ b/testrunner/test_defs/instrumentation_test.py
@@ -213,9 +213,9 @@
 class InstrumentationTestFactory(test_suite.AbstractTestFactory):
   """A factory for creating InstrumentationTestSuites"""
 
-  def __init__(self, test_root_path, upstream_build_path=None):
+  def __init__(self, test_root_path, build_path):
     test_suite.AbstractTestFactory.__init__(self, test_root_path,
-                                            upstream_build_path=upstream_build_path)
+                                            build_path)
 
   def CreateTests(self, sub_tests_path=None):
     """Create tests found in test_path.
diff --git a/testrunner/test_defs/test_suite.py b/testrunner/test_defs/test_suite.py
index 20f9629..d0bd9ee 100644
--- a/testrunner/test_defs/test_suite.py
+++ b/testrunner/test_defs/test_suite.py
@@ -109,19 +109,16 @@
 class AbstractTestFactory(object):
   """generic test suite factory."""
 
-  def __init__(self, test_root_path, upstream_build_path=None):
+  def __init__(self, test_root_path, build_path):
     """Creates a test suite factory.
 
     Args:
       test_root_path: the filesystem path to the tests build directory
-      upstream_build_path: optional filesystem path for the directory
-      to build when running tests. If unspecified, will use test_root_path
+      upstream_build_path: filesystem path for the directory
+      to build when running tests, relative to the source tree root.
     """
     self._test_root_path = test_root_path
-    if upstream_build_path:
-      self._build_path = upstream_build_path
-    else:
-      self._build_path = self._test_root_path
+    self._build_path = build_path
 
   def GetBuildPath(self):
     return self._build_path
diff --git a/testrunner/test_defs/test_walker.py b/testrunner/test_defs/test_walker.py
index 2989125..572f8b6 100755
--- a/testrunner/test_defs/test_walker.py
+++ b/testrunner/test_defs/test_walker.py
@@ -132,11 +132,12 @@
       return tests
     android_mk_parser = android_mk.CreateAndroidMK(path)
     if android_mk_parser:
+      build_rel_path = self._MakePathRelativeToBuild(path)
       if not upstream_build_path:
         # haven't found a parent makefile which builds this dir. Use current
         # dir as build path
         tests.extend(self._CreateSuites(
-            android_mk_parser, path, self._MakePathRelativeToBuild(path)))
+            android_mk_parser, path, build_rel_path))
       else:
         tests.extend(self._CreateSuites(android_mk_parser, path,
                                         upstream_build_path))
@@ -174,7 +175,7 @@
     else:
       return []
 
-  def _GetTestFactory(self, android_mk_parser, path, upstream_build_path=None):
+  def _GetTestFactory(self, android_mk_parser, path, build_path):
     """Get the test factory for given makefile.
 
     If given path is a valid tests build path, will return the TestFactory
@@ -183,17 +184,17 @@
     Args:
       android_mk_parser: the android mk to evaluate
       path: the filesystem path of the makefile
-      upstream_build_path: optional filesystem path for the directory
-      to build when running tests. If unspecified, will use path
+      build_path: filesystem path for the directory
+      to build when running tests, relative to source root.
 
     Returns:
       the TestFactory or None if path is not a valid tests build path
     """
     if android_mk_parser.HasGTest():
-      return gtest.GTestFactory(path, upstream_build_path=upstream_build_path)
+      return gtest.GTestFactory(path, build_path)
     elif instrumentation_test.HasInstrumentationTest(path):
       return instrumentation_test.InstrumentationTestFactory(path,
-          upstream_build_path=upstream_build_path)
+          build_path)
     else:
       # somewhat unusual, but will continue searching
       logger.SilentLog('Found makefile at %s, but did not detect any tests.'
@@ -215,7 +216,8 @@
     """
     android_mk_parser = android_mk.CreateAndroidMK(path)
     if android_mk_parser:
-      return self._GetTestFactory(android_mk_parser, path)
+      build_path = self._MakePathRelativeToBuild(path)
+      return self._GetTestFactory(android_mk_parser, path, build_path)
     else:
       return None
 
@@ -251,7 +253,7 @@
       the list of tests created
     """
     factory = self._GetTestFactory(android_mk_parser, path,
-                                   upstream_build_path=upstream_build_path)
+                                   build_path=upstream_build_path)
     if factory:
       return factory.CreateTests(path)
     else: