Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hadd] add tests for hadd argument parsing #1201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions root/io/datamodelevolution/00/test2.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "DataModelV2.h"
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TError.h"
#include "TBranch.h"

Expand Down
6 changes: 3 additions & 3 deletions root/io/evolution/versions/attmarker.ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
hadd Target file: result.root
hadd compression setting for all output: 101
Info in <hadd>: target file: result.root
Info in <hadd>: compression setting for all output: 101
hadd Source file 1: hsimple14.root
hadd Source file 2: hsimple20.root
hadd Sources and Target have different compression settings
Warning in <hadd>: Sources and Target have different compression settings
hadd merging will be slower
hadd Target path: result.root:/
113 changes: 108 additions & 5 deletions root/io/hadd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
if(ROOT_pyroot_FOUND)
ROOTTEST_ADD_TEST(compression_settings
MACRO test_compression_settings.py)
ROOTTEST_ADD_TEST(input_validation
MACRO input_validation.py)
if(NOT ROOT_pyroot_FOUND)
return()
endif()

ROOTTEST_ADD_TEST(compression_settings
MACRO test_compression_settings.py)
ROOTTEST_ADD_TEST(input_validation
MACRO input_validation.py)
ROOTTEST_ADD_TEST(test_MergeChangeComp
COPY_TO_BUILDDIR merge_gen_input_tuples.C merge_changeComp_check_output.C
PRECMD ${ROOT_root_CMD} -q -b -l "merge_gen_input_tuples.C(\"test_comp_in1.root\", \"test_comp_in2.root\")"
Expand All @@ -24,3 +25,105 @@ ROOTTEST_ADD_TEST(test_MergeNestedSameName
COMMAND ${ROOT_root_CMD} -q -b -l "hadd_check_nested_same_name.C"
OUTREF hadd_check_nested_same_name.ref
)

# ------------------------------------
# arg parsing tests
# ------------------------------------

ROOTTEST_ADD_TEST(test_hadd_args_gen_input
COPY_TO_BUILDDIR hadd_gen_input_tree.C
PRECMD ${CMAKE_COMMAND} -E rm -f hadd_args_in.root
COMMAND ${ROOT_root_CMD} -q -b -l "hadd_gen_input_tree.C(\"hadd_args_in.root\")"
)

ROOTTEST_ADD_TEST(test_hadd_args_n0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test only verifies that the message printed by hadd are correct? If yes, should we add some (minimal) test that the file produces is as expected (minimal requirement: contains the object we expects).

Rather than a POSTCMD deleting the file, I recommend a PRECMD (or not when we want to test that hadd complains about existing files). We may also want to keep the file after the end to have an opportunity to hand check the file.

DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -n0 hadd_args_n0_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_n0_out.root
OUTREF hadd_args_n0.ref
)

ROOTTEST_ADD_TEST(test_hadd_args_na
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -na hadd_args_na_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_na_out.root
PASSREGEX "Error in <hadd>: the argument after '-n' flag was not of the expected type."
)

ROOTTEST_ADD_TEST(test_hadd_args_n_1
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -n=1 hadd_args_n_1_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_n_1_out.root
OUTREF hadd_args_n_1.ref
)

ROOTTEST_ADD_TEST(test_hadd_args_jfa
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -jfa hadd_args_jfa_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_jfa_out.root
PASSREGEX "Error in <hadd>: the argument after '-j' flag was not of the expected type"
)

ROOTTEST_ADD_TEST(test_hadd_args_j_10a
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -j 10a hadd_args_j_10a_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_j_10a_out.root
PASSREGEX "Error in <hadd>: error parsing integer argument '10a'"
)

ROOTTEST_ADD_TEST(test_hadd_args_j
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -j hadd_args_j_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_j_out.root
PASSRC 0
)

ROOTTEST_ADD_TEST(test_hadd_args_ff_dbg_j_2
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -ff hadd_args_ff_dbg_j_2_out.root hadd_args_in.root hadd_args_in.root -dbg -j 2
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_ff_dbg_j_2_out.root
OUTREF hadd_args_ff_dbg_j_2.ref
)

ROOTTEST_ADD_TEST(test_hadd_args_minusminus
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -f0 -- --hadd_args_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f -- --hadd_args_out.root
OUTREF hadd_args_minusminus.ref
)

ROOTTEST_ADD_TEST(test_hadd_args_minusminus2
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -f --hadd_args2_out.root -- hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f -- --hadd_args2_out.root
PASSREGEX "Warning in <hadd>: unknown flag: --hadd_args2_out.root"
PASSRC 1
)

ROOTTEST_ADD_TEST(test_hadd_args_multiple_pos
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -ff hadd_args_multiple_pos_out.root -k hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_multiple_pos_out.root
PASSREGEX "Error in <hadd>: seen a positional argument 'hadd_args_in.root' after some flags."
)

ROOTTEST_ADD_TEST(test_hadd_args_cachesize
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} hadd_args_cachesize_out.root hadd_args_in.root -cachesize 100M -f
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_cachesize_out.root
OUTREF hadd_args_cachesize.ref
)

ROOTTEST_ADD_TEST(test_hadd_args_missing_arg
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} -n hadd_args_missing_arg_out.root hadd_args_in.root
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_missing_arg_out.root
PASSREGEX "Error in <hadd>: the argument after '-n' flag was not of the expected type"
)

ROOTTEST_ADD_TEST(test_hadd_args_missing_arg2
DEPENDS test_hadd_args_gen_input
COMMAND ${ROOT_hadd_CMD} hadd_args_missing_arg2_out.root hadd_args_in.root -n
POSTCMD ${CMAKE_COMMAND} -E rm -f hadd_args_missing_arg2_out.root
PASSREGEX "Error in <hadd>: expected argument after '-n' flag."
)
5 changes: 5 additions & 0 deletions root/io/hadd/hadd_args_cachesize.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Info in <hadd>: target file: hadd_args_cachesize_out.root
Info in <hadd>: Using cachesize=100M
Info in <hadd>: compression setting for all output: 101
hadd Source file 1: hadd_args_in.root
hadd Target path: hadd_args_cachesize_out.root:/
7 changes: 7 additions & 0 deletions root/io/hadd/hadd_args_ff_dbg_j_2.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Info in <hadd>: parallelizing with 2 processes.
Info in <hadd>: target file: hadd_args_ff_dbg_j_2_out.root
Info in <hadd>: compression setting for all output: 101
Info in <hadd>: each process should handle at least 3 files for efficiency. Setting the number of processes to: 1
hadd Source file 1: hadd_args_in.root
hadd Source file 2: hadd_args_in.root
hadd Target path: hadd_args_ff_dbg_j_2_out.root:/
6 changes: 6 additions & 0 deletions root/io/hadd/hadd_args_minusminus.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Info in <hadd>: target file: --hadd_args_out.root
Info in <hadd>: compression setting for all output: 0
hadd Source file 1: hadd_args_in.root
Warning in <hadd>: Sources and Target have different compression settings
hadd merging will be slower
hadd Target path: --hadd_args_out.root:/
4 changes: 4 additions & 0 deletions root/io/hadd/hadd_args_n0.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Info in <hadd>: target file: hadd_args_n0_out.root
Info in <hadd>: compression setting for all output: 101
hadd Source file 1: hadd_args_in.root
hadd Target path: hadd_args_n0_out.root:/
4 changes: 4 additions & 0 deletions root/io/hadd/hadd_args_n_1.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Info in <hadd>: target file: hadd_args_n_1_out.root
Info in <hadd>: compression setting for all output: 101
hadd Source file 1: hadd_args_in.root
hadd Target path: hadd_args_n_1_out.root:/
4 changes: 2 additions & 2 deletions root/io/hadd/input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_hadd_input_validation(self):
finally:
os.remove(outputfile)

assert f"hadd exiting due to error in {FILENAME+'_txt'}" in out.stderr.decode()
assert f"exiting due to error in {FILENAME+'_txt'}" in out.stderr.decode()

def test_hadd_input_validation_indirect(self):
"""
Expand All @@ -65,7 +65,7 @@ def test_hadd_input_validation_indirect(self):
finally:
os.remove(outputfile)

assert f"hadd exiting due to error in {FILENAME+'_txt'}" in out.stderr.decode()
assert f"exiting due to error in {FILENAME+'_txt'}" in out.stderr.decode()


if __name__ == "__main__":
Expand Down
Binary file added root/io/hadd/test_input.root
Binary file not shown.
4 changes: 2 additions & 2 deletions root/io/newstl/emulatedWrite.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hadd Target file: result.root
hadd compression setting for all output: 101
Info in <hadd>: target file: result.root
Info in <hadd>: compression setting for all output: 101
hadd Source file 1: cmsJets_0.root
Warning in <TClass::Init>: no dictionary for class edm::EDProduct is available
Warning in <TClass::Init>: no dictionary for class edm::EventAux is available
Expand Down
6 changes: 3 additions & 3 deletions root/io/transient/base/hadd_autoloadLZ4.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hadd Target file: data_merge.root
hadd compression setting for all output: 4
Info in <hadd>: target file: data_merge.root
Info in <hadd>: compression setting for all output: 4
hadd Source file 1: data1.root
hadd Source file 2: data2.root
hadd Target path: data_merge.root:/
Info in <hadd>: target path: data_merge.root:/
4 changes: 2 additions & 2 deletions root/io/transient/base/hadd_autoloadZLIB.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hadd Target file: data_merge.root
hadd compression setting for all output: 101
Info in <hadd>: target file: data_merge.root
Info in <hadd>: compression setting for all output: 101
hadd Source file 1: data1.root
hadd Source file 2: data2.root
hadd Target path: data_merge.root:/