Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringEnumColumn testing #2780

Merged
merged 11 commits into from
Sep 18, 2017
Merged

StringEnumColumn testing #2780

merged 11 commits into from
Sep 18, 2017

Conversation

ironage
Copy link
Contributor

@ironage ironage commented Aug 1, 2017

There was one bug introduced when the swap_row instruction was implemented: StringEnumColumn was forgotten so the default Column implementation is called. What ends up happening is we set a StringData payload into an IntegerColumn type bp-tree. The fix is simply implementing StringEnumColumn::swap_rows() just like StringColumn does it. This fixes #2766 (and adds the test there).

The rest of the changes increase coverage of the StringEnumColumn type by making use of the TEST_TYPES macro and some custom test structs implemented in test/test_string_types.hpp. I found that I couldn't see the test headers in the generated Xcode project, so I added them to the project via the CMakeLists.txt config.

The increased number of tests increased the test time too much, so I reduced the number of iterations in the biggest offender StringIndex_Insensitive_Fuzz.

Before:

Success: All 1114 tests passed (18058128 checks).
Test time: 1m8s
Top 5 time usage:
-----------------------------------------------------------------------------
StringIndex_Insensitive_Fuzz<std::__1::integral_constant<bool,+true>>   7.28s
StringIndex_Insensitive_Fuzz<std::__1::integral_constant<bool,+false>>  6.67s
ThreadSafety_RowDestruction                                             5.89s
Shared_StaticFuzzTestRunSanityCheck                                     5.06s
ThreadSafety_LinkViewDestruction                                        3.66s

After:

Success: All 1203 tests passed (15787255 checks).
Test time: 1m4s
Top 5 time usage:
------------------------------------------------
ThreadSafety_RowDestruction                6.14s
ThreadSafety_TableViewDestruction          4.24s
ThreadSafety_LinkViewDestruction           2.85s
StringIndex_Insensitive_Fuzz<enum_column>  2.70s
Shared_ManyReaders                         2.57s

@realm-ci
Copy link
Contributor

realm-ci commented Aug 1, 2017

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/1/Diff_Coverage

@realm-ci
Copy link
Contributor

realm-ci commented Aug 2, 2017

@realm-ci
Copy link
Contributor

realm-ci commented Aug 2, 2017

@realm-ci
Copy link
Contributor

realm-ci commented Aug 2, 2017

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/2/Diff_Coverage

@realm-ci
Copy link
Contributor

realm-ci commented Aug 2, 2017

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/3/Diff_Coverage

@realm-ci
Copy link
Contributor

realm-ci commented Aug 2, 2017

@ironage
Copy link
Contributor Author

ironage commented Aug 2, 2017

I've cherry-picked from #2778 because that needs to go into master, otherwise CI fails this PR.

@@ -162,6 +162,39 @@ void StringEnumColumn::do_move_last_over(size_t row_ndx, size_t last_row_ndx)
move_last_over_without_updating_index(row_ndx, last_row_ndx); // Throws
}

void StringEnumColumn::swap_rows(size_t row_ndx_1, size_t row_ndx_2)
{
REALM_ASSERT_3(row_ndx_1, <=, size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be < instead of <=?

set(row_ndx_2, realm::null());
}
else {
StringData copy{buffer_1.data(), buffer_1.size()};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just swap the integers with IntegerColumn::get() / IntegerColumn::set() instead of copying payload

@@ -207,7 +207,7 @@ Mixed construct_mixed(State& s, util::Optional<std::ostream&> log, std::string&
}
case 5: {
size_t rand_char = get_next(s);
size_t blob_size = get_int64(s) % ArrayBlob::max_binary_size;
size_t blob_size = static_cast<uint64_t>(get_int64(s)) % ArrayBlob::max_binary_size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do % (ArrayBlob::max_binary_size + 1) to be able to also trigger the maximum blob size, which is an important edge case

@ironage ironage force-pushed the js/string-enum-fixes branch from 71dd478 to e41fc1a Compare August 9, 2017 21:20
@ironage
Copy link
Contributor Author

ironage commented Aug 9, 2017

@rrrlasse I've made the optimisation in StringEnumColumn::swap_rows can you please review it for correctness and efficiency again? (commit a3545aa)

@realm-ci
Copy link
Contributor

realm-ci commented Aug 9, 2017

@realm-ci
Copy link
Contributor

realm-ci commented Aug 9, 2017

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/5/Diff_Coverage

@realm-ci
Copy link
Contributor

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/6/Diff_Coverage

@realm-ci
Copy link
Contributor

@ironage
Copy link
Contributor Author

ironage commented Aug 17, 2017

@finnschiermer @rrrlasse I've been running the fuzz tests on this branch for several days without finding any new crashes. I believe the StringEnumColumn to be stable. Please review when you have the time.

js@ubuntu-linux32bit:~/Documents/code/realm-core/build.afl$ afl-whatsup findings/
status check tool for afl-fuzz by <lcamtuf@google.com>

Individual fuzzers
==================

>>> fuzzer1 (2 days, 22 hrs) <<<

  cycle 1, lifetime speed 26 execs/sec, path 4036/17369 (23%)
  pending 1033/17185, coverage 39.13%, no crashes yet

>>> fuzzer2 (2 days, 22 hrs) <<<

  cycle 1, lifetime speed 11 execs/sec, path 2043/19539 (10%)
  pending 1093/19469, coverage 39.15%, no crashes yet

Summary stats
=============

       Fuzzers alive : 2
      Total run time : 5 days, 21 hours
         Total execs : 9 million
    Cumulative speed : 38 execs/sec
       Pending paths : 2126 faves, 36654 total
  Pending per fuzzer : 1063 faves, 18327 total (on average)
       Crashes found : 0 locally unique

@ironage
Copy link
Contributor Author

ironage commented Aug 18, 2017

Looks like I was a bit too hasty there, at the 10 million execution point AFL found some crashes in StringEnumColumn (not related to swap_rows) I'm investigating.

@ironage
Copy link
Contributor Author

ironage commented Aug 18, 2017

The fuzzer also found that Table::move_column() was broken when moving string enum columns around. It is fixed in ef46b28. I'll continue fuzz tests as a background task but these changes are ready for review.

@realm-ci
Copy link
Contributor

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/8/Diff_Coverage

@realm-ci
Copy link
Contributor

@ironage ironage force-pushed the js/string-enum-fixes branch from ef46b28 to 2c9c41c Compare August 22, 2017 19:16
@realm-ci
Copy link
Contributor

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/9/Diff_Coverage

@realm-ci
Copy link
Contributor

Copy link
Contributor

@finnschiermer finnschiermer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

}

// Update search index
// (it is important here that we do it before actually setting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ironage
Copy link
Contributor Author

ironage commented Sep 6, 2017

@rrrlasse did you get a chance to look at the changes here or is it good to go?

@ironage
Copy link
Contributor Author

ironage commented Sep 13, 2017

@rrrlasse bump for review

@realm-ci
Copy link
Contributor

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/10/Diff_Coverage

@realm-ci
Copy link
Contributor

Copy link
Contributor

@rrrlasse rrrlasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

{
REALM_ASSERT_3(row_ndx_1, <, size());
REALM_ASSERT_3(row_ndx_2, <, size());
REALM_ASSERT_DEBUG(row_ndx_1 != row_ndx_2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all other column types use != also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes other columns have the same asserts, in particular StringColumn.

@@ -678,7 +678,7 @@ void parse_and_apply_instructions(std::string& in, const std::string& path, util
bool insert_big_blob = get_next(s) % 2 == 0;
if (insert_big_blob) {
size_t rand_char = get_next(s);
size_t blob_size = get_next(s) + ArrayBlob::max_binary_size;
size_t blob_size = get_next(s) + (ArrayBlob::max_binary_size + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be static_cast<uint64_t>(get_int64(s)) % (ArrayBlob::max_binary_size + 1);? Or better yet, is there a reason for not reusing the existing generator in construct_mixed()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, updated to share the correct ™ binary creation code in a function.

@realm-ci
Copy link
Contributor

Please check your coverage here: https://ci.realm.io/job/realm/job/realm-core/job/PR-2780/11/Diff_Coverage

@realm-ci
Copy link
Contributor

@ironage ironage merged commit 1395515 into master Sep 18, 2017
@ironage ironage deleted the js/string-enum-fixes branch September 18, 2017 14:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StringEnumColumn crash
5 participants