Skip to content

Commit

Permalink
Configs
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Oct 19, 2023
1 parent 0fcbb10 commit d5474b7
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 26 deletions.
20 changes: 20 additions & 0 deletions src/tools/interop/idt/capture/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (c) 2023 Project CHIP Authors
# 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 logging

log_level = logging.INFO
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import os

from capture.file_utils import add_border, create_standard_log_name, print_and_write
from capture.file_utils import add_border, create_standard_log_name
from capture.log_format import print_and_write
from capture.platform.android import Android


Expand Down
18 changes: 18 additions & 0 deletions src/tools/interop/idt/capture/ecosystem/play_services/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Project CHIP Authors
# 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.
#

enable_foyer_probers = True
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from capture.file_utils import create_standard_log_name
from capture.platform.android import Android

from . import config
from .analysis import PlayServicesAnalysis
from .command_map import dumpsys, getprop
from .prober import PlayServicesProber
Expand Down Expand Up @@ -96,4 +97,7 @@ async def stop_capture(self) -> None:

async def analyze_capture(self) -> None:
self.analysis.do_analysis()
await PlayServicesProber(self.platform).probe_services()
if config.enable_foyer_probers:
await PlayServicesProber(self.platform).probe_services()
else:
self.logger.critical("Foyer probers disabled in config!")
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import os

from capture.base import EcosystemCapture, UnsupportedCapturePlatformException
from capture.file_utils import create_standard_log_name, print_and_write
from capture.file_utils import create_standard_log_name
from capture.log_format import print_and_write
from capture.platform.android.android import Android


Expand Down
3 changes: 2 additions & 1 deletion src/tools/interop/idt/capture/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import capture
from capture import log_format
from capture.base import EcosystemCapture, PlatformLogStreamer, UnsupportedCapturePlatformException
from capture.file_utils import border_print, safe_mkdir
from capture.file_utils import safe_mkdir
from capture.log_format import border_print

_CONFIG_TIMEOUT = 45.0
_PLATFORM_MAP: typing.Dict[str, PlatformLogStreamer] = {}
Expand Down
13 changes: 0 additions & 13 deletions src/tools/interop/idt/capture/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import os
import time
from pathlib import Path
from typing import TextIO


def add_border(to_print: str) -> str:
Expand All @@ -39,15 +38,3 @@ def create_standard_log_name(name: str, ext: str, parent: str = "") -> str:

def safe_mkdir(dir_name: str) -> None:
Path(dir_name).mkdir(parents=True, exist_ok=True)


def print_and_write(to_print: str, file: TextIO) -> None:
print(f"\x1b[32;1m{to_print}\x1b[0m")
file.write(to_print)


def border_print(to_print: str, important: bool = False) -> None:
len_borders = len(to_print)
border = f"\n{'_' * len_borders}\n"
i_border = f"\n{'!' * len_borders}\n" if important else ""
print(f"\x1b[35;1m{border}{i_border}{to_print}{i_border}{border}\x1b[0m")
3 changes: 1 addition & 2 deletions src/tools/interop/idt/capture/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ def fetch_impls(self):
module = importlib.import_module("." + item, self.root_package)
self.load_module(module)
except ModuleNotFoundError:
self.logger.warning(f"No module matching package name for {item}")
traceback.print_exc()
self.logger.warning(f"No module matching package name for {item}\n{traceback.format_exc()}")
21 changes: 18 additions & 3 deletions src/tools/interop/idt/capture/log_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#

import logging
from typing import TextIO

# TODO: Make CLI arg
_CONFIG_LEVEL = logging.INFO
from . import config

_CONFIG_LEVEL = config.log_level

blue = "\x1b[34;1m"
cyan = "\x1b[36;1m"
Expand All @@ -28,8 +30,9 @@
yellow = "\x1b[33;20m"
red_black_background = "\x1b[31;40;20m"
bold_red_yellow_background = "\x1b[31;43;1m"

reset = "\x1b[0m"
# TODO: Padding

format_pre = cyan + "%(asctime)s %(levelname)s {%(module)s} [%(funcName)s] " + reset
format_post = "%(message)s" + reset

Expand Down Expand Up @@ -59,3 +62,15 @@ def get_logger(logger_name) -> logging.Logger:
logger.addHandler(ch)
logger.propagate = False
return logger


def border_print(to_print: str, important: bool = False) -> None:
len_borders = len(to_print)
border = f"\n{'_' * len_borders}\n"
i_border = f"\n{'!' * len_borders}\n" if important else ""
print(f"\x1b[35;1m{border}{i_border}{to_print}{i_border}{border}\x1b[0m")


def print_and_write(to_print: str, file: TextIO) -> None:
print(f"\x1b[32;1m{to_print}\x1b[0m")
file.write(to_print)
3 changes: 1 addition & 2 deletions src/tools/interop/idt/capture/platform/android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ async def handle_stream_action(self, action: str) -> None:
try:
await getattr(stream, action)()
except:
# TODO: Log with color
traceback.print_exc()
self.logger.error(traceback.format_exc())
had_error = True
if had_error:
raise Exception("Propagating to controller!")
Expand Down
18 changes: 18 additions & 0 deletions src/tools/interop/idt/capture/platform/android/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2023 Project CHIP Authors
# 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.
#

enable_build_push_tcpdump = True
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from capture.file_utils import create_standard_log_name, safe_mkdir
from capture.shell_utils import Bash
from typing import TYPE_CHECKING
from ... import config
from ..streams_base import AndroidStream

if TYPE_CHECKING:
Expand Down Expand Up @@ -58,9 +59,12 @@ async def start(self):
self.pcap_proc.start_command()
self.pcap_pull = True
return
if not config.enable_build_push_tcpdump:
self.logger.critical("Android TCP Dump build and push disabled in configs!")
return
if not os.path.exists(os.path.join(self.build_dir, "tcpdump")):
self.logger.warning("tcpdump bin not found, attempting to build, please wait a few moments!")
build_script = os.path.join(os.path.dirname(__file__), "../build_tcpdump_64.sh")
build_script = os.path.join(os.path.dirname(__file__), "build_tcpdump_64.sh")
Bash(f"{build_script} 2>&1 >> BUILD_LOG.txt", sync=True, cwd=self.build_dir).start_command()
else:
self.logger.warning("Reusing existing tcpdump build")
Expand Down
3 changes: 2 additions & 1 deletion src/tools/interop/idt/idt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from pathlib import Path

from capture import EcosystemController, EcosystemFactory, PacketCaptureRunner, PlatformFactory
from capture.file_utils import border_print, create_file_timestamp, safe_mkdir
from capture.file_utils import create_file_timestamp, safe_mkdir
from capture.log_format import border_print
from discovery import MatterBleScanner, MatterDnssdListener


Expand Down

0 comments on commit d5474b7

Please sign in to comment.