Skip to content

Commit

Permalink
Fix test failures due to error handling changes
Browse files Browse the repository at this point in the history
Signed-off-by: Gu, Jinghui <[email protected]>
  • Loading branch information
gujinghui committed Sep 7, 2018
1 parent 7c2229f commit 30d8ed2
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/bench_ideep_pooling_forward.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class pooling_forward_test : public ::testing::TestWithParam<pool_test_params> {
p.aprop_kind, padding_kind::zero);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class allocator_test : public ::testing::TestWithParam<allocator_params> {
}
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

compute_ref_inner_product_fwd<data_t>(
Expand Down
27 changes: 27 additions & 0 deletions tests/test_ideep_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@

namespace ideep {

template<typename F> bool catch_ideep_expected_failures(const F &f,
bool expect_to_fail, mkldnn_status_t expected_status)
{
try {
f();
} catch (const ideep::error &e) {
// Rethrow the exception if it is not expected or the error status did
// not match.
if (!(expect_to_fail) || e.status != (expected_status)) {
// Ignore unimplemented
if (e.status == mkldnn_unimplemented)
return true;
else
throw e;
}
// Return normally if the failure is expected
if (expect_to_fail)
return true;
}

// Throw an exception if the failure is expected but did not happen
if (expect_to_fail)
throw std::exception();

return false;
}

// Helpers for migrating MKL-DNN test
inline size_t map_index(const mkldnn_memory_desc_t *md, size_t index) {
using fmt = mkldnn::memory::format;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_convolution_backward_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ TEST_P(convolution_test, TestCompute) {
padR_);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

tensor ref_gradx(gradx.get_descriptor());
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_convolution_backward_weights.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST_P(convolution_test, TestCompute) {
tensor::dims {cd.padh, cd.padw}, padR_);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

tensor ref_gradw(gradw.get_descriptor());
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ideep_convolution_forward.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST_P(convolution_test, TestManipulation) {
tensor::dims {cd.dilh, cd.dilw}, tensor::dims {cd.padh, cd.padw }, padR_);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

auto dup = comp;
Expand Down Expand Up @@ -147,7 +147,7 @@ TEST_P(convolution_test, TestCompute) {
padR_);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

tensor ref_dst(dst.get_descriptor());
Expand Down Expand Up @@ -176,7 +176,7 @@ TEST_P(convolution_test, TestCompute) {
//
// };
//
// if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
// if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
// return;
//
// // We expect the guessings are right.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_inner_product_backward_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TEST_P(inner_product_test_float, TestsBackwardData) {
inner_product_backward_data::compute(grady_, weights_, gradx_dims, gradx);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

compute_ref_inner_product_bwd_data<float>(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_inner_product_backward_weights.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST_P(inner_product_test_float, TestBackwardWeights) {
inner_product_backward_weights::compute(src_, grady_, gradw);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

compute_ref_inner_product_bwd_weights<float>(ipd, src_, grady_, gradw_ref_);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_inner_product_forward.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TEST_P(inner_product_test_float, TestsForward) {
inner_product_forward::compute(src_, weights_, dst);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

compute_ref_inner_product_fwd<float>(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ideep_pooling_backward.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class pooling_bwd_test : public ::testing::TestWithParam<pool_bwd_test_params> {
prop_kind::forward_training, padding_kind::zero);
// };

// if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
// if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
// return;

check_pool_fwd<data_t>(p, x_, y_);
Expand All @@ -68,7 +68,7 @@ class pooling_bwd_test : public ::testing::TestWithParam<pool_bwd_test_params> {
p.aalgorithm, padding_kind::zero);
// };

// if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
// if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
// return;

check_pool_bwd<data_t>(p, gradx, grady_, y_);
Expand All @@ -85,7 +85,7 @@ TEST_P(pooling_bwd_test_float, TestsPoolingBackward) {
Forward();
Backward();
};
if (catch_expected_failures(testcommon, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(testcommon, p.expect_to_fail, p.expected_status))
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_pooling_forward.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class pooling_forward_test : public ::testing::TestWithParam<pool_test_params> {
p.aprop_kind, padding_kind::zero);
};

if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

check_pool_fwd<data_t>(p, src_, dst);
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ideep_relu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class relu_tests:
algorithm::eltwise_relu, prop_kind::forward, p.negative_slope, 0.0);
// };

// if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
// if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
// return;

check_relu_fwd(p.negative_slope, src_, dst);
Expand All @@ -57,7 +57,7 @@ class relu_tests:
algorithm::eltwise_relu, p.negative_slope, 0.0);
// };

// if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
// if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
// return;

check_relu_bwd(p.negative_slope, src_, grady_, gradx);
Expand All @@ -75,7 +75,7 @@ TEST_P(relu_test_float, TestsRelu) {
Forward();
Backward();
};
if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ideep_reorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class reorder_simple_test:

test_simple_params<reorder_types> p
= ::testing::TestWithParam<decltype(p)>::GetParam();
if (catch_expected_failures(test, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test, p.expect_to_fail, p.expected_status))
return;

check_reorder(mpd_i_, mpd_o_, src_data_.get(), dst_data_.get());
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ideep_sum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ class sum_test: public ::testing::TestWithParam<sum_test_params> {
sum::compute(p.scale, srcs, dst2);
};

if (catch_expected_failures(test1, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test1, p.expect_to_fail, p.expected_status))
return;

if (catch_expected_failures(test2, p.expect_to_fail, p.expected_status))
if (catch_ideep_expected_failures(test2, p.expect_to_fail, p.expected_status))
return;

check_data(srcs, p.scale, dst1);
Expand Down

0 comments on commit 30d8ed2

Please sign in to comment.