Remove PluginTest and make MujocoTest load plugins.
MujocoTest now loads plugins from MUJOCO_PLUGIN_DIR if set. PluginTest is removed; all tests use MujocoTest directly. testspeed binary loads plugins from MUJOCO_PLUGIN_DIR. This is in preparation for moving common asset format parsing (obj, msh, stl, etc.) where we will always want to load those plugins. PiperOrigin-RevId: 874194428 Change-Id: Id90805a9ba5de4627911b56d8b9c4ab4e1b29310
This commit is contained in:
committed by
Copybara-Service
parent
6ec808e2ce
commit
82e92cbcaa
@@ -187,6 +187,12 @@ int main(int argc, char** argv) {
|
|||||||
nthread = mjMAX(1, mjMIN(maxthread, nthread));
|
nthread = mjMAX(1, mjMIN(maxthread, nthread));
|
||||||
npoolthread = mjMAX(1, mjMIN(maxthread, npoolthread));
|
npoolthread = mjMAX(1, mjMIN(maxthread, npoolthread));
|
||||||
|
|
||||||
|
// load plugins from MUJOCO_PLUGIN_DIR if set
|
||||||
|
const char* plugin_dir = std::getenv("MUJOCO_PLUGIN_DIR");
|
||||||
|
if (plugin_dir) {
|
||||||
|
mj_loadAllPluginLibraries(plugin_dir, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// get filename, determine file type
|
// get filename, determine file type
|
||||||
std::string filename(argv[1]);
|
std::string filename(argv[1]);
|
||||||
bool binary = (filename.find(".mjb") != std::string::npos); // NOLINT
|
bool binary = (filename.find(".mjb") != std::string::npos); // NOLINT
|
||||||
|
|||||||
@@ -376,10 +376,10 @@ int RegisterNoAttributePlugin() {
|
|||||||
return mjp_registerPlugin(&plugin);
|
return mjp_registerPlugin(&plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnginePluginTest : public PluginTest {
|
class EnginePluginTest : public MujocoTest {
|
||||||
public:
|
public:
|
||||||
// register all plugins
|
// register all plugins
|
||||||
EnginePluginTest() : PluginTest() {
|
EnginePluginTest() : MujocoTest() {
|
||||||
RegisterSensorPlugin();
|
RegisterSensorPlugin();
|
||||||
|
|
||||||
for (int i = 1; i <= kNumFakePlugins; ++i) {
|
for (int i = 1; i <= kNumFakePlugins; ++i) {
|
||||||
@@ -466,7 +466,7 @@ TEST_F(MujocoTest, EmptyPluginDisallowed) {
|
|||||||
mj_deleteModel(m);
|
mj_deleteModel(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, FirstPartyPlugins) {
|
TEST_F(MujocoTest, FirstPartyPlugins) {
|
||||||
EXPECT_THAT(mjp_pluginCount(), kNumTruePlugins);
|
EXPECT_THAT(mjp_pluginCount(), kNumTruePlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ using ::testing::DoubleNear;
|
|||||||
using ::testing::ElementsAre;
|
using ::testing::ElementsAre;
|
||||||
using ::testing::NotNull;
|
using ::testing::NotNull;
|
||||||
using ::testing::Pointwise;
|
using ::testing::Pointwise;
|
||||||
using RayTest = PluginTest;
|
using RayTest = MujocoTest;
|
||||||
|
|
||||||
TEST_F(RayTest, NoExclusions) {
|
TEST_F(RayTest, NoExclusions) {
|
||||||
char error[1024];
|
char error[1024];
|
||||||
|
|||||||
+18
-14
@@ -16,9 +16,12 @@
|
|||||||
#define MUJOCO_TEST_FIXTURE_H_
|
#define MUJOCO_TEST_FIXTURE_H_
|
||||||
|
|
||||||
#include <csetjmp>
|
#include <csetjmp>
|
||||||
|
#include <cstdio> // IWYU pragma: keep
|
||||||
|
#include <cstdlib> // IWYU pragma: keep
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <mutex> // IWYU pragma: keep
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -54,6 +57,21 @@ class MujocoErrorTestGuard {
|
|||||||
// trigger a test failure.
|
// trigger a test failure.
|
||||||
class MujocoTest : public ::testing::Test {
|
class MujocoTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
MujocoTest() {
|
||||||
|
static std::once_flag flag;
|
||||||
|
std::call_once(flag, []() {
|
||||||
|
const char* plugin_dir = std::getenv("MUJOCO_PLUGIN_DIR");
|
||||||
|
if (plugin_dir) {
|
||||||
|
mj_loadAllPluginLibraries(
|
||||||
|
plugin_dir, +[](const char* filename, int first, int count) {
|
||||||
|
std::printf("Plugins registered by library '%s':\n", filename);
|
||||||
|
for (int i = first; i < first + count; ++i) {
|
||||||
|
std::printf(" %s\n", mjp_getPluginAtSlot(i)->name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
~MujocoTest() { mj_freeLastXML(); }
|
~MujocoTest() { mj_freeLastXML(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -183,20 +201,6 @@ class MockFilesystem {
|
|||||||
std::string dir_; // current directory
|
std::string dir_; // current directory
|
||||||
};
|
};
|
||||||
|
|
||||||
// Installs all plugins
|
|
||||||
class PluginTest : public MujocoTest {
|
|
||||||
public:
|
|
||||||
// load plugin library
|
|
||||||
PluginTest() : MujocoTest() {
|
|
||||||
mj_loadAllPluginLibraries(
|
|
||||||
std::string(std::getenv("MUJOCO_PLUGIN_DIR")).c_str(), +[](const char* filename, int first, int count) {
|
|
||||||
std::printf("Plugins registered by library '%s':\n", filename);
|
|
||||||
for (int i = first; i < first + count; ++i) {
|
|
||||||
std::printf(" %s\n", mjp_getPluginAtSlot(i)->name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mujoco
|
} // namespace mujoco
|
||||||
#endif // MUJOCO_TEST_FIXTURE_H_
|
#endif // MUJOCO_TEST_FIXTURE_H_
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using PidTest = PluginTest;
|
using PidTest = MujocoTest;
|
||||||
using ::testing::DoubleNear;
|
using ::testing::DoubleNear;
|
||||||
using ::testing::HasSubstr;
|
using ::testing::HasSubstr;
|
||||||
using ::testing::IsNull;
|
using ::testing::IsNull;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ElasticityTest = PluginTest;
|
using ElasticityTest = MujocoTest;
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------- cable -----------------------------------
|
// -------------------------------- cable -----------------------------------
|
||||||
|
|||||||
+14
-14
@@ -171,7 +171,7 @@ TEST_F(MujocoTest, TreeTraversal) {
|
|||||||
mj_deleteSpec(spec);
|
mj_deleteSpec(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, ActivatePlugin) {
|
TEST_F(MujocoTest, ActivatePlugin) {
|
||||||
mjSpec* spec = mj_makeSpec();
|
mjSpec* spec = mj_makeSpec();
|
||||||
mjs_activatePlugin(spec, "mujoco.elasticity.cable");
|
mjs_activatePlugin(spec, "mujoco.elasticity.cable");
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ TEST_F(PluginTest, ActivatePlugin) {
|
|||||||
mj_deleteModel(model);
|
mj_deleteModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, DeletePlugin) {
|
TEST_F(MujocoTest, DeletePlugin) {
|
||||||
mjSpec* spec = mj_makeSpec();
|
mjSpec* spec = mj_makeSpec();
|
||||||
mjs_activatePlugin(spec, "mujoco.pid");
|
mjs_activatePlugin(spec, "mujoco.pid");
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ static constexpr char xml_plugin_2[] = R"(
|
|||||||
</actuator>
|
</actuator>
|
||||||
</mujoco>)";
|
</mujoco>)";
|
||||||
|
|
||||||
TEST_F(PluginTest, AttachPlugin) {
|
TEST_F(MujocoTest, AttachPlugin) {
|
||||||
std::array<char, 1000> err;
|
std::array<char, 1000> err;
|
||||||
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
|
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
|
||||||
ASSERT_THAT(parent, NotNull()) << err.data();
|
ASSERT_THAT(parent, NotNull()) << err.data();
|
||||||
@@ -316,7 +316,7 @@ TEST_F(PluginTest, AttachPlugin) {
|
|||||||
mj_deleteSpec(spec_3);
|
mj_deleteSpec(spec_3);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, DetachPlugin) {
|
TEST_F(MujocoTest, DetachPlugin) {
|
||||||
std::array<char, 1000> err;
|
std::array<char, 1000> err;
|
||||||
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
|
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
|
||||||
ASSERT_THAT(parent, NotNull()) << err.data();
|
ASSERT_THAT(parent, NotNull()) << err.data();
|
||||||
@@ -342,7 +342,7 @@ TEST_F(PluginTest, DetachPlugin) {
|
|||||||
mj_deleteSpec(child);
|
mj_deleteSpec(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, AttachExplicitPlugin) {
|
TEST_F(MujocoTest, AttachExplicitPlugin) {
|
||||||
static constexpr char xml_parent[] = R"(
|
static constexpr char xml_parent[] = R"(
|
||||||
<mujoco model="MuJoCo Model">
|
<mujoco model="MuJoCo Model">
|
||||||
<worldbody>
|
<worldbody>
|
||||||
@@ -396,7 +396,7 @@ TEST_F(PluginTest, AttachExplicitPlugin) {
|
|||||||
mj_deleteModel(model);
|
mj_deleteModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, ReplicatePlugin) {
|
TEST_F(MujocoTest, ReplicatePlugin) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<extension>
|
<extension>
|
||||||
@@ -429,7 +429,7 @@ TEST_F(PluginTest, ReplicatePlugin) {
|
|||||||
mj_deleteModel(model);
|
mj_deleteModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, ReplicateExplicitPlugin) {
|
TEST_F(MujocoTest, ReplicateExplicitPlugin) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<extension>
|
<extension>
|
||||||
@@ -484,7 +484,7 @@ TEST_F(MujocoTest, RecompileFails) {
|
|||||||
mj_deleteSpec(spec);
|
mj_deleteSpec(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, ModifyShellInertiaFails) {
|
TEST_F(MujocoTest, ModifyShellInertiaFails) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<asset>
|
<asset>
|
||||||
@@ -515,7 +515,7 @@ TEST_F(PluginTest, ModifyShellInertiaFails) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------- test recompilation multiple files -----------------------
|
// ------------------- test recompilation multiple files -----------------------
|
||||||
TEST_F(PluginTest, RecompileCompare) {
|
TEST_F(MujocoTest, RecompileCompare) {
|
||||||
mjtNum tol = 0;
|
mjtNum tol = 0;
|
||||||
std::string field = "";
|
std::string field = "";
|
||||||
|
|
||||||
@@ -606,7 +606,7 @@ TEST_F(PluginTest, RecompileCompare) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, RecompileEdit) {
|
TEST_F(MujocoTest, RecompileEdit) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<worldbody>
|
<worldbody>
|
||||||
@@ -640,7 +640,7 @@ TEST_F(PluginTest, RecompileEdit) {
|
|||||||
|
|
||||||
// ------------------- test cache with modified assets -------------------------
|
// ------------------- test cache with modified assets -------------------------
|
||||||
|
|
||||||
TEST_F(PluginTest, RecompileCompareObjCache) {
|
TEST_F(MujocoTest, RecompileCompareObjCache) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<asset>
|
<asset>
|
||||||
@@ -716,7 +716,7 @@ static constexpr uint8_t tex2[] = {
|
|||||||
0x82
|
0x82
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(PluginTest, RecompileComparePngCache) {
|
TEST_F(MujocoTest, RecompileComparePngCache) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<asset>
|
<asset>
|
||||||
@@ -753,7 +753,7 @@ TEST_F(PluginTest, RecompileComparePngCache) {
|
|||||||
mj_deleteVFS(vfs.get());
|
mj_deleteVFS(vfs.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PluginTest, DisableCache) {
|
TEST_F(MujocoTest, DisableCache) {
|
||||||
static constexpr char xml[] = R"(
|
static constexpr char xml[] = R"(
|
||||||
<mujoco>
|
<mujoco>
|
||||||
<asset>
|
<asset>
|
||||||
@@ -791,7 +791,7 @@ TEST_F(PluginTest, DisableCache) {
|
|||||||
|
|
||||||
// -------------------------------- test textures ------------------------------
|
// -------------------------------- test textures ------------------------------
|
||||||
|
|
||||||
TEST_F(PluginTest, TextureFromBuffer) {
|
TEST_F(MujocoTest, TextureFromBuffer) {
|
||||||
mjSpec* spec = mj_makeSpec();
|
mjSpec* spec = mj_makeSpec();
|
||||||
|
|
||||||
mjsTexture* t1 = mjs_addTexture(spec);
|
mjsTexture* t1 = mjs_addTexture(spec);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ using ::testing::HasSubstr;
|
|||||||
using ::testing::Not;
|
using ::testing::Not;
|
||||||
using ::testing::NotNull;
|
using ::testing::NotNull;
|
||||||
|
|
||||||
using XMLWriterTest = PluginTest;
|
using XMLWriterTest = MujocoTest;
|
||||||
|
|
||||||
static const char* const kNonRgbTextureXMLPath =
|
static const char* const kNonRgbTextureXMLPath =
|
||||||
"xml/testdata/hfield_png_nonrgb.xml";
|
"xml/testdata/hfield_png_nonrgb.xml";
|
||||||
|
|||||||
Reference in New Issue
Block a user