提交 ef29b522 编写于 作者: Y Yu Yang

Simplify unit test code

上级 4a604c26
...@@ -68,11 +68,8 @@ REGISTER_OP(my_test_op, paddle::framework::MyTestOp, ...@@ -68,11 +68,8 @@ REGISTER_OP(my_test_op, paddle::framework::MyTestOp,
TEST(OpRegistry, CreateOp) { TEST(OpRegistry, CreateOp) {
paddle::framework::OpDesc op_desc; paddle::framework::OpDesc op_desc;
op_desc.set_type("cos_sim"); op_desc.set_type("cos_sim");
auto* input = op_desc.add_inputs(); ConstructVars("input", {"aa"}, op_desc.add_inputs());
ConstructVars("input", {"aa"}, input); ConstructVars("output", {"bb"}, op_desc.add_outputs());
auto* output = op_desc.add_outputs();
ConstructVars("output", {"bb"}, output);
float scale = 3.3; float scale = 3.3;
auto attr = op_desc.mutable_attrs()->Add(); auto attr = op_desc.mutable_attrs()->Add();
...@@ -92,11 +89,8 @@ TEST(OpRegistry, CreateOp) { ...@@ -92,11 +89,8 @@ TEST(OpRegistry, CreateOp) {
TEST(OpRegistry, IllegalAttr) { TEST(OpRegistry, IllegalAttr) {
paddle::framework::OpDesc op_desc; paddle::framework::OpDesc op_desc;
op_desc.set_type("cos_sim"); op_desc.set_type("cos_sim");
auto* input = op_desc.add_inputs(); ConstructVars("input", {"aa"}, op_desc.add_inputs());
ConstructVars("input", {"aa"}, input); ConstructVars("output", {"bb"}, op_desc.add_outputs());
auto* output = op_desc.add_outputs();
ConstructVars("output", {"bb"}, output);
auto attr = op_desc.mutable_attrs()->Add(); auto attr = op_desc.mutable_attrs()->Add();
attr->set_name("scale"); attr->set_name("scale");
...@@ -120,11 +114,8 @@ TEST(OpRegistry, IllegalAttr) { ...@@ -120,11 +114,8 @@ TEST(OpRegistry, IllegalAttr) {
TEST(OpRegistry, DefaultValue) { TEST(OpRegistry, DefaultValue) {
paddle::framework::OpDesc op_desc; paddle::framework::OpDesc op_desc;
op_desc.set_type("cos_sim"); op_desc.set_type("cos_sim");
auto* input = op_desc.add_inputs(); ConstructVars("input", {"aa"}, op_desc.add_inputs());
ConstructVars("input", {"aa"}, input); ConstructVars("output", {"bb"}, op_desc.add_outputs());
auto* output = op_desc.add_outputs();
ConstructVars("output", {"bb"}, output);
ASSERT_TRUE(op_desc.IsInitialized()); ASSERT_TRUE(op_desc.IsInitialized());
...@@ -139,11 +130,8 @@ TEST(OpRegistry, DefaultValue) { ...@@ -139,11 +130,8 @@ TEST(OpRegistry, DefaultValue) {
TEST(OpRegistry, CustomChecker) { TEST(OpRegistry, CustomChecker) {
paddle::framework::OpDesc op_desc; paddle::framework::OpDesc op_desc;
op_desc.set_type("my_test_op"); op_desc.set_type("my_test_op");
auto* input = op_desc.add_inputs(); ConstructVars("input", {"ii"}, op_desc.add_inputs());
ConstructVars("input", {"ii"}, input); ConstructVars("output", {"oo"}, op_desc.add_outputs());
auto* output = op_desc.add_outputs();
ConstructVars("output", {"oo"}, output);
// attr 'test_attr' is not set // attr 'test_attr' is not set
bool caught = false; bool caught = false;
......
...@@ -71,12 +71,8 @@ REGISTER_OP(test_operator, paddle::framework::OpWithoutKernelTest, ...@@ -71,12 +71,8 @@ REGISTER_OP(test_operator, paddle::framework::OpWithoutKernelTest,
TEST(OperatorBase, all) { TEST(OperatorBase, all) {
paddle::framework::OpDesc op_desc; paddle::framework::OpDesc op_desc;
op_desc.set_type("test_operator"); op_desc.set_type("test_operator");
ConstructVars("IN1", {"input"}, op_desc.add_inputs());
auto* ipt = op_desc.mutable_inputs()->Add(); ConstructVars("OUT1", {"output"}, op_desc.add_outputs());
ConstructVars("IN1", {"input"}, ipt);
auto* output = op_desc.mutable_outputs()->Add();
ConstructVars("OUT1", {"output"}, output);
auto attr = op_desc.mutable_attrs()->Add(); auto attr = op_desc.mutable_attrs()->Add();
attr->set_name("scale"); attr->set_name("scale");
...@@ -195,11 +191,8 @@ REGISTER_OP_CPU_KERNEL(op_with_kernel, ...@@ -195,11 +191,8 @@ REGISTER_OP_CPU_KERNEL(op_with_kernel,
TEST(OpKernel, all) { TEST(OpKernel, all) {
paddle::framework::OpDesc op_desc; paddle::framework::OpDesc op_desc;
op_desc.set_type("op_with_kernel"); op_desc.set_type("op_with_kernel");
auto* ipt = op_desc.mutable_inputs()->Add(); ConstructVars("IN1", {"x"}, op_desc.add_inputs());
ConstructVars("IN1", {"x"}, ipt); ConstructVars("OUT1", {"y"}, op_desc.add_outputs());
auto* output = op_desc.mutable_outputs()->Add();
ConstructVars("OUT1", {"y"}, output);
auto attr = op_desc.mutable_attrs()->Add(); auto attr = op_desc.mutable_attrs()->Add();
attr->set_name("scale"); attr->set_name("scale");
...@@ -226,12 +219,9 @@ TEST(OpKernel, multi_inputs) { ...@@ -226,12 +219,9 @@ TEST(OpKernel, multi_inputs) {
OpDesc op_desc; OpDesc op_desc;
op_desc.set_type("op_multi_inputs_with_kernel"); op_desc.set_type("op_multi_inputs_with_kernel");
auto* x = op_desc.mutable_inputs()->Add(); ConstructVars("xs", {"x0", "x1", "x2"}, op_desc.add_inputs());
ConstructVars("xs", {"x0", "x1", "x2"}, x); ConstructVars("k", {"k0"}, op_desc.add_inputs());
auto* k = op_desc.mutable_inputs()->Add(); ConstructVars("ys", {"y0", "y1"}, op_desc.add_outputs());
ConstructVars("k", {"k0"}, k);
auto* y = op_desc.mutable_outputs()->Add();
ConstructVars("ys", {"y0", "y1"}, y);
auto attr = op_desc.mutable_attrs()->Add(); auto attr = op_desc.mutable_attrs()->Add();
attr->set_name("scale"); attr->set_name("scale");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册