From 85a6d759fd7cf2be9ba6bb55bf53d6aaccf7d185 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Tue, 18 Feb 2025 12:08:20 -0600 Subject: [PATCH] Slightly clean up tests, add new amd64 autopkgtest which checks a livefs. --- debian/changelog | 6 ++ debian/tests/control | 4 +- snapd-seed-glue/tests/CMakeLists.txt | 2 +- snapd-seed-glue/tests/cli-tests.cpp | 93 +++++++++++++++++++--------- 4 files changed, 74 insertions(+), 31 deletions(-) diff --git a/debian/changelog b/debian/changelog index f8107a3..1afc121 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +snapd-extra-utils (1.1.0) UNRELEASED; urgency=medium + + * Slightly clean up tests, add new amd64 autopkgtest which checks a livefs. + + -- Simon Quigley Sun, 16 Feb 2025 13:36:41 -0600 + snapd-extra-utils (1.0.7) plucky; urgency=medium * Add several extra Breaks/Replaces to be safe. diff --git a/debian/tests/control b/debian/tests/control index 3cdeb1f..847801f 100644 --- a/debian/tests/control +++ b/debian/tests/control @@ -1,3 +1,3 @@ Test-Command: snapd-seed-glue/tests/snapd_seed_glue_test -Depends: snapd-seed-glue, tree -Restrictions: needs-internet, build-needed +Depends: snapd-seed-glue, tree, livecd-rootfs [amd64] +Restrictions: needs-internet, build-needed, isolation-machine, needs-sudo diff --git a/snapd-seed-glue/tests/CMakeLists.txt b/snapd-seed-glue/tests/CMakeLists.txt index 99b42e1..0269440 100644 --- a/snapd-seed-glue/tests/CMakeLists.txt +++ b/snapd-seed-glue/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(snapd_seed_glue_test) set(CMAKE_CXX_STANDARD 23) diff --git a/snapd-seed-glue/tests/cli-tests.cpp b/snapd-seed-glue/tests/cli-tests.cpp index 7e1b668..c1e6406 100644 --- a/snapd-seed-glue/tests/cli-tests.cpp +++ b/snapd-seed-glue/tests/cli-tests.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Simon Quigley +// Copyright (C) 2024-2025 Simon Quigley // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -10,14 +10,21 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include #include +#include #include +#include + +#if defined(__x86_64__) || defined(__amd64__) +#include +#include +#endif std::string OUTPUT_FILE_CONTENTS; @@ -39,28 +46,33 @@ std::pair execute_command(const std::string& cmd) { } void confirm_success() { - if (OUTPUT_FILE_CONTENTS.find("Cleanup and validation completed") != std::string::npos) { - // Success, clear OUTPUT_FILE_CONTENTS - OUTPUT_FILE_CONTENTS.clear(); - } else { - exit(1); - } + if (OUTPUT_FILE_CONTENTS.find("Cleanup and validation completed") != std::string::npos) OUTPUT_FILE_CONTENTS.clear(); + else exit(1); } -void run_snapd_seed_glue(const std::vector& args) { - std::string cmd = "snapd-seed-glue/snapd-seed-glue --verbose --seed hello_test"; - for (const auto& arg : args) { - cmd += " " + arg; - } +void run_snapd_seed_glue(const std::vector& args, const std::string& dir = "") { + std::string cmd; + if (!dir.empty()) cmd = std::format("snapd-seed-glue/snapd-seed-glue --verbose --seed {}", dir); + else cmd = "snapd-seed-glue/snapd-seed-glue --verbose --seed hello_test"; + for (const auto& arg : args) cmd += " " + arg; + auto [output, exit_code] = execute_command(cmd); - // Append output to OUTPUT_FILE_CONTENTS OUTPUT_FILE_CONTENTS += output; - if (exit_code != 0) { - exit(1); - } + if (exit_code != 0) exit(exit_code); confirm_success(); } +#if defined(__x86_64__) || defined(__amd64__) +std::string get_version_codename() { + std::ifstream file("/etc/os-release"); + if (!file.is_open()) return {}; + std::string line; + constexpr std::string_view key = "VERSION_CODENAME="; + while (std::getline(file, line)) if (line.starts_with(key)) return line.substr(key.size()); + return ""; +} +#endif + int main() { std::cout << "[snapd-seed-glue autopkgtest] Testing snapd-seed-glue with hello...\n"; run_snapd_seed_glue({"hello"}); @@ -76,13 +88,38 @@ int main() { std::string cmd = "/usr/bin/snapd-seed-glue --verbose --seed test_dir " + invalid_snap; auto [output, exit_code] = execute_command(cmd); OUTPUT_FILE_CONTENTS += output; - if (exit_code != 0) { - std::cout << "Fail expected\n"; - } - if (OUTPUT_FILE_CONTENTS.find("cannot install snap \"" + invalid_snap + "\": snap not found") != std::string::npos) { - // Expected error message found - } else { - exit(1); + if (exit_code != 0) std::cout << "Fail expected\n"; + if (OUTPUT_FILE_CONTENTS.find("cannot install snap \"" + invalid_snap + "\": snap not found") == std::string::npos) exit(1); + +#if defined(__x86_64__) || defined(__amd64__) + std::cout << "[snapd-seed-glue autopkgtest] Confirm that a livefs can be created, and snapd-seed-glue can be used...\n"; + // Logic taken from lp:launchpad-buildd/lpbuildd/target/build_livefs.py + setenv("PROJECT", "lubuntu", 1); + setenv("ARCH", "amd64", 1); + setenv("SUITE", get_version_codename().c_str(), 1); + + if (!std::filesystem::create_directory("auto")) exit(1); + for (std::string lb_script : {"config", "build", "clean"}) { + auto [link_output, link_exit_code] = execute_command(std::format("ln -s /usr/share/livecd-rootfs/live-build/auto/{} auto/", lb_script)); + if (link_exit_code != 0) exit(link_exit_code); } + auto [clean_output, clean_exit_code] = execute_command("sudo -E lb clean --purge"); + if (clean_exit_code != 0) exit(clean_exit_code); + auto [config_output, config_exit_code] = execute_command("lb config"); + if (config_exit_code != 0) exit(config_exit_code); + auto [build_output, build_exit_code] = execute_command("sudo -E lb build"); + if (build_exit_code != 0) exit(build_exit_code); + auto [unsquashfs_output, unsquashfs_exit_code] = execute_command("sudo unsquashfs livecd.lubuntu.minimal.standard.squashfs /var/lib/snapd/seed/"); + if (unsquashfs_exit_code != 0) exit(unsquashfs_exit_code); + auto [clean2_output, clean2_exit_code] = execute_command("sudo -E lb clean --purge"); + if (clean2_exit_code != 0) exit(clean2_exit_code); + auto [chown_output, chown_exit_code] = execute_command(std::format("sudo chown -R {}:{} squashfs-root/", getuid(), getgid())); + if (chown_exit_code != 0) exit(chown_exit_code); + + std::cout << "[snapd-seed-glue autopkgtest] A livefs can be created. Confirm snapd-seed-glue can be used...\n"; + run_snapd_seed_glue({"firefox", "firmware-updater"}, "squashfs-root/var/lib/snapd/seed/"); + run_snapd_seed_glue({"firefox", "firmware-updater", "krita", "thunderbird"}, "squashfs-root/var/lib/snapd/seed/"); +#endif + return 0; }