From 1125fd2667f330f3d0f6dad718d093e3b01ea0c9 Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Fri, 29 Jul 2022 12:52:45 -0700 Subject: [PATCH] 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 --- fuzz/fuzz_targets/http_api.rs | 9 ++------- vmm/src/api/http.rs | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/fuzz/fuzz_targets/http_api.rs b/fuzz/fuzz_targets/http_api.rs index 7e24a82a2..f68201b6b 100644 --- a/fuzz/fuzz_targets/http_api.rs +++ b/fuzz/fuzz_targets/http_api.rs @@ -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>> = 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>> = + Lazy::new(|| HTTP_ROUTES.routes.values().collect()); fuzz_target!(|bytes| { if bytes.len() < 2 { diff --git a/vmm/src/api/http.rs b/vmm/src/api/http.rs index e6a6901ac..f9c5694d4 100644 --- a/vmm/src/api/http.rs +++ b/vmm/src/api/http.rs @@ -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>, + pub routes: BTreeMap>, } macro_rules! endpoint { @@ -134,7 +134,7 @@ macro_rules! endpoint { /// HTTP_ROUTES contain all the cloud-hypervisor HTTP routes. pub static HTTP_ROUTES: Lazy = Lazy::new(|| { let mut r = HttpRoutes { - routes: HashMap::new(), + routes: BTreeMap::new(), }; r.routes.insert(