-
Notifications
You must be signed in to change notification settings - Fork 11
Read API impl #89
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
Read API impl #89
Changes from all commits
423ff38
f3f9d87
0fd0b78
fa11f7c
ae979a9
dc1417c
3cfc9de
270aafb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ target_sources(test_fixture PRIVATE | |
| ) | ||
| target_link_libraries(test_fixture | ||
| ${COMMON_TEST_DEPS} | ||
| ) | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,4 +277,4 @@ class HBTestHelper { | |
| Waiter waiter_; | ||
| }; | ||
|
|
||
| } // namespace test_common | ||
| } // namespace test_common | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,18 +174,42 @@ class VolumeIOImpl { | |
| }); | ||
| } | ||
|
|
||
| void verify_all_data() { | ||
| for (auto& [lba, data_pattern] : m_lba_data) { | ||
| auto buffer = iomanager.iobuf_alloc(512, 4096); | ||
| vol_interface_req_ptr req(new vol_interface_req{buffer, lba, 1}); | ||
| void read_and_verify(lba_t start_lba, uint32_t nlbas) { | ||
| auto sz = nlbas * m_vol_ptr->info()->page_size; | ||
| sisl::io_blob_safe read_blob(sz, 512); | ||
| auto buf = read_blob.bytes(); | ||
| vol_interface_req_ptr req(new vol_interface_req{buf, start_lba, nlbas}); | ||
| auto read_resp = g_helper->inst()->volume_manager()->read(m_vol_ptr, req).get(); | ||
raakella1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(read_resp.hasError()) { | ||
| LOGERROR("Read failed with error={}", read_resp.error()); | ||
| } | ||
| RELEASE_ASSERT(!read_resp.hasError(), "Read failed with error={}", read_resp.error()); | ||
| auto read_sz = m_vol_ptr->info()->page_size; | ||
| for(auto lba = start_lba; lba < start_lba + nlbas; lba++, buf += read_sz) { | ||
| uint64_t data_pattern = 0; | ||
| if(auto it = m_lba_data.find(lba); it != m_lba_data.end()) { | ||
| data_pattern = it->second; | ||
| test_common::HBTestHelper::validate_data_buf(buf, m_vol_ptr->info()->page_size, data_pattern); | ||
| } | ||
|
|
||
| LOGDEBUG("Verify data lba={} pattern expected={} actual={}", lba, data_pattern, *r_cast< uint64_t* >(read_blob.bytes())); | ||
| } | ||
| } | ||
|
|
||
| auto vol_mgr = g_helper->inst()->volume_manager(); | ||
| vol_mgr->read(m_vol_ptr, req).get(); | ||
| test_common::HBTestHelper::validate_data_buf(buffer, 4096, data_pattern); | ||
| LOGDEBUG("Verify data vol={} lba={} pattern={} {}", m_vol_name, lba, data_pattern, | ||
| *r_cast< uint64_t* >(buffer)); | ||
| iomanager.iobuf_free(buffer); | ||
| void verify_all_data(uint64_t nlbas_per_io = 1) { | ||
| auto start_lba = m_lba_data.begin()->first; | ||
| auto max_lba = m_lba_data.rbegin()->first; | ||
| verify_data(start_lba, max_lba, nlbas_per_io); | ||
| } | ||
|
|
||
| void verify_data(lba_t start_lba, lba_t max_lba, uint64_t nlbas_per_io) { | ||
| uint64_t num_lbas_verified = 0; | ||
| for(auto lba = start_lba; lba < max_lba; lba += nlbas_per_io) { | ||
| auto num_lbas_this_round = std::min(nlbas_per_io, max_lba - lba); | ||
| read_and_verify(lba, num_lbas_this_round); | ||
| num_lbas_verified += num_lbas_this_round; | ||
| } | ||
| LOGINFO("Verified {} lbas for volume {}", num_lbas_verified, m_vol_ptr->info()->name); | ||
| } | ||
|
|
||
| #ifdef _PRERELEASE | ||
|
|
@@ -238,22 +262,21 @@ class VolumeIOTest : public ::testing::Test { | |
| // Get a random volume. | ||
| vol = m_vols_impl[rand() % m_vols_impl.size()]; | ||
| } | ||
|
|
||
| vol->generate_io(start_lba, nblks); | ||
| }); | ||
|
|
||
| if (wait) { g_helper->runner().execute().get(); } | ||
| LOGINFO("IO completed"); | ||
| } | ||
|
|
||
| void verify_all_data(shared< VolumeIOImpl > vol_impl = nullptr) { | ||
| void verify_all_data(shared< VolumeIOImpl > vol_impl = nullptr, uint64_t nlbas_per_io = 1) { | ||
| if (vol_impl) { | ||
| vol_impl->verify_all_data(); | ||
| vol_impl->verify_all_data(nlbas_per_io); | ||
| return; | ||
| } | ||
|
|
||
| for (auto& vol_impl : m_vols_impl) { | ||
| vol_impl->verify_all_data(); | ||
| vol_impl->verify_all_data(nlbas_per_io); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -266,6 +289,14 @@ class VolumeIOTest : public ::testing::Test { | |
|
|
||
| std::vector< shared< VolumeIOImpl > >& volume_list() { return m_vols_impl; } | ||
|
|
||
| template < typename T > | ||
| T get_random_number(T min, T max) { | ||
| static std::random_device rd; | ||
| static std::mt19937 gen(rd()); | ||
| std::uniform_int_distribution< T > dis(min, max); | ||
| return dis(gen); | ||
| } | ||
|
|
||
| private: | ||
| std::vector< shared< VolumeIOImpl > > m_vols_impl; | ||
| }; | ||
|
|
@@ -287,17 +318,76 @@ TEST_F(VolumeIOTest, SingleVolumeWriteData) { | |
|
|
||
| LOGINFO("Verify data"); | ||
| verify_all_data(vol); | ||
| //verify_data(vol, 30 /* nlbas_per_io */); | ||
|
|
||
| // Write and verify again on same LBA range to single volume multiple times. | ||
| LOGINFO("Write and verify data with num_iter={} start={} nblks={}", num_iter, start_lba, nblks); | ||
| for (uint32_t i = 0; i < num_iter; i++) { | ||
| generate_io_single(vol, start_lba, nblks); | ||
| } | ||
|
|
||
| verify_all_data(vol); | ||
| verify_all_data(vol, 30 /* nlbas_per_io */); | ||
|
|
||
| LOGINFO("SingleVolumeWriteData test done."); | ||
| } | ||
|
|
||
| TEST_F(VolumeIOTest, SingleVolumeReadData) { | ||
| // Write and verify fixed LBA range to single volume multiple times. | ||
| auto vol = volume_list().back(); | ||
| uint32_t nblks = 5000; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add some io's which have hole and your read covers those ranges with holes and ranges with data this PR or another PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will have a separate PR just for adding more test cases |
||
| lba_t start_lba = 500; | ||
| uint32_t num_iter = 1; | ||
| LOGINFO("Write and verify data with num_iter={} start={} nblks={}", num_iter, start_lba, nblks); | ||
| for (uint32_t i = 0; i < num_iter; i++) { | ||
| generate_io_single(vol, start_lba, nblks); | ||
| } | ||
|
|
||
| vol->verify_data(300, 800, 40); | ||
| vol->verify_data(2000, 3000, 40); | ||
| vol->verify_data(800, 1800, 40); | ||
|
|
||
| // random reads | ||
| num_iter = 100; | ||
| for(uint32_t i = 0; i < num_iter; i++) { | ||
| auto start_lba = get_random_number< lba_t >(0, 10000); | ||
| auto nblks = get_random_number< uint32_t >(1, 64); | ||
| auto no_lbas_per_io = get_random_number< uint64_t >(1, 50); | ||
| LOGINFO("iter {}: Read data start={} nblks={} no_lbas_per_io {}", i, start_lba, nblks, no_lbas_per_io); | ||
| vol->verify_data(start_lba, start_lba + nblks, no_lbas_per_io); | ||
| } | ||
|
|
||
| LOGINFO("SingleVolumeRead test done."); | ||
| } | ||
|
|
||
| TEST_F(VolumeIOTest, SingleVolumeReadHoles) { | ||
| auto vol = volume_list().back(); | ||
| uint32_t nblks = 5000; | ||
| lba_t start_lba = 500; | ||
| generate_io_single(vol, start_lba, nblks); | ||
|
|
||
| // Verify with no holes in the range | ||
| vol->verify_data(1000, 2000, 40); | ||
|
|
||
| start_lba = 10000; | ||
| nblks = 50; | ||
| for(uint32_t i = 0; i/2 < nblks; i+=2) { | ||
| generate_io_single(vol, start_lba+i, 1); | ||
| } | ||
|
|
||
| // Verfy with hole after each lba | ||
| vol->verify_data(10000, 10100, 50); | ||
|
|
||
| start_lba = 20000; | ||
| for(uint32_t i = 0; i < 100; i++) { | ||
| if(i%7 > 2) { | ||
| generate_io_single(vol, start_lba+i, 1); | ||
| } | ||
| } | ||
| // Verify with mixed holes in the range | ||
| vol->verify_data(20000, 20100, 50); | ||
|
|
||
| } | ||
|
|
||
| TEST_F(VolumeIOTest, MultipleVolumeWriteData) { | ||
| LOGINFO("Write data randomly on num_vols={} num_io={}", SISL_OPTIONS["num_vols"].as< uint32_t >(), | ||
| SISL_OPTIONS["num_io"].as< uint64_t >()); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.