forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[happy] Initial commit for adding Happy test (project-chip#2319)
* [happy] Initial commit for Adding Happy test * rename file * Add license header * Fix shebang * Update happy submodule * add shell for generating topology json * Restyled by shfmt * Update .gitmodules Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
48d9827
commit a5f59f9
Showing
15 changed files
with
1,774 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# Copyright (c) 2017 Nest Labs, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
|
||
import os | ||
import sys | ||
|
||
# | ||
# This module is imported by test scripts in the following directories: | ||
# - happy/tests/standalone | ||
# - happy/tests/service | ||
# | ||
# os.path.abspath(__file__) will return the path of the file that imports | ||
# this module, so the path to "src/test-apps/happy" is derived relative | ||
# to the above test scripts. | ||
# | ||
|
||
# look for the 'happy' folder in the file path | ||
|
||
path = os.path.abspath(__file__) | ||
path_parts = path.split('/') | ||
happy_idx = path_parts.index('happy') | ||
wrapper_home = '/'.join(str(x) for x in path_parts[0:happy_idx+1]) | ||
|
||
wrapper_dirs = [".", | ||
wrapper_home, | ||
wrapper_home + "/test-templates", | ||
wrapper_home + "/lib", | ||
wrapper_home + "/bin"] | ||
|
||
for wrapper_dir in wrapper_dirs: | ||
if os.path.exists(wrapper_dir): | ||
sys.path.append(wrapper_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# Copyright (c) 2015-2017 Nest Labs, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
## | ||
# @file | ||
# Implements CHIP class that wraps around standalone CHIP code library. | ||
# | ||
|
||
import os | ||
import sys | ||
|
||
from happy.Utils import * | ||
from ChipState import ChipState | ||
|
||
|
||
class Chip(ChipState): | ||
def __init__(self): | ||
ChipState.__init__(self) | ||
|
||
self.chip_happy_conf_path = None | ||
self.chip_build_path = None | ||
|
||
self.max_running_time = 1800 | ||
|
||
def __check_chip_path(self): | ||
# Pick chip path from configuration | ||
if "chip_path" in self.configuration.keys(): | ||
self.chip_happy_conf_path = self.configuration["chip_path"] | ||
emsg = "Found chip path: %s." % (self.chip_happy_conf_path) | ||
self.logger.debug("[localhost] Chip: %s" % (emsg)) | ||
|
||
# Check if Chip build path is set | ||
if "abs_builddir" in os.environ.keys(): | ||
self.chip_build_path = os.environ['abs_builddir'] | ||
emsg = "Found chip abs_builddir: %s." % (self.chip_build_path) | ||
self.logger.debug("[localhost] Chip: %s" % (emsg)) | ||
|
||
if self.chip_build_path is not None: | ||
self.chip_path = self.chip_build_path | ||
else: | ||
self.chip_path = self.chip_happy_conf_path | ||
|
||
if self.chip_path is None: | ||
emsg = "Unknown path to Chip directory (repository)." | ||
self.logger.error("[localhost] Chip: %s" % (emsg)) | ||
self.logger.info( | ||
"Set chip_path with happy-configuration and try again.") | ||
sys.exit(1) | ||
|
||
if not os.path.exists(self.chip_path): | ||
emsg = "Chip path %s does not exist." % (self.chip_path) | ||
self.logger.error("[localhost] Chip: %s" % (emsg)) | ||
self.logger.info( | ||
"Set correct chip_path with happy-configuration and try again.") | ||
sys.exit(1) | ||
|
||
if self.chip_path[-1] == "/": | ||
self.chip_path = self.chip_path[:-1] | ||
|
||
def __get_cmd_path(self, cmd_end): | ||
cmd_path = self.chip_path + "/" + str(cmd_end) | ||
if not os.path.exists(cmd_path): | ||
emsg = "Chip path %s does not exist." % (cmd_path) | ||
self.logger.error("[localhost] Chip: %s" % (emsg)) | ||
sys.exit(1) | ||
# return None | ||
else: | ||
return cmd_path | ||
|
||
def getChipInetLayerMulticastPath(self): | ||
self.__check_chip_path() | ||
cmd_path = self.__get_cmd_path("TestInetLayerMulticast") | ||
return cmd_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# Copyright (c) 2015-2018 Nest Labs, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
## | ||
# @file | ||
# Implements ChipState class that implements methods to retrieve | ||
# parts of state setup that relate to Chip plugin. | ||
# | ||
|
||
import json | ||
from happy.State import State | ||
from happy.utils.IP import IP | ||
|
||
options = {} | ||
options["quiet"] = False | ||
|
||
|
||
def option(): | ||
return options.copy() | ||
|
||
|
||
class ChipState(State): | ||
""" | ||
Displays Weave-related parameters for Weave nodes in a Happy network | ||
topology. | ||
weave-state [-h --help] [-q --quiet] | ||
Examples: | ||
$ weave-state | ||
Displays Weave-related parameters for all Weave nodes in the | ||
current Happy topology. | ||
return: | ||
0 success | ||
1 fail | ||
""" | ||
|
||
def __init__(self, opts=options): | ||
State.__init__(self) | ||
self.quiet = opts["quiet"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# Copyright (c) 2016-2017 Nest Labs, Inc. | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
## | ||
# @file | ||
# Implements ChipStateLoad class that sets up virtual network topology. | ||
# | ||
|
||
import json | ||
import os | ||
import sys | ||
|
||
from happy.ReturnMsg import ReturnMsg | ||
from happy.Utils import * | ||
|
||
import happy.HappyStateLoad | ||
|
||
from Chip import Chip | ||
from ChipState import ChipState | ||
|
||
options = {} | ||
options["quiet"] = False | ||
options["json_file"] = None | ||
|
||
LOG_TEXT_PREFIX = "[localhost] ChipStateLoad: " | ||
|
||
|
||
def option(): | ||
return options.copy() | ||
|
||
|
||
class ChipStateLoad(ChipState): | ||
def __init__(self, opts=options): | ||
ChipState.__init__(self) | ||
|
||
self.quiet = opts["quiet"] | ||
self.new_json_file = opts["json_file"] | ||
|
||
def __pre_check(self): | ||
if self.new_json_file is None: | ||
emsg = "Missing name of file that specifies virtual network topology." | ||
self.logger.error(LOG_TEXT_PREFIX + emsg) | ||
self.exit() | ||
|
||
if not os.path.exists(self.new_json_file): | ||
emsg = "Cannot find the configuration file {}".format( | ||
self.new_json_file) | ||
self.logger.error(LOG_TEXT_PREFIX + emsg) | ||
self.exit() | ||
|
||
self.new_json_file = os.path.realpath(self.new_json_file) | ||
|
||
emsg = "Loading Chip Topology from file {}.".format(self.new_json_file) | ||
self.logger.debug(LOG_TEXT_PREFIX + emsg) | ||
|
||
def __load_JSON(self): | ||
emsg = "Import state file {}.".format(self.new_json_file) | ||
self.logger.debug(LOG_TEXT_PREFIX + emsg) | ||
|
||
try: | ||
with open(self.new_json_file, 'r') as jfile: | ||
json_data = jfile.read() | ||
|
||
self.weave_topology = json.loads(json_data) | ||
|
||
except Exception: | ||
emsg = "Failed to load JSON state file: {}".format( | ||
self.new_json_file) | ||
self.logger.error(LOG_TEXT_PREFIX + emsg) | ||
self.exit() | ||
|
||
def __load_network_topology(self): | ||
emsg = "Loading network topology." | ||
self.logger.debug(LOG_TEXT_PREFIX + emsg) | ||
|
||
options = happy.HappyStateLoad.option() | ||
options["quiet"] = self.quiet | ||
options["json_file"] = self.new_json_file | ||
|
||
happyLoad = happy.HappyStateLoad.HappyStateLoad(options) | ||
happyLoad.run() | ||
|
||
self.readState() | ||
|
||
def __configure_network_gateway(self): | ||
emsg = "Configuring Weave gateway." | ||
self.logger.debug(LOG_TEXT_PREFIX + emsg) | ||
|
||
def __post_check(self): | ||
emsg = "Loading Weave Fabric completed." | ||
self.logger.debug(LOG_TEXT_PREFIX + emsg) | ||
|
||
def run(self): | ||
with self.getStateLockManager(): | ||
|
||
self.__pre_check() | ||
|
||
self.__load_JSON() | ||
|
||
self.__load_network_topology() | ||
|
||
self.__post_check() | ||
|
||
return ReturnMsg(0) |
Oops, something went wrong.