From 6fe6fe3dd1c0da878218494fb20728a78125461d Mon Sep 17 00:00:00 2001 From: "Adam L. Taylor" Date: Mon, 22 May 2023 15:48:31 -0400 Subject: [PATCH] master: -m --- mouselight_toolbox | 2 +- ...m => test_all_eight_major_configurations.m | 4 +- test_all_verification_conditions.m | 17 ++ test_single_major_configuration.m | 54 +++++++ test_verification_condition.m | 146 ++++++++++++++++++ 5 files changed, 220 insertions(+), 3 deletions(-) rename test_everything.m => test_all_eight_major_configurations.m (57%) create mode 100644 test_all_verification_conditions.m create mode 100644 test_single_major_configuration.m create mode 100644 test_verification_condition.m diff --git a/mouselight_toolbox b/mouselight_toolbox index 743b649..4b19a21 160000 --- a/mouselight_toolbox +++ b/mouselight_toolbox @@ -1 +1 @@ -Subproject commit 743b649365ba969a738c8bf4e4b0bddcb898024c +Subproject commit 4b19a2108d6e9beed17bbd01de93861a4087b0be diff --git a/test_everything.m b/test_all_eight_major_configurations.m similarity index 57% rename from test_everything.m rename to test_all_eight_major_configurations.m index 24e207c..481c9c2 100644 --- a/test_everything.m +++ b/test_all_eight_major_configurations.m @@ -1,8 +1,8 @@ -function test_everything() +function test_all_eight_major_configurations() for freezing_or_thawing = { 'freezing', 'thawing' } , for raw_tiles_or_octree = { 'raw-tiles', 'octree' } , for local_or_cluster = { 'local', 'cluster' } , - test_something(freezing_or_thawing{1}, raw_tiles_or_octree{1}, local_or_cluster{1}) + test_single_major_configuration(freezing_or_thawing{1}, raw_tiles_or_octree{1}, local_or_cluster{1}) ; end end end diff --git a/test_all_verification_conditions.m b/test_all_verification_conditions.m new file mode 100644 index 0000000..f21f719 --- /dev/null +++ b/test_all_verification_conditions.m @@ -0,0 +1,17 @@ +function test_all_verification_conditions() + %for freezing_or_thawing = { 'freezing', 'thawing' } , + for freezing_or_thawing = { 'thawing' } , + %for raw_tiles_or_octree = { 'raw-tiles', 'octree' } , + for raw_tiles_or_octree = { 'octree' } , + %for local_or_cluster = { 'local', 'cluster' } , + for local_or_cluster = { 'local' } , + for stack_or_non_stack = { 'stack', 'non-stack' } , + for exact_problem = { 'deleted', 'zero-length', 'corrupt' } , + test_verification_condition( ... + freezing_or_thawing{1}, raw_tiles_or_octree{1}, local_or_cluster{1}, stack_or_non_stack{1}, exact_problem{1}) ; + end + end + end + end + end +end diff --git a/test_single_major_configuration.m b/test_single_major_configuration.m new file mode 100644 index 0000000..68291b2 --- /dev/null +++ b/test_single_major_configuration.m @@ -0,0 +1,54 @@ +function test_single_major_configuration(freezing_or_thawing, raw_tiles_or_octree, local_or_cluster) + % Test, in one of 2^3==8 possible configurations. + + % Deal with the arguments + if ~strcmp(freezing_or_thawing, 'freezing') && ~strcmp(freezing_or_thawing, 'thawing') , + error('freezing_or_thawing must be ''freezing'' or ''thawing''') ; + end + if ~strcmp(raw_tiles_or_octree, 'raw-tiles') && ~strcmp(raw_tiles_or_octree, 'octree') , + error('raw_tiles_or_octree must be ''raw-tiles'' or ''octree''') ; + end + if ~strcmp(local_or_cluster, 'local') && ~strcmp(local_or_cluster, 'cluster') , + error('local_or_cluster must be ''local'' or ''cluster''') ; + end + + % Define all the needed inputs + path_to_this_folder = fileparts(mfilename('fullpath')) ; + output_folder_name = sprintf('%s-%s-test-output-folder', raw_tiles_or_octree, freezing_or_thawing) ; + output_folder_path = fullfile(path_to_this_folder, output_folder_name) ; + input_folder_name = sprintf('%s-%s-test-input-folder', raw_tiles_or_octree, freezing_or_thawing) ; + input_folder_path = fullfile(path_to_this_folder, input_folder_name) ; + compression_ratio = 10 ; % only used for freezing + do_run_on_cluster = strcmp(local_or_cluster, 'cluster') ; + do_try = false ; % if running locally, don't wrap in try so easier to debug + maximum_running_slot_count = 40 ; + submit_host_name = if_not_a_submit_host('login2.int.janelia.org') ; + + % Delete the test output folder + reset_for_test(output_folder_path) ; + + % Make sure the input folder exists + if ~logical(exist(input_folder_path, 'dir')) , + error('Input folder %s is missing, or is not a folder', input_folder_path) ; + end + + % Call the script + if strcmp(freezing_or_thawing, 'freezing') , + freeze_mouselight_folder(... + output_folder_path, ... + input_folder_path, ... + compression_ratio, ... + do_run_on_cluster, ... + do_try, ... + maximum_running_slot_count, ... + submit_host_name) ; + else + thaw_mouselight_folder(... + output_folder_path, ... + input_folder_path, ... + do_run_on_cluster, ... + do_try, ... + maximum_running_slot_count, ... + submit_host_name) ; + end +end diff --git a/test_verification_condition.m b/test_verification_condition.m new file mode 100644 index 0000000..2e0c7c5 --- /dev/null +++ b/test_verification_condition.m @@ -0,0 +1,146 @@ +function test_verification_condition(freezing_or_thawing, raw_tiles_or_octree, local_or_cluster, stack_or_non_stack, exact_problem) + % Deal with the arguments + if ~strcmp(freezing_or_thawing, 'freezing') && ~strcmp(freezing_or_thawing, 'thawing') , + error('freezing_or_thawing must be ''freezing'' or ''thawing''') ; + end + if ~strcmp(raw_tiles_or_octree, 'raw-tiles') && ~strcmp(raw_tiles_or_octree, 'octree') , + error('raw_tiles_or_octree must be ''raw-tiles'' or ''octree''') ; + end + if ~strcmp(local_or_cluster, 'local') && ~strcmp(local_or_cluster, 'cluster') , + error('local_or_cluster must be ''local'' or ''cluster''') ; + end + if ~strcmp(stack_or_non_stack, 'stack') && ~strcmp(stack_or_non_stack, 'non-stack') , + error('stack_or_non_stack must be ''stack'' or ''non-stack''') ; + end + if ~any(strcmp(exact_problem, {'deleted', 'zero-length', 'corrupt'})) , + error('exact_problem must be one of ''deleted'', ''zero-length'', or ''corrupt''') ; + end + + % Declare what test we're doing + fprintf('Testing %s %s %s %s %s...\n', ... + freezing_or_thawing, raw_tiles_or_octree, local_or_cluster, stack_or_non_stack, exact_problem) ; + + % Define all the needed inputs + path_to_this_folder = fileparts(mfilename('fullpath')) ; + output_folder_name = sprintf('%s-%s-test-output-folder', raw_tiles_or_octree, freezing_or_thawing) ; + output_folder_path = fullfile(path_to_this_folder, output_folder_name) ; + input_folder_name = sprintf('%s-%s-test-input-folder', raw_tiles_or_octree, freezing_or_thawing) ; + input_folder_path = fullfile(path_to_this_folder, input_folder_name) ; + compression_ratio = 10 ; % only used for freezing + do_run_on_cluster = false ; + do_try = true ; % if running locally, don't wrap in try so easier to debug + maximum_running_slot_count = 40 ; + submit_host_name = if_not_a_submit_host('login2.int.janelia.org') ; + + % Delete the test output folder + reset_for_test(output_folder_path) ; + + % Make sure the input folder exists + if ~logical(exist(input_folder_path, 'dir')) , + error('Input folder %s is missing, or is not a folder', input_folder_path) ; + end + + % Call the script, but don't do verification + if strcmp(freezing_or_thawing, 'freezing') , + freeze_mouselight_folder(... + output_folder_path, ... + input_folder_path, ... + compression_ratio, ... + do_run_on_cluster, ... + do_try, ... + maximum_running_slot_count, ... + submit_host_name, ... + 'do_freezing', true, ... + 'do_verification', false) ; + else + thaw_mouselight_folder(... + output_folder_path, ... + input_folder_path, ... + do_run_on_cluster, ... + do_try, ... + maximum_running_slot_count, ... + submit_host_name, ... + 'do_thawing', true, ... + 'do_verification', false) ; + end + + % Figure out what file we will mess with + if strcmp(stack_or_non_stack, 'stack') , + if strcmp(freezing_or_thawing, 'freezing') , + if strcmp(raw_tiles_or_octree, 'octree') , + perverted_output_file_relative_path = '1/default.1.mj2' ; + else + perverted_output_file_relative_path = '2018-12-12/00/00241/00241-ngc.0.mj2' ; + end + else + % thawing + if strcmp(raw_tiles_or_octree, 'octree') , + perverted_output_file_relative_path = '1/default.1.tif' ; + else + perverted_output_file_relative_path = 'Tiling/2017-11-03/02/02013-ngc.0_comp-10.tif' ; + end + end + else + % non-stack file + if strcmp(freezing_or_thawing, 'freezing') , + if strcmp(raw_tiles_or_octree, 'octree') , + perverted_output_file_relative_path = 'set_parameters.jl' ; + else + perverted_output_file_relative_path = '2018-12-09/02/02017/02017-ngc.microscope' ; + end + else + % thawing + if strcmp(raw_tiles_or_octree, 'octree') , + perverted_output_file_relative_path = 'tilebase.cache.yml' ; + else + perverted_output_file_relative_path = 'Tiling/2017-11-03/02/02013-ngc.acquisition' ; + end + end + end + + % Fake a failure by messing with one of the destination files + perverted_output_file_path = fullfile(output_folder_path, perverted_output_file_relative_path) ; + if strcmp(exact_problem, 'deleted') , + delete(perverted_output_file_path) ; + elseif strcmp(exact_problem, 'zero-length') , + delete(perverted_output_file_path) ; + touch(perverted_output_file_path) ; + else + set_all_file_bytes_to_zero(perverted_output_file_path) ; + end + + % Now do verification, which should fail + try + if strcmp(freezing_or_thawing, 'freezing') , + freeze_mouselight_folder(... + output_folder_path, ... + input_folder_path, ... + compression_ratio, ... + do_run_on_cluster, ... + do_try, ... + maximum_running_slot_count, ... + submit_host_name, ... + 'do_freezing', false, ... + 'do_verification', true) ; + else + thaw_mouselight_folder(... + output_folder_path, ... + input_folder_path, ... + do_run_on_cluster, ... + do_try, ... + maximum_running_slot_count, ... + submit_host_name, ... + 'do_thawing', false, ... + 'do_verification', true) ; + end + error('Verification succeeded, even though a destination file was corrupted') ; + catch me + if strcmp(me.identifier, 'mouselight_toolbox:verification_failed') , + % All is well, nothing to do + fprintf('Test %s %s %s %s %s passed.\n', ... + freezing_or_thawing, raw_tiles_or_octree, local_or_cluster, stack_or_non_stack, exact_problem) ; + else + rethrow(me) ; + end + end +end