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:
Sam Haves
2026-02-23 12:14:37 -08:00
committed by Copybara-Service
parent 6ec808e2ce
commit 82e92cbcaa
8 changed files with 45 additions and 35 deletions
+6
View File
@@ -187,6 +187,12 @@ int main(int argc, char** argv) {
nthread = mjMAX(1, mjMIN(maxthread, nthread));
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
std::string filename(argv[1]);
bool binary = (filename.find(".mjb") != std::string::npos); // NOLINT
+3 -3
View File
@@ -376,10 +376,10 @@ int RegisterNoAttributePlugin() {
return mjp_registerPlugin(&plugin);
}
class EnginePluginTest : public PluginTest {
class EnginePluginTest : public MujocoTest {
public:
// register all plugins
EnginePluginTest() : PluginTest() {
EnginePluginTest() : MujocoTest() {
RegisterSensorPlugin();
for (int i = 1; i <= kNumFakePlugins; ++i) {
@@ -466,7 +466,7 @@ TEST_F(MujocoTest, EmptyPluginDisallowed) {
mj_deleteModel(m);
}
TEST_F(PluginTest, FirstPartyPlugins) {
TEST_F(MujocoTest, FirstPartyPlugins) {
EXPECT_THAT(mjp_pluginCount(), kNumTruePlugins);
}
+1 -1
View File
@@ -82,7 +82,7 @@ using ::testing::DoubleNear;
using ::testing::ElementsAre;
using ::testing::NotNull;
using ::testing::Pointwise;
using RayTest = PluginTest;
using RayTest = MujocoTest;
TEST_F(RayTest, NoExclusions) {
char error[1024];
+18 -14
View File
@@ -16,9 +16,12 @@
#define MUJOCO_TEST_FIXTURE_H_
#include <csetjmp>
#include <cstdio> // IWYU pragma: keep
#include <cstdlib> // IWYU pragma: keep
#include <cstring>
#include <iomanip>
#include <iostream>
#include <mutex> // IWYU pragma: keep
#include <string>
#include <string_view>
#include <vector>
@@ -54,6 +57,21 @@ class MujocoErrorTestGuard {
// trigger a test failure.
class MujocoTest : public ::testing::Test {
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(); }
private:
@@ -183,20 +201,6 @@ class MockFilesystem {
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
#endif // MUJOCO_TEST_FIXTURE_H_
+1 -1
View File
@@ -29,7 +29,7 @@
namespace mujoco {
namespace {
using PidTest = PluginTest;
using PidTest = MujocoTest;
using ::testing::DoubleNear;
using ::testing::HasSubstr;
using ::testing::IsNull;
+1 -1
View File
@@ -26,7 +26,7 @@
namespace mujoco {
namespace {
using ElasticityTest = PluginTest;
using ElasticityTest = MujocoTest;
// -------------------------------- cable -----------------------------------
+14 -14
View File
@@ -171,7 +171,7 @@ TEST_F(MujocoTest, TreeTraversal) {
mj_deleteSpec(spec);
}
TEST_F(PluginTest, ActivatePlugin) {
TEST_F(MujocoTest, ActivatePlugin) {
mjSpec* spec = mj_makeSpec();
mjs_activatePlugin(spec, "mujoco.elasticity.cable");
@@ -196,7 +196,7 @@ TEST_F(PluginTest, ActivatePlugin) {
mj_deleteModel(model);
}
TEST_F(PluginTest, DeletePlugin) {
TEST_F(MujocoTest, DeletePlugin) {
mjSpec* spec = mj_makeSpec();
mjs_activatePlugin(spec, "mujoco.pid");
@@ -267,7 +267,7 @@ static constexpr char xml_plugin_2[] = R"(
</actuator>
</mujoco>)";
TEST_F(PluginTest, AttachPlugin) {
TEST_F(MujocoTest, AttachPlugin) {
std::array<char, 1000> err;
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
ASSERT_THAT(parent, NotNull()) << err.data();
@@ -316,7 +316,7 @@ TEST_F(PluginTest, AttachPlugin) {
mj_deleteSpec(spec_3);
}
TEST_F(PluginTest, DetachPlugin) {
TEST_F(MujocoTest, DetachPlugin) {
std::array<char, 1000> err;
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
ASSERT_THAT(parent, NotNull()) << err.data();
@@ -342,7 +342,7 @@ TEST_F(PluginTest, DetachPlugin) {
mj_deleteSpec(child);
}
TEST_F(PluginTest, AttachExplicitPlugin) {
TEST_F(MujocoTest, AttachExplicitPlugin) {
static constexpr char xml_parent[] = R"(
<mujoco model="MuJoCo Model">
<worldbody>
@@ -396,7 +396,7 @@ TEST_F(PluginTest, AttachExplicitPlugin) {
mj_deleteModel(model);
}
TEST_F(PluginTest, ReplicatePlugin) {
TEST_F(MujocoTest, ReplicatePlugin) {
static constexpr char xml[] = R"(
<mujoco>
<extension>
@@ -429,7 +429,7 @@ TEST_F(PluginTest, ReplicatePlugin) {
mj_deleteModel(model);
}
TEST_F(PluginTest, ReplicateExplicitPlugin) {
TEST_F(MujocoTest, ReplicateExplicitPlugin) {
static constexpr char xml[] = R"(
<mujoco>
<extension>
@@ -484,7 +484,7 @@ TEST_F(MujocoTest, RecompileFails) {
mj_deleteSpec(spec);
}
TEST_F(PluginTest, ModifyShellInertiaFails) {
TEST_F(MujocoTest, ModifyShellInertiaFails) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
@@ -515,7 +515,7 @@ TEST_F(PluginTest, ModifyShellInertiaFails) {
}
// ------------------- test recompilation multiple files -----------------------
TEST_F(PluginTest, RecompileCompare) {
TEST_F(MujocoTest, RecompileCompare) {
mjtNum tol = 0;
std::string field = "";
@@ -606,7 +606,7 @@ TEST_F(PluginTest, RecompileCompare) {
}
}
TEST_F(PluginTest, RecompileEdit) {
TEST_F(MujocoTest, RecompileEdit) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
@@ -640,7 +640,7 @@ TEST_F(PluginTest, RecompileEdit) {
// ------------------- test cache with modified assets -------------------------
TEST_F(PluginTest, RecompileCompareObjCache) {
TEST_F(MujocoTest, RecompileCompareObjCache) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
@@ -716,7 +716,7 @@ static constexpr uint8_t tex2[] = {
0x82
};
TEST_F(PluginTest, RecompileComparePngCache) {
TEST_F(MujocoTest, RecompileComparePngCache) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
@@ -753,7 +753,7 @@ TEST_F(PluginTest, RecompileComparePngCache) {
mj_deleteVFS(vfs.get());
}
TEST_F(PluginTest, DisableCache) {
TEST_F(MujocoTest, DisableCache) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
@@ -791,7 +791,7 @@ TEST_F(PluginTest, DisableCache) {
// -------------------------------- test textures ------------------------------
TEST_F(PluginTest, TextureFromBuffer) {
TEST_F(MujocoTest, TextureFromBuffer) {
mjSpec* spec = mj_makeSpec();
mjsTexture* t1 = mjs_addTexture(spec);
+1 -1
View File
@@ -44,7 +44,7 @@ using ::testing::HasSubstr;
using ::testing::Not;
using ::testing::NotNull;
using XMLWriterTest = PluginTest;
using XMLWriterTest = MujocoTest;
static const char* const kNonRgbTextureXMLPath =
"xml/testdata/hfield_png_nonrgb.xml";