mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
vmm: api: Use 'BTreeMap' for 'HttpRoutes'
In this way, we get the values sorted by its key by default, which is useful for the 'http_api' fuzzer. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
e5155bab62
commit
1125fd2667
@ -14,13 +14,8 @@ use vmm::{EpollContext, EpollDispatch};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
// Need to be ordered for test case reproducibility
|
||||
static ROUTES: Lazy<Vec<&Box<dyn EndpointHandler + Sync + Send>>> = Lazy::new(|| {
|
||||
let mut keys: Vec<&String> = HTTP_ROUTES.routes.keys().collect();
|
||||
keys.sort();
|
||||
keys.iter()
|
||||
.map(|k| HTTP_ROUTES.routes.get(*k).unwrap())
|
||||
.collect()
|
||||
});
|
||||
static ROUTES: Lazy<Vec<&Box<dyn EndpointHandler + Sync + Send>>> =
|
||||
Lazy::new(|| HTTP_ROUTES.routes.values().collect());
|
||||
|
||||
fuzz_target!(|bytes| {
|
||||
if bytes.len() < 2 {
|
||||
|
@ -12,7 +12,7 @@ use micro_http::{Body, HttpServer, MediaType, Method, Request, Response, StatusC
|
||||
use once_cell::sync::Lazy;
|
||||
use seccompiler::{apply_filter, SeccompAction};
|
||||
use serde_json::Error as SerdeError;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::File;
|
||||
use std::os::unix::io::{IntoRawFd, RawFd};
|
||||
use std::os::unix::net::UnixListener;
|
||||
@ -122,7 +122,7 @@ pub trait EndpointHandler {
|
||||
/// An HTTP routes structure.
|
||||
pub struct HttpRoutes {
|
||||
/// routes is a hash table mapping endpoint URIs to their endpoint handlers.
|
||||
pub routes: HashMap<String, Box<dyn EndpointHandler + Sync + Send>>,
|
||||
pub routes: BTreeMap<String, Box<dyn EndpointHandler + Sync + Send>>,
|
||||
}
|
||||
|
||||
macro_rules! endpoint {
|
||||
@ -134,7 +134,7 @@ macro_rules! endpoint {
|
||||
/// HTTP_ROUTES contain all the cloud-hypervisor HTTP routes.
|
||||
pub static HTTP_ROUTES: Lazy<HttpRoutes> = Lazy::new(|| {
|
||||
let mut r = HttpRoutes {
|
||||
routes: HashMap::new(),
|
||||
routes: BTreeMap::new(),
|
||||
};
|
||||
|
||||
r.routes.insert(
|
||||
|
Loading…
x
Reference in New Issue
Block a user