am 9c1a21bc: am 8af013a3: am 77eb7290: am 72604e38: am bd914e49: am e78365c9: Try reading every file on /sys
# Via Android Git Automerger (5) and Nick Kralevich (1)
* commit '9c1a21bc73883475b8e739018b53d71fb1c74002':
Try reading every file on /sys
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 1b09fb2..0e94992 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -25,6 +25,7 @@
import java.io.File;
import java.io.FileFilter;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
@@ -517,6 +518,46 @@
writableDirs.isEmpty());
}
+ @LargeTest
+ public void testReadingSysFilesDoesntFail() throws Exception {
+ tryToReadFromAllIn(new File("/sys"));
+ }
+
+ private static void tryToReadFromAllIn(File dir) throws IOException {
+ assertTrue(dir.isDirectory());
+
+ if (isSymbolicLink(dir)) {
+ // don't examine symbolic links.
+ return;
+ }
+
+ File[] files = dir.listFiles();
+
+ if (files != null) {
+ for (File f : files) {
+ if (f.isDirectory()) {
+ tryToReadFromAllIn(f);
+ } else {
+ tryFileRead(f);
+ }
+ }
+ }
+ }
+
+ private static void tryFileRead(File f) {
+ byte[] b = new byte[1024];
+ try {
+ System.out.println("looking at " + f.getCanonicalPath());
+ FileInputStream fis = new FileInputStream(f);
+ while(fis.read(b) != -1) {
+ // throw away data
+ }
+ fis.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
private static final Set<File> SYS_EXCEPTIONS = new HashSet<File>(
Arrays.asList(
new File("/sys/kernel/debug/tracing/trace_marker")