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.

boot.py 2.6 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2019 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. This utils is used for running akg test case more easy and relaxed. even by
  16. python common line. the run command is equal to testarg of testcase
  17. example 1: use string test_run function to avoid import it explicitly
  18. -------------------
  19. boot.run("bias_add_64_1024", "bias_add_run", ([64, 1024], "float16"), [(8, 8), (1024, 1024)])
  20. example 2: use test_run function directly
  21. -------------------
  22. from test_run.bias_add_run import bias_add_run
  23. boot.run("bias_add_64_1024", bias_add_run, ([64, 1024], "float16"), [(8, 8), (1024, 1024)])
  24. """
  25. import os
  26. import sys
  27. from tests.common.base import TestBase
  28. class TestCase(TestBase):
  29. def setup(self, case, build_only=False):
  30. self._build_only = False
  31. func = case[1]
  32. case_name = "test_akg_boot"
  33. case_path = os.getcwd()
  34. # params init
  35. self.params_init(case_name, case_path)
  36. if isinstance(func, str):
  37. lib = "tests.common.test_run." + func
  38. exec("import " + lib)
  39. mod = sys.modules[lib]
  40. self._build_only = build_only and hasattr(mod, func.split('_run')[0] + "_compile")
  41. # backward compatible with xxx_run function entry
  42. if hasattr(mod, func):
  43. case = list(case)
  44. case[1] = getattr(mod, func)
  45. self._log.info("============= {0} Setup case============".format(self.casename))
  46. self.testarg = [case]
  47. def test_run(self, is_conv=False):
  48. if self._build_only:
  49. self.common_run(self.testarg, mode='compile', is_conv=is_conv)
  50. else:
  51. self.common_run(self.testarg, is_conv=is_conv)
  52. def teardown(self):
  53. self._log.info("============= {0} Teardown============".format(self.casename))
  54. def run(*case):
  55. a = TestCase()
  56. a.setup(case)
  57. a.test_run()
  58. a.teardown()
  59. def run_conv(*case):
  60. a = TestCase()
  61. a.setup(case)
  62. a.test_run(True)
  63. a.teardown()
  64. def build(*case):
  65. a = TestCase()
  66. a.setup(case, True)
  67. a.test_run()
  68. a.teardown()