#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Clock inventory binding and fail-before-mutation checks; no hardware.""" from dataclasses import replace from pathlib import Path import struct import sys import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'probes')) from clocktree import CounterClockBootSpec, populate_counter_clock class Tree: def __init__(self): self.props = { ('/io', 'compatible'): b'io,test\0', ('/io', 'clock-frequencies'): struct.pack('<6Q', 11, 22, 33, 44, 0, 66), ('/io/timer', 'compatible'): b'timer,test\0', ('/io/timer', 'clock-ids'): struct.pack('<2I', 1, 4), ('/cpus/cpu0', 'state'): b'running\0', } def get(self, node, key): return self.props.get((node, key)) def put(self, node, key, value): self.props[node, key] = value class ClockTreeTests(unittest.TestCase): spec = CounterClockBootSpec('/io', b'io,test', '/cpus/cpu0', '/io/timer', b'timer,test', 1, 4) def test_frequency_binding_and_serialization(self): for hz in (19200000, 24000000, 100000000, 0xffffffff): tree = Tree() populate_counter_clock(tree, self.spec, hz) self.assertEqual(tree.get('/cpus/cpu0', 'fixed-frequency'), struct.pack('