Skip to content

Commit

Permalink
Update version increment to wrap correctly. (#550)
Browse files Browse the repository at this point in the history
* Update version increment to wrap correctly.

* Tests for issue549

* Added note to explain HandleVersionWrapAround test.

* Fixed style tab->spaces
  • Loading branch information
ygottlieb-vencorelabs-com authored and antoninbas committed Mar 12, 2018
1 parent 30de761 commit bc88bdf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bm_sim/match_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,8 @@ MatchUnitGeneric<K, V>::delete_entry_(entry_handle_t handle) {
Entry &entry = entries[handle_];
if (HANDLE_VERSION(handle) != entry.key.version)
return MatchErrorCode::EXPIRED_HANDLE;
entry.key.version += 1;
entry.key.version = HANDLE_VERSION(HANDLE_SET((entry.key.version + 1),
handle_));
lookup_structure->delete_entry(entry.key);

return this->unset_handle(handle_);
Expand Down
17 changes: 17 additions & 0 deletions tests/test_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ TYPED_TEST(TableSizeTwo, DeleteEntryHandleUpdate) {
ASSERT_EQ(MatchErrorCode::EXPIRED_HANDLE, rc);
}

// This test was added for this issue:
// https://github.com/p4lang/behavioral-model/issues/549.
// Removing and entry increments the version field; the handle's version wraps
// around, but the entry's did not.
TYPED_TEST(TableSizeTwo, HandleVersionWrapAround) {
std::string key_ = "\xaa\xaa";
ByteContainer key("0xaaaa");
entry_handle_t handle;
MatchErrorCode rc;
for (unsigned int i = 0; i < 257; ++i) {
rc = this->add_entry(key_, &handle);
ASSERT_EQ(MatchErrorCode::SUCCESS, rc);
rc = this->table->delete_entry(handle);
ASSERT_EQ(MatchErrorCode::SUCCESS, rc);
}
}

TYPED_TEST(TableSizeTwo, LookupEntry) {
std::string key_ = "\x0a\xba";
ByteContainer key("0x0aba");
Expand Down

0 comments on commit bc88bdf

Please sign in to comment.