Add travis sanitizers tests. (#3557)
* Add travis sanitizers tests. * Add gcc-7 in Travis. * Add SANITIZER_PATH for CMake. * Enable sanitizer tests in Travis. * Fix memory leaks in tests. * Fix all memory leaks reported by Address Sanitizer. * tests/cpp/helpers.h/CreateDMatrix now returns raw pointer.
This commit is contained in:
committed by
Rory Mitchell
parent
983cb0b374
commit
cf2d86a4f6
@@ -13,14 +13,14 @@ TEST(c_api, XGDMatrixCreateFromMatDT) {
|
||||
DMatrixHandle handle;
|
||||
XGDMatrixCreateFromDT(data.data(), types.data(), 3, 2, &handle,
|
||||
0);
|
||||
std::shared_ptr<xgboost::DMatrix> dmat =
|
||||
*static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
|
||||
xgboost::MetaInfo &info = dmat->Info();
|
||||
std::shared_ptr<xgboost::DMatrix> *dmat =
|
||||
static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
|
||||
xgboost::MetaInfo &info = (*dmat)->Info();
|
||||
ASSERT_EQ(info.num_col_, 2);
|
||||
ASSERT_EQ(info.num_row_, 3);
|
||||
ASSERT_EQ(info.num_nonzero_, 6);
|
||||
|
||||
auto iter = dmat->RowIterator();
|
||||
auto iter = (*dmat)->RowIterator();
|
||||
iter->BeforeFirst();
|
||||
while (iter->Next()) {
|
||||
auto batch = iter->Value();
|
||||
@@ -29,6 +29,8 @@ TEST(c_api, XGDMatrixCreateFromMatDT) {
|
||||
ASSERT_EQ(batch[2][0].fvalue, 3.0f);
|
||||
ASSERT_EQ(batch[2][1].fvalue, 0.0f);
|
||||
}
|
||||
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
TEST(c_api, XGDMatrixCreateFromMat_omp) {
|
||||
@@ -46,14 +48,14 @@ TEST(c_api, XGDMatrixCreateFromMat_omp) {
|
||||
std::numeric_limits<float>::quiet_NaN(), &handle,
|
||||
0);
|
||||
|
||||
std::shared_ptr<xgboost::DMatrix> dmat =
|
||||
*static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
|
||||
xgboost::MetaInfo &info = dmat->Info();
|
||||
std::shared_ptr<xgboost::DMatrix> *dmat =
|
||||
static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
|
||||
xgboost::MetaInfo &info = (*dmat)->Info();
|
||||
ASSERT_EQ(info.num_col_, num_cols);
|
||||
ASSERT_EQ(info.num_row_, row);
|
||||
ASSERT_EQ(info.num_nonzero_, num_cols * row - num_missing);
|
||||
|
||||
auto iter = dmat->RowIterator();
|
||||
auto iter = (*dmat)->RowIterator();
|
||||
iter->BeforeFirst();
|
||||
while (iter->Next()) {
|
||||
auto batch = iter->Value();
|
||||
@@ -64,5 +66,6 @@ TEST(c_api, XGDMatrixCreateFromMat_omp) {
|
||||
}
|
||||
}
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user