- Choose the recording folder (head unit, any mounted USB volume, or a typed path); real write test, falls back to the head unit if the stick is missing; clips/events in old folders stay managed - USB budget bounded by stick size (its free-space figure drifts on this head unit, per upstream) - Parked (P + standing still) records at 1.5 Mbit/s 10 fps by default (or medium/full/off); clips rotate on mode change; parked clips are deleted first and can age out sooner (default 7 days) - Default driving bitrate 9 -> 6 Mbit/s; quality picker shows GB/hour - Drive log sidecar per clip and per event (speed, SoC, range, gear, GPS), uploaded with the clip - Dashboard: synced speed/battery/gear readouts, route map (OSM via cached server proxy), speed graph with click-to-seek, drive distance/top speed/battery, speed+position at event press, parked footage in storage meters - Tests: parked-first deletion and parked retention
108 lines
6.0 KiB
Java
108 lines
6.0 KiB
Java
package cloud.molberg.mgutility;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
public final class DashcamPolicyTest {
|
|
private static int failures;
|
|
|
|
private static void check(boolean ok, String name) {
|
|
if (ok) System.out.println("ok - " + name);
|
|
else { System.out.println("FAIL - " + name); failures++; }
|
|
}
|
|
|
|
private static final long MIN = 60_000L;
|
|
private static final long MB = 1024L * 1024L;
|
|
|
|
private static DashcamPolicy.Clip clip(String name, long start, long sizeMb) {
|
|
return new DashcamPolicy.Clip(name, start, start + MIN, sizeMb * MB);
|
|
}
|
|
|
|
private static List<String> names(List<DashcamPolicy.Clip> clips) {
|
|
List<String> out = new ArrayList<String>();
|
|
for (DashcamPolicy.Clip c : clips) out.add(c.name);
|
|
return out;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
long now = 1_800_000_000_000L;
|
|
long day = DashcamPolicy.DAY_MS;
|
|
|
|
// Names round-trip.
|
|
String name = DashcamPolicy.clipName(now);
|
|
long parsed = DashcamPolicy.clipStart(name);
|
|
check(Math.abs(parsed - now) < 1000L, "clip name round-trips to the second");
|
|
check(DashcamPolicy.clipStart("notes.txt") == -1L, "foreign file ignored");
|
|
check(DashcamPolicy.clipStart("20261399_000000.mp4") == -1L, "invalid date ignored");
|
|
|
|
// Age-based retention deletes only unprotected clips older than the limit.
|
|
List<DashcamPolicy.Clip> clips = Arrays.asList(
|
|
clip("old", now - 40 * day, 50),
|
|
clip("kept-old", now - 35 * day, 50),
|
|
clip("recent", now - 2 * day, 50));
|
|
List<DashcamPolicy.Range> tags = Collections.singletonList(
|
|
new DashcamPolicy.Range(now - 35 * day + 10_000L, now - 35 * day + 20_000L));
|
|
List<String> del = names(DashcamPolicy.selectForDeletion(clips, tags, now, 0, 30, 0, null));
|
|
check(del.equals(Collections.singletonList("old")), "30-day retention removes only the old unprotected clip");
|
|
del = names(DashcamPolicy.selectForDeletion(clips, tags, now, 0, 0, 0, null));
|
|
check(del.isEmpty(), "retention 0 disables age deletion");
|
|
|
|
// Storage cap deletes oldest unprotected first, skips protected and active.
|
|
List<DashcamPolicy.Clip> cap = Arrays.asList(
|
|
clip("a", now - 10 * MIN, 100),
|
|
clip("b", now - 9 * MIN, 100),
|
|
clip("c", now - 8 * MIN, 100),
|
|
clip("d", now - 7 * MIN, 100),
|
|
clip("live", now - MIN, 100));
|
|
List<DashcamPolicy.Range> keepB = Collections.singletonList(
|
|
new DashcamPolicy.Range(now - 9 * MIN + 1000L, now - 9 * MIN + 2000L));
|
|
del = names(DashcamPolicy.selectForDeletion(cap, keepB, now, 300 * MB, 30, 0, "live"));
|
|
check(del.equals(Arrays.asList("a", "c")), "cap trims oldest unprotected clips: " + del);
|
|
del = names(DashcamPolicy.selectForDeletion(cap, keepB, now, 300 * MB, 30, 100 * MB, "live"));
|
|
check(del.equals(Arrays.asList("a", "c", "d")), "headroom for next segment is respected: " + del);
|
|
del = names(DashcamPolicy.selectForDeletion(cap, keepB, now, 50 * MB, 30, 0, "live"));
|
|
check(!del.contains("b") && !del.contains("live"), "never deletes protected or active clip even when over cap");
|
|
check(DashcamPolicy.protectedBytes(cap, keepB) == 100 * MB, "protected bytes counted");
|
|
|
|
// Tag spanning a boundary protects both neighbours.
|
|
List<DashcamPolicy.Range> span = Collections.singletonList(
|
|
new DashcamPolicy.Range(now - 8 * MIN - 5000L, now - 8 * MIN + 5000L));
|
|
check(DashcamPolicy.clipsInRange(cap, span.get(0)).size() == 2, "range across boundary covers two clips");
|
|
|
|
// Sessions split on gaps.
|
|
List<DashcamPolicy.Clip> drive = Arrays.asList(
|
|
clip("s2b", now + MIN, 1), clip("s1a", now - 60 * MIN, 1),
|
|
clip("s1b", now - 59 * MIN, 1), clip("s2a", now, 1));
|
|
List<List<DashcamPolicy.Clip>> sessions = DashcamPolicy.sessions(drive, 2 * MIN);
|
|
check(sessions.size() == 2 && sessions.get(0).size() == 2 && sessions.get(1).get(0).name.equals("s2a"),
|
|
"clips grouped into drives");
|
|
|
|
// Parked footage is trimmed before driving footage, regardless of age.
|
|
List<DashcamPolicy.Clip> mixed = Arrays.asList(
|
|
new DashcamPolicy.Clip("drive-old", now - 10 * MIN, now - 9 * MIN, 100 * MB, false),
|
|
new DashcamPolicy.Clip("parked-new", now - 5 * MIN, now - 4 * MIN, 30 * MB, true),
|
|
new DashcamPolicy.Clip("parked-newer", now - 3 * MIN, now - 2 * MIN, 30 * MB, true),
|
|
new DashcamPolicy.Clip("drive-new", now - 2 * MIN, now - MIN, 100 * MB, false));
|
|
del = names(DashcamPolicy.selectForDeletion(mixed, Collections.<DashcamPolicy.Range>emptyList(), now, 200 * MB, 30, 0, 0, null));
|
|
check(del.equals(Arrays.asList("parked-new", "parked-newer")), "parked clips go first: " + del);
|
|
del = names(DashcamPolicy.selectForDeletion(mixed, Collections.<DashcamPolicy.Range>emptyList(), now, 150 * MB, 30, 0, 0, null));
|
|
check(del.equals(Arrays.asList("parked-new", "parked-newer", "drive-old")), "then oldest driving clip: " + del);
|
|
List<DashcamPolicy.Clip> aged = Arrays.asList(
|
|
new DashcamPolicy.Clip("p", now - 5 * day, now - 5 * day, MB, true),
|
|
new DashcamPolicy.Clip("d", now - 5 * day, now - 5 * day, MB, false));
|
|
del = names(DashcamPolicy.selectForDeletion(aged, Collections.<DashcamPolicy.Range>emptyList(), now, 0, 30, 3, 0, null));
|
|
check(del.equals(Collections.singletonList("p")), "parked retention shorter than driving: " + del);
|
|
|
|
check(DashcamPolicy.segmentBytes(9_000_000, 60) == 70_875_000L, "segment size estimate");
|
|
check(DashcamPolicy.minutesForBudget(10L * 1024 * MB, 9_000_000) == 151L, "minutes for 10 GB at 9 Mbit/s");
|
|
|
|
if (failures > 0) {
|
|
System.out.println(failures + " failure(s)");
|
|
System.exit(1);
|
|
}
|
|
System.out.println("DashcamPolicyTest: all tests passed");
|
|
}
|
|
}
|