@@ -739,6 +739,56 @@ def check_blocksize_constraints():
739739 if field not in cmd_output :
740740 test .fail ('Expected field "%s" not found in export output: %s' % (field , cmd_output ))
741741
742+ def test_count_filter ():
743+ from subprocess import Popen , TimeoutExpired
744+
745+ log_path = os .path .join (data_dir .get_tmp_dir (), "nbdkit_debug.log" )
746+
747+ try :
748+ with open (log_path , "a" ) as log_file :
749+ LOG .info (f"Starting nbdkit" )
750+ cmd = ["nbdkit" , "-f" , "-v" , "memory" , "10M" , "--filter=count" ]
751+ # Start nbdkit as a background process, piping stderr to log file
752+ p = Popen (cmd , stderr = log_file , stdout = log_file )
753+
754+ if p .poll () is not None :
755+ test .fail (f"nbdkit failed to start! Check { log_path } " )
756+
757+ # Allow nbdkit instances time to start listening
758+ import time
759+ time .sleep (1 )
760+
761+ # Trigger activity with qemu-io
762+ LOG .info ("Writing to nbdkit" )
763+ qemu_cmd = f"qemu-io -f raw nbd://localhost -c \' write 0 1M\' -c \' read 0 1M\' -c \' discard 0 1M\' "
764+
765+ result = process .run (qemu_cmd , shell = True )
766+ if result .exit_status != 0 :
767+ test .fail (f"qemu-io failed" )
768+
769+ # VALIDATION: Check the log file for the read, written, zeroed, trimmed reports
770+ with open (log_path , 'r' ) as f :
771+ log_content = f .read ()
772+ LOG .info (f"logging info ----> { log_content } " )
773+ # Look for the expected pattern
774+ expected_patterns = ["count: pwrite count=1048576" , "count: pread count=1048576" , "count: trim count=1048576" ]
775+
776+ for pattern in expected_patterns :
777+ if pattern not in log_content :
778+ test .fail (f"'{ pattern } ' was not found in debug logs!" )
779+ LOG .info (f"Pattern { pattern } appears in the debug logs" )
780+ finally :
781+ # Cleanup: Kill the processes
782+ LOG .info ("Cleanup: Kill the processes" )
783+ if p .poll () is None :
784+ p .terminate ()
785+ try :
786+ # Wait up to 5 seconds for it to exit
787+ p .wait (timeout = 5 )
788+ except TimeoutExpired :
789+ # Force kill if it's being stubborn
790+ p .kill ()
791+
742792 if version_required and not multiple_versions_compare (
743793 version_required ):
744794 test .cancel ("Testing requires version: %s" % version_required )
@@ -817,5 +867,7 @@ def check_blocksize_constraints():
817867 check_blkhash_option ()
818868 elif checkpoint == 'blocksize_constraints' :
819869 check_blocksize_constraints ()
870+ elif checkpoint == 'test_count_filter' :
871+ test_count_filter ()
820872 else :
821873 test .error ('Not found testcase: %s' % checkpoint )
0 commit comments