From ba9564ce04f688fa3f21ed1b1033cce8155e68b8 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 3 Oct 2022 15:40:36 +0200 Subject: [PATCH] Add a version of the state test with null cookies Since setting the cookie fields is optional. --- src/tests/plugin.rs | 17 ++++++++++++++++- src/tests/plugin/state.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/tests/plugin.rs b/src/tests/plugin.rs index d175c5b..1216e80 100644 --- a/src/tests/plugin.rs +++ b/src/tests/plugin.rs @@ -16,6 +16,7 @@ const INCONSISTENT_NOTE_PROCESSING: &str = "process-note-inconsistent"; const CONVERT_PARAMS: &str = "param-conversions"; const WRONG_NAMESPACE_SET_PARAMS: &str = "param-set-wrong-namespace"; const BASIC_STATE_REPRODUCIBILITY: &str = "state-reproducibility-basic"; +const NULL_COOKIES_STATE_REPRODUCIBILITY: &str = "state-reproducibility-null-cookies"; const FLUSH_STATE_REPRODUCIBILITY: &str = "state-reproducibility-flush"; const BUFFERED_STATE_STREAMS: &str = "state-buffered-streams"; @@ -28,6 +29,7 @@ pub enum PluginTestCase { ConvertParams, WrongNamespaceSetParams, BasicStateReproducibility, + NullCookiesStateReproducibility, FlushStateReproducibility, BufferedStateStreams, } @@ -44,6 +46,7 @@ impl<'a> TestCase<'a> for PluginTestCase { PluginTestCase::ConvertParams, PluginTestCase::WrongNamespaceSetParams, PluginTestCase::BasicStateReproducibility, + PluginTestCase::NullCookiesStateReproducibility, PluginTestCase::FlushStateReproducibility, PluginTestCase::BufferedStateStreams, ]; @@ -60,6 +63,9 @@ impl<'a> TestCase<'a> for PluginTestCase { CONVERT_PARAMS => Some(PluginTestCase::ConvertParams), WRONG_NAMESPACE_SET_PARAMS => Some(PluginTestCase::WrongNamespaceSetParams), BASIC_STATE_REPRODUCIBILITY => Some(PluginTestCase::BasicStateReproducibility), + NULL_COOKIES_STATE_REPRODUCIBILITY => { + Some(PluginTestCase::NullCookiesStateReproducibility) + } FLUSH_STATE_REPRODUCIBILITY => Some(PluginTestCase::FlushStateReproducibility), BUFFERED_STATE_STREAMS => Some(PluginTestCase::BufferedStateStreams), _ => None, @@ -74,6 +80,7 @@ impl<'a> TestCase<'a> for PluginTestCase { PluginTestCase::ConvertParams => CONVERT_PARAMS, PluginTestCase::WrongNamespaceSetParams => WRONG_NAMESPACE_SET_PARAMS, PluginTestCase::BasicStateReproducibility => BASIC_STATE_REPRODUCIBILITY, + PluginTestCase::NullCookiesStateReproducibility => NULL_COOKIES_STATE_REPRODUCIBILITY, PluginTestCase::FlushStateReproducibility => FLUSH_STATE_REPRODUCIBILITY, PluginTestCase::BufferedStateStreams => BUFFERED_STATE_STREAMS, } @@ -112,6 +119,11 @@ impl<'a> TestCase<'a> for PluginTestCase { the same and whether saving the state once more results in the same state file \ as before. The parameter values are updated using the process function.", ), + PluginTestCase::NullCookiesStateReproducibility => format!( + "The exact same test as {BASIC_STATE_REPRODUCIBILITY}, but with all cookies in \ + the parameter events set to null pointers. The plugin should handle this in the \ + same way as the other test case.", + ), PluginTestCase::FlushStateReproducibility => String::from( "Randomizes a plugin's parameters, saves its state, recreates the plugin \ instance, sets the same parameters as before, saves the state again, and then \ @@ -159,7 +171,10 @@ impl<'a> TestCase<'a> for PluginTestCase { params::test_wrong_namespace_set_params(library, plugin_id) } PluginTestCase::BasicStateReproducibility => { - state::test_basic_state_reproducibility(library, plugin_id) + state::test_basic_state_reproducibility(library, plugin_id, false) + } + PluginTestCase::NullCookiesStateReproducibility => { + state::test_basic_state_reproducibility(library, plugin_id, true) } PluginTestCase::FlushStateReproducibility => { state::test_flush_state_reproducibility(library, plugin_id) diff --git a/src/tests/plugin/state.rs b/src/tests/plugin/state.rs index 4e63aaf..6fbd8e4 100644 --- a/src/tests/plugin/state.rs +++ b/src/tests/plugin/state.rs @@ -25,7 +25,15 @@ const ACTUAL_STATE_FILE_NAME: &str = "state-actual"; /// The test for `PluginTestCase::BasicStateReproducibility`. See the description of this test for a /// detailed explanation, but we essentially check if saving a loaded state results in the same /// state file, and whether a plugin's parameters are the same after loading the state. -pub fn test_basic_state_reproducibility(library: &PluginLibrary, plugin_id: &str) -> TestStatus { +/// +/// The `zero_out_cookies` parameter offers an alternative on this test that sends parameter change +/// events with all cookies set to null pointers. The plugin should behave identically when this +/// happens. +pub fn test_basic_state_reproducibility( + library: &PluginLibrary, + plugin_id: &str, + zero_out_cookies: bool, +) -> TestStatus { let mut prng = new_prng(); let host = Host::new(); @@ -72,9 +80,24 @@ pub fn test_basic_state_reproducibility(library: &PluginLibrary, plugin_id: &str // We can't compare the values from these events direclty as the plugin // may round the values during the parameter set let param_fuzzer = ParamFuzzer::new(¶m_infos); - let random_param_set_events: Vec<_> = + let mut random_param_set_events: Vec<_> = param_fuzzer.randomize_params_at(&mut prng, 0).collect(); + // This is a variation on the test that checks whether the plugin handles null + // pointer cookies correctly + if zero_out_cookies { + for event in &mut random_param_set_events { + match event { + Event::ParamValue(event) => { + event.cookie = std::ptr::null_mut(); + } + event => { + panic!("Unexpected event {event:?}, this is a clap-validator bug") + } + } + } + } + let (mut input_buffers, mut output_buffers) = audio_ports_config.create_buffers(512); ProcessingTest::new_out_of_place(&plugin, &mut input_buffers, &mut output_buffers)?