Ensure that pushed file are declared as dependencies

Test: unit tests
Bug: 223652676
Change-Id: Ibc397008b1b9b29fd8342efba67e1a71c84ddb6b
diff --git a/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java b/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java
index eba00b8..ced6aaf 100644
--- a/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java
+++ b/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java
@@ -37,7 +37,6 @@
 import org.junit.runners.JUnit4;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -90,15 +89,17 @@
                     if (prep instanceof FilePusher && ((FilePusher) prep).shouldAppendBitness()) {
                         for (File f : ((PushFilePreparer) prep).getPushSpecs(null).values()) {
                             String path = f.getPath();
-                            if (!new File(testcases, path + "32").exists()
-                                    || !new File(testcases, path + "64").exists()) {
+                            File file32 = FileUtil.findFile(config.getParentFile(), path + "32");
+                            File file64 = FileUtil.findFile(config.getParentFile(), path + "64");
+                            if (file32 == null || file64 == null) {
                                 // TODO: Enforce should abort on failure is True in CTS
                                 if (((FilePusher) prep).shouldAbortOnFailure()) {
                                     fail(
                                             String.format(
-                                                    "File %s[32/64] wasn't found in testcases/ while "
-                                                            + "it's expected to be pushed as part of "
-                                                            + "%s",
+                                                    "File %s[32/64] wasn't found in module "
+                                                            + "dependencies while "
+                                                            + "it's expected to be pushed as part"
+                                                            + " of %s.",
                                                     path, config.getName()));
                                 }
                             }
@@ -106,13 +107,15 @@
                     } else if (prep instanceof PushFilePreparer) {
                         for (File f : ((PushFilePreparer) prep).getPushSpecs(null).values()) {
                             String path = f.getPath();
-                            if (!new File(testcases, path).exists()) {
+                            File toBePushed = FileUtil.findFile(config.getParentFile(), path);
+                            if (toBePushed == null) {
                                 // TODO: Enforce should abort on failure is True in CTS
                                 if (((PushFilePreparer) prep).shouldAbortOnFailure()) {
                                     fail(
                                             String.format(
-                                                    "File %s wasn't found in testcases/ while it's "
-                                                            + "expected to be pushed as part of %s",
+                                                    "File %s wasn't found in module dependencies "
+                                                            + "while it's expected to be pushed "
+                                                            + "as part of %s.",
                                                     path, config.getName()));
                                 }
                             }
diff --git a/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java b/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java
index 02fb395..7b6e0d1 100644
--- a/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java
+++ b/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java
@@ -48,7 +48,6 @@
 import org.junit.runners.JUnit4;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
diff --git a/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java b/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
index c35afb3..94a65bf 100644
--- a/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
+++ b/tools/cts-tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
@@ -29,20 +29,17 @@
 import org.junit.runners.JUnit4;
 
 import java.io.File;
-import java.io.FilenameFilter;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
-import java.util.Set;
 
 /**
  * Tests to validate that the build is containing usable test artifact.