Merge "Update PageTypeInfoParser to be less restrictive."

This commit is contained in:
Tri Vo
2018-09-04 21:12:12 +00:00
committed by Gerrit Code Review
3 changed files with 6 additions and 11 deletions

View File

@@ -75,18 +75,13 @@ PageTypeInfoParser::Parse(const int in, const int out) const
} else return BAD_VALUE;
// expect part 2 starts with "type"
if (stripPrefix(&record[2], "type")) {
// expect the rest of part 2 has number of (pageBlockOrder + 2) parts
// An example looks like:
// header line: type 0 1 2 3 4 5 6 7 8 9 10
// record line: Unmovable 426 279 226 1 1 1 0 0 2 2 0
// The pageBlockOrder = 10 and it's zero-indexed. so total parts
// are 10 + 1(zero-indexed) + 1(the type part) = 12.
record_t pageCounts = parseRecord(record[2]);
int pageCountsSize = pageBlockOrder + 2;
if ((int)pageCounts.size() != pageCountsSize) return BAD_VALUE;
proto.write(PageTypeInfoProto::MigrateType::TYPE, pageCounts[0]);
for (auto i=1; i<pageCountsSize; i++) {
for (size_t i=1; i<pageCounts.size(); i++) {
proto.write(PageTypeInfoProto::MigrateType::FREE_PAGES_COUNT, toInt(pageCounts[i]));
}
} else return BAD_VALUE;
@@ -125,4 +120,4 @@ PageTypeInfoParser::Parse(const int in, const int out) const
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
return NO_ERROR;
}
}

View File

@@ -1,5 +1,5 @@
Page block order: 10
Pages per block: 1024
Page block order: 9
Pages per block: 512
Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10
Node 0, zone DMA, type Unmovable 426 279 226 1 1 1 0 0 2 2 0

View File

@@ -54,8 +54,8 @@ TEST_F(PageTypeInfoParserTest, Success) {
PageTypeInfoParser parser;
PageTypeInfoProto expected;
expected.set_page_block_order(10);
expected.set_pages_per_block(1024);
expected.set_page_block_order(9);
expected.set_pages_per_block(512);
PageTypeInfoProto::MigrateType* mt1 = expected.add_migrate_types();
mt1->set_node(0);