Skip to content

Conversation

@lobis
Copy link
Member

@lobis lobis commented Feb 4, 2022

Large lobis 342

Related to #125.

The goal of this PR is to clean the CMake build system wherever possible (it is really complex, it could probably be simplified) and also modify it to support unit testing via ctest. Also I would like to install external dependencies via cmake instead of just copying them into the framework (such as tinyxml) but I won't change tinyxml since its been this way forever, if anything we should probably remove this dependency altogether and replace it by the ROOT xml library which can do what we want.

Testing is enabled via the -DTEST=ON flag, disabled by default.

Tests can be run via ´ctest´ from the build directory.

I will write the boilerplate for testing in all modules. (#163).

Some information about running tests can be found at rest-for-physics/rest-for-physics.github.io@43a1e66.

@lobis lobis requested review from jgalan, juanangp and nkx111 February 4, 2022 18:21
@lobis lobis self-assigned this Feb 4, 2022
@jgalan
Copy link
Member

jgalan commented Feb 7, 2022

As we get more and more activity on the repositories we should be more and more explicit on describing the intention of the updates at a specific PR. Please, give details on the problem and the enhancements that will bring this PR, including the reasons that triggered it. Those habits will be good to incentive discussions on the different contributions.

@lobis
Copy link
Member Author

lobis commented Feb 8, 2022

As we get more and more activity on the repositories we should be more and more explicit on describing the intention of the updates at a specific PR. Please, give details on the problem and the enhancements that will bring this PR, including the reasons that triggered it. Those habits will be good to incentive discussions on the different contributions.

That is why I made the PR a draft, so I could fill the information as I go, but I agree I should have been a bit more detailed. Thanks!

@lobis
Copy link
Member Author

lobis commented Feb 8, 2022

Currently there is a problem I don't know how to fix, perhaps @nkx111 or @jgalan can give me a hand. It has to do with the startup.cpp script.

Currently I cannot compile the tests due to an error at the end of compilation:

sh: 1: rest-config: not found
CMake Error at /usr/share/cmake-3.16/Modules/GoogleTestAddTests.cmake:40 (message):
  Error running test executable.

    Path: '/tmp/tmp.1ggMShb7jT/cmake-build-dockerdev/source/framework/test/testFramework'
    Result: Child aborted
    Output:
      REST ERROR!! Lacking system env "REST_PATH"! Cannot start!
      You need to source "thisREST.sh" first

To get the error just compile REST with the new TEST flag on: cmake -DTEST=ON ...

I am not sure how/why a script is being run at compilation but for the all the tests targets I would like to avoid it, but don't know how to do this without probably breaking something since I don't understand this part of the code. This is blocking testing right now :(

I think the implementation of the tests is good and I can't think of a modification that would avoid this so we probably need to modify startup.cpp or some cmake section that is "linking" this?

Thanks!

@lobis lobis added the enhancement New feature or request label Feb 8, 2022
This was linked to issues Feb 8, 2022
@nkx111
Copy link
Member

nkx111 commented Feb 8, 2022

Currently there is a problem I don't know how to fix, perhaps @nkx111 or @jgalan can give me a hand. It has to do with the startup.cpp script.

Currently I cannot compile the tests due to an error at the end of compilation:

sh: 1: rest-config: not found
CMake Error at /usr/share/cmake-3.16/Modules/GoogleTestAddTests.cmake:40 (message):
  Error running test executable.

    Path: '/tmp/tmp.1ggMShb7jT/cmake-build-dockerdev/source/framework/test/testFramework'
    Result: Child aborted
    Output:
      REST ERROR!! Lacking system env "REST_PATH"! Cannot start!
      You need to source "thisREST.sh" first

To get the error just compile REST with the new TEST flag on: cmake -DTEST=ON ...

I am not sure how/why a script is being run at compilation but for the all the tests targets I would like to avoid it, but don't know how to do this without probably breaking something since I don't understand this part of the code. This is blocking testing right now :(

I think the implementation of the tests is good and I can't think of a modification that would avoid this so we probably need to modify startup.cpp or some cmake section that is "linking" this?

Thanks!

It seems that the new ExampleTest.cxx is being executed and raised this error. The part of error code is from startup.cpp and will run as long as the framework library is linked.

I suggest not to avoid linking it. We can try adding those envs to gtest system.

@lobis
Copy link
Member Author

lobis commented Feb 8, 2022

Currently there is a problem I don't know how to fix, perhaps @nkx111 or @jgalan can give me a hand. It has to do with the startup.cpp script.
Currently I cannot compile the tests due to an error at the end of compilation:

sh: 1: rest-config: not found
CMake Error at /usr/share/cmake-3.16/Modules/GoogleTestAddTests.cmake:40 (message):
  Error running test executable.

    Path: '/tmp/tmp.1ggMShb7jT/cmake-build-dockerdev/source/framework/test/testFramework'
    Result: Child aborted
    Output:
      REST ERROR!! Lacking system env "REST_PATH"! Cannot start!
      You need to source "thisREST.sh" first

To get the error just compile REST with the new TEST flag on: cmake -DTEST=ON ...
I am not sure how/why a script is being run at compilation but for the all the tests targets I would like to avoid it, but don't know how to do this without probably breaking something since I don't understand this part of the code. This is blocking testing right now :(
I think the implementation of the tests is good and I can't think of a modification that would avoid this so we probably need to modify startup.cpp or some cmake section that is "linking" this?
Thanks!

It seems that the new ExampleTest.cxx is being executed and raised this error. The part of error code is from startup.cpp and will run as long as the framework library is linked.

I suggest not to avoid linking it. We can try adding those envs to gtest system.

but how is it being executed on the build? How could we add this env to the gtest in a simple way? are you sure running some code when linking to REST library is a good practise? seems it can cause a lot of trouble.

@lobis
Copy link
Member Author

lobis commented Feb 8, 2022

something very weird happened with this branch I cannot fix the bug

@jgalan
Copy link
Member

jgalan commented Feb 8, 2022

Also I would like to install external dependencies via cmake instead of just copying them into the framework (such as tinyxml)

In principle, there is no problem to do that with the present cmake system, if tinyxml would be installed as a system library it would just pick up it. I believe @nkx introduced some modifications to the tinyxml library, so thats why the library is copied into the repository. Not because it is not possible to link external libraries.

@juanangp
Copy link
Member

Perhaps you should mention somewhere that the support for old Garfield versions have been removed, since you removed FindGarfieldOld, therefore is related with rest-for-physics/detectorlib#41

@lobis
Copy link
Member Author

lobis commented Mar 25, 2022

Perhaps you should mention somewhere that the support for old Garfield versions have been removed, since you removed FindGarfieldOld, therefore is related with rest-for-physics/detectorlib#41

I decided to keep this file and remove it in a more appropriate PR.

@@ -0,0 +1 @@
<metadata p1="75" p2="12.32" p3="Aloha" /> No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

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

It does not keep the convention that the xml header is the name of the c++ metadata class, which is metadataTestClass.

EXPECT_TRUE(fs::exists(BASIC_TRESTMETADATA_RML));

// Create new TRestMetadata class
class metadataTestClass: public TRestMetadata{
Copy link
Member

Choose a reason for hiding this comment

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

Any REST class should be starting by TRest

Copy link
Member Author

Choose a reason for hiding this comment

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

Any REST class should be starting by TRest

but this is not a class, its just a cpp file

Copy link
Member

@jgalan jgalan Mar 26, 2022

Choose a reason for hiding this comment

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

well, it is a class, as it is stated in front of it name, I agree we could make an exception inside tests, but I thought it was not possible that the XML header and the class name would be different, it is this possible? @nkx?

Copy link
Member Author

@lobis lobis Mar 26, 2022

Choose a reason for hiding this comment

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

Okay now I see what you mean. but this is not a class definition, the same test file could contain many class definitions, it should not begin by TRest imho.

This was introduced by @DavidDiezIb and I think its a great idea to test a class such as TRestMetadata.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind the naming convention, we can change it if you prefer. Just I thought it was better not to use REST naming convenctions to avoid confussion with any real REST classes.
This is a fake one created to be able to test GetParameter function from TRestMetadata. It is a pure abstract class so we can't call it, we can only inherit from it.

Related to the name of the metadata section, I can modify it to coincide with name of the class, maybe is easier to read. But meta.LoadConfigFromFile(BASIC_TRESTMETADATA_RML, "metadata"); is telling where has to look for the parameters to initialize metadataTestClass (the XML section called "metadata") so doesn't seem to have any problem.

Copy link
Member

Choose a reason for hiding this comment

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

This was introduced by @DavidDiezIb and I think its a great idea to test a class such as TRestMetadata.

I am not debating that

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's right, maybe we should remove the option to select the section by hand in LoadFromConfigFile. I don't know if this is useful somewhere.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I didn't know that was possible, we never use it that way, isn't @nkx?

Int_t TRestMetadata::LoadConfigFromFile(string cfgFileName, string sectionName) {
    fConfigFileName = cfgFileName;
    if (TRestTools::fileExists(fConfigFileName)) {
        if (sectionName == "") {
            sectionName = this->ClassName();
        }

So probably we should remove the second argument of that method, and just define a local variable sectionName=this->ClassName()?

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, I agree.

Copy link
Member

Choose a reason for hiding this comment

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

However I am a bit surprised, I thought the second argument was the given name, so that if I got two TRestMyMetadata definitions I am able to select the one I am interested in:

<TRestMyMetadata name="md1" />

<TRestMyMetadata name="md2" />

So that the constructor would pick up the right definition using:

TRestMyMetadata *md = new TRestMyMetadata("file.rml", "md1" );
md->LoadConfigFromFile( "file.rml", "md1");

At least thats how I am using it inside for example TRestAxionMagneticField and it works.

I guess it is because either option is posible as from the definition NameOrDeclare at:

TiXmlElement* TRestMetadata::GetElementFromFile(std::string cfgFileName, std::string NameOrDecalre) 

But why do we need Declare @nkx?

@lobis lobis requested a review from jgalan March 27, 2022 10:08
@lobis
Copy link
Member Author

lobis commented Mar 27, 2022

I think we should not make any more changes to this branch from this point and merge into master unless someone has any objection @rest-for-physics/core_dev @jgalan . More tests can be added in other PRs.

@jgalan
Copy link
Member

jgalan commented Mar 28, 2022

The upgrade at #165 should allow now to include a test using directly TRestRun.

@lobis lobis merged commit b05be52 into master Mar 28, 2022
@lobis lobis deleted the cmake-ctest branch April 26, 2022 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor CMake build Introduce a testing framework

6 participants