Skip to content

Commit

Permalink
Rearrange schema evolution tests to not interfere with others
Browse files Browse the repository at this point in the history
Make the schema evolution datamodel the new one and use the original one
to write old data. This allows the roundtrip tests to work without
additional work because the additional schema evolution code is not used
anywhere for that.
  • Loading branch information
tmadlener committed Sep 12, 2023
1 parent 51462d9 commit 8b8f99a
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 40 deletions.
2 changes: 0 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ SET(podio_PYTHON_DIR ${PROJECT_SOURCE_DIR}/python CACHE PATH "Path to the podio

PODIO_GENERATE_DATAMODEL(datamodel datalayout.yaml headers sources
IO_BACKEND_HANDLERS ${PODIO_IO_HANDLERS}
OLD_DESCRIPTION schema_evolution/datalayout_old.yaml
SCHEMA_EVOLUTION schema_evolution/schema_evolution.yaml
)

# Use the cmake building blocks to add the different parts (conditionally)
Expand Down
7 changes: 6 additions & 1 deletion tests/datalayout.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
schema_version : 3
schema_version : 2

options :
# should getters / setters be prefixed with get / set?
Expand All @@ -9,6 +9,11 @@ options :
includeSubfolder: True

components :
ToBeDroppedStruct:
Description: "A struct to be dropped during schema evolution"
Members:
- int x

SimpleStruct:
Members:
- int x [mm]
Expand Down
28 changes: 15 additions & 13 deletions tests/schema_evolution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
PODIO_GENERATE_DATAMODEL(datamodel datalayout_old.yaml headers sources
PODIO_GENERATE_DATAMODEL(datamodel datalayout_new.yaml headers sources
IO_BACKEND_HANDLERS ${PODIO_IO_HANDLERS}
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/datamodel_old
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/datamodel_new
OLD_DESCRIPTION ${PROJECT_SOURCE_DIR}/tests/datalayout.yaml
SCHEMA_EVOLUTION schema_evolution.yaml
)

PODIO_ADD_DATAMODEL_CORE_LIB(TestDataModel_v1 "${headers}" "${sources}"
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/datamodel_old
PODIO_ADD_DATAMODEL_CORE_LIB(TestDataModel_v3 "${headers}" "${sources}"
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/datamodel_new
)

PODIO_ADD_ROOT_IO_DICT(TestDataModel_v1Dict TestDataModel_v1 "${headers}" ${CMAKE_CURRENT_BINARY_DIR}/datamodel_old/src/selection.xml
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/datamodel_old
PODIO_ADD_ROOT_IO_DICT(TestDataModel_v3Dict TestDataModel_v3 "${headers}" ${CMAKE_CURRENT_BINARY_DIR}/datamodel_new/src/selection.xml
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}/datamodel_new
)

PODIO_ADD_SIO_IO_BLOCKS(TestDataModel_v1 "${headers}" "${sources}")
PODIO_ADD_SIO_IO_BLOCKS(TestDataModel_v3 "${headers}" "${sources}")

#--- Helper function to create a test in an environment that is suitable to
#--- write data in an old schema version
function(PODIO_CREATE_WRITE_OLD_DATA_TEST sourcefile additional_libs)
#--- read data in a new schema version
function(PODIO_CREATE_READ_NEW_DATA_TEST sourcefile additional_libs)
string( REPLACE ".cpp" "" name ${sourcefile} )
add_executable( ${name} ${sourcefile} )
add_test(NAME ${name} COMMAND ${name})

target_link_libraries(${name} PRIVATE TestDataModel_v1 ${additional_libs})
target_include_directories(${name} PRIVATE ${CMAKE_SOURCE_DIR}/tests/schema_evolution)
target_link_libraries(${name} PRIVATE TestDataModel_v3 ${additional_libs})
target_include_directories(${name} PRIVATE ${PROJECT_SOURCE_DIR}/tests/schema_evolution)

set_property(TEST ${name}
PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src:${CMAKE_BINARY_DIR}/tests/schema_evolution:$<TARGET_FILE_DIR:ROOT::Tree>:$<$<TARGET_EXISTS:SIO::sio>:$<TARGET_FILE_DIR:SIO::sio>>:$ENV{LD_LIBRARY_PATH}
LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/src:${PROJECT_BINARY_DIR}/tests/schema_evolution:$<TARGET_FILE_DIR:ROOT::Tree>:$<$<TARGET_EXISTS:SIO::sio>:$<TARGET_FILE_DIR:SIO::sio>>:$ENV{LD_LIBRARY_PATH}
PODIO_SIO_BLOCK=${CMAKE_CURRENT_BINARY_DIR}
ROOT_INCLUDE_PATH=${CMAKE_BINARY_DIR}/tests/schema_evolution/datamodel_old:${CMAKE_SOURCE_DIR}/include
ROOT_INCLUDE_PATH=${PROJECT_BINARY_DIR}/tests/schema_evolution/datamodel_new:${PROJECT_SOURCE_DIR}/include
)
endfunction()

Expand Down
14 changes: 7 additions & 7 deletions tests/schema_evolution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
This folder contains tests for the schema evolution functionality in podio. The
functionality is tested by first writing data with an old schema version and
then reading in with the current schema version.
[`datalayout_old.yaml`](./datalayout_old.yaml) holds the definition of the old
version, using schema version 1, while the
[`datalayout_new.yaml`](./datalayout_new.yaml) holds the definition of the new
version, using schema version 3, while the
[`datalayout.yaml`](../datalayout.yaml) that is also used for the other I/O
tests is used as the current version (schema version 2).
tests is used as the old version (schema version 2).

## Differences between the two schema versions
Since it is not immediately visible from the test code this list contains the
differences between the two schema versions, and also how this evolution is
tested (if it is supported)

| component / datatype | difference from v1 to v2 | purpose of test | tested with |
| component / datatype | difference from v2 to v3 | purpose of test | tested with |
|--|--|--|--|
| `SimpleStruct` | no `int y` member in v1 | Addition of new members in components | As member of `ExampleWithArrayComponent` |
| `ExampleHit` | no `double energy` member in v1 | Addition of new members in datatypes | Directly via `ExampleHit` |
| `ex2::NamespaceStruct` | renaming of `y_old` to `y` | Renaming of member variables | As member of `ex42::ExampleWithNamespace` |
| `SimpleStruct` | no `int t` member in v2 | Addition of new members in components | As member of `ExampleWithArrayComponent` |
| `ExampleHit` | no `double t` member in v1 | Addition of new members in datatypes | Directly via `ExampleHit` |
| `ex2::NamespaceStruct` | renaming of `y` to `y_new` | Renaming of member variables | As member of `ex42::ExampleWithNamespace` |
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
schema_version : 2
schema_version : 3

options :
# should getters / setters be prefixed with get / set?
Expand All @@ -10,14 +10,12 @@ options :

components :

ToBeDroppedStruct:
Members:
- int x

SimpleStruct:
Members:
- int x
- int y
- int z
- int t
- std::array<int, 4> p
# can also add c'tors:
ExtraCode :
Expand All @@ -33,7 +31,7 @@ components :
ex2::NamespaceStruct:
Members:
- int x
- int y_old
- int y_new

ex2::NamespaceInNamespaceStruct:
Members:
Expand All @@ -52,7 +50,7 @@ components :

datatypes :

EventInfoOldName:
EventInfoNewName:
Description : "Event info"
Author : "B. Hegner"
Members :
Expand All @@ -71,6 +69,8 @@ datatypes :
- double x // x-coordinate
- double y // y-coordinate
- double z // z-coordinate
- double energy // energy
- double t // time

ExampleMC :
Description : "Example MC-particle"
Expand Down
5 changes: 3 additions & 2 deletions tests/schema_evolution/read_new_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ int readExampleHit(const podio::Frame& event) {
const auto& coll = event.get<ExampleHitCollection>("datatypeMemberAdditionTest");
auto elem = coll[0];

ASSERT_EQUAL(elem.energy(), 0, "New datatype member variable not 0 initialized");
ASSERT_EQUAL(elem.t(), 0, "New datatype member variable not 0 initialized");
ASSERT_EQUAL(elem.x(), 1.23, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.y(), 1.23, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.z(), 1.23, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.energy(), 0, "Member variables unrelated to schema evolution have changed");
ASSERT_EQUAL(elem.cellID(), 0xcaffee, "Member variables unrelated to schema evolution have changed");

return 0;
Expand All @@ -45,7 +46,7 @@ int readExampleWithNamespace(const podio::Frame& event) {
const auto& coll = event.get<ex42::ExampleWithNamespaceCollection>("componentMemberRenameTest");
auto elem = coll[0];

ASSERT_EQUAL(elem.y(), 42, "Renamed component member variable does not have the expected value");
ASSERT_EQUAL(elem.y_new(), 42, "Renamed component member variable does not have the expected value");
ASSERT_EQUAL(elem.x(), 123, "Member variables unrelated to schema evolution have changed");

return 0;
Expand Down
4 changes: 2 additions & 2 deletions tests/schema_evolution/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PODIO_CREATE_WRITE_OLD_DATA_TEST(write_old_data_root.cpp "TestDataModel_v1Dict;podio::podioRootIO")
CREATE_PODIO_TEST(write_old_data_root.cpp "TestDataModelDict;podioRootIO")
PODIO_CREATE_READ_NEW_DATA_TEST(read_new_data_root.cpp "TestDataModel_v3Dict;podio::podioRootIO")

CREATE_PODIO_TEST(read_new_data_root.cpp "TestDataModelDict;podioRootIO")
set_property(TEST read_new_data_root PROPERTY DEPENDS write_old_data_root)
2 changes: 1 addition & 1 deletion tests/schema_evolution/root_io/read_new_data_root.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "schema_evolution/read_new_data.h"
#include "read_new_data.h"

#include "podio/ROOTFrameReader.h"

Expand Down
2 changes: 1 addition & 1 deletion tests/schema_evolution/root_io/write_old_data_root.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "write_old_data.h"
#include "schema_evolution/write_old_data.h"

#include "podio/ROOTFrameWriter.h"

Expand Down
6 changes: 3 additions & 3 deletions tests/schema_evolution/schema_evolution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ evolutions:

ex2::NamespaceStruct:
member_rename:
- y_old
- y
- y_new

EventInfoOldName:
class_renamed_to: EventInfo
EventInfo:
class_renamed_to: EventInfoNewName
2 changes: 1 addition & 1 deletion tests/schema_evolution/write_old_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ auto writeExampleHit() {
auto writeExampleWithNamespace() {
ex42::ExampleWithNamespaceCollection coll;
auto elem = coll.create();
elem.y_old(42);
elem.y(42);
elem.x(123);

return coll;
Expand Down

0 comments on commit 8b8f99a

Please sign in to comment.