use turkos_os_portability::devices::{ compute_portability_devices_binding_digest, PortabilityDevicesCoordinator, PortabilityDevicesError, PortabilityDevicesRequest, EXPECTED_CASE_BOUND_SUPPORT_CELLS, EXPECTED_DEVICE_DECISION_PROFILES, EXPECTED_DISTINCT_NON_SUPPORT_STATES, EXPECTED_UNTESTED_SUPPORTED_LABELS, PORTABILITY_DEVICES_ACCEPTANCE, PORTABILITY_DEVICES_COUNTEREXAMPLE, PORTABILITY_DEVICES_INVARIANT, PORTABILITY_DEVICES_POSITIVE, PORTABILITY_DEVICES_SCHEMA, }; fn valid_request() -> PortabilityDevicesRequest { let device_decision_profiles = EXPECTED_DEVICE_DECISION_PROFILES; let distinct_non_support_states = EXPECTED_DISTINCT_NON_SUPPORT_STATES; let case_bound_support_cells = EXPECTED_CASE_BOUND_SUPPORT_CELLS; let devices_epoch = 86; let previous_devices_epoch = 85; let devices_table_digest = 0x2480_5052_4445_5653; let devices_binding_digest = compute_portability_devices_binding_digest( device_decision_profiles, distinct_non_support_states, case_bound_support_cells, EXPECTED_UNTESTED_SUPPORTED_LABELS, devices_epoch, devices_table_digest, ); PortabilityDevicesRequest { supported_label_without_real_test: false, absent_unsupported_untested_collapsed: false, every_support_cell_bound_to_real_case: true, device_decision_profiles, distinct_non_support_states, case_bound_support_cells, devices_epoch, previous_devices_epoch, devices_table_digest, devices_binding_digest, } } #[test] fn os_portability_devices_contract_constants() { assert_eq!( PORTABILITY_DEVICES_SCHEMA, "turkos.os.portability.devices.v1" ); assert_eq!( PORTABILITY_DEVICES_INVARIANT, "Absent unsupported untested ayrı durumlardır" ); assert_eq!( PORTABILITY_DEVICES_POSITIVE, "MMIO PCI GPU input profilleri" ); assert_eq!( PORTABILITY_DEVICES_COUNTEREXAMPLE, "Test yokken supported etiketi" ); assert_eq!( PORTABILITY_DEVICES_ACCEPTANCE, "Her destek hücresi gerçek casee bağlı" ); } #[test] fn os_portability_devices_positive() { let mut coord = PortabilityDevicesCoordinator::new(); let req = valid_request(); let receipt = coord .commit_device_decision_table(&req) .expect("Supported device decision table across MMIO, PCI, GPU, and input profiles with distinct absent/unsupported/untested states must succeed"); assert!(coord.is_committed()); assert_eq!(coord.committed_total(), 1); assert_eq!(coord.rejected_total(), 0); assert_eq!( receipt.device_decision_profiles, EXPECTED_DEVICE_DECISION_PROFILES ); assert_eq!( receipt.distinct_non_support_states, EXPECTED_DISTINCT_NON_SUPPORT_STATES ); assert_eq!( receipt.case_bound_support_cells, EXPECTED_CASE_BOUND_SUPPORT_CELLS ); assert_eq!( receipt.untested_supported_labels, EXPECTED_UNTESTED_SUPPORTED_LABELS ); assert!(receipt.every_support_cell_bound_to_real_case); assert_eq!(receipt.devices_epoch, req.devices_epoch); assert_eq!(receipt.devices_table_digest, req.devices_table_digest); assert_eq!( receipt.receipt_digest, req.devices_binding_digest ^ 0x2480_ACE0_4445_5631 ); assert_eq!(coord.committed_receipt(), Some(receipt)); let dup = coord.commit_device_decision_table(&req); assert_eq!(dup, Err(PortabilityDevicesError::AlreadyCommitted)); assert_eq!(coord.rejected_total(), 1); } #[test] fn os_portability_devices_negative() { let mut coord = PortabilityDevicesCoordinator::new(); let mut r1 = valid_request(); r1.supported_label_without_real_test = true; assert_eq!( coord.commit_device_decision_table(&r1), Err(PortabilityDevicesError::SupportedLabelWithoutRealTest) ); assert_eq!(coord.device_classification_refusals(), 1); let mut r2 = valid_request(); r2.absent_unsupported_untested_collapsed = true; assert_eq!( coord.commit_device_decision_table(&r2), Err(PortabilityDevicesError::AbsentUnsupportedUntestedCollapsed) ); assert_eq!(coord.device_classification_refusals(), 2); let mut r3 = valid_request(); r3.every_support_cell_bound_to_real_case = false; assert_eq!( coord.commit_device_decision_table(&r3), Err(PortabilityDevicesError::SupportCellUnboundToRealCase) ); assert_eq!(coord.device_classification_refusals(), 3); let mut r4 = valid_request(); r4.device_decision_profiles = 0; assert_eq!( coord.commit_device_decision_table(&r4), Err(PortabilityDevicesError::DeviceDecisionProfilesMismatch) ); assert_eq!(coord.device_accounting_refusals(), 1); let mut r5 = valid_request(); r5.distinct_non_support_states = 0; assert_eq!( coord.commit_device_decision_table(&r5), Err(PortabilityDevicesError::DistinctNonSupportStatesMismatch) ); assert_eq!(coord.device_accounting_refusals(), 2); let mut r6 = valid_request(); r6.case_bound_support_cells = 0; assert_eq!( coord.commit_device_decision_table(&r6), Err(PortabilityDevicesError::CaseBoundSupportCellsMismatch) ); assert_eq!(coord.device_accounting_refusals(), 3); let mut r7 = valid_request(); r7.devices_binding_digest ^= 0xDEAD; assert_eq!( coord.commit_device_decision_table(&r7), Err(PortabilityDevicesError::UnboundPortabilityDevicesDigest) ); assert_eq!(coord.device_accounting_refusals(), 4); assert!(!coord.is_committed()); assert_eq!(coord.committed_receipt(), None); } #[test] fn os_portability_devices_validation_and_bounds() { let mut coord = PortabilityDevicesCoordinator::new(); let mut zero_epoch = valid_request(); zero_epoch.devices_epoch = 0; assert_eq!( coord.commit_device_decision_table(&zero_epoch), Err(PortabilityDevicesError::ZeroDevicesEpoch) ); let mut non_mono = valid_request(); non_mono.devices_epoch = non_mono.previous_devices_epoch; assert_eq!( coord.commit_device_decision_table(&non_mono), Err(PortabilityDevicesError::NonMonotonicDevicesEpoch) ); let mut zero_digest = valid_request(); zero_digest.devices_table_digest = 0; assert_eq!( coord.commit_device_decision_table(&zero_digest), Err(PortabilityDevicesError::ZeroDevicesTableDigest) ); }