From fa3cc55d0063f36a5d5e9d8d77d0d26565bc2f59 Mon Sep 17 00:00:00 2001 From: Martin Pärtel Date: Wed, 19 Apr 2017 10:33:45 +0300 Subject: Added option: --block-devices-as-files Fixes #53. --- tests/test_block_devices_as_files.rb | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tests/test_block_devices_as_files.rb (limited to 'tests') diff --git a/tests/test_block_devices_as_files.rb b/tests/test_block_devices_as_files.rb new file mode 100755 index 0000000..29a81ee --- /dev/null +++ b/tests/test_block_devices_as_files.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby +# +# Copyright 2006,2007,2008,2009,2010 Martin Pärtel +# +# This file is part of bindfs. +# +# bindfs is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# bindfs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with bindfs. If not, see . +# + +# if we are being run by make check it will set srcdir and we should use it +$LOAD_PATH << (ENV['srcdir'] || '.') +require 'common.rb' + +raise "Please run this as root" unless Process.uid == 0 + +if ARGV.include?("-h") || ARGV.include?("--help") || ARGV.length != 1 + puts + puts "Usage: #{$0} /dev/some-block-device" + puts + puts "This test will attempt to read the block device through bindfs." + puts "This is a separate test file because it's nontrivial to set up a" + puts "block device for testing in a non-intrusive and portable way." + puts + exit(1) +end + +device = ARGV[0] + +root_testenv("--block-devices-as-files --resolve-symlinks") do + symlink(device, 'src/devicelink') + + size_through_bindfs = File.size('mnt/devicelink') + measured_size = File.open(device, "r") do |f| + f.seek(0, IO::SEEK_END) + f.tell + end + assert { size_through_bindfs == measured_size } + assert { measured_size >= 512 } + puts "Device size: #{size_through_bindfs}" + + data_read_through_bindfs = File.read('mnt/devicelink', 512) + data_read_directly= File.read(device, 512) + assert { data_read_through_bindfs == data_read_directly } +end -- cgit v1.2.3