@@ -96,7 +96,7 @@ class VolumeIOImpl {
9696 data_bytes += page_size;
9797 // Store the lba to pattern mapping
9898 m_lba_data[lba] = data_pattern;
99- LOGINFO (" Generate data lba={} pattern={}" , lba, data_pattern);
99+ // LOGDEBUG ("Generate data lba={} pattern={}", lba, data_pattern);
100100 lba++;
101101 }
102102
@@ -131,18 +131,44 @@ class VolumeIOImpl {
131131 });
132132 }
133133
134- void verify_data () {
135- for (auto & [lba, data_pattern] : m_lba_data) {
136- auto buffer = iomanager.iobuf_alloc (512 , 4096 );
137- vol_interface_req_ptr req (new vol_interface_req{buffer, lba, 1 });
134+ void read_and_verify (lba_t start_lba, uint32_t nlbas) {
135+ auto sz = nlbas * m_vol_ptr->info ()->page_size ;
136+ sisl::io_blob_safe read_blob (sz, 512 );
137+ auto buf = read_blob.bytes ();
138+ vol_interface_req_ptr req (new vol_interface_req{buf, start_lba, nlbas});
139+ auto read_resp = g_helper->inst ()->volume_manager ()->read (m_vol_ptr, req).get ();
140+ if (read_resp.hasError ()) {
141+ LOGERROR (" Read failed with error={}" , read_resp.error ());
142+ }
143+ RELEASE_ASSERT (!read_resp.hasError (), " Read failed with error={}" , read_resp.error ());
144+ auto read_sz = m_vol_ptr->info ()->page_size ;
145+ for (auto lba = start_lba; lba < start_lba + nlbas; lba++, buf += read_sz) {
146+ uint64_t data_pattern = 0 ;
147+ if (auto it = m_lba_data.find (lba); it != m_lba_data.end ()) {
148+ data_pattern = it->second ;
149+ test_common::HBTestHelper::validate_data_buf (buf, m_vol_ptr->info ()->page_size , data_pattern);
150+ } else {
151+ test_common::HBTestHelper::validate_zeros (buf, m_vol_ptr->info ()->page_size );
152+ }
153+
154+ LOGDEBUG (" Verify data lba={} pattern expected={} actual={}" , lba, data_pattern, *r_cast< uint64_t * >(read_blob.bytes ()));
155+ }
156+ }
138157
139- auto vol_mgr = g_helper->inst ()->volume_manager ();
140- vol_mgr->read (m_vol_ptr, req).get ();
141- // LOGINFO("Data read={}", fmt::format("{}", spdlog::to_hex((buffer), (buffer) + (128))));
142- test_common::HBTestHelper::validate_data_buf (buffer, 4096 , data_pattern);
143- LOGINFO (" Verify data lba={} pattern={} {}" , lba, data_pattern, *r_cast< uint64_t * >(buffer));
144- iomanager.iobuf_free (buffer);
158+ void verify_data (uint64_t nlbas_per_io = 1 ) {
159+ auto start_lba = m_lba_data.begin ()->first ;
160+ auto max_lba = m_lba_data.rbegin ()->first ;
161+ verify_data (start_lba, max_lba, nlbas_per_io);
162+ }
163+
164+ void verify_data (lba_t start_lba, lba_t max_lba, uint64_t nlbas_per_io) {
165+ uint64_t num_lbas_verified = 0 ;
166+ for (auto lba = start_lba; lba < max_lba; lba += nlbas_per_io) {
167+ auto num_lbas_this_round = std::min (nlbas_per_io, max_lba - lba);
168+ read_and_verify (lba, num_lbas_this_round);
169+ num_lbas_verified += num_lbas_this_round;
145170 }
171+ LOGINFO (" Verified {} lbas for volume {}" , num_lbas_verified, m_vol_ptr->info ()->name );
146172 }
147173
148174#ifdef _PRERELEASE
@@ -191,22 +217,21 @@ class VolumeIOTest : public ::testing::Test {
191217 // Get a random volume.
192218 vol = m_vols_impl[rand () % m_vols_impl.size ()];
193219 }
194-
195220 vol->generate_io (start_lba, nblks);
196221 });
197222
198223 if (wait) { g_helper->runner ().execute ().get (); }
199224 LOGINFO (" IO completed" );
200225 }
201226
202- void verify_data (shared< VolumeIOImpl > vol_impl = nullptr ) {
227+ void verify_data (shared< VolumeIOImpl > vol_impl = nullptr , uint64_t nlbas_per_io = 1 ) {
203228 if (vol_impl) {
204- vol_impl->verify_data ();
229+ vol_impl->verify_data (nlbas_per_io );
205230 return ;
206231 }
207232
208233 for (auto & vol_impl : m_vols_impl) {
209- vol_impl->verify_data ();
234+ vol_impl->verify_data (nlbas_per_io );
210235 }
211236 }
212237
@@ -233,18 +258,38 @@ TEST_F(VolumeIOTest, SingleVolumeWriteData) {
233258 vol->reset ();
234259
235260 LOGINFO (" Verify data" );
236- verify_data (vol);
261+ verify_data (vol, 30 /* nlbas_per_io */ );
237262
238263 // Write and verify again on same LBA range to single volume multiple times.
239264 LOGINFO (" Write and verify data with num_iter={} start={} nblks={}" , num_iter, start_lba, nblks);
240265 for (uint32_t i = 0 ; i < num_iter; i++) {
241266 generate_io_single (vol, start_lba, nblks);
242267 }
243-
244268 verify_data (vol);
269+
270+ // verify random lba ranges
271+
245272 LOGINFO (" SingleVolumeWriteData test done." );
246273}
247274
275+ TEST_F (VolumeIOTest, SingleVolumeReadData) {
276+ // Write and verify fixed LBA range to single volume multiple times.
277+ auto vol = volume_list ().back ();
278+ uint32_t nblks = 500 ;
279+ lba_t start_lba = 1000 ;
280+ uint32_t num_iter = 1 ;
281+ LOGINFO (" Write and verify data with num_iter={} start={} nblks={}" , num_iter, start_lba, nblks);
282+ for (uint32_t i = 0 ; i < num_iter; i++) {
283+ generate_io_single (vol, start_lba, nblks);
284+ }
285+
286+ vol->verify_data (300 , 800 , 40 );
287+ vol->verify_data (2000 , 3000 , 40 );
288+ vol->verify_data (800 , 1800 , 40 );
289+
290+ LOGINFO (" SingleVolumeReadHoles test done." );
291+ }
292+
248293TEST_F (VolumeIOTest, MultipleVolumeWriteData) {
249294 LOGINFO (" Write data randomly on num_vols={} num_io={}" , SISL_OPTIONS[" num_vols" ].as < uint32_t >(),
250295 SISL_OPTIONS[" num_io" ].as < uint64_t >());
0 commit comments