You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_analyze_fail.py 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2022 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """
  16. Watchpoints test script for dump analyze_fail.dat when infer failed.
  17. """
  18. # pylint: disable=too-many-function-args
  19. import os
  20. import pytest
  21. import mindspore
  22. from mindspore import ops, Tensor, nn
  23. from tests.security_utils import security_off_wrap
  24. @security_off_wrap
  25. def test_infer_fail_generate_analyze_fail_dat():
  26. """
  27. Feature: test dump analyze_fail.dat.
  28. Description: test dump analyze_fail.dat if infer failed.
  29. Expectation: success.
  30. """
  31. class Net(nn.Cell):
  32. def __init__(self):
  33. super().__init__()
  34. self.add = ops.Add()
  35. self.sub = ops.Sub()
  36. self.mul = ops.Mul()
  37. self.div = ops.Div()
  38. def func(self, x, y):
  39. return self.div(x, y)
  40. def construct(self, x, y):
  41. a = self.sub(x, 1)
  42. b = self.add(a, y)
  43. c = self.mul(b, self.func(a, a, b))
  44. return c
  45. input1 = Tensor(3, mindspore.float32)
  46. input2 = Tensor(2, mindspore.float32)
  47. net = Net()
  48. with pytest.raises(TypeError) as excinfo:
  49. net(input1, input2)
  50. assert "rank_0/om/analyze_fail.dat" in str(excinfo.value)
  51. assert os.path.exists("./rank_0/om/analyze_fail.dat") is True