Skip to content

Comments

Fix tests#157

Open
johnrichardrinehart wants to merge 5 commits intolouwrentius:masterfrom
johnrichardrinehart:nix-packaging_fix-tests
Open

Fix tests#157
johnrichardrinehart wants to merge 5 commits intolouwrentius:masterfrom
johnrichardrinehart:nix-packaging_fix-tests

Conversation

@johnrichardrinehart
Copy link

@johnrichardrinehart johnrichardrinehart commented Aug 26, 2025

Description

This actually relies (builds) on the work of #156. It fixes the below, but maybe not in the desired way. Changes should be reviewed.

Running phase: pytestCheckPhase
@nix { "action": "setPhase", "phase": "pytestCheckPhase" }
Executing pytestCheckPhase
pytest flags: -m pytest
============================= test session starts ==============================
platform linux -- Python 3.13.5, pytest-8.3.5, pluggy-1.6.0
rootdir: /build/source
configfile: pyproject.toml
collected 8 items                                                              

tests/bench_fio_test.py .FFFFFF                                          [ 87%]
tests/test_3d.py F                                                       [100%]

=================================== FAILURES ===================================
____________________ TestFunctions.test_calculate_duration _____________________

self = <bench_fio_test.TestFunctions testMethod=test_calculate_duration>

    def test_calculate_duration(self):
>       self.assertEqual(
            display.calculate_duration(self.settings, self.tests), "1:38:00"
        )
E       AssertionError: '0:49:00' != '1:38:00'
E       - 0:49:00
E       + 1:38:00

tests/bench_fio_test.py:34: AssertionError
____________________ TestFunctions.test_generate_benchmarks ____________________

self = <bench_fio_test.TestFunctions testMethod=test_generate_benchmarks>

    def test_generate_benchmarks(self):
>       self.assertEqual(len(supporting.generate_test_list(self.settings)), 98)
E       AssertionError: 49 != 98

tests/bench_fio_test.py:21: AssertionError
__________________ TestFunctions.test_generate_benchmarks_big __________________

self = <bench_fio_test.TestFunctions testMethod=test_generate_benchmarks_big>

    def test_generate_benchmarks_big(self):
        self.settings["target"] = ["filea", "fileb", "filec", "filed"]
        self.settings["block_size"] = ["4k", "8k", "16k", "32k"]
>       self.assertEqual(len(supporting.generate_test_list(self.settings)), 1568)
E       AssertionError: 784 != 1568

tests/bench_fio_test.py:26: AssertionError
______________ TestFunctions.test_generate_output_directory_mixed ______________

self = <bench_fio_test.TestFunctions testMethod=test_generate_output_directory_mixed>

    def test_generate_output_directory_mixed(self):
        self.settings["mode"] = ["rw"]
        self.settings["rwmixread"] = [75]
        self.settings["loop_items"].append("rwmixread")
        tests = supporting.generate_test_list(self.settings)
        benchmark = tests[0]
        self.assertEqual(
>           supporting.generate_output_directory(self.settings, benchmark),
            "output_directory/device/rw75/4k",
        )

tests/bench_fio_test.py:52: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

settings = {'basename_list': ['precondition_template'], 'benchmarks': 49, 'block_size': ['4k'], 'ceph_pool': None, ...}
benchmark = {'block_size': '4k', 'iodepth': 1, 'mode': 'rw', 'numjobs': 1, ...}

    def generate_output_directory(settings, benchmark):
        settings["output"] = os.path.expanduser(settings["output"])
        if benchmark["mode"] in settings["mixed"]:
            directory = (
>               f"{settings['output']}/{os.path.basename(benchmark['target_base'])}/"
                f"{benchmark['mode']}{benchmark['rwmixread']}/{benchmark['block_size']}"
            )
E           KeyError: 'target_base'

bench_fio/benchlib/supporting.py:45: KeyError
_____________ TestFunctions.test_generate_output_directory_regular _____________

self = <bench_fio_test.TestFunctions testMethod=test_generate_output_directory_regular>

    def test_generate_output_directory_regular(self):
        benchmark = self.tests[0]
        self.assertEqual(
>           supporting.generate_output_directory(self.settings, benchmark),
            "output_directory/device/4k",
        )

tests/bench_fio_test.py:41: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

settings = {'basename_list': ['precondition_template'], 'benchmarks': 49, 'block_size': ['4k'], 'ceph_pool': None, ...}
benchmark = {'block_size': '4k', 'iodepth': 1, 'mode': 'randread', 'numjobs': 1, ...}

    def generate_output_directory(settings, benchmark):
        settings["output"] = os.path.expanduser(settings["output"])
        if benchmark["mode"] in settings["mixed"]:
            directory = (
                f"{settings['output']}/{os.path.basename(benchmark['target_base'])}/"
                f"{benchmark['mode']}{benchmark['rwmixread']}/{benchmark['block_size']}"
            )
        else:
>           directory = f"{settings['output']}/{os.path.basename(benchmark['target_base'])}/{benchmark['block_size']}"
E           KeyError: 'target_base'

bench_fio/benchlib/supporting.py:49: KeyError
____________________ TestFunctions.test_number_of_settings _____________________

self = <bench_fio_test.TestFunctions testMethod=test_number_of_settings>

    def test_number_of_settings(self):
        filtered_settings = []
        for setting in self.settings.keys():
            if setting not in self.settings["filter_items"]:
                filtered_settings.append(str(setting))
        filtered_settings.sort()
        descriptions = list((argparsing.get_argument_description()).keys())
        descriptions.sort()
>       self.assertEqual(len(filtered_settings), len(descriptions))
E       AssertionError: 32 != 33

tests/bench_fio_test.py:64: AssertionError
________________________ Test3D.test_correct_bars_drawn ________________________

self = <test_3d.Test3D testMethod=test_correct_bars_drawn>

    def test_correct_bars_drawn(self):
        settings = {
            "type": ["iops"],
            "rw": "read",
            "source": "test",
            "title": "test",
            "subtitle": "",
            "filter": ["read", "write"],
            # intentionally using prime numbers
            "iodepth": [2, 3],
            "numjobs": [5, 11],
            "maxjobs": 32,
            "maxdepth": 32,
            "max": None,
            "dpi": 200,
            "disable_fio_version": 2.0,
            "output_filename": "/tmp/test.png"
        }
    
        dataset = [{"data": []}]
        for iodepth in settings["iodepth"]:
            for numjobs in settings["numjobs"]:
                dataset[0]["data"].append(
                    {
                        "fio_version": 3.1,
                        "iodepth": str(iodepth),
                        "numjobs": str(numjobs),
                        "rw": "read",
                        "type": "read",
                        "iops": iodepth * numjobs,
                    }
                )
>       plot_3d(settings, dataset)

tests/test_3d.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

settings = {'disable_fio_version': 2.0, 'dpi': 200, 'filter': ['read', 'write'], 'iodepth': [2, 3], ...}
dataset = [{'data': [{'fio_version': 3.1, 'iodepth': '2', 'iops': 10, 'numjobs': '5', ...}, {'fio_version': 3.1, 'iodepth': '2',...epth': '3', 'iops': 15, 'numjobs': '5', ...}, {'fio_version': 3.1, 'iodepth': '3', 'iops': 33, 'numjobs': '11', ...}]}]

    def plot_3d(settings, dataset):
        """This function is responsible for plotting the entire 3D plot."""
    
        if not settings["type"]:
            print("The type of data must be specified with -t (iops/lat/bw).")
            exit(1)
    
        dataset_types = shared.get_dataset_types(dataset)
        metric = settings["type"][0]
        rw = settings["rw"]
        iodepth = dataset_types["iodepth"]
        numjobs = dataset_types["numjobs"]
        data = shared.get_record_set_3d(settings, dataset, dataset_types, rw, metric)
    
        fig = plt.figure()
        ax1 = fig.add_subplot(projection="3d", elev=25)
        fig.set_size_inches(15, 10)
        ax1.set_box_aspect((4, 4, 3), zoom=1.2)
    
        lx = len(dataset_types["iodepth"])
        ly = len(dataset_types["numjobs"])
    
        # This code is meant to make the 3D chart to honour the maxjobs and
        # the maxdepth command line settings. It won't win any prizes for sure.
        if settings["maxjobs"]:
            numjobs = [x for x in numjobs if x <= settings["maxjobs"]]
            ly = len(numjobs)
        if settings["maxdepth"]:
            iodepth = [x for x in iodepth if x <= settings["maxdepth"]]
            lx = len(iodepth)
            if not iodepth:
                print(
                    f"\nDefault maximum iodepth {settings['maxdepth']} is lower than specified iops {settings['iodepth']}."
                )
                print(
                    "\nPlease specify a higher maximum iodepth for the graph with -M <iodepth> like '-M 512'\n"
                )
                sys.exit(1)
        if settings["maxjobs"] or settings["maxdepth"]:
            temp_x = []
            for item in data["values"]:
                if len(temp_x) < len(iodepth):
                    temp_y = []
                    for record in item:
                        if len(temp_y) < len(numjobs):
                            temp_y.append(record)
                    temp_x.append(temp_y)
            data["iodepth"] = iodepth
            data["numjobs"] = numjobs
            data["values"] = temp_x
    
        # Ton of code to scale latency or bandwidth
        if metric == "lat" or metric == "bw":
            scale_factors = []
            for row in data["values"]:
                if metric == "lat":
                    scale_factor = supporting.get_scale_factor_lat(row)
                if metric == "bw":
                    scale_factor = supporting.get_scale_factor_bw(row)
                scale_factors.append(scale_factor)
            largest_scale_factor = supporting.get_largest_scale_factor(scale_factors)
            # pprint.pprint(largest_scale_factor)
    
            scaled_values = []
            for row in data["values"]:
                result = supporting.scale_yaxis(row, largest_scale_factor)
                scaled_values.append(result["data"])
            z_axis_label = largest_scale_factor["label"]
    
        else:
            scaled_values = data["values"]
            z_axis_label = metric
    
        n = np.array(scaled_values, dtype=float)
    
        if lx < ly:
            size = ly * 0.03  # thickness of the bar
        else:
            size = lx * 0.05  # thickness of the bar
    
        xpos_orig = np.arange(0, lx, 1)
        ypos_orig = np.arange(0, ly, 1)
    
        xpos = np.arange(0, lx, 1)
        ypos = np.arange(0, ly, 1)
        xpos, ypos = np.meshgrid(xpos - (size / lx), ypos - (size * (ly / lx)))
    
        xpos_f = xpos.flatten()  # Convert positions to 1D array
        ypos_f = ypos.flatten()
    
        zpos = np.zeros(lx * ly)
    
        # Positioning and sizing of the bars
        dx = size * np.ones_like(zpos)
        dy = size * (ly / lx) * np.ones_like(zpos)
        dz = n.flatten(order="F")
        values = dz / (dz.max() / 1)
    
        # Configure max value for z-axis
>       if settings["max_z"]:
E       KeyError: 'max_z'

fio_plot/fiolib/bar3d.py:115: KeyError
=========================== short test summary info ============================
FAILED tests/bench_fio_test.py::TestFunctions::test_calculate_duration - AssertionError: '0:49:00' != '1:38:00'
FAILED tests/bench_fio_test.py::TestFunctions::test_generate_benchmarks - AssertionError: 49 != 98
FAILED tests/bench_fio_test.py::TestFunctions::test_generate_benchmarks_big - AssertionError: 784 != 1568
FAILED tests/bench_fio_test.py::TestFunctions::test_generate_output_directory_mixed - KeyError: 'target_base'
FAILED tests/bench_fio_test.py::TestFunctions::test_generate_output_directory_regular - KeyError: 'target_base'
FAILED tests/bench_fio_test.py::TestFunctions::test_number_of_settings - AssertionError: 32 != 33
FAILED tests/test_3d.py::Test3D::test_correct_bars_drawn - KeyError: 'max_z'
========================= 7 failed, 1 passed in 0.80s ==========================

FAILED tests/bench_fio_test.py::TestFunctions::test_number_of_settings - AssertionError: 32 != 33
…er of bench_fio tests

python3.13-fio_plot> =================================== FAILURES ===================================
python3.13-fio_plot> ____________________ TestFunctions.test_calculate_duration _____________________
python3.13-fio_plot> self = <bench_fio_test.TestFunctions testMethod=test_calculate_duration>
python3.13-fio_plot>     def test_calculate_duration(self):
python3.13-fio_plot> >       self.assertEqual(
python3.13-fio_plot>             display.calculate_duration(self.settings, self.tests), "1:38:00"
python3.13-fio_plot>         )
python3.13-fio_plot> E       AssertionError: '0:49:00' != '1:38:00'
python3.13-fio_plot> E       - 0:49:00
python3.13-fio_plot> E       + 1:38:00
python3.13-fio_plot> tests/bench_fio_test.py:34: AssertionError
python3.13-fio_plot> ----------------------------- Captured stdout call -----------------------------
python3.13-fio_plot> len(tests)=49
python3.13-fio_plot> ____________________ TestFunctions.test_generate_benchmarks ____________________
python3.13-fio_plot> self = <bench_fio_test.TestFunctions testMethod=test_generate_benchmarks>
python3.13-fio_plot>     def test_generate_benchmarks(self):
python3.13-fio_plot> >       self.assertEqual(len(supporting.generate_test_list(self.settings)), 98)
python3.13-fio_plot> E       AssertionError: 49 != 98
python3.13-fio_plot> tests/bench_fio_test.py:21: AssertionError
python3.13-fio_plot> __________________ TestFunctions.test_generate_benchmarks_big __________________
python3.13-fio_plot> self = <bench_fio_test.TestFunctions testMethod=test_generate_benchmarks_big>
python3.13-fio_plot>     def test_generate_benchmarks_big(self):
python3.13-fio_plot>         self.settings["target"] = ["filea", "fileb", "filec", "filed"]
python3.13-fio_plot>         self.settings["block_size"] = ["4k", "8k", "16k", "32k"]
python3.13-fio_plot> >       self.assertEqual(len(supporting.generate_test_list(self.settings)), 1568)
python3.13-fio_plot> E       AssertionError: 784 != 1568
python3.13-fio_plot> tests/bench_fio_test.py:26: AssertionError
```
python3.13-fio_plot> =================================== FAILURES ===================================
<...>
<...>
<...>
python3.13-fio_plot> ________________________ Test3D.test_correct_bars_drawn ________________________
python3.13-fio_plot> self = <test_3d.Test3D testMethod=test_correct_bars_drawn>
python3.13-fio_plot>     def test_correct_bars_drawn(self):
python3.13-fio_plot>         settings = {
python3.13-fio_plot>             "type": ["iops"],
python3.13-fio_plot>             "rw": "read",
python3.13-fio_plot>             "source": "test",
python3.13-fio_plot>             "title": "test",
python3.13-fio_plot>             "subtitle": "",
python3.13-fio_plot>             "filter": ["read", "write"],
python3.13-fio_plot>             # intentionally using prime numbers
python3.13-fio_plot>             "iodepth": [2, 3],
python3.13-fio_plot>             "numjobs": [5, 11],
python3.13-fio_plot>             "maxjobs": 32,
python3.13-fio_plot>             "maxdepth": 32,
python3.13-fio_plot>             "max_z": None,
python3.13-fio_plot>             "dpi": 200,
python3.13-fio_plot>             "disable_fio_version": 2.0,
python3.13-fio_plot>             "output_filename": "/tmp/test.png"
python3.13-fio_plot>         }
python3.13-fio_plot>
python3.13-fio_plot>         dataset = [{"data": []}
python3.13-fio_plot>         for iodepth in settings["iodepth"]:
python3.13-fio_plot>             for numjobs in settings["numjobs"]:
python3.13-fio_plot>                 dataset[0]["data"].append(
python3.13-fio_plot>                     {
python3.13-fio_plot>                         "fio_version": 3.1,
python3.13-fio_plot>                         "iodepth": str(iodepth),
python3.13-fio_plot>                         "numjobs": str(numjobs),
python3.13-fio_plot>                         "rw": "read",
python3.13-fio_plot>                         "type": "read",
python3.13-fio_plot>                         "iops": iodepth * numjobs,
python3.13-fio_plot>                     }
python3.13-fio_plot>                 )
python3.13-fio_plot> >       plot_3d(settings, dataset)
python3.13-fio_plot> tests/test_3d.py:38:
python3.13-fio_plot> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
python3.13-fio_plot> fio_plot/fiolib/bar3d.py:174: in plot_3d
python3.13-fio_plot>     supporting.create_title_and_sub(
python3.13-fio_plot> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
python3.13-fio_plot> settings = {'disable_fio_version': 2.0, 'dpi': 200, 'filter': ['read', 'write'], 'iodepth': [2, 3], ...}
python3.13-fio_plot> plt = <module 'matplotlib.pyplot' from '/nix/store/1akc2bq0qhxk99lgd4yj5lmz4gwh16x7-python3.13-matplotlib-3.10.3/lib/python3.13/site-packages/matplotlib/pyplot.py'>
python3.13-fio_plot> bs = None, skip_keys = ['iodepth', 'numjobs'], sub_x_offset = 0.57
python3.13-fio_plot> sub_y_offset = 1.15
python3.13-fio_plot>     def create_title_and_sub(
python3.13-fio_plot>         settings, plt, bs=None, skip_keys=[], sub_x_offset=0, sub_y_offset=0
python3.13-fio_plot>     ):
python3.13-fio_plot>         #
python3.13-fio_plot>         # Offset title/subtitle if there is a 3rd y-axis
python3.13-fio_plot>         #
python3.13-fio_plot>         number_of_types = len(settings["type"])
python3.13-fio_plot>         y_offset = 1.02
python3.13-fio_plot>         if number_of_types <= 2:
python3.13-fio_plot>             x_offset = 0.5
python3.13-fio_plot>         else:
python3.13-fio_plot>             x_offset = 0.425
python3.13-fio_plot>
python3.13-fio_plot>         if sub_x_offset > 0:
python3.13-fio_plot>             x_offset = sub_x_offset
python3.13-fio_plot>         if sub_y_offset > 0:
python3.13-fio_plot>             y_offset = sub_y_offset
python3.13-fio_plot>
python3.13-fio_plot>         #
python3.13-fio_plot>         # plt.subtitle sets title and plt.title sets subtitle ....
python3.13-fio_plot>         #
python3.13-fio_plot> >       plt.suptitle(settings["title"], fontsize=settings["title_fontsize"])
python3.13-fio_plot> E       KeyError: 'title_fontsize'
python3.13-fio_plot> fio_plot/fiolib/supporting.py:382: KeyError
```
```
python3.13-fio_plot> =================================== FAILURES ===================================
python3.13-fio_plot> ______________ TestFunctions.test_generate_output_directory_mixed ______________
python3.13-fio_plot> self = <bench_fio_test.TestFunctions testMethod=test_generate_output_directory_mixed>
python3.13-fio_plot>     def test_generate_output_directory_mixed(self):
python3.13-fio_plot>         self.settings["mode"] = ["rw"]
python3.13-fio_plot>         self.settings["rwmixread"] = [75]
python3.13-fio_plot>         self.settings["loop_items"].append("rwmixread")
python3.13-fio_plot>         tests = supporting.generate_test_list(self.settings)
python3.13-fio_plot>         benchmark = tests[0]
python3.13-fio_plot>         self.assertEqual(
python3.13-fio_plot> >           supporting.generate_output_directory(self.settings, benchmark),
python3.13-fio_plot>             "output_directory/device/rw75/4k",
python3.13-fio_plot>         )
python3.13-fio_plot> tests/bench_fio_test.py:52:
python3.13-fio_plot> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
python3.13-fio_plot> settings = {'basename_list': ['precondition_template'], 'benchmarks': 49, 'block_size': ['4k'], 'ceph_pool': None, ...}
python3.13-fio_plot> benchmark = {'block_size': '4k', 'iodepth': 1, 'mode': 'rw', 'numjobs': 1, ...}
python3.13-fio_plot>     def generate_output_directory(settings, benchmark):
python3.13-fio_plot>         settings["output"] = os.path.expanduser(settings["output"])
python3.13-fio_plot>         if benchmark["mode"] in settings["mixed"]:
python3.13-fio_plot>             directory = (
python3.13-fio_plot> >               f"{settings['output']}/{os.path.basename(benchmark['target_base'])}/"
python3.13-fio_plot>                 f"{benchmark['mode']}{benchmark['rwmixread']}/{benchmark['block_size']}"
python3.13-fio_plot>             )
python3.13-fio_plot> E           KeyError: 'target_base'
python3.13-fio_plot> bench_fio/benchlib/supporting.py:45: KeyError
python3.13-fio_plot> _____________ TestFunctions.test_generate_output_directory_regular _____________
python3.13-fio_plot> self = <bench_fio_test.TestFunctions testMethod=test_generate_output_directory_regular>
python3.13-fio_plot>     def test_generate_output_directory_regular(self):
python3.13-fio_plot>         benchmark = self.tests[0]
python3.13-fio_plot>         self.assertEqual(
python3.13-fio_plot> >           supporting.generate_output_directory(self.settings, benchmark),
python3.13-fio_plot>             "output_directory/device/4k",
python3.13-fio_plot>         )
python3.13-fio_plot> tests/bench_fio_test.py:41:
python3.13-fio_plot> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
python3.13-fio_plot> settings = {'basename_list': ['precondition_template'], 'benchmarks': 49, 'block_size': ['4k'], 'ceph_pool': None, ...}
python3.13-fio_plot> benchmark = {'block_size': '4k', 'iodepth': 1, 'mode': 'randread', 'numjobs': 1, ...}
python3.13-fio_plot>     def generate_output_directory(settings, benchmark):
python3.13-fio_plot>         settings["output"] = os.path.expanduser(settings["output"])
python3.13-fio_plot>         if benchmark["mode"] in settings["mixed"]:
python3.13-fio_plot>             directory = (
python3.13-fio_plot>                 f"{settings['output']}/{os.path.basename(benchmark['target_base'])}/"
python3.13-fio_plot>                 f"{benchmark['mode']}{benchmark['rwmixread']}/{benchmark['block_size']}"
python3.13-fio_plot>             )
python3.13-fio_plot>         else:
python3.13-fio_plot> >           directory = f"{settings['output']}/{os.path.basename(benchmark['target_base'])}/{benchmark['block_size']}"
python3.13-fio_plot> E           KeyError: 'target_base'
python3.13-fio_plot> bench_fio/benchlib/supporting.py:49: KeyError
```
@louwrentius
Copy link
Owner

Thanks for the pr, I have to look into it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants