trustformers-mobile 0.1.1

Mobile deployment support for TrustformeRS (iOS, Android)
Documentation
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
//! Mobile Testing Configuration
//!
//! This module contains all configuration structures for the mobile testing framework.

use serde::{Deserialize, Serialize};
use std::time::Duration;

/// Mobile testing configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MobileTestingConfig {
    /// Enable testing framework
    pub enabled: bool,
    /// Maximum test duration in seconds
    pub max_test_duration: Duration,
    /// Performance benchmark configuration
    pub benchmark_config: BenchmarkConfig,
    /// Battery testing configuration
    pub battery_test_config: BatteryTestConfig,
    /// Stress testing configuration
    pub stress_test_config: StressTestConfig,
    /// Memory testing configuration
    pub memory_test_config: MemoryTestConfig,
    /// Enable detailed logging
    pub enable_detailed_logging: bool,
    /// Output directory for test results
    pub output_directory: String,
    /// Device farm configuration
    pub device_farm_config: Option<DeviceFarmConfig>,
}

/// Performance benchmark configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkConfig {
    pub warmup_iterations: usize,
    pub benchmark_iterations: usize,
    pub input_sizes: Vec<Vec<usize>>,
    pub target_latency_ms: f32,
    pub target_throughput: f32,
    pub precision_modes: Vec<PrecisionMode>,
    pub power_modes: Vec<PowerMode>,
    pub thermal_conditions: Vec<ThermalCondition>,
}

/// Battery testing configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatteryTestConfig {
    pub test_duration: Duration,
    pub inference_frequency: Duration,
    pub power_measurement_interval: Duration,
    pub target_power_consumption_mw: f32,
    pub target_battery_drain_percent_per_hour: f32,
}

/// Stress testing configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StressTestConfig {
    pub test_duration: Duration,
    pub concurrent_threads: usize,
    pub memory_pressure_enabled: bool,
    pub thermal_stress_enabled: bool,
    pub cpu_stress_level: f32,
    pub memory_stress_level: f32,
}

/// Memory testing configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryTestConfig {
    pub enable_leak_detection: bool,
    pub memory_stress_duration: Duration,
    pub max_memory_usage_mb: usize,
    pub gc_stress_enabled: bool,
}

/// Device farm configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmConfig {
    /// Selected device farm provider
    pub provider: DeviceFarmProvider,
    /// Provider-specific credentials
    pub credentials: DeviceFarmCredentials,
    /// Execution settings
    pub execution_settings: DeviceFarmExecutionSettings,
    /// Device selection criteria
    pub device_selection: DeviceSelectionCriteria,
    /// Parallel execution settings
    pub parallelism: DeviceFarmParallelism,
    /// Timeout settings
    pub timeouts: DeviceFarmTimeouts,
    /// Result aggregation settings
    pub result_aggregation: ResultAggregationSettings,
}

/// Device farm providers
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DeviceFarmProvider {
    AWS {
        region: String,
        project_name: String,
    },
    Firebase {
        project_id: String,
        test_lab_id: String,
    },
    BrowserStack {
        username: String,
        build_name: String,
    },
    SauceLabs {
        datacenter: String,
        build_name: String,
    },
    AppCenter {
        owner_name: String,
        app_name: String,
    },
    Local {
        device_pool_size: usize,
        devices: Vec<String>,
    },
}

/// Device farm credentials
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmCredentials {
    pub access_key: Option<String>,
    pub secret_key: Option<String>,
    pub api_token: Option<String>,
    pub username: Option<String>,
    pub password: Option<String>,
    pub service_account_json: Option<String>,
}

/// Device farm execution settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmExecutionSettings {
    /// Maximum parallel device executions
    pub max_parallel_devices: usize,
    /// Test execution timeout per device
    pub execution_timeout: Duration,
    /// Retry failed tests
    pub retry_failed_tests: bool,
    /// Maximum retry attempts
    pub max_retry_attempts: usize,
    /// Video recording enabled
    pub video_recording: bool,
    /// Screenshot capture enabled
    pub screenshot_capture: bool,
    /// Performance monitoring enabled
    pub performance_monitoring: bool,
    /// Device logs collection enabled
    pub device_logs: bool,
    /// Network logs collection enabled
    pub network_logs: bool,
    /// App crash logs collection enabled
    pub app_crash_logs: bool,
}

/// Device selection criteria
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceSelectionCriteria {
    /// Target device types
    pub device_types: Vec<DeviceType>,
    /// OS version requirements
    pub os_versions: Vec<String>,
    /// Hardware requirements
    pub hardware_requirements: HardwareRequirements,
    /// GPU requirements
    pub gpu_requirements: GpuRequirements,
    /// Geographic regions
    pub regions: Vec<String>,
    /// Device availability requirements
    pub availability_requirements: Vec<String>,
}

/// Device type enum
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum DeviceType {
    Phone,
    Tablet,
    Watch,
    TV,
    Auto,
    Generic,
}

/// Hardware requirements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HardwareRequirements {
    /// Minimum RAM in MB
    pub min_ram_mb: usize,
    /// Minimum CPU cores
    pub min_cpu_cores: usize,
    /// Minimum storage in GB
    pub min_storage_gb: usize,
    /// Required sensors
    pub required_sensors: Vec<String>,
    /// Required connectivity
    pub required_connectivity: Vec<String>,
}

/// GPU requirements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GpuRequirements {
    /// GPU vendor requirements
    pub vendor: Option<String>,
    /// Minimum GPU memory in MB
    pub min_memory_mb: Option<usize>,
    /// Required GPU features
    pub required_features: Vec<String>,
    /// Compute capability requirements
    pub min_compute_capability: Option<f32>,
}

/// Device farm parallelism settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmParallelism {
    /// Test distribution strategy
    pub distribution_strategy: TestDistributionStrategy,
    /// Load balancing settings
    pub load_balancing: LoadBalancingSettings,
}

/// Test distribution strategies
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TestDistributionStrategy {
    RoundRobin,
    LeastLoaded,
    Random,
    DeviceCapabilityBased,
    GeographicOptimal,
    CostOptimal,
    PerformanceOptimal,
    AvailabilityBased,
    CustomWeighted { weights: Vec<(String, f32)> },
}

/// Load balancing settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoadBalancingSettings {
    /// Enable dynamic rebalancing
    pub dynamic_rebalancing: bool,
    /// Rebalancing interval
    pub rebalancing_interval: Duration,
}

/// Device farm timeout settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmTimeouts {
    /// Device allocation timeout
    pub device_allocation_timeout: Duration,
    /// Test execution timeout
    pub test_execution_timeout: Duration,
    /// Result collection timeout
    pub result_collection_timeout: Duration,
    /// Device cleanup timeout
    pub device_cleanup_timeout: Duration,
    /// Overall session timeout
    pub overall_session_timeout: Duration,
}

/// Result aggregation settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResultAggregationSettings {
    /// Statistical analysis settings
    pub statistical_analysis: StatisticalAnalysisSettings,
    /// Report generation settings
    pub report_generation: ReportGenerationSettings,
}

/// Statistical analysis settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StatisticalAnalysisSettings {
    /// Calculate percentiles
    pub calculate_percentiles: bool,
    /// Percentile levels to calculate
    pub percentile_levels: Vec<f32>,
    /// Statistical confidence level
    pub confidence_level: f32,
    /// Outlier detection enabled
    pub outlier_detection: bool,
}

/// Report generation settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReportGenerationSettings {
    /// Output formats
    pub formats: Vec<ReportFormat>,
    /// Include detailed device info
    pub include_device_details: bool,
    /// Include performance charts
    pub include_charts: bool,
    /// Include raw data
    pub include_raw_data: bool,
}

/// Report format enum
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ReportFormat {
    JSON,
    XML,
    HTML,
    PDF,
    CSV,
    Markdown,
}

/// Precision mode for benchmarks
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PrecisionMode {
    FP32,
    FP16,
    INT8,
    INT4,
    Mixed,
}

/// Power mode for testing
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PowerMode {
    HighPerformance,
    Balanced,
    PowerSaver,
    Adaptive,
}

/// Thermal condition for testing
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ThermalCondition {
    Cool,
    Nominal,
    Warm,
    Hot,
    Critical,
}

/// Target performance metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TargetMetrics {
    pub target_latency_ms: f32,
    pub target_throughput_ops_per_sec: f32,
    pub target_accuracy_percent: f32,
    pub target_memory_usage_mb: usize,
    pub target_power_consumption_mw: f32,
    pub target_thermal_efficiency: f32,
}

// Default implementations
impl Default for MobileTestingConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            max_test_duration: Duration::from_secs(300), // 5 minutes
            benchmark_config: BenchmarkConfig::default(),
            battery_test_config: BatteryTestConfig::default(),
            stress_test_config: StressTestConfig::default(),
            memory_test_config: MemoryTestConfig::default(),
            enable_detailed_logging: true,
            output_directory: "./test_results".to_string(),
            device_farm_config: None,
        }
    }
}

impl Default for BenchmarkConfig {
    fn default() -> Self {
        Self {
            warmup_iterations: 10,
            benchmark_iterations: 100,
            input_sizes: vec![
                vec![1, 224, 224, 3], // Image input
                vec![1, 512],         // Text input
                vec![1, 1024],        // Feature vector
            ],
            target_latency_ms: 100.0,
            target_throughput: 10.0,
            precision_modes: vec![PrecisionMode::FP32, PrecisionMode::FP16],
            power_modes: vec![PowerMode::Balanced],
            thermal_conditions: vec![ThermalCondition::Nominal],
        }
    }
}

impl Default for BatteryTestConfig {
    fn default() -> Self {
        Self {
            test_duration: Duration::from_secs(3600),        // 1 hour
            inference_frequency: Duration::from_millis(100), // 10 FPS
            power_measurement_interval: Duration::from_secs(1),
            target_power_consumption_mw: 500.0,
            target_battery_drain_percent_per_hour: 5.0,
        }
    }
}

impl Default for StressTestConfig {
    fn default() -> Self {
        Self {
            test_duration: Duration::from_secs(600), // 10 minutes
            concurrent_threads: 4,
            memory_pressure_enabled: true,
            thermal_stress_enabled: true,
            cpu_stress_level: 0.8,
            memory_stress_level: 0.8,
        }
    }
}

impl Default for MemoryTestConfig {
    fn default() -> Self {
        Self {
            enable_leak_detection: true,
            memory_stress_duration: Duration::from_secs(300), // 5 minutes
            max_memory_usage_mb: 512,
            gc_stress_enabled: true,
        }
    }
}