Skip to content
Closed
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
14 changes: 11 additions & 3 deletions .github/workflows/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ runs:
uses: ./.github/workflows/auto-cache
with:
path: /tmp/scons_cache
key: scons-${{ runner.arch }}-${{ env.CACHE_COMMIT_DATE }}-${{ github.sha }}
key: scons-${{ runner.os }}-${{ runner.arch }}-${{ env.CACHE_COMMIT_DATE }}-${{ github.sha }}
restore-keys: |
scons-${{ runner.arch }}-${{ env.CACHE_COMMIT_DATE }}
scons-${{ runner.arch }}
scons-${{ runner.os }}-${{ runner.arch }}-${{ env.CACHE_COMMIT_DATE }}
scons-${{ runner.os }}-${{ runner.arch }}
# venv cache
- id: venv-cache
uses: ./.github/workflows/auto-cache
with:
path: ${{ github.workspace }}/.venv
key: venv-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('uv.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ runner.arch }}
- shell: bash
name: Run setup
run: ./tools/op.sh setup
Expand Down
17 changes: 2 additions & 15 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,9 @@ jobs:
- uses: actions/checkout@v6
with:
submodules: true
- run: echo "CACHE_COMMIT_DATE=$(git log -1 --pretty='format:%cd' --date=format:'%Y-%m-%d-%H:%M')" >> $GITHUB_ENV
- name: Install dependencies
run: ./tools/mac_setup.sh
env:
HOMEBREW_DISPLAY_INSTALL_TIMES: 1
- run: git lfs pull
- name: Getting scons cache
uses: ./.github/workflows/auto-cache
with:
path: /tmp/scons_cache
key: scons-${{ runner.arch }}-macos-${{ env.CACHE_COMMIT_DATE }}-${{ github.sha }}
restore-keys: |
scons-${{ runner.arch }}-macos-${{ env.CACHE_COMMIT_DATE }}
scons-${{ runner.arch }}-macos
- uses: ./.github/workflows/setup-with-retry
- name: Building openpilot
run: . .venv/bin/activate && scons
run: scons

static_analysis:
name: static analysis
Expand Down
6 changes: 6 additions & 0 deletions selfdrive/ui/mici/layouts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def _setup_callbacks(self):
self._onroad_layout.set_click_callback(lambda: self._scroll_to(self._home_layout))
device.add_interactive_timeout_callback(self._on_interactive_timeout)

def show_event(self):
self._scroller.show_event()

def hide_event(self):
self._scroller.hide_event()

def _scroll_to(self, layout: Widget):
layout_x = int(layout.rect.x)
self._scroller.scroll_to(layout_x, smooth=True)
Expand Down
26 changes: 24 additions & 2 deletions selfdrive/ui/mici/layouts/settings/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@
from openpilot.selfdrive.ui.lib.prime_state import PrimeType
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.widgets.nav_widget import NavWidget
from openpilot.system.ui.lib.wifi_manager import WifiManager, Network, MeteredType, ConnectStatus, normalize_ssid
from openpilot.system.ui.lib.wifi_manager import WifiManager, Network, MeteredType, ConnectStatus, SecurityType, normalize_ssid


class WifiNetworkButton(BigButton):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._lock_txt = gui_app.texture("icons_mici/settings/network/new/lock.png", 28, 36)
self._draw_lock = False

def set_draw_lock(self, draw: bool):
self._draw_lock = draw

def _draw_content(self, btn_y: float):
super()._draw_content(btn_y)
# Render lock icon at lower right of wifi icon if secured
if self._draw_lock:
icon_x = self._rect.x + self._rect.width - 30 - self._txt_icon.width
icon_y = btn_y + 30
lock_x = icon_x + self._txt_icon.width - self._lock_txt.width + 7
lock_y = icon_y + self._txt_icon.height - self._lock_txt.height + 8
rl.draw_texture_ex(self._lock_txt, (lock_x, lock_y), 0.0, 1.0, rl.WHITE)


class NetworkLayoutMici(NavWidget):
Expand Down Expand Up @@ -68,7 +88,7 @@ def network_metered_callback(value: str):
self._wifi_medium_txt = gui_app.texture("icons_mici/settings/network/wifi_strength_medium.png", 64, 47)
self._wifi_full_txt = gui_app.texture("icons_mici/settings/network/wifi_strength_full.png", 64, 47)

self._wifi_button = BigButton("wi-fi", "not connected", self._wifi_slash_txt, scroll=True)
self._wifi_button = WifiNetworkButton("wi-fi", "not connected", self._wifi_slash_txt, scroll=True)
self._wifi_button.set_click_callback(lambda: gui_app.push_widget(self._wifi_ui))

# ******** Advanced settings ********
Expand Down Expand Up @@ -131,8 +151,10 @@ def _update_state(self):
if display_network is not None:
strength = WifiIcon.get_strength_icon_idx(display_network.strength)
self._wifi_button.set_icon(self._wifi_full_txt if strength == 2 else self._wifi_medium_txt if strength == 1 else self._wifi_low_txt)
self._wifi_button.set_draw_lock(display_network.security_type not in (SecurityType.OPEN, SecurityType.UNSUPPORTED))
else:
self._wifi_button.set_icon(self._wifi_slash_txt)
self._wifi_button.set_draw_lock(False)

def show_event(self):
super().show_event()
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/ui/mici/layouts/settings/network/wifi_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def network(self) -> Network:

@property
def _show_forget_btn(self):
if self._network.is_tethering:
return False

return (self._is_saved and not self._wrong_password) or self._is_connecting

def _handle_mouse_release(self, mouse_pos: MousePos):
Expand Down
21 changes: 20 additions & 1 deletion system/loggerd/deleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,33 @@ def deleter_thread(exit_event: threading.Event):
out_of_percent = get_available_percent(default=MIN_PERCENT + 1) < MIN_PERCENT

if out_of_percent or out_of_bytes:
# clean up non-directory entries that listdir_by_creation skips
# (e.g. stray .tar.gz files, broken symlinks)
try:
all_entries = os.listdir(Paths.log_root())
except OSError:
all_entries = []
for entry in all_entries:
entry_path = os.path.join(Paths.log_root(), entry)
if not os.path.isdir(entry_path):
try:
cloudlog.info(f"deleting non-directory {entry_path}")
os.remove(entry_path)
except OSError:
cloudlog.exception(f"issue deleting non-directory {entry_path}")

dirs = listdir_by_creation(Paths.log_root())
preserved_dirs = get_preserved_segments(dirs)

# remove the earliest directory we can
for delete_dir in sorted(dirs, key=lambda d: (d in DELETE_LAST, d in preserved_dirs)):
delete_path = os.path.join(Paths.log_root(), delete_dir)

if any(name.endswith(".lock") for name in os.listdir(delete_path)):
try:
if any(name.endswith(".lock") for name in os.listdir(delete_path)):
continue
except OSError:
cloudlog.exception(f"issue listing {delete_path}")
continue

try:
Expand Down
117 changes: 117 additions & 0 deletions system/loggerd/tests/test_deleter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import time
import threading
from collections import namedtuple
Expand Down Expand Up @@ -115,3 +116,119 @@ def test_no_delete_with_lock_file(self):
self.join_thread()

assert f_path.exists(), "File deleted when locked"

# -- robustness tests for non-standard entries in the log root --

def _wait_for_path_removal(self, path: Path, timeout: float = 3) -> bool:
"""Wait for a path to be removed. Returns True if removed.
Uses os.path.lexists to correctly detect broken symlinks."""
self.start_thread()
try:
start = time.monotonic()
while os.path.lexists(path) and time.monotonic() - start < timeout:
time.sleep(0.01)
return not os.path.lexists(path)
finally:
self.join_thread()

def test_delete_stray_file(self):
"""A regular file (e.g. tar.gz archive) in the log root should be deleted."""
from openpilot.system.hardware.hw import Paths
stray = Path(Paths.log_root()) / "2023-09-23.tar.gz"
stray.write_bytes(os.urandom(1024))

assert self._wait_for_path_removal(stray), "Stray file was not deleted"

def test_delete_broken_symlink(self):
"""A symlink pointing to a non-existent target should be deleted."""
from openpilot.system.hardware.hw import Paths
link = Path(Paths.log_root()) / "broken-link"
link.symlink_to("/does/not/exist")

assert self._wait_for_path_removal(link), "Broken symlink was not deleted"

def test_delete_valid_symlink_to_file(self):
"""A symlink pointing to a real file should be removed (unlinked)."""
from openpilot.system.hardware.hw import Paths
target = Path(Paths.log_root()) / "target.txt"
target.write_bytes(b"data")
link = Path(Paths.log_root()) / "link-to-file"
link.symlink_to(target)

assert self._wait_for_path_removal(link), "Valid file symlink was not deleted"

def test_delete_empty_file(self):
"""A zero-byte file should be deleted."""
from openpilot.system.hardware.hw import Paths
empty = Path(Paths.log_root()) / "empty_file"
empty.touch()

assert self._wait_for_path_removal(empty), "Empty file was not deleted"

def test_delete_hidden_file(self):
"""A dotfile should be deleted."""
from openpilot.system.hardware.hw import Paths
hidden = Path(Paths.log_root()) / ".hidden_temp"
hidden.write_bytes(b"hidden")

assert self._wait_for_path_removal(hidden), "Hidden file was not deleted"

def test_delete_fifo(self):
"""A named pipe (FIFO) should be deleted."""
from openpilot.system.hardware.hw import Paths
fifo = Path(Paths.log_root()) / "test.fifo"
os.mkfifo(fifo)

assert self._wait_for_path_removal(fifo), "FIFO was not deleted"

def test_stray_files_deleted_before_segments(self):
"""Non-directory entries should be cleaned up alongside segment dirs."""
from openpilot.system.hardware.hw import Paths

stray = Path(Paths.log_root()) / "stray_backup.tar.gz"
stray.write_bytes(os.urandom(512))

seg_path = self.make_file_with_data(self.seg_dir, self.f_type)

self.start_thread()
try:
with Timeout(3, "Timeout waiting for cleanup"):
while stray.exists() or seg_path.exists():
time.sleep(0.01)
finally:
self.join_thread()

def test_mixed_entries_no_crash(self):
"""Deleter should handle a mix of normal segments, stray files, symlinks,
and empty directories without crashing."""
from openpilot.system.hardware.hw import Paths
root = Path(Paths.log_root())

# normal segment directory
seg_path = self.make_file_with_data(self.seg_format.format(0), self.f_type)

# stray regular files
(root / "backup.tar.gz").write_bytes(os.urandom(256))
(root / "notes.txt").write_bytes(b"test")
(root / ".DS_Store").write_bytes(b"\x00" * 32)

# broken symlink
(root / "dead-link").symlink_to("/nonexistent/path")

# empty directory (not a segment)
(root / "tmp_work").mkdir()

# FIFO
os.mkfifo(root / "pipe")

self.start_thread()
try:
with Timeout(5, "Timeout waiting for mixed cleanup"):
# wait for all non-directory entries to be cleaned up
while any(os.path.lexists(root / f) for f in ["backup.tar.gz", "notes.txt", ".DS_Store", "dead-link", "pipe"]):
time.sleep(0.01)
# segment should also be deleted eventually
while seg_path.exists():
time.sleep(0.01)
finally:
self.join_thread()
8 changes: 5 additions & 3 deletions system/ui/lib/wifi_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,19 @@ class Network:
ssid: str
strength: int
security_type: SecurityType
is_tethering: bool

@classmethod
def from_dbus(cls, ssid: str, aps: list["AccessPoint"]) -> "Network":
def from_dbus(cls, ssid: str, aps: list["AccessPoint"], is_tethering: bool) -> "Network":
# we only want to show the strongest AP for each Network/SSID
strongest_ap = max(aps, key=lambda ap: ap.strength)
security_type = get_security_type(strongest_ap.flags, strongest_ap.wpa_flags, strongest_ap.rsn_flags)

return cls(
ssid=ssid,
strength=strongest_ap.strength,
strength=100 if is_tethering else strongest_ap.strength,
security_type=security_type,
is_tethering=is_tethering,
)


Expand Down Expand Up @@ -820,7 +822,7 @@ def worker():
# catch all for parsing errors
cloudlog.exception(f"Failed to parse AP properties for {ap_path}")

networks = [Network.from_dbus(ssid, ap_list) for ssid, ap_list in aps.items()]
networks = [Network.from_dbus(ssid, ap_list, ssid == self._tethering_ssid) for ssid, ap_list in aps.items()]
networks.sort(key=lambda n: (n.ssid != self._wifi_state.ssid, not self.is_connection_saved(n.ssid), -n.strength, n.ssid.lower()))
self._networks = networks

Expand Down
7 changes: 6 additions & 1 deletion system/ui/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,12 @@ def _render(self, _):
# draw black fade on left and right
fade_width = 20
rl.draw_rectangle_gradient_h(int(self._rect.x + self._rect.width - fade_width), int(self._rect.y), fade_width, int(self._rect.height), rl.BLANK, rl.BLACK)
if self._scroll_state != ScrollState.STARTING:

# stop drawing left fade once text scrolls past
text_width = visible_sizes[0].x if visible_sizes else 0
first_copy_in_view = self._scroll_offset + text_width > 0
draw_left_fade = self._scroll_state != ScrollState.STARTING and first_copy_in_view
if draw_left_fade:
rl.draw_rectangle_gradient_h(int(self._rect.x), int(self._rect.y), fade_width, int(self._rect.height), rl.BLACK, rl.BLANK)

rl.end_scissor_mode()
Expand Down
Loading