4 # Copyright (c) 2020 Project CHIP Authors
5 # Copyright (c) 2015-2017 Nest Labs, Inc.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
23 # Implements CHIP class that wraps around standalone CHIP code library.
29 from happy.Utils import *
30 from ChipState import ChipState
33 class Chip(ChipState):
35 ChipState.__init__(self)
37 self.chip_happy_conf_path = None
38 self.chip_build_path = None
40 self.max_running_time = 1800
42 def __check_chip_path(self):
43 # Pick chip path from configuration
44 if "chip_path" in self.configuration.keys():
45 self.chip_happy_conf_path = self.configuration["chip_path"]
46 emsg = "Found chip path: %s." % (self.chip_happy_conf_path)
47 self.logger.debug("[localhost] Chip: %s" % (emsg))
49 # Check if Chip build path is set
50 if "TEST_BIN_DIR" in os.environ.keys():
51 self.chip_build_path = os.environ['TEST_BIN_DIR']
52 emsg = "Found chip TEST_BIN_DIR: %s." % (self.chip_build_path)
53 self.logger.debug("[localhost] Chip: %s" % (emsg))
55 if self.chip_build_path is not None:
56 self.chip_path = self.chip_build_path
58 self.chip_path = self.chip_happy_conf_path
60 if self.chip_path is None:
61 emsg = "Unknown path to Chip directory (repository)."
62 self.logger.error("[localhost] Chip: %s" % (emsg))
64 "Set chip_path with happy-configuration and try again.")
67 if not os.path.exists(self.chip_path):
68 emsg = "Chip path %s does not exist." % (self.chip_path)
69 self.logger.error("[localhost] Chip: %s" % (emsg))
71 "Set correct chip_path with happy-configuration and try again.")
74 if self.chip_path[-1] == "/":
75 self.chip_path = self.chip_path[:-1]
77 def __get_cmd_path(self, cmd_end):
78 cmd_path = self.chip_path + "/" + str(cmd_end)
79 if not os.path.exists(cmd_path):
80 emsg = "Chip path %s does not exist." % (cmd_path)
81 self.logger.error("[localhost] Chip: %s" % (emsg))
87 def getChipInetLayerMulticastPath(self):
88 self.__check_chip_path()
89 cmd_path = self.__get_cmd_path("TestInetLayerMulticast")