Skip to content

Commit

Permalink
Updates and Fixes to the Script
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsalghelani-csa committed Jun 17, 2024
1 parent f37cbdd commit 70c8252
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
42 changes: 17 additions & 25 deletions scripts/tests/py/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
# limitations under the License.

import os
import tempfile
import unittest
import tempfile
from typing import List

from metadata import MetadataReader

from metadata import MetadataReader, Metadata

class TestMetadataReader(unittest.TestCase):

Expand All @@ -39,47 +38,40 @@ class TestMetadataReader(unittest.TestCase):
TRACE_TEST_PERFETTO: out/trace_data/test-{SCRIPT_BASE_NAME}
'''

expected_metadata = Metadata(
script_args="--commissioning-method on-network --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto",
py_script_path="",
app_args="--discriminator 1234 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json",
run="run1",
app="out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app",
factoryreset=True
)

def generate_temp_file(self, directory: str, file_content: str) -> str:
fd, temp_file_path = tempfile.mkstemp(dir=directory)
with os.fdopen(fd, 'w') as fp:
fp.write(file_content)
return temp_file_path

def generate_run_commands(self, reader: MetadataReader, script_path: str) -> List[str]:
metadata_list = reader.parse_script(script_path)
commands = []

for metadata in metadata_list:
cmd = (
"scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py "
f"--app {metadata.app} "
f"{'--factoryreset' if metadata.factoryreset else ''} "
f"--app-args \"{metadata.app_args}\" "
f"--script \"{metadata.py_script_path}\" "
f"--script-args \"{metadata.script_args}\"'"
)
commands.append(cmd.strip())

return commands

def test_run_arg_generation(self):
with tempfile.TemporaryDirectory() as temp_dir:
temp_file = self.generate_temp_file(temp_dir, self.test_file_content)
env_file = self.generate_temp_file(temp_dir, self.env_file_content)

reader = MetadataReader(env_file)
self.maxDiff = None

test_file_expected_arg_string = (
"scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py "
"--app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app "
"--factoryreset --app-args \"--discriminator 1234 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json\" "
"--script \"" + temp_file + "\" --script-args \"--commissioning-method on-network "
"--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto\"'"
)

actual = self.generate_run_commands(reader, temp_file)[0]
self.assertEqual(test_file_expected_arg_string, actual)

self.expected_metadata.py_script_path = temp_file
actual = reader.parse_script(temp_file)[0]
self.assertEqual(self.expected_metadata, actual)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/run_python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def main(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: st
]

for run in runs:
print(f"Executing run: {run.py_script_path}")
print(f"Executing {run.py_script_path.split('/')[-1]} {run.run}")
main_impl(run.app, run.factoryreset, run.factoryreset_app_only, run.app_args,
run.py_script_path, run.script_args, run.script_gdb, run.quiet)

Expand Down
1 change: 1 addition & 0 deletions src/python_testing/TC_SC_3_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# test-runner-runs: run1
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
# test-runner-run/run1/factoryreset: True
# test-runner-run/run1/quiet: True
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto

Expand Down

0 comments on commit 70c8252

Please sign in to comment.