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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
//!
//! This file is part of Ri.
//! The Ri project belongs to the Dunimd Team.
//!
//! Licensed under the Apache License, Version 2.0 (the "License");
//! You may not use this file except in compliance with the License.
//! You may obtain a copy of the License at
//!
//! http://www.apache.org/licenses/LICENSE-2.0
//!
//! Unless required by applicable law or agreed to in writing, software
//! distributed under the License is distributed on an "AS IS" BASIS,
//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//! See the License for the specific language governing permissions and
//! limitations under the License.
use ;
use ;
/// Device discovery and resource scheduling test module for Ri tooling.
///
/// This module provides comprehensive test coverage for the device management
/// components that handle hardware resource discovery and scheduling in the
/// Ri tooling layer. The tests validate device detection, capability matching,
/// and resource allocation strategies.
///
/// ## Test Coverage
///
/// - **Device Discovery Engine**: Tests the scanning functionality that detects
/// and identifies hardware devices from scan results, including device type
/// classification based on detected capabilities and metadata.
///
/// - **Device Capability Matching**: Validates the capability matching logic
/// that determines whether a device satisfies resource requirements, including
/// memory, compute units, bandwidth, and custom capability constraints.
///
/// - **Resource Scheduling**: Tests the scheduling algorithm that selects
/// appropriate devices for resource requests based on availability and
/// requirement matching, prioritizing devices that fully satisfy constraints.
///
/// - **Multi-Device Selection**: Validates scenarios with multiple candidate
/// devices, verifying that the scheduler correctly identifies and selects
/// the optimal device based on resource requirements and priorities.
///
/// ## Design Principles
///
/// The device discovery system supports hot-plugging and dynamic device
/// detection, enabling runtime discovery of hardware resources. Tests verify
/// that scan results are correctly transformed into device representations
/// with appropriate type classification.
///
/// The capability model uses a flexible key-value format for custom
/// capabilities, enabling extension to new device types and vendor-specific
/// features without modifying core scheduling logic. Tests verify that
/// capability matching correctly interprets requirement constraints.
///
/// The resource scheduler implements a best-fit allocation strategy,
/// selecting devices that satisfy requirements with minimal excess capacity.
Tests verify that scheduling decisions correctly balance multiple
/// requirements including memory, compute, bandwidth, and custom features.
/// Tests RiDeviceDiscoveryEngine device discovery from scan results.
///
/// Verifies that the discovery engine can transform raw scan results
/// into device representations with proper type classification.
///
/// ## Discovery Process
///
/// 1. **Scan Results Input**: Raw device information from system scan
/// - device_id: Unique identifier for the device
/// - device_name: Human-readable name
/// - device_info: Key-value metadata about the device
///
/// 2. **Device Classification**: The engine analyzes device info to determine type
/// - NVIDIA GPUs are classified as GPU type
/// - CPUs are classified as CPU type
/// - Other accelerators use type inference
///
/// 3. **Device Output**: Transformed device representation
/// - RiDevice with unique ID
/// - Classified device type
/// - Initial status set to Unknown
///
/// ## Test Scenario
///
/// 1. Create a discovery engine instance
/// 2. Provide a scan result for an NVIDIA GPU with device info
/// 3. Call discover_devices() with the scan results
/// 4. Verify exactly one device is returned
/// 5. Verify the device type is classified as GPU
///
/// ## Expected Behavior
///
/// - The scan result is transformed into a device
/// - The device has GPU type classification
/// - Device count matches input count
/// Tests RiResourceScheduler device selection for resource requests.
///
/// Verifies that the scheduler can match resource requests to
/// available devices based on capability requirements.
///
/// ## Scheduling Algorithm
///
/// The scheduler implements a best-fit selection strategy:
/// 1. Filter devices by required type
/// 2. Filter devices meeting all capability requirements
/// 3. If multiple candidates exist, select one (implementation-specific)
/// 4. Return the selected device ID
///
/// ## Capability Requirements
///
/// - **required_memory_gb**: Device must have at least this much memory
/// - **required_compute_units**: Device must have at least this many compute units
/// - **required_bandwidth_gbps**: Device must have at least this bandwidth
/// - **required_custom_capabilities**: Device must have all specified capabilities
///
/// ## Test Scenario
///
/// 1. Create a resource scheduler
/// 2. Define a request requiring 8GB memory, 256 compute units, 100Gbps bandwidth
/// 3. Create a device with sufficient capabilities (16GB, 512 units, 900Gbps, CUDA support)
/// 4. Call schedule_resource() with request and devices
/// 5. Verify the scheduler selects the device
///
/// ## Expected Behavior
///
/// - The scheduler finds a matching device
/// - The returned device ID matches the input device
/// - The selected device satisfies all requirements