Skip to content

Commit

Permalink
Remove parameterized (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk authored Nov 29, 2024
1 parent 7399cbf commit 08fd4ba
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 150 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dev = [
"pytest == 8.0.0",
"pytest-xdist == 3.5.0",
"hypothesis == 6.99.6",
"parameterized == 0.8.1",
# Documentation
"pep8-naming == 0.13.3",
"Sphinx == 5.1.1",
Expand Down
48 changes: 19 additions & 29 deletions test/core/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from collections import deque
from typing import Iterable, Callable
from parameterized import parameterized, parameterized_class

from transactron.testing import TestCaseWithSimulator, TestbenchIO, data_layout

Expand Down Expand Up @@ -119,16 +118,14 @@ def elaborate(self, platform):
return tm


@parameterized_class(
("name", "scheduler"),
@pytest.mark.parametrize(
"scheduler",
[
("trivial_roundrobin", trivial_roundrobin_cc_scheduler),
("eager_deterministic", eager_deterministic_cc_scheduler),
trivial_roundrobin_cc_scheduler,
eager_deterministic_cc_scheduler,
],
)
class TestTransactionConflict(TestCaseWithSimulator):
scheduler: TransactionScheduler

def setup_method(self):
random.seed(42)

Expand Down Expand Up @@ -182,21 +179,22 @@ def chk(x: int):

return self.make_process(self.m.out, prob, self.out_stream, tgt, chk)

@parameterized.expand(
@pytest.mark.parametrize(
"name, prob1, prob2, probout",
[
("fullcontention", 1, 1, 1),
("highcontention", 0.5, 0.5, 0.75),
("lowcontention", 0.1, 0.1, 0.5),
]
],
)
def test_calls(self, name, prob1, prob2, probout):
def test_calls(self, name, scheduler: TransactionScheduler, prob1, prob2, probout):
self.in1_stream = range(0, 100)
self.in2_stream = range(100, 200)
self.out_stream = range(200, 400)
self.in_expected = deque()
self.out1_expected = deque()
self.out2_expected = deque()
self.m = TransactionConflictTestCircuit(self.__class__.scheduler)
self.m = TransactionConflictTestCircuit(scheduler)

with self.run_simulation(self.m, add_transaction_module=False) as sim:
sim.add_testbench(self.make_in1_process(prob1))
Expand Down Expand Up @@ -276,18 +274,14 @@ def _():
return m


@parameterized_class(
("name", "circuit"), [("transaction", TransactionPriorityTestCircuit), ("method", MethodPriorityTestCircuit)]
)
@pytest.mark.parametrize("circuit", [TransactionPriorityTestCircuit, MethodPriorityTestCircuit])
class TestTransactionPriorities(TestCaseWithSimulator):
circuit: type[PriorityTestCircuit]

def setup_method(self):
random.seed(42)

@parameterized.expand([(Priority.UNDEFINED,), (Priority.LEFT,), (Priority.RIGHT,)])
def test_priorities(self, priority: Priority):
m = self.circuit(priority)
@pytest.mark.parametrize("priority", [Priority.UNDEFINED, Priority.LEFT, Priority.RIGHT])
def test_priorities(self, circuit: type[PriorityTestCircuit], priority: Priority):
m = circuit(priority)

async def process(sim):
to_do = 5 * [(0, 1), (1, 0), (1, 1)]
Expand All @@ -306,9 +300,9 @@ async def process(sim):
with self.run_simulation(m) as sim:
sim.add_testbench(process)

@parameterized.expand([(Priority.UNDEFINED,), (Priority.LEFT,), (Priority.RIGHT,)])
def test_unsatisfiable(self, priority: Priority):
m = self.circuit(priority, True)
@pytest.mark.parametrize("priority", [Priority.UNDEFINED, Priority.LEFT, Priority.RIGHT])
def test_unsatisfiable(self, circuit: type[PriorityTestCircuit], priority: Priority):
m = circuit(priority, True)

import graphlib

Expand Down Expand Up @@ -362,17 +356,13 @@ def _():
return tm


@parameterized_class(
("name", "circuit"), [("transaction", NestedTransactionsTestCircuit), ("method", NestedMethodsTestCircuit)]
)
@pytest.mark.parametrize("circuit", [NestedTransactionsTestCircuit, NestedMethodsTestCircuit])
class TestNested(TestCaseWithSimulator):
circuit: type[SchedulingTestCircuit]

def setup_method(self):
random.seed(42)

def test_scheduling(self):
m = self.circuit()
def test_scheduling(self, circuit: type[SchedulingTestCircuit]):
m = circuit()

async def process(sim):
to_do = 5 * [(0, 1), (1, 0), (1, 1)]
Expand Down
11 changes: 5 additions & 6 deletions test/lib/test_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from operator import and_
from functools import reduce
from typing import TypeAlias
from parameterized import parameterized

from amaranth import *
from transactron import *
Expand Down Expand Up @@ -59,23 +58,23 @@ async def reader(sim: TestbenchContext):


class TestFIFO(TestFifoBase):
@parameterized.expand([(0, 0), (2, 0), (0, 2), (1, 1)])
@pytest.mark.parametrize("writer_rand, reader_rand", [(0, 0), (2, 0), (0, 2), (1, 1)])
def test_fifo(self, writer_rand, reader_rand):
self.do_test_fifo(FIFO, writer_rand=writer_rand, reader_rand=reader_rand, fifo_kwargs=dict(depth=4))


class TestConnect(TestFifoBase):
@parameterized.expand([(0, 0), (2, 0), (0, 2), (1, 1)])
@pytest.mark.parametrize("writer_rand, reader_rand", [(0, 0), (2, 0), (0, 2), (1, 1)])
def test_fifo(self, writer_rand, reader_rand):
self.do_test_fifo(Connect, writer_rand=writer_rand, reader_rand=reader_rand)

@parameterized.expand([(0, 0), (2, 0), (0, 2), (1, 1)])
@pytest.mark.parametrize("writer_rand, reader_rand", [(0, 0), (2, 0), (0, 2), (1, 1)])
def test_rev_fifo(self, writer_rand, reader_rand):
self.do_test_fifo(RevConnect, writer_rand=writer_rand, reader_rand=reader_rand)


class TestForwarder(TestFifoBase):
@parameterized.expand([(0, 0), (2, 0), (0, 2), (1, 1)])
@pytest.mark.parametrize("writer_rand, reader_rand", [(0, 0), (2, 0), (0, 2), (1, 1)])
def test_fifo(self, writer_rand, reader_rand):
self.do_test_fifo(Forwarder, writer_rand=writer_rand, reader_rand=reader_rand)

Expand Down Expand Up @@ -116,7 +115,7 @@ async def process(sim: TestbenchContext):


class TestPipe(TestFifoBase):
@parameterized.expand([(0, 0), (2, 0), (0, 2), (1, 1)])
@pytest.mark.parametrize("writer_rand, reader_rand", [(0, 0), (2, 0), (0, 2), (1, 1)])
def test_fifo(self, writer_rand, reader_rand):
self.do_test_fifo(Pipe, writer_rand=writer_rand, reader_rand=reader_rand)

Expand Down
16 changes: 4 additions & 12 deletions test/lib/test_fifo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
from amaranth import *

from transactron.lib import AdapterTrans, BasicFifo

from transactron.testing import TestCaseWithSimulator, TestbenchIO, data_layout, TestbenchContext
from collections import deque
from parameterized import parameterized_class
import random


Expand All @@ -24,18 +24,10 @@ def elaborate(self, platform):
return m


@parameterized_class(
("name", "depth"),
[
("notpower", 5),
("power", 4),
],
)
class TestBasicFifo(TestCaseWithSimulator):
depth: int

def test_randomized(self):
fifoc = BasicFifoTestCircuit(depth=self.depth)
@pytest.mark.parametrize("depth", [5, 4])
def test_randomized(self, depth):
fifoc = BasicFifoTestCircuit(depth=depth)
expq = deque()

cycles = 256
Expand Down
54 changes: 22 additions & 32 deletions test/lib/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import json
import random
import queue
import pytest
from typing import Type
from enum import IntFlag, IntEnum, auto, Enum

from parameterized import parameterized_class

from amaranth import *

from transactron.lib.metrics import *
Expand Down Expand Up @@ -229,8 +228,8 @@ def _(data):
return m


@parameterized_class(
("bucket_count", "sample_width"),
@pytest.mark.parametrize(
"bucket_count, sample_width",
[
(5, 5), # last bucket is [8, inf), max sample=31
(8, 5), # last bucket is [64, inf), max sample=31
Expand All @@ -239,24 +238,21 @@ def _(data):
],
)
class TestHwHistogram(TestCaseWithSimulator):
bucket_count: int
sample_width: int

def test_histogram(self):
def test_histogram(self, bucket_count: int, sample_width: int):
random.seed(42)

m = SimpleTestCircuit(ExpHistogramCircuit(bucket_cnt=self.bucket_count, sample_width=self.sample_width))
m = SimpleTestCircuit(ExpHistogramCircuit(bucket_cnt=bucket_count, sample_width=sample_width))
DependencyContext.get().add_dependency(HwMetricsEnabledKey(), True)

max_sample_value = 2**self.sample_width - 1
max_sample_value = 2**sample_width - 1

async def test_process(sim):
min = max_sample_value
max = 0
sum = 0
count = 0

buckets = [0] * self.bucket_count
buckets = [0] * bucket_count

for _ in range(500):
if random.randrange(3) == 0:
Expand All @@ -267,8 +263,8 @@ async def test_process(sim):
max = value
sum += value
count += 1
for i in range(self.bucket_count):
if value < 2**i or i == self.bucket_count - 1:
for i in range(bucket_count):
if value < 2**i or i == bucket_count - 1:
buckets[i] += 1
break
await m.method.call(sim, data=value)
Expand All @@ -283,7 +279,7 @@ async def test_process(sim):
assert count == sim.get(histogram.count.value)

total_count = 0
for i in range(self.bucket_count):
for i in range(bucket_count):
bucket_value = sim.get(histogram.buckets[i].value)
total_count += bucket_value
assert buckets[i] == bucket_value
Expand All @@ -310,8 +306,8 @@ def check_latencies(self, sim, m: SimpleTestCircuit, latencies: list[int]):
assert count == sim.get(m._dut.histogram.buckets[i].value)


@parameterized_class(
("slots_number", "expected_consumer_wait"),
@pytest.mark.parametrize(
"slots_number, expected_consumer_wait",
[
(2, 5),
(2, 10),
Expand All @@ -322,13 +318,10 @@ def check_latencies(self, sim, m: SimpleTestCircuit, latencies: list[int]):
],
)
class TestFIFOLatencyMeasurer(TestLatencyMeasurerBase):
slots_number: int
expected_consumer_wait: float

def test_latency_measurer(self):
def test_latency_measurer(self, slots_number: int, expected_consumer_wait: float):
random.seed(42)

m = SimpleTestCircuit(FIFOLatencyMeasurer("latency", slots_number=self.slots_number, max_latency=300))
m = SimpleTestCircuit(FIFOLatencyMeasurer("latency", slots_number=slots_number, max_latency=300))
DependencyContext.get().add_dependency(HwMetricsEnabledKey(), True)

latencies: list[int] = []
Expand Down Expand Up @@ -357,7 +350,7 @@ async def consumer(sim: TestbenchContext):

latencies.append(sim.get(ticks) - event_queue.get())

await self.random_wait_geom(sim, 1.0 / self.expected_consumer_wait)
await self.random_wait_geom(sim, 1.0 / expected_consumer_wait)

self.check_latencies(sim, m, latencies)

Expand All @@ -366,8 +359,8 @@ async def consumer(sim: TestbenchContext):
sim.add_testbench(consumer)


@parameterized_class(
("slots_number", "expected_consumer_wait"),
@pytest.mark.parametrize(
"slots_number, expected_consumer_wait",
[
(2, 5),
(2, 10),
Expand All @@ -378,19 +371,16 @@ async def consumer(sim: TestbenchContext):
],
)
class TestIndexedLatencyMeasurer(TestLatencyMeasurerBase):
slots_number: int
expected_consumer_wait: float

def test_latency_measurer(self):
def test_latency_measurer(self, slots_number: int, expected_consumer_wait: float):
random.seed(42)

m = SimpleTestCircuit(TaggedLatencyMeasurer("latency", slots_number=self.slots_number, max_latency=300))
m = SimpleTestCircuit(TaggedLatencyMeasurer("latency", slots_number=slots_number, max_latency=300))
DependencyContext.get().add_dependency(HwMetricsEnabledKey(), True)

latencies: list[int] = []

events = list(0 for _ in range(self.slots_number))
free_slots = list(k for k in range(self.slots_number))
events = list(0 for _ in range(slots_number))
free_slots = list(k for k in range(slots_number))
used_slots: list[int] = []

finish = False
Expand Down Expand Up @@ -433,7 +423,7 @@ async def consumer(sim):
used_slots.remove(slot_id)
free_slots.append(slot_id)

await self.random_wait_geom(sim, 1.0 / self.expected_consumer_wait)
await self.random_wait_geom(sim, 1.0 / expected_consumer_wait)

self.check_latencies(sim, m, latencies)

Expand Down
8 changes: 4 additions & 4 deletions test/lib/test_transformers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import random
from parameterized import parameterized

from amaranth import *
from transactron import *
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_method_filter_with_methods(self):
with self.run_simulation(m) as sim:
sim.add_testbench(self.source)

@parameterized.expand([(True,), (False,)])
@pytest.mark.parametrize("use_condition", [True, False])
def test_method_filter_plain(self, use_condition):
self.initialize()

Expand Down Expand Up @@ -182,7 +182,7 @@ def elaborate(self, platform):


class TestMethodProduct(TestCaseWithSimulator):
@parameterized.expand([(1, False), (2, False), (5, True)])
@pytest.mark.parametrize("targets, add_combiner", [(1, False), (2, False), (5, True)])
def test_method_product(self, targets: int, add_combiner: bool):
random.seed(14)

Expand Down Expand Up @@ -226,7 +226,7 @@ async def method_process(sim: TestbenchContext):


class TestMethodTryProduct(TestCaseWithSimulator):
@parameterized.expand([(1, False), (2, False), (5, True)])
@pytest.mark.parametrize("targets, add_combiner", [(1, False), (2, False), (5, True)])
def test_method_try_product(self, targets: int, add_combiner: bool):
random.seed(14)

Expand Down
Loading

0 comments on commit 08fd4ba

Please sign in to comment.