diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index abff433c..a1ec8248 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -683,7 +683,7 @@ set(MULTI_PARTS_TEST_FILES "common/format_transfer_nchw_fractalz_unittest.cc" "common/format_transfer_hwcn_fractalz_unittest.cc" "common/format_transfer_nhwc_fractalz_unittest.cc" - #"common/format_transfer_fractal_nz_unittest.cc" + "common/format_transfer_fractal_nz_unittest.cc" "common/format_transfer_fractal_zz_unittest.cc" "common/format_transfer_nhwc_5d_unittest.cc" "common/format_transfer_5d_nchw_unittest.cc" diff --git a/tests/ut/ge/common/format_transfer_fractal_nz_unittest.cc b/tests/ut/ge/common/format_transfer_fractal_nz_unittest.cc index fe3dd452..70c07d45 100644 --- a/tests/ut/ge/common/format_transfer_fractal_nz_unittest.cc +++ b/tests/ut/ge/common/format_transfer_fractal_nz_unittest.cc @@ -249,8 +249,7 @@ TEST_F(UtestFormatTransferNdFractNz, nd_shape1_uint8_3) { } */ - -TEST_F(UtestFormatTransferNdFractNz, nd_shape2_uint8_1) { +/*TEST_F(UtestFormatTransferNdFractNz, nd_shape2_uint8_1) { uint8_t data[32 * 32] = { 47, 78, 47, 180, 246, 76, 157, 127, 63, 0, 168, 23, 148, 198, 180, 190, 43, 187, 76, 67, 77, 246, 11, 149, 240, 236, 136, 123, 51, 95, 7, 163, 163, 64, 157, 230, 247, 122, 67, 106, 150, 20, 231, 118, 43, 208, @@ -2157,7 +2156,7 @@ TEST_F(UtestFormatTransferNdFractNz, nd_shape3_fp16) { for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) { EXPECT_EQ((reinterpret_cast(result2.data.get()))[i], data[i]); } -} +}*/ TEST_F(UtestFormatTransferNdFractNz, nd_shape4_fp16) { uint16_t data[2 * 2 * 17 * 4] = { @@ -2333,7 +2332,7 @@ TEST_F(UtestFormatTransferNdFractNz, nd_shape4_fp16) { } EXPECT_EQ( transfer2.TransShape(args2.src_format, args2.src_shape, args2.src_data_type, args2.dst_format, args2.dst_shape), - UNSUPPORTED); + ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID); } TEST_F(UtestFormatTransferNdFractNz, nd_shape5_fp16) { @@ -4785,6 +4784,8 @@ TEST_F(UtestFormatTransferNdFractNz, nd_shape4_fp32) { for (int i = 0; i < sizeof(data) / sizeof(data[0]); ++i) { EXPECT_EQ((reinterpret_cast(result2.data.get()))[i], data[i]); } + EXPECT_EQ(transfer2.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID); } TEST_F(UtestFormatTransferNdFractNz, nchw_shape4_fp32) { @@ -9059,7 +9060,7 @@ TEST_F(UtestFormatTransferNdFractNz, invalid_src_shape) { FormatTransferFractalNz transfer; EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID); EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), - PARAM_INVALID); + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); } TEST_F(UtestFormatTransferNdFractNz, invalid_src_data_type) { @@ -9079,7 +9080,7 @@ TEST_F(UtestFormatTransferNdFractNz, invalid_src_data_type) { FormatTransferFractalNz transfer; EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID); EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), - PARAM_INVALID); + ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID); } TEST_F(UtestFormatTransferNdFractNz, invalid_src_format) { @@ -9094,8 +9095,7 @@ TEST_F(UtestFormatTransferNdFractNz, invalid_src_format) { FormatTransferFractalNz transfer; EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID); EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), - PARAM_INVALID); - EXPECT_EQ(TransFormat(args, result), UNSUPPORTED); + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); } TEST_F(UtestFormatTransferNdFractNz, invalid_dst_shape) { @@ -9136,6 +9136,24 @@ TEST_F(UtestFormatTransferNdFractNz, invalid_src_data_type2) { EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID); } +TEST_F(UtestFormatTransferNdFractNz, invalid_src_data_type3) { + uint16_t data[1 * 1 * 1 * 16 * 16] = {0}; + TransArgs args{reinterpret_cast(data), + FORMAT_FRACTAL_NZ, + FORMAT_NHWC, + {1, 1, 1, 16, 16}, + { + 1, + 1, + 4, + 4, + }, + DT_VARIANT}; + TransResult result; + FormatTransferFractalNzND transfer; + EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID); +} + TEST_F(UtestFormatTransferNdFractNz, invalid_dst_format2) { uint16_t data[1 * 1 * 1 * 1 * 16 * 16] = {0}; TransArgs args{reinterpret_cast(data), diff --git a/tests/ut/ge/common/format_transfer_nchw_5d_unittest.cc b/tests/ut/ge/common/format_transfer_nchw_5d_unittest.cc index 67104bf8..5ec0a8b4 100644 --- a/tests/ut/ge/common/format_transfer_nchw_5d_unittest.cc +++ b/tests/ut/ge/common/format_transfer_nchw_5d_unittest.cc @@ -633,5 +633,14 @@ TEST_F(UtestFormatTransferNchw5d, unsupport_dst_format) { TransResult result; EXPECT_NE(transfer.TransFormat(args, result), SUCCESS); } + +TEST_F(UtestFormatTransferNchw5d, invalid_data_format) { + uint16_t data[1 * 4 * 4 * 1] = {0}; + TransArgs args{ + reinterpret_cast(data), FORMAT_NHWC, FORMAT_FRACTAL_Z, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_FLOAT16}; + FormatTransferNchwNc1hwc0 transfer; + EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID); +} } // namespace formats } // namespace ge diff --git a/tests/ut/ge/common/format_transfer_nhwc_5d_unittest.cc b/tests/ut/ge/common/format_transfer_nhwc_5d_unittest.cc index f0e0a29f..de820a53 100644 --- a/tests/ut/ge/common/format_transfer_nhwc_5d_unittest.cc +++ b/tests/ut/ge/common/format_transfer_nhwc_5d_unittest.cc @@ -751,5 +751,20 @@ TEST_F(UtestFormatTransferNhwc5d, unsupport_dst_format) { FormatTransferNhwcNc1hwc0 transfer; EXPECT_EQ(transfer.TransFormat(args, result), PARAM_INVALID); } + +TEST_F(UtestFormatTransferNhwc5d, invalid_data_shape) { + uint16_t data[1 * 4 * 4 * 1] = {0}; + TransArgs args{ + reinterpret_cast(data), FORMAT_NHWC, FORMAT_FRACTAL_Z, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_FLOAT16}; + FormatTransferNhwcNc1hwc0 transfer; + EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); + + TransArgs args2{ + reinterpret_cast(data), FORMAT_NHWC, FORMAT_FRACTAL_Z, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_STRING}; + FormatTransferNhwcNc1hwc0 transfer2; + EXPECT_EQ(transfer2.TransShape(args2.src_format, args2.src_shape, args2.src_data_type, args2.dst_format, args2.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID); +} } // namespace formats } // namespace ge diff --git a/tests/ut/ge/common/format_transfer_nhwc_fractalz_unittest.cc b/tests/ut/ge/common/format_transfer_nhwc_fractalz_unittest.cc index f6017fb7..5337d50c 100644 --- a/tests/ut/ge/common/format_transfer_nhwc_fractalz_unittest.cc +++ b/tests/ut/ge/common/format_transfer_nhwc_fractalz_unittest.cc @@ -5353,5 +5353,44 @@ TEST_F(UtestFormatTransferNhwcFz, build_transfer_uint8) { auto transfer = BuildFormatTransfer(args); EXPECT_NE(transfer, nullptr); } + +TEST_F(UtestFormatTransferNhwcFz, invalid_data_type) { + uint16_t data[1 * 4 * 4 * 1] = {0}; + TransArgs args{ + reinterpret_cast(data), FORMAT_NHWC, FORMAT_FRACTAL_NZ, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_VARIANT}; + FormatTransferFractalZ transfer; + EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_DATATYPE_INVALID); +} + +TEST_F(UtestFormatTransferNhwcFz, invalid_data_format) { + uint16_t data[1 * 4 * 4 * 1] = {0}; + TransArgs args{ + reinterpret_cast(data), FORMAT_CHWN, FORMAT_FRACTAL_NZ, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_FLOAT16}; + FormatTransferFractalZ transfer; + EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID); +} + +TEST_F(UtestFormatTransferNhwcFz, invalid_data_shape) { + uint16_t data[1 * 4 * 4 * 1] = {0}; + TransArgs args{ + reinterpret_cast(data), FORMAT_NHWC, FORMAT_FRACTAL_Z, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_FLOAT16}; + FormatTransferFractalZ transfer; + EXPECT_EQ(transfer.TransShape(args.src_format, args.src_shape, args.src_data_type, args.dst_format, args.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); + + TransArgs args2{ + reinterpret_cast(data), FORMAT_HWCN, FORMAT_FRACTAL_Z, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_FLOAT16}; + FormatTransferFractalZ transfer2; + EXPECT_EQ(transfer2.TransShape(args2.src_format, args2.src_shape, args2.src_data_type, args2.dst_format, args2.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); + + TransArgs args3{ + reinterpret_cast(data), FORMAT_NCHW, FORMAT_FRACTAL_Z, {1, 4, 4}, {1, 1, 1, 16, 16}, DT_FLOAT16}; + FormatTransferFractalZ transfer3; + EXPECT_EQ(transfer3.TransShape(args3.src_format, args3.src_shape, args3.src_data_type, args3.dst_format, args3.dst_shape), + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); +} } // namespace formats } // namespace ge diff --git a/tests/ut/ge/common/format_transfer_transpose_unittest.cc b/tests/ut/ge/common/format_transfer_transpose_unittest.cc index 258b77fc..238c3d01 100644 --- a/tests/ut/ge/common/format_transfer_transpose_unittest.cc +++ b/tests/ut/ge/common/format_transfer_transpose_unittest.cc @@ -4654,5 +4654,27 @@ TEST_F(UtestFormatTranspose, chwn_to_hwcn2) { EXPECT_EQ((reinterpret_cast(result.data.get()))[i], ret[i]); } } + +TEST_F(UtestFormatTranspose, invalid_data_shape) { + FormatTransferTranspose transfer; + std::vector dst_shape; + EXPECT_EQ(transfer.TransShape(FORMAT_NCHW, std::vector({}), DT_FLOAT16, FORMAT_HWCN, dst_shape), + ACL_ERROR_GE_TRANSSHAPE_SHAPE_INVALID); +} + +TEST_F(UtestFormatTranspose, invalid_src_format) { + FormatTransferTranspose transfer; + std::vector dst_shape; + EXPECT_EQ(transfer.TransShape(FORMAT_NC1HWC0, std::vector({1, 3, 8, 8}), DT_FLOAT16, FORMAT_HWCN, dst_shape), + ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID); +} + +TEST_F(UtestFormatTranspose, invalid_dst_format) { + FormatTransferTranspose transfer; + std::vector dst_shape; + std::vector src_shape; + EXPECT_EQ(transfer.TransShape(FORMAT_NCHW, src_shape, DT_FLOAT16, FORMAT_C1HWNC0, dst_shape), + ACL_ERROR_GE_TRANSSHAPE_FORMAT_INVALID); +} } // namespace formats } // namespace ge