@@ -809,6 +809,60 @@ def test_nbdkit_instance_name():
809809 # Force kill if it's being stubborn
810810 p .kill ()
811811
812+ def test_count_filter ():
813+ from subprocess import Popen , TimeoutExpired
814+
815+ log_path = os .path .join (data_dir .get_tmp_dir (), "nbdkit_count_filter_debug.log" )
816+
817+ try :
818+ with open (log_path , "w" ) as log_file :
819+ LOG .info ("Starting nbdkit" )
820+ cmd = ["nbdkit" , "-f" , "-v" , "memory" , "10M" , "--filter=count" ]
821+ # Start nbdkit as a background process, piping stderr and stdout to log file
822+ p = Popen (cmd , stderr = log_file , stdout = log_file )
823+
824+ if p .poll () is not None :
825+ test .fail (f"nbdkit failed to start! Check { log_path } " )
826+
827+ # Allow nbdkit instances time to start listening
828+ import time
829+ time .sleep (1 )
830+
831+ # Trigger activity with qemu-io
832+ LOG .info ("Writing data to nbdkit" )
833+ qemu_cmd = "qemu-io -f raw nbd://localhost -c \' write 0 1M\' -c \' read 0 1M\' -c \' write -z 1M 1M\' -c \' discard 0 1M\' "
834+
835+ result = process .run (qemu_cmd , shell = True )
836+ if result .exit_status != 0 :
837+ test .fail ("qemu-io failed" )
838+
839+ # VALIDATION: Check the log file for the read, written, zeroed, trimmed reports
840+ with open (log_path , 'r' ) as f :
841+ log_content = f .read ()
842+ # Look for the expected pattern
843+ expected_patterns = [
844+ "count: pwrite count=1048576" ,
845+ "count: pread count=1048576" ,
846+ "count: pzero count=1048576" ,
847+ "count: trim count=1048576"
848+ ]
849+
850+ for pattern in expected_patterns :
851+ if pattern not in log_content :
852+ test .fail (f"'{ pattern } ' was not found in debug logs!" )
853+ LOG .info (f"Pattern { pattern } appears in the debug logs" )
854+ finally :
855+ # Cleanup: Kill the processes
856+ LOG .info ("Cleanup: Kill the processes" )
857+ if p .poll () is None :
858+ p .terminate ()
859+ try :
860+ # Wait up to 5 seconds for it to exit
861+ p .wait (timeout = 5 )
862+ except TimeoutExpired :
863+ # Force kill if it's being stubborn
864+ p .kill ()
865+
812866 if version_required and not multiple_versions_compare (
813867 version_required ):
814868 test .cancel ("Testing requires version: %s" % version_required )
@@ -889,5 +943,7 @@ def test_nbdkit_instance_name():
889943 check_blocksize_constraints ()
890944 elif checkpoint == 'test_nbdkit_instance_name' :
891945 test_nbdkit_instance_name ()
946+ elif checkpoint == 'test_count_filter' :
947+ test_count_filter ()
892948 else :
893949 test .error ('Not found testcase: %s' % checkpoint )
0 commit comments