From 71128d156934198579aab985b10b8ba4aae4bf66 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 4 Mar 2024 23:24:23 -0500 Subject: [PATCH 1/3] Create smoketest mode (#1264) Create test mode that exists after confirming libraries load OK --- .github/workflows/build.yml | 77 +++++++++++++++++++ .../src/main/java/org/photonvision/Main.java | 25 +++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c87572cf5..af7b66e0a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -260,6 +260,83 @@ jobs: with: name: jar-${{ matrix.artifact-name }} path: photon-server/build/libs + + run-smoketest-native: + needs: [build-package] + + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + artifact-name: jar-Linux + extraOpts: -Djdk.lang.Process.launchMechanism=vfork + - os: windows-latest + artifact-name: jar-Win64 + extraOpts: "" + - os: macos-latest + artifact-name: jar-macOS + architecture: x64 + + runs-on: ${{ matrix.os }} + + steps: + - name: Install Java 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: temurin + - uses: actions/download-artifact@v4 + with: + name: ${{ matrix.artifact-name }} + # On linux, install mrcal packages + - run: | + sudo apt-get update + sudo apt-get install --yes libcholmod3 liblapack3 libsuitesparseconfig5 + if: ${{ (matrix.os) == 'ubuntu-latest' }} + # and actually run the jar + - run: java -jar ${{ matrix.extraOpts }} *.jar --smoketest + if: ${{ (matrix.os) != 'windows-latest' }} + - run: ls *.jar | %{ Write-Host "Running $($_.Name)"; Start-Process "java" -ArgumentList "-jar `"$($_.FullName)`" --smoketest" -NoNewWindow -Wait; break } + if: ${{ (matrix.os) == 'windows-latest' }} + + run-smoketest-chroot: + needs: [build-package] + + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + artifact-name: LinuxArm64 + image_suffix: RaspberryPi + image_url: https://github.com/PhotonVision/photon-image-modifier/releases/download/v2024.0.4/photonvision_raspi.img.xz + cpu: cortex-a7 + image_additional_mb: 0 + extraOpts: -Djdk.lang.Process.launchMechanism=vfork + + runs-on: ${{ matrix.os }} + name: smoketest-${{ matrix.image_suffix }} + + steps: + - uses: actions/download-artifact@v4 + with: + name: jar-${{ matrix.artifact-name }} + + - uses: pguyot/arm-runner-action@v2 + name: Run photon smoketest + id: generate_image + with: + base_image: ${{ matrix.image_url }} + image_additional_mb: ${{ matrix.image_additional_mb }} + optimize_image: yes + cpu: ${{ matrix.cpu }} + # We do _not_ wanna copy photon into the image. Bind mount instead + bind_mount_repository: true + # our image better have java installed already + commands: | + java -jar ${{ matrix.extraOpts }} *.jar --smoketest + build-image: needs: [build-package] diff --git a/photon-server/src/main/java/org/photonvision/Main.java b/photon-server/src/main/java/org/photonvision/Main.java index 8ae7c8fd92..a78c0a79fc 100644 --- a/photon-server/src/main/java/org/photonvision/Main.java +++ b/photon-server/src/main/java/org/photonvision/Main.java @@ -65,6 +65,7 @@ public class Main { private static final boolean isRelease = PhotonVersion.isRelease; private static boolean isTestMode = false; + private static boolean isSmoketest = false; private static Path testModeFolder = null; private static boolean printDebugLogs; @@ -90,6 +91,11 @@ private static boolean handleArgs(String[] args) throws ParseException { "clear-config", false, "Clears PhotonVision pipeline and networking settings. Preserves log files"); + options.addOption( + "s", + "smoketest", + false, + "Exit Photon after loading native libraries and camera configs, but before starting up camera runners"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); @@ -127,6 +133,10 @@ private static boolean handleArgs(String[] args) throws ParseException { if (cmd.hasOption("clear-config")) { ConfigManager.getInstance().clearConfig(); } + + if (cmd.hasOption("smoketest")) { + isSmoketest = true; + } } return true; } @@ -337,11 +347,17 @@ private static void addTestModeSources() { public static void main(String[] args) { try { - TestUtils.loadLibraries(); - logger.info("Native libraries loaded."); + boolean success = TestUtils.loadLibraries(); + + if (!success) { + logger.error("Failed to load native libraries! Giving up :("); + System.exit(1); + } } catch (Exception e) { logger.error("Failed to load native libraries!", e); + System.exit(1); } + logger.info("Native libraries loaded."); try { if (Platform.isRaspberryPi()) { @@ -412,6 +428,11 @@ public static void main(String[] args) { NeuralNetworkModelManager.getInstance() .initialize(ConfigManager.getInstance().getModelsDirectory()); + if (isSmoketest) { + logger.info("PhotonVision base functionality loaded -- smoketest complete"); + System.exit(0); + } + if (!isTestMode) { logger.debug("Loading VisionSourceManager..."); VisionSourceManager.getInstance() From bad676f67c68e826104eb31d6bee59a487e75069 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 4 Mar 2024 23:27:39 -0500 Subject: [PATCH 2/3] Pipe cscore logs through photonvision (#1260) This means we can see even more logs about mjpeg server status as well --- .../photonvision/common/logging/LogGroup.java | 3 +- .../photonvision/common/logging/Logger.java | 3 +- .../common/logging/PvCSCoreLogger.java | 70 +++++++++++++++++++ .../src/main/java/org/photonvision/Main.java | 3 + 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 photon-core/src/main/java/org/photonvision/common/logging/PvCSCoreLogger.java diff --git a/photon-core/src/main/java/org/photonvision/common/logging/LogGroup.java b/photon-core/src/main/java/org/photonvision/common/logging/LogGroup.java index 50524db63f..0cdd9e92a9 100644 --- a/photon-core/src/main/java/org/photonvision/common/logging/LogGroup.java +++ b/photon-core/src/main/java/org/photonvision/common/logging/LogGroup.java @@ -23,5 +23,6 @@ public enum LogGroup { VisionModule, Data, General, - Config + Config, + CSCore, } diff --git a/photon-core/src/main/java/org/photonvision/common/logging/Logger.java b/photon-core/src/main/java/org/photonvision/common/logging/Logger.java index 0e2ef96ef5..c60911a727 100644 --- a/photon-core/src/main/java/org/photonvision/common/logging/Logger.java +++ b/photon-core/src/main/java/org/photonvision/common/logging/Logger.java @@ -99,6 +99,7 @@ public static String format( levelMap.put(LogGroup.Data, LogLevel.INFO); levelMap.put(LogGroup.VisionModule, LogLevel.INFO); levelMap.put(LogGroup.Config, LogLevel.INFO); + levelMap.put(LogGroup.CSCore, LogLevel.TRACE); } static { @@ -194,7 +195,7 @@ public boolean shouldLog(LogLevel logLevel) { return logLevel.code <= levelMap.get(group).code; } - private void log(String message, LogLevel level) { + void log(String message, LogLevel level) { if (shouldLog(level)) { log(message, level, group, className); } diff --git a/photon-core/src/main/java/org/photonvision/common/logging/PvCSCoreLogger.java b/photon-core/src/main/java/org/photonvision/common/logging/PvCSCoreLogger.java new file mode 100644 index 0000000000..9e01462602 --- /dev/null +++ b/photon-core/src/main/java/org/photonvision/common/logging/PvCSCoreLogger.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) Photon Vision. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.photonvision.common.logging; + +import edu.wpi.first.cscore.CameraServerJNI; +import java.nio.file.Path; + +/** Redirect cscore logs to our logger */ +public class PvCSCoreLogger { + private static PvCSCoreLogger INSTANCE; + + public static PvCSCoreLogger getInstance() { + if (INSTANCE == null) { + INSTANCE = new PvCSCoreLogger(); + } + return INSTANCE; + } + + private Logger logger; + + private PvCSCoreLogger() { + CameraServerJNI.setLogger(this::logMsg, 7); + this.logger = new Logger(getClass(), LogGroup.CSCore); + } + + private void logMsg(int level, String file, int line, String msg) { + if (level == 20) { + logger.info(msg); + return; + } + + file = Path.of(file).getFileName().toString(); + + String levelmsg; + LogLevel pvlevel; + if (level >= 50) { + levelmsg = "CRITICAL"; + pvlevel = LogLevel.ERROR; + } else if (level >= 40) { + levelmsg = "ERROR"; + pvlevel = LogLevel.ERROR; + } else if (level >= 30) { + levelmsg = "WARNING"; + pvlevel = LogLevel.WARN; + } else if (level >= 20) { + levelmsg = "INFO"; + pvlevel = LogLevel.INFO; + } else { + levelmsg = "DEBUG"; + pvlevel = LogLevel.DEBUG; + } + logger.log( + "CS: " + levelmsg + " " + level + ": " + msg + " (" + file + ":" + line + ")", pvlevel); + } +} diff --git a/photon-server/src/main/java/org/photonvision/Main.java b/photon-server/src/main/java/org/photonvision/Main.java index a78c0a79fc..858813659d 100644 --- a/photon-server/src/main/java/org/photonvision/Main.java +++ b/photon-server/src/main/java/org/photonvision/Main.java @@ -35,6 +35,7 @@ import org.photonvision.common.logging.LogGroup; import org.photonvision.common.logging.LogLevel; import org.photonvision.common.logging.Logger; +import org.photonvision.common.logging.PvCSCoreLogger; import org.photonvision.common.networking.NetworkManager; import org.photonvision.common.util.TestUtils; import org.photonvision.common.util.numbers.IntegerCouple; @@ -409,6 +410,8 @@ public static void main(String[] args) { + Platform.getPlatformName() + (Platform.isRaspberryPi() ? (" (Pi " + PiVersion.getPiVersion() + ")") : "")); + PvCSCoreLogger.getInstance(); + logger.debug("Loading ConfigManager..."); ConfigManager.getInstance().load(); // init config manager ConfigManager.getInstance().requestSave(); From 587ac478f4815cf17adf2deaf2104a01375e3785 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 6 Mar 2024 10:51:49 -0500 Subject: [PATCH 3/3] Bump mrcal to include solver fixes (#1265) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d1b9cbf706..116360088b 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ ext { photonGlDriverLibVersion = "dev-v2023.1.0-9-g75fc678" rknnVersion = "dev-v2024.0.0-64-gc0836a6" frcYear = "2024" - mrcalVersion = "dev-v2024.0.0-7-gc976aaa"; + mrcalVersion = "dev-v2024.0.0-18-gb903a09"; pubVersion = versionString