generate_memory_usage_report/gcc_map_reader BUG? #721
unit test showing the issue
This commit is contained in:
parent
6d55e0380e
commit
f1bb43abb5
|
@ -12,13 +12,14 @@ import java.util.regex.Pattern;
|
|||
* This is an utility to print the information from GCC linked .map file
|
||||
*
|
||||
* @author Andrey Belomutskiy
|
||||
* 10/16/13
|
||||
* 10/16/13
|
||||
*/
|
||||
public class GccMapReader {
|
||||
private static final Pattern p2 = Pattern.compile(".*0x(\\S*)(.*)");
|
||||
private static final Pattern MULTI_LINE_PATTERN = Pattern.compile(".*0x(\\S*)(.*)");
|
||||
private static final Pattern SINGLE_LINE_PATTERN = Pattern.compile(".*\\.bss\\.(\\S*).*0x.*0x(\\S*)(.*)");
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length!=1) {
|
||||
if (args.length != 1) {
|
||||
System.err.println("file name parameter expected");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
@ -26,7 +27,7 @@ public class GccMapReader {
|
|||
BufferedReader fr = new BufferedReader(new FileReader(fileName));
|
||||
|
||||
String line;
|
||||
List<String> lines = new ArrayList<String>();
|
||||
List<String> lines = new ArrayList<>();
|
||||
|
||||
while ((line = fr.readLine()) != null)
|
||||
lines.add(line);
|
||||
|
@ -35,12 +36,7 @@ public class GccMapReader {
|
|||
|
||||
List<Record> records = process(lines);
|
||||
|
||||
Collections.sort(records, new Comparator<Record>() {
|
||||
@Override
|
||||
public int compare(Record o1, Record o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
});
|
||||
Collections.sort(records, Comparator.reverseOrder());
|
||||
|
||||
int totalSize = 0;
|
||||
for (Record record : records) {
|
||||
|
@ -51,9 +47,7 @@ public class GccMapReader {
|
|||
System.out.println("Total size: " + totalSize);
|
||||
}
|
||||
|
||||
private static List<Record> process(List<String> lines) {
|
||||
Pattern p1 = Pattern.compile(".*\\.bss\\.(\\S*).*0x.*0x(\\S*)(.*)");
|
||||
|
||||
static List<Record> process(List<String> lines) {
|
||||
|
||||
List<Record> result = new ArrayList<Record>();
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
|
@ -62,7 +56,7 @@ public class GccMapReader {
|
|||
continue;
|
||||
debug(line);
|
||||
|
||||
Matcher m1 = p1.matcher(line);
|
||||
Matcher m1 = SINGLE_LINE_PATTERN.matcher(line);
|
||||
|
||||
if (m1.matches()) {
|
||||
parseSingleLine(result, line, m1, i);
|
||||
|
@ -78,7 +72,7 @@ public class GccMapReader {
|
|||
String suffix = line;
|
||||
line = lines.get(++lineIndex);
|
||||
|
||||
Matcher m2 = p2.matcher(line);
|
||||
Matcher m2 = MULTI_LINE_PATTERN.matcher(line);
|
||||
|
||||
if (!m2.matches()) {
|
||||
debug("Skipping " + line);
|
||||
|
@ -161,5 +155,13 @@ public class GccMapReader {
|
|||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,58 @@ package rusefi;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class GccMapReaderTest {
|
||||
@Test
|
||||
public void testMapFile() {
|
||||
public void testSingleLine() {
|
||||
List<GccMapReader.Record> r = GccMapReader.process(Collections.singletonList(" .bss.PWMD1 0x1fff9a0c 0x18 build_kinetis/obj/hal_pwm_lld.o"));
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x18, r.get(0).getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiLine() {
|
||||
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
|
||||
" .bss._ZL12turnOffEvent",
|
||||
"0x1fff9db8 0x60 build_kinetis/obj/aux_valves.o"));
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x60, r.get(0).getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThreeLine() {
|
||||
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
|
||||
" .bss.ch_idle_thread_wa",
|
||||
" 0x1fff8d10 0x610 build_kinetis/obj/chsys.o",
|
||||
" 0x1fff8d10 ch_idle_thread_wa"));
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x610, r.get(0).getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue() {
|
||||
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
|
||||
".bss 0x1fff8d10 0xf2e4 load address 0x0002b1bc",
|
||||
" 0x1fff8d10 . = ALIGN (0x4)",
|
||||
" 0x1fff8d10 _bss_start = .",
|
||||
" *(.bss)",
|
||||
" *(.bss.*)",
|
||||
" .bss.ch_idle_thread_wa",
|
||||
" 0x1fff8d10 0x610 build_kinetis/obj/chsys.o",
|
||||
" 0x1fff8d10 ch_idle_thread_wa",
|
||||
" .bss.ch 0x1fff9320 0x80 build_kinetis/obj/chschd.o",
|
||||
" 0x1fff9320 ch"));
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x80, r.get(0).getSize());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue