*/
#include <iostream>
+#include <memory>
#include <gtest/gtest.h>
#include "include/stringify.h"
#include <set>
-CrushWrapper *build_indep_map(CephContext *cct, int num_rack, int num_host,
- int num_osd)
+std::unique_ptr<CrushWrapper> build_indep_map(CephContext *cct, int num_rack,
+ int num_host, int num_osd)
{
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
c->create();
c->set_type_name(5, "root");
delete f;
}
- return c;
+ return std::move(c);
}
int get_num_dups(const vector<int>& v)
}
TEST(CRUSH, indep_toosmall) {
- CrushWrapper *c = build_indep_map(g_ceph_context, 1, 3, 1);
+ std::unique_ptr<CrushWrapper> c(build_indep_map(g_ceph_context, 1, 3, 1));
vector<__u32> weight(c->get_max_devices(), 0x10000);
c->dump_tree(&cout, NULL);
ASSERT_EQ(2, num_none);
ASSERT_EQ(0, get_num_dups(out));
}
- delete c;
}
TEST(CRUSH, indep_basic) {
- CrushWrapper *c = build_indep_map(g_ceph_context, 3, 3, 3);
+ std::unique_ptr<CrushWrapper> c(build_indep_map(g_ceph_context, 3, 3, 3));
vector<__u32> weight(c->get_max_devices(), 0x10000);
c->dump_tree(&cout, NULL);
ASSERT_EQ(0, num_none);
ASSERT_EQ(0, get_num_dups(out));
}
- delete c;
}
TEST(CRUSH, indep_out_alt) {
- CrushWrapper *c = build_indep_map(g_ceph_context, 3, 3, 3);
+ std::unique_ptr<CrushWrapper> c(build_indep_map(g_ceph_context, 3, 3, 3));
vector<__u32> weight(c->get_max_devices(), 0x10000);
// mark a bunch of osds out
ASSERT_EQ(0, num_none);
ASSERT_EQ(0, get_num_dups(out));
}
- delete c;
}
TEST(CRUSH, indep_out_contig) {
- CrushWrapper *c = build_indep_map(g_ceph_context, 3, 3, 3);
+ std::unique_ptr<CrushWrapper> c(build_indep_map(g_ceph_context, 3, 3, 3));
vector<__u32> weight(c->get_max_devices(), 0x10000);
// mark a bunch of osds out
ASSERT_EQ(1, num_none);
ASSERT_EQ(0, get_num_dups(out));
}
- delete c;
}
TEST(CRUSH, indep_out_progressive) {
- CrushWrapper *c = build_indep_map(g_ceph_context, 3, 3, 3);
+ std::unique_ptr<CrushWrapper> c(build_indep_map(g_ceph_context, 3, 3, 3));
c->set_choose_total_tries(100);
vector<__u32> tweight(c->get_max_devices(), 0x10000);
c->dump_tree(&cout, NULL);
}
cout << tchanged << " total changed" << std::endl;
- delete c;
}
TEST(CRUSH, straw_zero) {
// zero weight items should have no effect on placement.
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 1;
c->set_type_name(ROOT_TYPE, "root");
const int OSD_TYPE = 0;
// compare the result and verify that the resulting mapping is
// almost identical.
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 1;
c->set_type_name(ROOT_TYPE, "root");
const int OSD_TYPE = 0;
double calc_straw2_stddev(int *weights, int n, bool verbose)
{
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
const int HOST_TYPE = 1;
};
int n = 15;
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
const int HOST_TYPE = 1;