Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions test/hardware/proxy_e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,19 @@ npx tsx run-e2e.ts COM3

# With custom timeout (default 120 seconds):
npx tsx run-e2e.ts COM3 180000 # 3 minutes

# With pre-configured device address (if serial output is missed):
npx tsx run-e2e.ts COM3 --address 0xABCD1234...

# All options:
npx tsx run-e2e.ts COM15 --timeout 180000 --address 0x123...
```

**Note:** The runner automatically resets the ESP32 when it opens the serial port (DTR/RTS pulse). This ensures it captures all serial output from boot. If the device address is missed, use `--address` flag or set `TELEMETRY_API_KEY` for automatic fallback.

## Test Protocol

The test firmware follows this sequence:
The test firmware and runner follow this sequence:

```
1. E2E:START
Expand All @@ -145,10 +153,16 @@ The test firmware follows this sequence:
10. E2E:KEEPALIVE count=1
11. E2E:KEEPALIVE count=2
12. E2E:KEEPALIVE count=3
13. E2E:API_CALL name="..." count=1 (if triggered)
14. E2E:DONE PASS time_ms=45000
13. E2E:WAITING_FOR_API
→ Runner calls: GET https://scriptproxy.percolate.one/api/<device_address>/e2eTest
→ Proxy forwards opcode 0x04 to device
→ Device receives API call and responds with opcode 0x08
14. E2E:API_CALL name="e2eTest" count=1
15. E2E:DONE PASS time_ms=45000
```

**Note:** The test runner actively triggers an API call when it sees `WAITING_FOR_API`. The device will **fail** if no API call is received within 60 seconds, as this tests the complete end-to-end flow through the public proxy.

## Serial Line Format

All test lines start with `E2E:` prefix and use key=value pairs:
Expand All @@ -171,7 +185,9 @@ E2E:TEST=STATUS key1=value1 key2="quoted value"
| `E2E:LOGIN=OK opcode=0x09` | TCP bridge authenticated |
| `E2E:DIAG_SENT opcode=0x0A` | Diagnostics sent |
| `E2E:KEEPALIVE count=N` | Keep-alive message N |
| `E2E:WAITING_FOR_API` | Waiting for API call from runner |
| `E2E:API_CALL name="..." count=N` | API call N handled |
| `E2E:API_CALLS_RECEIVED=N` | Total API calls received |
| `E2E:DONE PASS time_ms=T` | Test passed in T ms |
| `E2E:DONE FAIL` | Test failed |
| `E2E:FAIL reason="..."` | Failure reason |
Expand Down
95 changes: 69 additions & 26 deletions test/hardware/proxy_e2e/git_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,72 @@
import subprocess
import os

try:
# Get short git SHA from the Web3E repo root
repo_root = os.path.join(env['PROJECT_DIR'], '../../..')
git_sha = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD'],
cwd=repo_root
).decode('ascii').strip()

fw_version = 'e2e-{}'.format(git_sha)

# Remove any existing FW_VERSION definitions
env['CPPDEFINES'] = [
define for define in env['CPPDEFINES']
if not (isinstance(define, tuple) and define[0] == 'FW_VERSION')
and not (isinstance(define, str) and define.startswith('FW_VERSION='))
]

# Add our FW_VERSION
env.Append(CPPDEFINES=[('FW_VERSION', '\\"{}\\"'.format(fw_version))])
print('Building with firmware version: {}'.format(fw_version))

except Exception as e:
print('Warning: Could not get git SHA: {}'.format(e))
# Fallback to a default
env.Append(CPPDEFINES=[('FW_VERSION', '\\"e2e-unknown\\"')])
print('Using fallback firmware version: e2e-unknown')
def get_git_version():
"""Get e2e-<short_sha>[-dirty] version string, or 'e2e-unknown' if git unavailable."""
try:
# Get absolute path to Web3E repo root (3 levels up from this script)
# SCons exec context: use env['PROJECT_DIR'] if available
try:
project_dir = env['PROJECT_DIR']
except:
# Fallback: assume this script is in test/hardware/proxy_e2e/
project_dir = os.path.dirname(os.path.abspath(__file__)) if '__file__' in globals() else os.getcwd()

repo_root = os.path.abspath(os.path.join(project_dir, '..', '..', '..'))

# Check if git is available and this is a git repo
try:
subprocess.check_output(
['git', 'rev-parse', '--git-dir'],
cwd=repo_root,
stderr=subprocess.STDOUT
)
except (subprocess.CalledProcessError, OSError):
return 'e2e-unknown'

# Get short git SHA
git_sha = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD'],
cwd=repo_root,
stderr=subprocess.STDOUT
).decode('ascii').strip()

# Check if working tree is dirty (ignore untracked files to avoid build artifacts)
try:
# Use git diff to check tracked files only
subprocess.check_output(
['git', 'diff', '--quiet', 'HEAD'],
cwd=repo_root,
stderr=subprocess.STDOUT
)
is_dirty = False
except subprocess.CalledProcessError:
# Exit code 1 means there are differences
is_dirty = True
except:
is_dirty = False

# Build version string (max 32 ASCII chars)
fw_version = 'e2e-{}{}'.format(git_sha, '-dirty' if is_dirty else '')
return fw_version[:32] # Ensure <=32 chars

except Exception as e:
print('Warning: Could not get git version: {}'.format(e))
return 'e2e-unknown'

fw_version = get_git_version()

# Initialize CPPDEFINES if not present
if 'CPPDEFINES' not in env:
env['CPPDEFINES'] = []

# Remove any existing FW_VERSION definitions
env['CPPDEFINES'] = [
define for define in env.get('CPPDEFINES', [])
if not (isinstance(define, tuple) and define[0] == 'FW_VERSION')
and not (isinstance(define, str) and define.startswith('FW_VERSION='))
]

# Add our FW_VERSION
env.Append(CPPDEFINES=[('FW_VERSION', '\\"{}\\"'.format(fw_version))])
print('Building with firmware version: {}'.format(fw_version))
Loading
Loading