Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/testflinger-assets/test_binary_device_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ set -e
sudo kill ${JOURNAL_PID} || true

# Exit with the test's exit status
exit $TEST_EXIT_STATUS
exit "$TEST_EXIT_STATUS"
23 changes: 18 additions & 5 deletions .github/testflinger-assets/test_snap_device_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ while sudo snap debug state /var/lib/snapd/state.json | grep -qE 'Doing|Undoing|
sleep 10
done
sudo snap connect fpgad:device-tree-overlays
echo " --- connecting to dfx-mgr-socket interface"
while sudo snap debug state /var/lib/snapd/state.json | grep -qE 'Doing|Undoing|Waiting'; do
echo " --- snapd internal tasks still running... waiting..."
sleep 10
done
sudo snap connect fpgad:dfx-mgr-socket
echo " --- connecting dbus interfaces"
while sudo snap debug state /var/lib/snapd/state.json | grep -qE 'Doing|Undoing|Waiting'; do
echo " --- snapd internal tasks still running... waiting..."
Expand All @@ -60,11 +66,18 @@ sudo snap connect fpgad:cli-dbus fpgad:daemon-dbus
echo "INFO: Done making necessary connections"

echo "INFO: Running snap test script"
# NOTE: tarball contains "k24-starter-kits/..." and "k26-starter-kits/..." at tarball root from daemon/tests/test_data
# NOTE: test_data.gz contains "k24-starter-kits/..." and "k26-starter-kits/..." at tarball root from daemon/tests/test_data
# NOTE: tests.gz contains the test structure (common/, test_universal/, test_xlnx/, test_default/, etc.)
mkdir -p fpgad/artifacts
echo " --- Extracting test data"
tar -xzvf test_data.gz -C fpgad
sudo journalctl -f -n1 > fpgad/artifacts/journal.log 2>&1 &
JOURNAL_PID=$!
sudo python3 -u -m unittest ./snap_tests.py -v 2>&1 | tee fpgad/artifacts/snap_test.log
sudo kill ${JOURNAL_PID} || true
echo " --- Extracting tests"
mkdir -p tests
tar -xzvf tests.gz -C tests
echo " --- Saving timestamp for journal log retrieval"
TEST_START_TIME=$(date '+%Y-%m-%d %H:%M:%S')
echo " --- Running tests with unittest discovery"
sudo tests/snap_testing/test_snap.sh 2>&1 | tee fpgad/artifacts/snap_test.log
echo " --- Collecting journal logs since test start"
sudo journalctl --since "$TEST_START_TIME" -u "snap.fpgad*" > fpgad/artifacts/journal.log 2>&1 || true
echo "INFO: Done running snap test script"
6 changes: 5 additions & 1 deletion .github/workflows/integration_tests.yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ jobs:
tar -czvf test_data.gz -C daemon/tests/test_data/ .
echo "::endgroup::"

echo "::group::Create tests tarball"
tar -czvf tests.gz -C tests/ .
echo "::endgroup::"

echo "::group::creating job.yaml"
yq '.test_data.attachments = [
{ "agent": "device_script.sh", "local": "'"$(pwd)"'/.github/testflinger-assets/test_snap_device_script.sh" },
{ "agent": "fpgad.snap", "local": "'"$(pwd)"'/fpgad.snap" },
{ "agent": "test_data.gz", "local": "'"$(pwd)"'/test_data.gz" },
{ "agent": "snap_tests.py", "local": "'"$(pwd)"'/tests/snap_tests.py" }
{ "agent": "tests.gz", "local": "'"$(pwd)"'/tests.gz" }
]' .github/testflinger-assets/testflinger_job.yaml | tee job.yaml
echo "::endgroup::"

Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["daemon", "cli", "fpgad_macros"]

[workspace.package]
version = "0.2.0"
version = "0.2.1"
edition = "2024"
license = "GPL-3.0"
homepage = "https://github.com/canonical/fpgad"
Expand Down
43 changes: 33 additions & 10 deletions cli/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async fn call_apply_overlay(
///
/// # Arguments
///
/// * `platform_override` - Optional platform string to bypass platform detection
/// * `dev_handle` - Optional [device handle](../index.html#device-handles) (e.g., "fpga0")
/// * `file_path` - Path to the overlay file (.dtbo)
/// * `overlay_handle` - Optional [overlay handle](../index.html#overlay-handles) for the overlay directory
Expand All @@ -133,28 +134,40 @@ async fn call_apply_overlay(
/// * `Err(zbus::Error)` - DBus communication error, device detection failure, or FpgadError.
/// See [Error Handling](../index.html#error-handling) for details.
async fn apply_overlay(
platform_override: &Option<String>,
dev_handle: &Option<String>,
file_path: &str,
overlay_handle: &Option<String>,
) -> Result<String, zbus::Error> {
// Determine platform and overlay handle based on provided parameters
let (platform, overlay_handle_to_use) = match (dev_handle, overlay_handle) {
// Both are provided
(Some(dev), Some(overlay)) => (call_get_platform_type(dev).await?, overlay.clone()),
let (platform, overlay_handle_to_use) = match (platform_override, dev_handle, overlay_handle) {
// Platform override provided - use it regardless of other params
(Some(plat), _, Some(overlay)) => (plat.clone(), overlay.clone()),
(Some(plat), Some(dev), None) => (plat.clone(), dev.clone()),
(Some(plat), None, None) => {
let overlay = get_first_device_handle()
.await
.unwrap_or("overlay0".to_string());
(plat.clone(), overlay)
}

// No platform override - use detection logic
// Both device and overlay are provided
(None, Some(dev), Some(overlay)) => (call_get_platform_type(dev).await?, overlay.clone()),

// dev_handle provided, overlay_handle not provided so use device name as overlay handle
(Some(dev), None) => {
(None, Some(dev), None) => {
let platform = call_get_platform_type(dev).await?;
(platform, dev.clone())
}
// dev_handle not provided, so use first platform
(None, Some(overlay)) => {
(None, None, Some(overlay)) => {
let platform = get_first_platform().await?;
(platform, overlay.clone())
}
// neither provided so get first device to and use its platform as platform and its name as
// overlay_handle
(None, None) => {
(None, None, None) => {
// this saves making two dbus calls by getting it all from the hashmap
let platforms = call_get_platform_types().await?;
let platform = platforms
Expand Down Expand Up @@ -186,6 +199,7 @@ async fn apply_overlay(
///
/// # Arguments
///
/// * `platform_override` - Optional platform string to bypass platform detection
/// * `device_handle` - Optional [device handle](../index.html#device-handles) (e.g., "fpga0")
/// * `file_path` - Path to the bitstream file
///
Expand All @@ -194,14 +208,19 @@ async fn apply_overlay(
/// * `Err(zbus::Error)` - DBus communication error, device detection failure, or FpgadError.
/// See [Error Handling](../index.html#error-handling) for details.
async fn load_bitstream(
platform_override: &Option<String>,
device_handle: &Option<String>,
file_path: &str,
) -> Result<String, zbus::Error> {
let dev = match device_handle {
None => get_first_device_handle().await?,
Some(dev) => dev.clone(),
};
call_load_bitstream("", &dev, &sanitize_path_str(file_path)?, "").await
let platform_str = match platform_override {
None => "",
Some(plat) => plat.as_str(),
};
call_load_bitstream(platform_str, &dev, &sanitize_path_str(file_path)?, "").await
}

/// Main handler for the load command.
Expand All @@ -212,6 +231,7 @@ async fn load_bitstream(
///
/// # Arguments
///
/// * `platform_override` - Optional platform string to bypass platform detection
/// * `dev_handle` - Optional [device handle](../index.html#device-handles)
/// * `sub_command` - The load subcommand specifying what to load (overlay or bitstream)
///
Expand All @@ -220,13 +240,16 @@ async fn load_bitstream(
/// * `Err(zbus::Error)` - DBus communication error, operation failure, or FpgadError.
/// See [Error Handling](../index.html#error-handling) for details.
pub async fn load_handler(
platform_override: &Option<String>,
dev_handle: &Option<String>,
sub_command: &LoadSubcommand,
) -> Result<String, zbus::Error> {
match sub_command {
LoadSubcommand::Overlay { file, handle } => {
apply_overlay(dev_handle, file.as_ref(), handle).await
LoadSubcommand::Overlay { file, name } => {
apply_overlay(platform_override, dev_handle, file.as_ref(), name).await
}
LoadSubcommand::Bitstream { file } => {
load_bitstream(platform_override, dev_handle, file.as_ref()).await
}
LoadSubcommand::Bitstream { file } => load_bitstream(dev_handle, file.as_ref()).await,
}
}
Loading
Loading