Command Palette

Search for a command to run...

Назад к скиллам
скилл № 09875

test-patterns

Test structure for this repo: Pattern A (val/) vs Pattern B (projects/components/), the mandatory cocotb_test_* prefix, pytest function naming, the three…

БесплатноБез исполняемых скриптов
sean-gallowayот sean-galloway★ 30 звёзд на GitHub

Установить test-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Test patterns

Moved out of the root CLAUDE.md, which loaded all of this into every session whether or not a test was in scope. /GLOBAL_REQUIREMENTS.md remains the enforcement authority and wins on conflict.

Writing Tests

Every RTL module requires a test!

# Run specific test
pytest val/{subsystem}/test_{module}.py -v

# Run all tests in subsystem
pytest val/{subsystem}/ -v

# Run with coverage
pytest val/{subsystem}/ --cov=rtl/{subsystem}/

Test Structure:

  1. Use CocoTB framework
  2. Import appropriate BFMs from bin/TBClasses/
  3. Target >95% functional coverage
  4. Document test methodology in file header
  5. Include waveform dumps for debugging

Test File Location:

  • val/common/test_{module}.py for rtl/common/
  • val/math/test_{module}.py for rtl/math/
  • val/amba/test_{module}.py for rtl/amba/
  • projects/components/{name}/dv/tests/ for project-specific tests (RAPIDS, STREAM, bridge, ...)

CRITICAL: Test Structure Pattern

The repository uses TWO different test patterns depending on the location:

Pattern A: Direct CocoTB (val/common/, val/amba/ areas)

import cocotb
from cocotb_test.simulator import run

# CocoTB test function - direct @cocotb.test() decorator
@cocotb.test(timeout_time=3, timeout_unit="ms")
async def fifo_test(dut):
    tb = FifoBufferTB(dut, dut.clk, dut.rst_n)
    await tb.start_clock('clk', 10, 'ns')
    # ... test logic

# Pytest wrapper function
@pytest.mark.parametrize("data_width, depth", params)
def test_fifo_buffer(request, data_width, depth):
    # ... setup paths, filelist, parameters
    run(
        python_search=[tests_dir],
        verilog_sources=verilog_sources,
        toplevel=dut_name,
        module=module,  # Python module containing cocotb tests
        # ... compilation args
    )

Pattern B: CocoTB + Pytest Wrappers (projects/components/ areas)

HARD REQUIREMENT for projects/components/: MUST use Pattern B

import cocotb
from cocotb_test.simulator import run

# 1. CocoTB test functions - prefix with "cocotb_test_*" to prevent pytest collection
@cocotb.test(timeout_time=100, timeout_unit="ms")
async def cocotb_test_basic(dut):  # ← "cocotb_test_*" prefix!
    """CocoTB test function - NOT collected by pytest"""
    tb = SimpleSRAMTB(dut)
    await tb.setup_clocks_and_reset()
    # ... test logic

@cocotb.test(timeout_time=100, timeout_unit="ms")
async def cocotb_test_stress(dut):  # ← "cocotb_test_*" prefix!
    """Another CocoTB test function"""
    tb = SimpleSRAMTB(dut)
    await tb.setup_clocks_and_reset()
    # ... stress test logic

# 2. Pytest wrapper functions - call specific cocotb_test_* functions
@pytest.mark.parametrize("addr_width, data_width", params)
def test_basic(request, addr_width, data_width):
    """Pytest wrapper - calls cocotb_test_basic"""
    module, repo_root, tests_dir, log_dir, rtl_dict = get_paths({
        'rtl_stream_fub': '../../../../rtl/fub',
    })

    verilog_sources, includes = get_sources_from_filelist(
        repo_root=repo_root,
        filelist_path='projects/components/dma-ip/stream/rtl/filelists/fub/sram_controller.f'
    )

    run(
        python_search=[tests_dir],
        verilog_sources=verilog_sources,
        includes=includes,
        toplevel=dut_name,
        module=module,
        testcase="cocotb_test_basic",  # ← Explicitly specify which cocotb function to run
        parameters=rtl_parameters,
        # ... compilation args
    )

@pytest.mark.parametrize("addr_width, data_width", params)
def test_stress(request, addr_width, data_width):
    """Pytest wrapper - calls cocotb_test_stress"""
    # ... same setup as above
    run(
        # ... same args except:
        testcase="cocotb_test_stress",  # ← Different cocotb function
        # ...
    )

Why Two Patterns?

Aspect Pattern A (val/) Pattern B (projects/)
CocoTB prefix No prefix needed cocotb_test_* prefix REQUIRED
Pytest collection Collects module Collects only wrappers
Test selection Runs all cocotb tests Runs specific test via testcase=
Use case Simple modules Complex parameterized tests
Example Counter, FIFO SRAM, engines, integration

Critical Rules for Pattern B (projects/components/):

  1. All CocoTB functions MUST be prefixed with cocotb_test_*

    • Prevents pytest from collecting them as test functions
    • Only pytest wrappers (test_*) are collected
  2. Each pytest wrapper calls ONE specific CocoTB function

    • Use testcase="cocotb_test_name" in run() call
    • Allows parameter sweeps at pytest level
  3. Testbench classes MUST be in project area

    • projects/components/{name}/dv/tbclasses/ (NOT framework!)
    • See "Organizational Requirements" section

When to Use Which Pattern:

  • Use Pattern A: Simple modules in val/common, val/amba
  • Use Pattern B: ALL tests in projects/components/
  • Never mix patterns
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл test-patterns?

Test structure for this repo: Pattern A (val/) vs Pattern B (projects/components/), the mandatory cocotb_test_* prefix, pytest function naming, the three required TB methods, and the gate/func/full level convention. Use before writing or changing any test.

Как установить скилл test-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл test-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить test-patterns с