Add error reporting to model loading in engine tests, where missing

PiperOrigin-RevId: 795844607
Change-Id: I4163c53c05796c2e3036af28a98f58c15bb1c99c
This commit is contained in:
Yuval Tassa
2025-08-16 08:11:11 -07:00
committed by Copybara-Service
parent bbb70d98a4
commit 5a24eb2d34
16 changed files with 220 additions and 98 deletions
+22 -8
View File
@@ -15,7 +15,6 @@
// Tests for engine/engine_island.c.
#include <string>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -30,6 +29,7 @@ namespace {
using ::testing::DoubleNear;
using ::testing::ElementsAre;
using ::testing::NotNull;
using ::testing::Pointwise;
using IslandTest = MujocoTest;
@@ -185,7 +185,9 @@ static const char* const kAbacusPath =
TEST_F(IslandTest, Abacus) {
const std::string xml_path = GetTestDataFilePath(kAbacusPath);
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(model, NotNull()) << error;
// disable gravity
model->opt.disableflags |= mjDSBL_GRAVITY;
@@ -292,7 +294,9 @@ static const char* const kTendonWrapPath =
TEST_F(IslandTest, DenseSparse) {
const std::string xml_path = GetTestDataFilePath(kTendonWrapPath);
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(model, NotNull()) << error;
mjData* data1 = mj_makeData(model);
mjData* data2 = mj_makeData(model);
@@ -349,7 +353,9 @@ static const char* const kIlslandEfcPath =
TEST_F(IslandTest, IslandEfc) {
const std::string xml_path = GetTestDataFilePath(kIlslandEfcPath);
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(model, NotNull()) << error;
mjData* data = mj_makeData(model);
while (data->time < 0.2) {
@@ -369,7 +375,9 @@ TEST_F(IslandTest, IslandEfc) {
TEST_F(IslandTest, IslandFlex) {
const std::string xml_path = GetTestDataFilePath("testdata/flex.xml");
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(model, NotNull()) << error;
mjData* data1 = mj_makeData(model);
mjData* data2 = mj_makeData(model);
@@ -396,7 +404,9 @@ static const char* const k2H100Path = "engine/testdata/island/2humanoid100.xml";
TEST_F(IslandTest, IslandJacobian) {
for (const char* local_path : {kIlslandEfcPath, k2H100Path}) {
const std::string xml_path = GetTestDataFilePath(local_path);
mjModel* m = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* m = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(m, NotNull()) << error;
int jac0 = m->opt.jacobian;
mjData* d = mj_makeData(m);
@@ -496,7 +506,9 @@ TEST_F(IslandTest, IslandJacobian) {
TEST_F(IslandTest, IslandInertia) {
for (const char* local_path : {kIlslandEfcPath, k2H100Path}) {
const std::string xml_path = GetTestDataFilePath(local_path);
mjModel* m = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* m = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(m, NotNull()) << error;
int nv = m->nv;
mjData* d = mj_makeData(m);
mjtNum* M = (mjtNum*)mju_malloc(sizeof(mjtNum) * nv * nv);
@@ -543,7 +555,9 @@ TEST_F(IslandTest, IslandInertia) {
TEST_F(IslandTest, IslandEfcElliptic) {
const std::string xml_path = GetTestDataFilePath(kIlslandEfcPath);
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
char error[1024];
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, error, sizeof(error));
ASSERT_THAT(model, NotNull()) << error;
mjData* data = mj_makeData(model);
model->opt.cone = mjCONE_ELLIPTIC;