|
| 1 | +# Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +# Copyright (c) 2023 Intel Finland Oy. All rights reserved. |
| 3 | +# |
| 4 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +# of this software and associated documentation files (the "Software"), to deal |
| 6 | +# in the Software without restriction, including without limitation the rights |
| 7 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +# copies of the Software, and to permit persons to whom the Software is |
| 9 | +# furnished to do so, subject to the following conditions: |
| 10 | +# |
| 11 | +# The above copyright notice and this permission notice shall be included in |
| 12 | +# all copies or substantial portions of the Software. |
| 13 | +# |
| 14 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +# THE SOFTWARE. |
| 21 | + |
| 22 | +from hiptestsuite.TesterRepository import Tester, Test, TestData |
| 23 | +from hiptestsuite.Test import HIPTestData, TestResult, HIP_PLATFORM |
| 24 | +from typing import Union, List |
| 25 | +from hiptestsuite.test_classifier import TestClassifier |
| 26 | +from hiptestsuite.applications.hpc_apps.libceed.libceed_build_amd import BuildRunAmd |
| 27 | +from hiptestsuite.common.hip_get_packages import HipPackages |
| 28 | +from hiptestsuite.common.hip_shell import execshellcmd |
| 29 | + |
| 30 | +import os |
| 31 | +import re |
| 32 | + |
| 33 | +# Common class to clone, set up, build and run test |
| 34 | +class PrepareTest(): |
| 35 | + def __init__(self, cwd): |
| 36 | + self.cwdAbs = cwd |
| 37 | + self.app_path = os.path.join(self.cwdAbs,\ |
| 38 | + "src/hiptestsuite/applications/hpc_apps/libceed/libCEED") |
| 39 | + self.thistestpath = self.app_path |
| 40 | + self.prepareobj = None |
| 41 | + self.libceed_repo = "" # Default |
| 42 | + self.libceed_branch = "" |
| 43 | + self.libceed_commitId = "" |
| 44 | + |
| 45 | + def set_libceed_repoinfo(self, test_data: HIPTestData): |
| 46 | + validrepconfig = True |
| 47 | + if test_data.repos["libCEED"].repo_url != None: |
| 48 | + self.libceed_repo = test_data.repos["libCEED"].repo_url |
| 49 | + else: |
| 50 | + print("invalid config: no repo") |
| 51 | + validrepconfig = False |
| 52 | + if test_data.repos["libCEED"].branch != None: |
| 53 | + self.libceed_branch = test_data.repos["libCEED"].branch |
| 54 | + if test_data.repos["libCEED"].commit_id != None: |
| 55 | + self.libceed_commitId = test_data.repos["libCEED"].commit_id |
| 56 | + return validrepconfig |
| 57 | + |
| 58 | + def downloadtest(self, logFile, test_data: HIPTestData): |
| 59 | + return HipPackages().pull_repo(logFile, self.libceed_repo,\ |
| 60 | + self.libceed_branch, self.libceed_commitId, "libCEED") |
| 61 | + |
| 62 | + def buildtest(self, logFile, platform, cuda_target): |
| 63 | + if platform == HIP_PLATFORM.amd: |
| 64 | + self.prepareobj = BuildRunAmd(self.thistestpath, logFile) |
| 65 | + else: |
| 66 | + print("Invalid/Unsupported Platform") |
| 67 | + return False |
| 68 | + if not self.prepareobj: |
| 69 | + return False |
| 70 | + return self.prepareobj.buildtest() |
| 71 | + |
| 72 | + def clean(self): |
| 73 | + if self.prepareobj != None: |
| 74 | + self.prepareobj.clean() |
| 75 | + |
| 76 | + def runtest(self, testnum): |
| 77 | + if self.prepareobj != None: |
| 78 | + self.prepareobj.runtest(testnum) |
| 79 | + |
| 80 | + def parse_result(self, testnum): |
| 81 | + if self.prepareobj != None: |
| 82 | + return self.prepareobj.parse_result(testnum) |
| 83 | + return False |
| 84 | + |
| 85 | +class LIBCEED(TestClassifier): |
| 86 | + def __init__(self): |
| 87 | + TestClassifier.__init__(self) |
| 88 | + |
| 89 | + def add_matched_with_names(self, matched_with_names: Union[None, dict] = None): |
| 90 | + TestClassifier.add_matched_with_names(self, {"libceed": matched_with_names}) |
| 91 | + |
| 92 | +class UNIT(TestClassifier): |
| 93 | + def __init__(self): |
| 94 | + LIBCEED.__init__(self) |
| 95 | + |
| 96 | + def add_matched_with_names(self, matched_with_names: Union[None, dict] = None): |
| 97 | + LIBCEED.add_matched_with_names(self, {"libceed": matched_with_names}) |
| 98 | + |
| 99 | +class LIBCEED_UNIT_TEST(Tester, PrepareTest): |
| 100 | + def __init__(self): |
| 101 | + Tester.__init__(self) |
| 102 | + self.cwd = os.getcwd() |
| 103 | + PrepareTest.__init__(self, self.cwd) |
| 104 | + |
| 105 | + def getTests(self) -> List[Test]: |
| 106 | + test = Test() |
| 107 | + test.test_name = self.__class__.__name__ |
| 108 | + classifier = UNIT() |
| 109 | + classifier.add_matched_with_names() |
| 110 | + test.classifiers = [classifier] |
| 111 | + test.tester = self |
| 112 | + return [test] |
| 113 | + |
| 114 | + def clean(self): |
| 115 | + PrepareTest.clean(self) |
| 116 | + |
| 117 | + def test(self, test_data: HIPTestData): |
| 118 | + print("=============== libCEED UNIT test ===============") |
| 119 | + # Set repo info |
| 120 | + isrepocfgvalid = self.set_libceed_repoinfo(test_data) |
| 121 | + if not isrepocfgvalid: |
| 122 | + test_data.test_result = TestResult.ERROR |
| 123 | + return |
| 124 | + |
| 125 | + # Create the log directory |
| 126 | + resultLogDir = test_data.log_location |
| 127 | + with open(resultLogDir + "/libceed_unit.log", 'w+') as testLogger: |
| 128 | + res = self.downloadtest(testLogger, test_data) |
| 129 | + test_data.test_result = TestResult.FAIL |
| 130 | + if not res: |
| 131 | + return |
| 132 | + res = self.buildtest(testLogger, test_data.HIP_PLATFORM, test_data.build_for_cuda_target) |
| 133 | + if not res: |
| 134 | + return |
| 135 | + self.runtest(1) |
| 136 | + # Parse the test result |
| 137 | + if self.parse_result(1): |
| 138 | + test_data.test_result = TestResult.PASS |
| 139 | + |
0 commit comments