Skip to content

Commit c606723

Browse files
committed
Remove file based memory reading test
1 parent 8a8e8ed commit c606723

File tree

2 files changed

+1
-89
lines changed

2 files changed

+1
-89
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeMetadataManager.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
import com.google.firebase.perf.util.StorageUnit;
2323
import com.google.firebase.perf.util.Utils;
2424
import com.google.firebase.perf.v1.GaugeMetadata;
25-
import java.io.BufferedReader;
26-
import java.io.FileReader;
27-
import java.io.IOException;
28-
import java.util.regex.Matcher;
29-
import java.util.regex.Pattern;
3025

3126
/**
3227
* The {@code GaugeMetadataManager} class is responsible for collecting {@link GaugeMetadata}
@@ -73,23 +68,4 @@ public int getMaxEncouragedAppJavaHeapMemoryKb() {
7368
public int getDeviceRamSizeKb() {
7469
return Utils.saturatedIntCast(StorageUnit.BYTES.toKilobytes(memoryInfo.totalMem));
7570
}
76-
77-
/** Returns the total ram size of the device (in kilobytes) by reading the "proc/meminfo" file. */
78-
@VisibleForTesting
79-
int readTotalRAM(String procFileName) {
80-
try (BufferedReader br = new BufferedReader(new FileReader(procFileName))) {
81-
for (String s = br.readLine(); s != null; s = br.readLine()) {
82-
if (s.startsWith("MemTotal")) {
83-
Matcher m = Pattern.compile("\\d+").matcher(s);
84-
return m.find() ? Integer.parseInt(m.group()) : 0;
85-
}
86-
}
87-
} catch (IOException ioe) {
88-
logger.warn("Unable to read '" + procFileName + "' file: " + ioe.getMessage());
89-
} catch (NumberFormatException nfe) {
90-
logger.warn("Unable to parse '" + procFileName + "' file: " + nfe.getMessage());
91-
}
92-
93-
return 0;
94-
}
9571
}

firebase-perf/src/test/java/com/google/firebase/perf/session/gauges/GaugeMetadataManagerTest.java

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,20 @@
1515
package com.google.firebase.perf.session.gauges;
1616

1717
import static com.google.common.truth.Truth.assertThat;
18-
import static java.nio.charset.StandardCharsets.UTF_8;
1918
import static org.mockito.MockitoAnnotations.initMocks;
2019
import static org.robolectric.Shadows.shadowOf;
2120

2221
import android.app.ActivityManager;
2322
import android.content.Context;
24-
import android.os.Environment;
2523
import androidx.test.core.app.ApplicationProvider;
2624
import com.google.firebase.perf.FirebasePerformanceTestBase;
2725
import com.google.firebase.perf.util.StorageUnit;
28-
import java.io.File;
2926
import java.io.IOException;
30-
import java.io.Writer;
31-
import java.nio.file.Files;
3227
import org.junit.Before;
3328
import org.junit.Test;
3429
import org.junit.runner.RunWith;
3530
import org.mockito.Mock;
3631
import org.robolectric.RobolectricTestRunner;
37-
import org.robolectric.shadows.ShadowEnvironment;
3832

3933
/** Unit tests for {@link com.google.firebase.perf.session.gauges.GaugeMetadataManager} */
4034
@RunWith(RobolectricTestRunner.class)
@@ -49,12 +43,11 @@ public class GaugeMetadataManagerTest extends FirebasePerformanceTestBase {
4943

5044
@Mock private Runtime runtime;
5145
private ActivityManager activityManager;
52-
private Context appContext;
5346

5447
@Before
5548
public void setUp() {
5649
initMocks(this);
57-
appContext = ApplicationProvider.getApplicationContext();
50+
Context appContext = ApplicationProvider.getApplicationContext();
5851
activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
5952

6053
mockMemory();
@@ -90,62 +83,5 @@ public void testGetDeviceRamSize_returnsExpectedValue() throws IOException {
9083
int ramSize = testGaugeMetadataManager.getDeviceRamSizeKb();
9184

9285
assertThat(ramSize).isEqualTo(StorageUnit.BYTES.toKilobytes(DEVICE_RAM_SIZE_BYTES));
93-
assertThat(ramSize).isEqualTo(testGaugeMetadataManager.readTotalRAM(createFakeMemInfoFile()));
9486
}
95-
96-
/** @return The file path of this fake file which can be used to read the file. */
97-
private String createFakeMemInfoFile() throws IOException {
98-
// Due to file permission issues on forge, it's easiest to just write this file to the emulated
99-
// robolectric external storage.
100-
ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED);
101-
102-
File file = new File(Environment.getExternalStorageDirectory(), "FakeProcMemInfoFile");
103-
Writer fileWriter;
104-
105-
fileWriter = Files.newBufferedWriter(file.toPath(), UTF_8);
106-
fileWriter.write(MEM_INFO_CONTENTS);
107-
fileWriter.close();
108-
109-
return file.getAbsolutePath();
110-
}
111-
112-
private static final String MEM_INFO_CONTENTS =
113-
"MemTotal: "
114-
+ DEVICE_RAM_SIZE_KB
115-
+ " kB\n"
116-
+ "MemFree: 542404 kB\n"
117-
+ "MemAvailable: 1392324 kB\n"
118-
+ "Buffers: 64292 kB\n"
119-
+ "Cached: 826180 kB\n"
120-
+ "SwapCached: 4196 kB\n"
121-
+ "Active: 934768 kB\n"
122-
+ "Inactive: 743812 kB\n"
123-
+ "Active(anon): 582132 kB\n"
124-
+ "Inactive(anon): 241500 kB\n"
125-
+ "Active(file): 352636 kB\n"
126-
+ "Inactive(file): 502312 kB\n"
127-
+ "Unevictable: 5148 kB\n"
128-
+ "Mlocked: 256 kB\n"
129-
+ "SwapTotal: 524284 kB\n"
130-
+ "SwapFree: 484800 kB\n"
131-
+ "Dirty: 4 kB\n"
132-
+ "Writeback: 0 kB\n"
133-
+ "AnonPages: 789404 kB\n"
134-
+ "Mapped: 241928 kB\n"
135-
+ "Shmem: 30632 kB\n"
136-
+ "Slab: 122320 kB\n"
137-
+ "SReclaimable: 42552 kB\n"
138-
+ "SUnreclaim: 79768 kB\n"
139-
+ "KernelStack: 22816 kB\n"
140-
+ "PageTables: 35344 kB\n"
141-
+ "NFS_Unstable: 0 kB\n"
142-
+ "Bounce: 0 kB\n"
143-
+ "WritebackTmp: 0 kB\n"
144-
+ "CommitLimit: 2042280 kB\n"
145-
+ "Committed_AS: 76623352 kB\n"
146-
+ "VmallocTotal: 251658176 kB\n"
147-
+ "VmallocUsed: 232060 kB\n"
148-
+ "VmallocChunk: 251347444 kB\n"
149-
+ "NvMapMemFree: 48640 kB\n"
150-
+ "NvMapMemUsed: 471460 kB\n";
15187
}

0 commit comments

Comments
 (0)