Skip to content

Commit 82e92cb

Browse files
havesscopybara-github
authored andcommitted
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
1 parent 6ec808e commit 82e92cb

File tree

8 files changed

+45
-35
lines changed

8 files changed

+45
-35
lines changed

sample/testspeed.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ int main(int argc, char** argv) {
187187
nthread = mjMAX(1, mjMIN(maxthread, nthread));
188188
npoolthread = mjMAX(1, mjMIN(maxthread, npoolthread));
189189

190+
// load plugins from MUJOCO_PLUGIN_DIR if set
191+
const char* plugin_dir = std::getenv("MUJOCO_PLUGIN_DIR");
192+
if (plugin_dir) {
193+
mj_loadAllPluginLibraries(plugin_dir, nullptr);
194+
}
195+
190196
// get filename, determine file type
191197
std::string filename(argv[1]);
192198
bool binary = (filename.find(".mjb") != std::string::npos); // NOLINT

test/engine/engine_plugin_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,10 @@ int RegisterNoAttributePlugin() {
376376
return mjp_registerPlugin(&plugin);
377377
}
378378

379-
class EnginePluginTest : public PluginTest {
379+
class EnginePluginTest : public MujocoTest {
380380
public:
381381
// register all plugins
382-
EnginePluginTest() : PluginTest() {
382+
EnginePluginTest() : MujocoTest() {
383383
RegisterSensorPlugin();
384384

385385
for (int i = 1; i <= kNumFakePlugins; ++i) {
@@ -466,7 +466,7 @@ TEST_F(MujocoTest, EmptyPluginDisallowed) {
466466
mj_deleteModel(m);
467467
}
468468

469-
TEST_F(PluginTest, FirstPartyPlugins) {
469+
TEST_F(MujocoTest, FirstPartyPlugins) {
470470
EXPECT_THAT(mjp_pluginCount(), kNumTruePlugins);
471471
}
472472

test/engine/engine_ray_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ using ::testing::DoubleNear;
8282
using ::testing::ElementsAre;
8383
using ::testing::NotNull;
8484
using ::testing::Pointwise;
85-
using RayTest = PluginTest;
85+
using RayTest = MujocoTest;
8686

8787
TEST_F(RayTest, NoExclusions) {
8888
char error[1024];

test/fixture.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
#define MUJOCO_TEST_FIXTURE_H_
1717

1818
#include <csetjmp>
19+
#include <cstdio> // IWYU pragma: keep
20+
#include <cstdlib> // IWYU pragma: keep
1921
#include <cstring>
2022
#include <iomanip>
2123
#include <iostream>
24+
#include <mutex> // IWYU pragma: keep
2225
#include <string>
2326
#include <string_view>
2427
#include <vector>
@@ -54,6 +57,21 @@ class MujocoErrorTestGuard {
5457
// trigger a test failure.
5558
class MujocoTest : public ::testing::Test {
5659
public:
60+
MujocoTest() {
61+
static std::once_flag flag;
62+
std::call_once(flag, []() {
63+
const char* plugin_dir = std::getenv("MUJOCO_PLUGIN_DIR");
64+
if (plugin_dir) {
65+
mj_loadAllPluginLibraries(
66+
plugin_dir, +[](const char* filename, int first, int count) {
67+
std::printf("Plugins registered by library '%s':\n", filename);
68+
for (int i = first; i < first + count; ++i) {
69+
std::printf(" %s\n", mjp_getPluginAtSlot(i)->name);
70+
}
71+
});
72+
}
73+
});
74+
}
5775
~MujocoTest() { mj_freeLastXML(); }
5876

5977
private:
@@ -183,20 +201,6 @@ class MockFilesystem {
183201
std::string dir_; // current directory
184202
};
185203

186-
// Installs all plugins
187-
class PluginTest : public MujocoTest {
188-
public:
189-
// load plugin library
190-
PluginTest() : MujocoTest() {
191-
mj_loadAllPluginLibraries(
192-
std::string(std::getenv("MUJOCO_PLUGIN_DIR")).c_str(), +[](const char* filename, int first, int count) {
193-
std::printf("Plugins registered by library '%s':\n", filename);
194-
for (int i = first; i < first + count; ++i) {
195-
std::printf(" %s\n", mjp_getPluginAtSlot(i)->name);
196-
}
197-
});
198-
}
199-
};
200204

201205
} // namespace mujoco
202206
#endif // MUJOCO_TEST_FIXTURE_H_

test/plugin/actuator/pid_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
namespace mujoco {
3030
namespace {
3131

32-
using PidTest = PluginTest;
32+
using PidTest = MujocoTest;
3333
using ::testing::DoubleNear;
3434
using ::testing::HasSubstr;
3535
using ::testing::IsNull;

test/plugin/elasticity/elasticity_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
namespace mujoco {
2727
namespace {
2828

29-
using ElasticityTest = PluginTest;
29+
using ElasticityTest = MujocoTest;
3030

3131

3232
// -------------------------------- cable -----------------------------------

test/user/user_api_test.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ TEST_F(MujocoTest, TreeTraversal) {
171171
mj_deleteSpec(spec);
172172
}
173173

174-
TEST_F(PluginTest, ActivatePlugin) {
174+
TEST_F(MujocoTest, ActivatePlugin) {
175175
mjSpec* spec = mj_makeSpec();
176176
mjs_activatePlugin(spec, "mujoco.elasticity.cable");
177177

@@ -196,7 +196,7 @@ TEST_F(PluginTest, ActivatePlugin) {
196196
mj_deleteModel(model);
197197
}
198198

199-
TEST_F(PluginTest, DeletePlugin) {
199+
TEST_F(MujocoTest, DeletePlugin) {
200200
mjSpec* spec = mj_makeSpec();
201201
mjs_activatePlugin(spec, "mujoco.pid");
202202

@@ -267,7 +267,7 @@ static constexpr char xml_plugin_2[] = R"(
267267
</actuator>
268268
</mujoco>)";
269269

270-
TEST_F(PluginTest, AttachPlugin) {
270+
TEST_F(MujocoTest, AttachPlugin) {
271271
std::array<char, 1000> err;
272272
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
273273
ASSERT_THAT(parent, NotNull()) << err.data();
@@ -316,7 +316,7 @@ TEST_F(PluginTest, AttachPlugin) {
316316
mj_deleteSpec(spec_3);
317317
}
318318

319-
TEST_F(PluginTest, DetachPlugin) {
319+
TEST_F(MujocoTest, DetachPlugin) {
320320
std::array<char, 1000> err;
321321
mjSpec* parent = mj_parseXMLString(xml_plugin_1, 0, err.data(), err.size());
322322
ASSERT_THAT(parent, NotNull()) << err.data();
@@ -342,7 +342,7 @@ TEST_F(PluginTest, DetachPlugin) {
342342
mj_deleteSpec(child);
343343
}
344344

345-
TEST_F(PluginTest, AttachExplicitPlugin) {
345+
TEST_F(MujocoTest, AttachExplicitPlugin) {
346346
static constexpr char xml_parent[] = R"(
347347
<mujoco model="MuJoCo Model">
348348
<worldbody>
@@ -396,7 +396,7 @@ TEST_F(PluginTest, AttachExplicitPlugin) {
396396
mj_deleteModel(model);
397397
}
398398

399-
TEST_F(PluginTest, ReplicatePlugin) {
399+
TEST_F(MujocoTest, ReplicatePlugin) {
400400
static constexpr char xml[] = R"(
401401
<mujoco>
402402
<extension>
@@ -429,7 +429,7 @@ TEST_F(PluginTest, ReplicatePlugin) {
429429
mj_deleteModel(model);
430430
}
431431

432-
TEST_F(PluginTest, ReplicateExplicitPlugin) {
432+
TEST_F(MujocoTest, ReplicateExplicitPlugin) {
433433
static constexpr char xml[] = R"(
434434
<mujoco>
435435
<extension>
@@ -484,7 +484,7 @@ TEST_F(MujocoTest, RecompileFails) {
484484
mj_deleteSpec(spec);
485485
}
486486

487-
TEST_F(PluginTest, ModifyShellInertiaFails) {
487+
TEST_F(MujocoTest, ModifyShellInertiaFails) {
488488
static constexpr char xml[] = R"(
489489
<mujoco>
490490
<asset>
@@ -515,7 +515,7 @@ TEST_F(PluginTest, ModifyShellInertiaFails) {
515515
}
516516

517517
// ------------------- test recompilation multiple files -----------------------
518-
TEST_F(PluginTest, RecompileCompare) {
518+
TEST_F(MujocoTest, RecompileCompare) {
519519
mjtNum tol = 0;
520520
std::string field = "";
521521

@@ -606,7 +606,7 @@ TEST_F(PluginTest, RecompileCompare) {
606606
}
607607
}
608608

609-
TEST_F(PluginTest, RecompileEdit) {
609+
TEST_F(MujocoTest, RecompileEdit) {
610610
static constexpr char xml[] = R"(
611611
<mujoco>
612612
<worldbody>
@@ -640,7 +640,7 @@ TEST_F(PluginTest, RecompileEdit) {
640640

641641
// ------------------- test cache with modified assets -------------------------
642642

643-
TEST_F(PluginTest, RecompileCompareObjCache) {
643+
TEST_F(MujocoTest, RecompileCompareObjCache) {
644644
static constexpr char xml[] = R"(
645645
<mujoco>
646646
<asset>
@@ -716,7 +716,7 @@ static constexpr uint8_t tex2[] = {
716716
0x82
717717
};
718718

719-
TEST_F(PluginTest, RecompileComparePngCache) {
719+
TEST_F(MujocoTest, RecompileComparePngCache) {
720720
static constexpr char xml[] = R"(
721721
<mujoco>
722722
<asset>
@@ -753,7 +753,7 @@ TEST_F(PluginTest, RecompileComparePngCache) {
753753
mj_deleteVFS(vfs.get());
754754
}
755755

756-
TEST_F(PluginTest, DisableCache) {
756+
TEST_F(MujocoTest, DisableCache) {
757757
static constexpr char xml[] = R"(
758758
<mujoco>
759759
<asset>
@@ -791,7 +791,7 @@ TEST_F(PluginTest, DisableCache) {
791791

792792
// -------------------------------- test textures ------------------------------
793793

794-
TEST_F(PluginTest, TextureFromBuffer) {
794+
TEST_F(MujocoTest, TextureFromBuffer) {
795795
mjSpec* spec = mj_makeSpec();
796796

797797
mjsTexture* t1 = mjs_addTexture(spec);

test/xml/xml_native_writer_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using ::testing::HasSubstr;
4444
using ::testing::Not;
4545
using ::testing::NotNull;
4646

47-
using XMLWriterTest = PluginTest;
47+
using XMLWriterTest = MujocoTest;
4848

4949
static const char* const kNonRgbTextureXMLPath =
5050
"xml/testdata/hfield_png_nonrgb.xml";

0 commit comments

Comments
 (0)