From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cyril Hrubis Date: Tue, 5 Mar 2019 15:19:03 +0100 Subject: [LTP] [PATCH v2 1/2] syscalls/sync_file_range: add partial file sync test-case In-Reply-To: <1551770065-20444-1-git-send-email-sumit.garg@linaro.org> References: <1551770065-20444-1-git-send-email-sumit.garg@linaro.org> Message-ID: <20190305141903.GD13703@rei> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it Hi! > +static void verify_sync_partial_file(void) > +{ > + int fd; > + unsigned long written; > + > + fd = SAFE_OPEN(FNAME, O_RDWR|O_CREAT, MODE); > + > + tst_dev_bytes_written(tst_device->dev); > + > + tst_fill_fd(fd, 0xff, TST_MB, FILE_SIZE_MB); > + > + TEST(sync_file_range(fd, FILE_SIZE/4, FILE_SIZE/2, > + SYNC_FILE_RANGE_WAIT_BEFORE | > + SYNC_FILE_RANGE_WRITE | > + SYNC_FILE_RANGE_WAIT_AFTER)); > + > + if (TST_RET) > + tst_brk(TFAIL | TTERRNO, "sync_file_range() failed"); > + > + written = tst_dev_bytes_written(tst_device->dev); > + > + SAFE_CLOSE(fd); > + > + if (written >= FILE_SIZE/2) > + tst_res(TPASS, "Test file range synced to device"); > + else > + tst_res(TFAIL, "Synced %li, expected %i", written, > + FILE_SIZE/2); > +} Looking at this the function is nearly the same as the other one, I guess that we may as well define the function as: static void verify_sync_file_range(off64_t off, off64_t size, char byte) { ... } Also I'm not sure I was clear enough, but I was suggesting to check for upper bound for the synced size as well, which is why I suggested to do full write, sync only part of it, then check that the size was within bounds, i.e. >= size and <= size + epsilon. I guess that we can even extend this to call the sync over a range that has been only partially written, but for that we would have to be careful and make sure all the data has been either synced@the end of the test function or use a different file for each test. -- Cyril Hrubis chrubis@suse.cz