telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 264 forks source link

Not same building mode for unit_test and regular code #2726

Open fgalan opened 7 years ago

fgalan commented 7 years ago

Do the following comparison.

First, look for this line in Entity::check()

if (((apiVersion == V2) && (len = strlen(id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest))

Change V2 by 2 and run make debug or make. Everything is ok.

Now, look for the following line in mongoQueryTypes_test.cpp

ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false);

Change V1 by 1 and run make unit_test. You should get the following compiler error:

/home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp: In member function ‘virtual void mongoQueryTypes_queryAllType_Test::TestBody()’:
/home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp:204:81: error: invalid conversion from ‘int’ to ‘ApiVersion’ [-fpermissive]
     ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, 1, NULL, false);
                                                                                 ^
In file included from /home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp:32:0:
/home/fermin/src/fiware-orion/src/lib/mongoBackend/mongoQueryTypes.h:55:23: note: initializing argument 5 of ‘HttpStatusCode mongoEntityTypes(EntityTypeVectorResponse*, const string&, const std::vector<std::basic_string<char> >&, std::map<std::basic_string<char>, std::basic_string<char> >&, ApiVersion, unsigned int*, bool)’
 extern HttpStatusCode mongoEntityTypes
                       ^

My theory is that CMakeList.txt are in a way in which unit test and regular build is not the same. The unit test build is more strict, so we should change regular build to be the same.


Edit: running second case with VERBOSE=1

cd /home/fermin/src/fiware-orion/BUILD_UNITTEST/test/unittests && /usr/bin/c++   -DDEBUG -DDEBUG_fermin -DLINUX -DUNIT_TEST -Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -Werror -fno-var-tracking-assignments -DLINUX -Wno-unused-variable -fprofile-arcs -ftest-coverage -g -I/home/fermin/src/fiware-orion -I/home/fermin/src/fiware-orion/src/lib -I/home/fermin/src/fiware-orion/src/app -I/home/fermin/src/fiware-orion/test/unittests    -fPIC -DDEBUG_SER    -o CMakeFiles/unitTest.dir/mongoBackend/mongoQueryTypes_test.cpp.o -c /home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp
/home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp: In member function ‘virtual void mongoQueryTypes_queryAllType_Test::TestBody()’:
/home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp:204:81: error: invalid conversion from ‘int’ to ‘ApiVersion’ [-fpermissive]
     ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, 1, NULL, false);
                                                                                 ^
In file included from /home/fermin/src/fiware-orion/test/unittests/mongoBackend/mongoQueryTypes_test.cpp:32:0:
/home/fermin/src/fiware-orion/src/lib/mongoBackend/mongoQueryTypes.h:55:23: note: initializing argument 5 of ‘HttpStatusCode mongoEntityTypes(EntityTypeVectorResponse*, const string&, const std::vector<std::basic_string<char> >&, std::map<std::basic_string<char>, std::basic_string<char> >&, ApiVersion, unsigned int*, bool)’
 extern HttpStatusCode mongoEntityTypes
                       ^
test/unittests/CMakeFiles/unitTest.dir/build.make:2883: recipe for target 'test/unittests/CMakeFiles/unitTest.dir/mongoBackend/mongoQueryTypes_test.cpp.o' failed
fgalan commented 7 years ago

More info:

Running with VERBOSE=1 we have, for debug target (random file):

cd /home/fermin/src/fiware-orion/BUILD_DEBUG/src/lib/parseArgs && /usr/bin/c++   -DDEBUG 
-DDEBUG_fermin -DLINUX -DLM_ON -Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE 
-D_GNU_SOURCE -Werror -fno-var-tracking-assignments -DLINUX -g
 -I/home/fermin/src/fiware-orion/src/lib    -fPIC -DDEBUG_SER  -fstack-check -fstack-protector
 -o CMakeFiles/pa.dir/paParse.cpp.o -c /home/fermin/src/fiware-orion/src/lib/parseArgs/paParse.cpp

Same file, for the unit_test target:

cd /home/fermin/src/fiware-orion/BUILD_UNITTEST/src/lib/parseArgs && /usr/bin/c++   -DDEBUG 
-DDEBUG_fermin -DLINUX -DUNIT_TEST -Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE 
-D_GNU_SOURCE -Werror -fno-var-tracking-assignments -DLINUX -Wno-unused-variable -fprofile-arcs 
-ftest-coverage -g -I/home/fermin/src/fiware-orion/src/lib    -fPIC -DDEBUG_SER  -fstack-check 
-fstack-protector -o CMakeFiles/pa.dir/paParse.cpp.o 
-c /home/fermin/src/fiware-orion/src/lib/parseArgs/paParse.cpp

"Canceling" the differences what we have, for the debug case:

-DLM_ON

and for the unit_test case

-DUNIT_TEST -Wno-unused-variable -fprofile-arcs -ftest-coverage    
fgalan commented 7 years ago

Another interesting fact...

With the V2 -> 2 modification in:

if (((apiVersion == V2) && (len = strlen(id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest))

Both make debug and make unit_test work. So, it is not a matter of global build configuration different betwen targets. It seems some local build configuration that affect only files under test/unittests.

Weird...