File size: 2,393 Bytes
4344b33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# tests/test_schema.py — Tests for master JSON schema

from __future__ import annotations

import json
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))


def test_schema_exists():
    schema_path = Path("configs/schema/master_schema.json")
    assert schema_path.exists()
    schema = json.loads(schema_path.read_text())
    assert schema["$id"] is not None
    assert "definitions" in schema
    assert "interface" in schema["definitions"]
    assert "register" in schema["definitions"]
    assert "field" in schema["definitions"]
    assert "signal" in schema["definitions"]


def test_schema_has_required_top_level():
    schema_path = Path("configs/schema/master_schema.json")
    schema = json.loads(schema_path.read_text())
    assert "design_name" in schema.get("properties", {})
    assert "interfaces" in schema.get("properties", {})
    assert "registers" in schema.get("properties", {})
    assert "clock_reset" in schema.get("properties", {})
    assert "required" in schema
    assert "design_name" in schema["required"]
    assert "interfaces" in schema["required"]


def test_schema_defines_all_protocols():
    schema_path = Path("configs/schema/master_schema.json")
    schema = json.loads(schema_path.read_text())
    proto_enum = schema["definitions"]["interface"]["properties"]["protocol"]["enum"]
    assert "uart" in proto_enum
    assert "spi" in proto_enum
    assert "i2c" in proto_enum
    assert "axi" in proto_enum
    assert "axi4" in proto_enum
    assert "apb" in proto_enum
    assert "wishbone" in proto_enum


def test_schema_has_fab_validation_rules():
    schema_path = Path("configs/schema/master_schema.json")
    schema = json.loads(schema_path.read_text())
    props = schema.get("properties", {})
    assert "validation_rules" in props
    rules = props["validation_rules"]
    assert "properties" in rules
    rule_props = rules["properties"]
    assert "require_reset" in rule_props
    assert "address_alignment" in rule_props
    assert "no_reserved_holes" in rule_props


def test_schema_has_interrupts_and_memory_maps():
    schema_path = Path("configs/schema/master_schema.json")
    schema = json.loads(schema_path.read_text())
    props = schema.get("properties", {})
    assert "interrupts" in props
    assert "memory_maps" in props
    assert "assertions" in props
    assert "coverage" in props