1 #include <gtest/gtest.h>
8 #include "config/config.h"
9 #include "logging/logging.h"
10 #include "primary/aktualizr.h"
11 #include "storage/sqlstorage.h"
13 int updateOneCycle(
const boost::filesystem::path &storage_dir,
const std::string &server) {
15 conf.pacman.type = PACKAGE_MANAGER_NONE;
16 conf.pacman.fake_need_reboot =
true;
17 conf.provision.device_id =
"device_id";
18 conf.provision.ecu_registration_endpoint = server +
"/director/ecus";
19 conf.tls.server = server;
20 conf.uptane.director_server = server +
"/director";
21 conf.uptane.repo_server = server +
"/repo";
22 conf.uptane.key_type = KeyType::kED25519;
23 conf.provision.server = server;
24 conf.provision.provision_path =
"tests/test_data/cred.zip";
25 conf.provision.primary_ecu_serial =
"CA:FE:A6:D2:84:9D";
26 conf.provision.primary_ecu_hardware_id =
"primary_hw";
27 conf.storage.path = storage_dir;
28 conf.bootloader.reboot_sentinel_dir = storage_dir;
29 conf.postUpdateValues();
30 logger_set_threshold(boost::log::trivial::debug);
35 aktualizr.Initialize();
38 if (update_result.status != result::UpdateStatus::kUpdatesAvailable) {
39 LOG_ERROR <<
"no update available";
43 result::Download download_result = aktualizr.Download(update_result.updates).get();
44 if (download_result.status != result::DownloadStatus::kSuccess) {
45 LOG_ERROR <<
"download failed";
49 result::Install install_result = aktualizr.Install(update_result.updates).get();
50 if (install_result.ecu_reports.size() != 1) {
51 LOG_ERROR <<
"install failed";
54 if (install_result.ecu_reports[0].install_res.result_code.num_code != data::ResultCode::Numeric::kNeedCompletion) {
60 boost::filesystem::remove(conf.bootloader.reboot_sentinel_dir / conf.bootloader.reboot_sentinel_name);
65 aktualizr.Initialize();
68 if (update_result.status != result::UpdateStatus::kNoUpdatesAvailable) {
69 LOG_ERROR <<
"finalize failed";
77 int main(
int argc,
char **argv) {
81 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the storage directory "
82 <<
"and url of uptane server\n";
85 boost::filesystem::path storage_dir = argv[1];
86 std::string server = argv[2];
88 return updateOneCycle(storage_dir, server);