i2c: Add tests to cover basic backend operations

This still doesn't emulate the descriptors and descriptor chains over
the vrings. That will be added later.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
This commit is contained in:
Viresh Kumar 2021-09-09 13:34:03 +05:30 committed by Andreea Florescu
parent cd23ce7502
commit c5e90cfee9
2 changed files with 24 additions and 1 deletions

View File

@ -1,5 +1,5 @@
{
"coverage_score": 36.3,
"coverage_score": 40.6,
"exclude_path": "",
"crate_features": ""
}

View File

@ -299,3 +299,26 @@ impl<A: I2cAdapterTrait> VhostUserBackendMut<VringRwLock, ()> for VhostUserI2cBa
Some(self.exit_event.try_clone().expect("Cloning exit eventfd"))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::i2c::tests::I2cMockAdapter;
#[test]
fn verify_backend() {
let i2c_map: I2cMap<I2cMockAdapter> = I2cMap::new("1:4,2:32:21,5:10:23").unwrap();
let mut backend = VhostUserI2cBackend::new(Arc::new(i2c_map)).unwrap();
assert_eq!(backend.num_queues(), NUM_QUEUES);
assert_eq!(backend.max_queue_size(), QUEUE_SIZE);
assert_eq!(backend.features(), 0x171000000);
assert_eq!(backend.protocol_features(), VhostUserProtocolFeatures::MQ);
assert_eq!(backend.queues_per_thread(), vec![0xffff_ffff]);
assert_eq!(backend.get_config(0, 0), vec![]);
backend.set_event_idx(true);
assert!(backend.event_idx);
}
}