Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / test_driver / happy / lib / Chip.py
1 #!/usr/bin/env python3
2
3 #
4 #    Copyright (c) 2020 Project CHIP Authors
5 #    Copyright (c) 2015-2017 Nest Labs, Inc.
6 #    All rights reserved.
7 #
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
11 #
12 #        http://www.apache.org/licenses/LICENSE-2.0
13 #
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.
19 #
20
21 ##
22 #    @file
23 #       Implements CHIP class that wraps around standalone CHIP code library.
24 #
25
26 import os
27 import sys
28
29 from happy.Utils import *
30 from ChipState import ChipState
31
32
33 class Chip(ChipState):
34     def __init__(self):
35         ChipState.__init__(self)
36
37         self.chip_happy_conf_path = None
38         self.chip_build_path = None
39
40         self.max_running_time = 1800
41
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))
48
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))
54
55         if self.chip_build_path is not None:
56             self.chip_path = self.chip_build_path
57         else:
58             self.chip_path = self.chip_happy_conf_path
59
60         if self.chip_path is None:
61             emsg = "Unknown path to Chip directory (repository)."
62             self.logger.error("[localhost] Chip: %s" % (emsg))
63             self.logger.info(
64                 "Set chip_path with happy-configuration and try again.")
65             sys.exit(1)
66
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))
70             self.logger.info(
71                 "Set correct chip_path with happy-configuration and try again.")
72             sys.exit(1)
73
74         if self.chip_path[-1] == "/":
75             self.chip_path = self.chip_path[:-1]
76
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))
82             sys.exit(1)
83             # return None
84         else:
85             return cmd_path
86
87     def getChipInetLayerMulticastPath(self):
88         self.__check_chip_path()
89         cmd_path = self.__get_cmd_path("TestInetLayerMulticast")
90         return cmd_path