@@ -3,3 +3,4 @@ pycryptodomex==3.21.0
pytest==6.2.5
pytest-xdist==2.5.0
FATtools==1.0.42
+requests=2.32.3
@@ -1,7 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
# (C) Copyright 2023, Advanced Micro Devices, Inc.
+import os
import pytest
+import requests
"""
Test the bootstage command.
@@ -40,15 +42,50 @@ def test_bootstage_report_json(ubman):
assert '"reset~board_init_f"' in output
@pytest.mark.buildconfigspec('bootstage')
+
+# Extract the text string between two delimiters
+def extract_between(text, start_delimiter, end_delimiter):
+ startp = text.find(start_delimiter)
+ if startp == -1:
+ return None
+ startp += len(start_delimiter)
+ endp = text.find(end_delimiter, startp)
+ if endp == -1:
+ return None
+ return text[startp:endp].strip()
+
+def send_data_to_influxdb(data):
+ uri = os.environ.get("BOOTSTAGE_INFLUXDB_URI")
+ token = os.environ.get("BOOTSTAGE_INFLUXDB_TOKEN")
+ if not uri or not token:
+ print("Warning: BOOTSTAGE_INFLUXDB_URI or BOOTSTAGE_INFLUXDB_TOKEN "
+ "not set, cannot send bootstage data")
+ return
+ headers = {
+ "Authorization": f"Token {token}",
+ "Content-Type": "text/plain;charset=utf-8"
+ }
+ try:
+ rsp = requests.post(uri, headers= headers, data=data.encode('utf-8'))
+ rsp.raise_for_status()
+ print(f"Data succcessfully sent to {uri}")
+ except requests.exceptions.RequestException as e:
+ print(f"Error sending data to {uri}: {e}")
+
@pytest.mark.buildconfigspec('cmd_bootstage')
@pytest.mark.buildconfigspec('bootstage_report_influxdb')
def test_bootstage_report_influxdb(ubman):
output = ubman.run_command('bootstage report')
- assert '=== Begin InfluxDB v2 bootstage report ===' in output
+ start_delimiter = '=== Begin InfluxDB v2 bootstage report ==='
+ end_delimiter = '=== End InfluxDB v2 bootstage report ==='
+ assert start_delimiter in output
assert 'u-boot_bootstage_report,' in output
assert 'u_boot_version=' in output
assert 'dm_r=' in output
assert 'reset~board_init_f=' in output
+ data = extract_between(output, start_delimiter, end_delimiter)
+ if data:
+ send_data_to_influxdb(data)
@pytest.mark.buildconfigspec('bootstage')
@pytest.mark.buildconfigspec('cmd_bootstage')
If the BOOTSTAGE_INFLUXDB_URI and BOOTSTAGE_INFLUXDB_TOKEN environment variables are set, the bootstage test will upload the timing information to the specified InfluxDB instance. This is meant to be used in CI to publish results for a particular board/build for later analysis. Note: use "precision=us" in the URI, not "precision=ns" as shown in most examples in the InfluxDB documentation. For details see [1]. [1] https://docs.influxdata.com/influxdb/v2/write-data/developer-tools/api Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> --- test/py/requirements.txt | 1 + test/py/tests/test_bootstage.py | 39 ++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-)