diff --git a/Extras/Serialize/BulletFileLoader/bFile.cpp b/Extras/Serialize/BulletFileLoader/bFile.cpp index 469ee6715..35135ba7a 100644 --- a/Extras/Serialize/BulletFileLoader/bFile.cpp +++ b/Extras/Serialize/BulletFileLoader/bFile.cpp @@ -644,7 +644,7 @@ void bFile::preSwap() swap(dataPtrHead, dataChunk,ignoreEndianFlag); } else { - printf("unknown chunk\n"); + //printf("unknown chunk\n"); } } diff --git a/Extras/Serialize/BulletFileLoader/btBulletFile.cpp b/Extras/Serialize/BulletFileLoader/btBulletFile.cpp index f3ed47c40..18cb15321 100644 --- a/Extras/Serialize/BulletFileLoader/btBulletFile.cpp +++ b/Extras/Serialize/BulletFileLoader/btBulletFile.cpp @@ -224,7 +224,7 @@ void btBulletFile::parseData() // } } else { - printf("unknown chunk\n"); + //printf("unknown chunk\n"); mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)dataPtrHead); } diff --git a/data/r2d2.urdf b/data/r2d2.urdf index 460be6758..8e44dcdec 100644 --- a/data/r2d2.urdf +++ b/data/r2d2.urdf @@ -234,6 +234,7 @@ + diff --git a/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp b/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp index 317fe9c13..f5a70a0cf 100644 --- a/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp +++ b/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp @@ -316,12 +316,12 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArraysize(); visualShape.m_numIndices = visualShape.m_indices->size(); visualShape.m_numvertices = visualShape.m_vertices->size(); } - printf("geometry name=%s\n",geometryName); + //b3Printf("geometry name=%s\n",geometryName); name2Shape.insert(geometryName,shapeIndex); @@ -331,7 +331,7 @@ void readLibraryGeometries(TiXmlDocument& doc, btAlignedObjectArray& name2Shape, btAlignedObjectArray& visualShapeInstances, const btMatrix4x4& parentTransMat) { const char* nodeName = node->Attribute("id"); - printf("processing node %s\n", nodeName); + //printf("processing node %s\n", nodeName); btMatrix4x4 nodeTrans; @@ -356,7 +356,7 @@ void readNodeHierarchy(TiXmlElement* node,btHashMap& name2Shap nodeTrans = nodeTrans*t; } else { - printf("Error: expected 16 elements in a element, skipping\n"); + b3Warning("Error: expected 16 elements in a element, skipping\n"); } } } @@ -412,19 +412,19 @@ void readNodeHierarchy(TiXmlElement* node,btHashMap& name2Shap instanceGeom=instanceGeom->NextSiblingElement("instance_geometry")) { const char* geomUrl = instanceGeom->Attribute("url"); - printf("node referring to geom %s\n", geomUrl); + //printf("node referring to geom %s\n", geomUrl); geomUrl++; int* shapeIndexPtr = name2Shape[geomUrl]; if (shapeIndexPtr) { // int index = *shapeIndexPtr; - printf("found geom with index %d\n", *shapeIndexPtr); + //printf("found geom with index %d\n", *shapeIndexPtr); ColladaGraphicsInstance& instance = visualShapeInstances.expand(); instance.m_shapeIndex = *shapeIndexPtr; instance.m_worldTransform = nodeTrans; } else { - printf("geom not found\n"); + b3Warning("geom not found\n"); } } @@ -492,7 +492,7 @@ void getUnitMeterScalingAndUpAxisTransform(TiXmlDocument& doc, btTransform& tr, if (unitMeter) { const char* meterText = unitMeter->Attribute("meter"); - printf("meterText=%s\n", meterText); + //printf("meterText=%s\n", meterText); unitMeterScaling = atof(meterText); } @@ -565,7 +565,7 @@ void LoadMeshFromCollada(const char* relativeFileName, btAlignedObjectArray vertices; //int numVerts = sizeof(barrel_vertices)/(9*sizeof(float)); @@ -306,7 +305,6 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref } case URDF_GEOM_BOX: { - printf("processing a box\n"); btVector3 extents = visual->m_geometry.m_boxSize; @@ -318,7 +316,6 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref } case URDF_GEOM_SPHERE: { - printf("processing a sphere\n"); btScalar radius = visual->m_geometry.m_sphereRadius; btSphereShape* sphereShape = new btSphereShape(radius); convexColShape = sphereShape; @@ -331,14 +328,14 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref { if (visual->m_name.length()) { - printf("visual->name=%s\n", visual->m_name.c_str()); + //b3Printf("visual->name=%s\n", visual->m_name.c_str()); } if (1)//visual->m_geometry) { if (visual->m_geometry.m_meshFileName.length()) { const char* filename = visual->m_geometry.m_meshFileName.c_str(); - printf("mesh->filename=%s\n", filename); + //b3Printf("mesh->filename=%s\n", filename); char fullPath[1024]; int fileType = 0; @@ -471,7 +468,7 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref } default: { - printf("Error: unsupported file type for Visual mesh: %s\n", fullPath); + b3Warning("Error: unsupported file type for Visual mesh: %s\n", fullPath); btAssert(0); } } @@ -482,13 +479,13 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref } else { - printf("issue extracting mesh from COLLADA/STL file %s\n", fullPath); + b3Warning("issue extracting mesh from COLLADA/STL file %s\n", fullPath); } } else { - printf("mesh geometry not found %s\n", fullPath); + b3Warning("mesh geometry not found %s\n", fullPath); } @@ -500,7 +497,7 @@ void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPref } default: { - printf("Error: unknown visual geometry type\n"); + b3Warning("Error: unknown visual geometry type\n"); } } @@ -593,7 +590,6 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co { case URDF_GEOM_CYLINDER: { - printf("processing a cylinder\n"); btScalar cylRadius = collision->m_geometry.m_cylinderRadius; btScalar cylLength = collision->m_geometry.m_cylinderLength; @@ -623,7 +619,6 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co } case URDF_GEOM_BOX: { - printf("processing a box\n"); btVector3 extents = collision->m_geometry.m_boxSize; btBoxShape* boxShape = new btBoxShape(extents*0.5f); //btConvexShape* boxShape = new btConeShapeX(extents[2]*0.5,extents[0]*0.5); @@ -633,7 +628,6 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co } case URDF_GEOM_SPHERE: { - printf("processing a sphere\n"); btScalar radius = collision->m_geometry.m_sphereRadius; btSphereShape* sphereShape = new btSphereShape(radius); @@ -647,14 +641,14 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co { if (collision->m_name.length()) { - printf("collision->name=%s\n",collision->m_name.c_str()); + //b3Printf("collision->name=%s\n",collision->m_name.c_str()); } if (1) { if (collision->m_geometry.m_meshFileName.length()) { const char* filename = collision->m_geometry.m_meshFileName.c_str(); - printf("mesh->filename=%s\n",filename); + //b3Printf("mesh->filename=%s\n",filename); char fullPath[1024]; int fileType = 0; sprintf(fullPath,"%s%s",urdfPathPrefix,filename); @@ -783,7 +777,7 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co } default: { - printf("Unsupported file type in Collision: %s\n",fullPath); + b3Warning("Unsupported file type in Collision: %s\n",fullPath); btAssert(0); } } @@ -791,7 +785,7 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co if (glmesh && (glmesh->m_numvertices>0)) { - printf("extracted %d verticed from STL file %s\n", glmesh->m_numvertices,fullPath); + //b3Printf("extracted %d verticed from STL file %s\n", glmesh->m_numvertices,fullPath); //int shapeId = m_glApp->m_instancingRenderer->registerShape(&gvertices[0].pos[0],gvertices.size(),&indices[0],indices.size()); //convex->setUserIndex(shapeId); btAlignedObjectArray convertedVerts; @@ -809,12 +803,12 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co shape = cylZShape; } else { - printf("issue extracting mesh from STL file %s\n", fullPath); + b3Warning("issue extracting mesh from STL file %s\n", fullPath); } } else { - printf("mesh geometry not found %s\n",fullPath); + b3Warning("mesh geometry not found %s\n",fullPath); } @@ -826,7 +820,7 @@ btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, co } default: { - printf("Error: unknown visual geometry type\n"); + b3Warning("Error: unknown visual geometry type\n"); } } return shape; diff --git a/examples/Importers/ImportURDFDemo/UrdfParser.cpp b/examples/Importers/ImportURDFDemo/UrdfParser.cpp index a40d864fa..27e8a156f 100644 --- a/examples/Importers/ImportURDFDemo/UrdfParser.cpp +++ b/examples/Importers/ImportURDFDemo/UrdfParser.cpp @@ -766,9 +766,10 @@ bool UrdfParser::loadUrdf(const char* urdfText, ErrorLogger* logger, bool forceF } } - char msg[1024]; - sprintf(msg,"Num materials=%d", m_model.m_materials.size()); - logger->printMessage(msg); + +// char msg[1024]; +// sprintf(msg,"Num materials=%d", m_model.m_materials.size()); +// logger->printMessage(msg); for (TiXmlElement* link_xml = robot_xml->FirstChildElement("link"); link_xml; link_xml = link_xml->NextSiblingElement("link")) diff --git a/src/Bullet3Serialize/Bullet2FileLoader/b3BulletFile.cpp b/src/Bullet3Serialize/Bullet2FileLoader/b3BulletFile.cpp index 6f47f3b6e..c3ceb8388 100644 --- a/src/Bullet3Serialize/Bullet2FileLoader/b3BulletFile.cpp +++ b/src/Bullet3Serialize/Bullet2FileLoader/b3BulletFile.cpp @@ -215,7 +215,7 @@ void b3BulletFile::parseData() // } } else { - printf("unknown chunk\n"); + //printf("unknown chunk\n"); mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)dataPtrHead); } @@ -420,4 +420,4 @@ void b3BulletFile::addStruct(const char* structType,void* data, int len, void* o mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)data); m_chunks.push_back(dataChunk); -} \ No newline at end of file +} diff --git a/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp b/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp index e684fcc42..01d3a696c 100644 --- a/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp +++ b/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp @@ -612,7 +612,7 @@ void bFile::preSwap() swap(dataPtrHead, dataChunk,ignoreEndianFlag); } else { - printf("unknown chunk\n"); + //printf("unknown chunk\n"); } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e8b0842a0..2b08544e7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ IF(BUILD_BULLET3) #SUBDIRS( TestBullet3OpenCL ) - SUBDIRS( InverseDynamics ) + SUBDIRS( InverseDynamics SharedMemory ) ENDIF(BUILD_BULLET3) -SUBDIRS( gtest-1.7.0 collision BulletDynamics/pendulum ) +SUBDIRS( gtest-1.7.0 collision BulletDynamics/pendulum ) diff --git a/test/SharedMemory/CMakeLists.txt b/test/SharedMemory/CMakeLists.txt new file mode 100644 index 000000000..eb259f9b5 --- /dev/null +++ b/test/SharedMemory/CMakeLists.txt @@ -0,0 +1,73 @@ + +INCLUDE_DIRECTORIES( + . + ../../src + ../gtest-1.7.0/include + ../../examples + ../../examples/ThirdPartyLibs +) + + +#ADD_DEFINITIONS(-DGTEST_HAS_PTHREAD=1) +ADD_DEFINITIONS(-DPHYSICS_LOOP_BACK -DPHYSICS_SERVER_DIRECT -DENABLE_GTEST -D_VARIADIC_MAX=10) + + +LINK_LIBRARIES( + BulletFileLoader BulletWorldImporter Bullet3Common BulletDynamics BulletCollision LinearMath gtest +) + +IF (NOT WIN32) + LINK_LIBRARIES( pthread ) +ENDIF() + + ADD_EXECUTABLE(Test_PhysicsClientServer + gtestwrap.cpp + ../../examples/SharedMemory/PhysicsClient.cpp + ../../examples/SharedMemory/PhysicsClient.h + ../../examples/SharedMemory/PhysicsServer.cpp + ../../examples/SharedMemory/PhysicsServer.h + ../../examples/SharedMemory/PhysicsServerSharedMemory.cpp + ../../examples/SharedMemory/PhysicsServerSharedMemory.h + ../../examples/SharedMemory/PhysicsDirect.cpp + ../../examples/SharedMemory/PhysicsDirect.h + ../../examples/SharedMemory/PhysicsDirectC_API.cpp + ../../examples/SharedMemory/PhysicsDirectC_API.h + ../../examples/SharedMemory/PhysicsServerCommandProcessor.cpp + ../../examples/SharedMemory/PhysicsServerCommandProcessor.h + ../../examples/SharedMemory/PhysicsClientSharedMemory.cpp + ../../examples/SharedMemory/PhysicsClientSharedMemory.h + ../../examples/SharedMemory/PhysicsClientC_API.cpp + ../../examples/SharedMemory/PhysicsClientC_API.h + ../../examples/SharedMemory/PhysicsLoopBack.cpp + ../../examples/SharedMemory/PhysicsLoopBack.h + ../../examples/SharedMemory/PhysicsLoopBackC_API.cpp + ../../examples/SharedMemory/PhysicsLoopBackC_API.h + ../../examples/SharedMemory/Win32SharedMemory.cpp + ../../examples/SharedMemory/Win32SharedMemory.h + ../../examples/SharedMemory/PosixSharedMemory.cpp + ../../examples/SharedMemory/PosixSharedMemory.h + ../../examples/Utils/b3ResourcePath.cpp + ../../examples/Utils/b3ResourcePath.h + ../../examples/ThirdPartyLibs/tinyxml/tinystr.cpp + ../../examples/ThirdPartyLibs/tinyxml/tinyxml.cpp + ../../examples/ThirdPartyLibs/tinyxml/tinyxmlerror.cpp + ../../examples/ThirdPartyLibs/tinyxml/tinyxmlparser.cpp + ../../examples/ThirdPartyLibs/Wavefront/tiny_obj_loader.cpp + ../../examples/ThirdPartyLibs/Wavefront/tiny_obj_loader.h + ../../examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp + ../../examples/Importers/ImportObjDemo/LoadMeshFromObj.cpp + ../../examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp + ../../examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp + ../../examples/Importers/ImportURDFDemo/MyMultiBodyCreator.cpp + ../../examples/Importers/ImportURDFDemo/URDF2Bullet.cpp + ../../examples/Importers/ImportURDFDemo/UrdfParser.cpp + ../../examples/Importers/ImportURDFDemo/urdfStringSplit.cpp + ) + +ADD_TEST(Test_PhysicsClientServer_PASS Test_PhysicsClientServer) + +IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) + SET_TARGET_PROPERTIES(Test_PhysicsClientServer PROPERTIES DEBUG_POSTFIX "_Debug") + SET_TARGET_PROPERTIES(Test_PhysicsClientServer PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") + SET_TARGET_PROPERTIES(Test_PhysicsClientServer PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") +ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) diff --git a/test/SharedMemory/gtestwrap.cpp b/test/SharedMemory/gtestwrap.cpp new file mode 100644 index 000000000..c26073485 --- /dev/null +++ b/test/SharedMemory/gtestwrap.cpp @@ -0,0 +1,23 @@ +#include +#include "test.c" +#include "Bullet3Common/b3Logging.h" + +void myprintf(const char* bla) +{ +} + + +int main(int argc, char **argv) { + +b3SetCustomPrintfFunc(myprintf); +b3SetCustomWarningMessageFunc(myprintf); + + +#if _MSC_VER + _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); + //void *testWhetherMemoryLeakDetectionWorks = malloc(1); +#endif + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + diff --git a/test/SharedMemory/test.c b/test/SharedMemory/test.c index 6171acdff..dd8c7dfe8 100644 --- a/test/SharedMemory/test.c +++ b/test/SharedMemory/test.c @@ -22,8 +22,14 @@ #include +#ifndef ENABLE_GTEST +#include +#define ASSERT_EQ(a,b) assert((a)==(b)); +#else +#define printf +#endif -int main(int argc, char* argv[]) +void testSharedMemory(b3PhysicsClientHandle sm) { int i, dofCount , posVarCount, ret ,numJoints ; int sensorJointIndexLeft=-1; @@ -34,21 +40,6 @@ int main(int argc, char* argv[]) double startPosX, startPosY,startPosZ; int imuLinkIndex = -1; int bodyIndex = -1; -#ifdef PHYSICS_LOOP_BACK - b3PhysicsClientHandle sm = b3ConnectPhysicsLoopback(SHARED_MEMORY_KEY); -#endif - -#ifdef PHYSICS_SERVER_DIRECT - b3PhysicsClientHandle sm = b3ConnectPhysicsDirect(); -#endif - -#ifdef PHYSICS_IN_PROCESS_EXAMPLE_BROWSER - b3PhysicsClientHandle sm = b3CreateInProcessPhysicsServerAndConnect(argc,argv); -#endif -#ifdef PHYSICS_SHARED_MEMORY - b3PhysicsClientHandle sm = b3ConnectSharedMemory(SHARED_MEMORY_KEY); -#endif //PHYSICS_SHARED_MEMORY - if (b3CanSubmitCommand(sm)) { @@ -72,10 +63,7 @@ int main(int argc, char* argv[]) ret = b3LoadUrdfCommandSetStartPosition(command, startPosX,startPosY,startPosZ); statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); statusType = b3GetStatusType(statusHandle); - if (statusType != CMD_URDF_LOADING_COMPLETED) - { - printf("Loading URDF failed, status type = %d\n",statusType); - } + ASSERT_EQ(statusType, CMD_URDF_LOADING_COMPLETED); bodyIndex = b3GetStatusBodyIndex(statusHandle); } @@ -87,7 +75,7 @@ int main(int argc, char* argv[]) struct b3JointInfo jointInfo; b3GetJointInfo(sm,bodyIndex, i,&jointInfo); - printf("jointInfo[%d].m_jointName=%s\n",i,jointInfo.m_jointName); + // printf("jointInfo[%d].m_jointName=%s\n",i,jointInfo.m_jointName); //pick the IMU link index based on torso name if (strstr(jointInfo.m_linkName,"base_link")) { @@ -144,15 +132,16 @@ int main(int argc, char* argv[]) b3SharedMemoryStatusHandle statusHandle; statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); statusType = b3GetStatusType(statusHandle); - + ASSERT_EQ(statusType, CMD_ACTUAL_STATE_UPDATE_COMPLETED); + if (statusType == CMD_ACTUAL_STATE_UPDATE_COMPLETED) { b3GetStatusActualState(statusHandle, 0, &posVarCount, &dofCount, 0, 0, 0, 0); + ASSERT_EQ(posVarCount,15); + ASSERT_EQ(dofCount,14); - b3Printf("posVarCount = %d\n",posVarCount); - printf("dofCount = %d\n",dofCount); } } @@ -176,11 +165,7 @@ int main(int argc, char* argv[]) statusHandle = b3SubmitClientCommandAndWaitStatus(sm, b3InitStepSimulationCommand(sm)); statusType = b3GetStatusType(statusHandle); - if (statusType != CMD_STEP_FORWARD_SIMULATION_COMPLETED) - { - printf("Step Simulation failed, Unexpected status type = %d\n",statusType); - break; - } + ASSERT_EQ(statusType, CMD_STEP_FORWARD_SIMULATION_COMPLETED); } { @@ -222,3 +207,43 @@ int main(int argc, char* argv[]) b3DisconnectSharedMemory(sm); } + + + +#ifdef ENABLE_GTEST + + +TEST(BulletPhysicsClientServerTest, DirectConnection) { + b3PhysicsClientHandle sm = b3ConnectPhysicsDirect(); + testSharedMemory(sm); +} + +TEST(BulletPhysicsClientServerTest, LoopBackSharedMemory) { + b3PhysicsClientHandle sm = b3ConnectPhysicsLoopback(SHARED_MEMORY_KEY); + testSharedMemory(sm); +} + + +#else + +int main(int argc, char* argv[]) +{ +#ifdef PHYSICS_LOOP_BACK + b3PhysicsClientHandle sm = b3ConnectPhysicsLoopback(SHARED_MEMORY_KEY); +#endif + +#ifdef PHYSICS_SERVER_DIRECT + b3PhysicsClientHandle sm = b3ConnectPhysicsDirect(); +#endif + +#ifdef PHYSICS_IN_PROCESS_EXAMPLE_BROWSER + b3PhysicsClientHandle sm = b3CreateInProcessPhysicsServerAndConnect(argc,argv); +#endif +#ifdef PHYSICS_SHARED_MEMORY + b3PhysicsClientHandle sm = b3ConnectSharedMemory(SHARED_MEMORY_KEY); +#endif //PHYSICS_SHARED_MEMORY + + testSharedMemory(sm); +} +#endif +