1 #include <gtest/gtest.h> 8 #include <boost/filesystem.hpp> 9 #include <boost/program_options.hpp> 12 #include "logging/logging.h" 13 #include "primary/reportqueue.h" 14 #include "primary/sotauptaneclient.h" 15 #include "storage/invstorage.h" 16 #include "test_utils.h" 17 #include "uptane/tuf.h" 18 #include "uptane/uptanerepository.h" 19 #include "uptane_test_common.h" 20 #include "utilities/utils.h" 22 namespace bpo = boost::program_options;
28 TEST(
Uptane, RandomSerial) {
29 RecordProperty(
"zephyr_key",
"OTA-989,TST-155");
32 Config conf_1(
"tests/config/basic.toml");
33 conf_1.storage.path = temp_dir1.Path();
34 Config conf_2(
"tests/config/basic.toml");
35 conf_2.storage.path = temp_dir2.Path();
37 conf_1.provision.primary_ecu_serial =
"";
38 conf_2.provision.primary_ecu_serial =
"";
40 UptaneTestCommon::addDefaultSecondary(conf_1, temp_dir1,
"",
"secondary_hardware",
false);
41 UptaneTestCommon::addDefaultSecondary(conf_2, temp_dir2,
"",
"secondary_hardware",
false);
44 auto storage_1 = INvStorage::newStorage(conf_1.storage);
45 auto storage_2 = INvStorage::newStorage(conf_2.storage);
46 auto http1 = std::make_shared<HttpFake>(temp_dir1.Path());
47 auto http2 = std::make_shared<HttpFake>(temp_dir2.Path());
49 auto uptane_client1 = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf_1, storage_1, http1);
50 ASSERT_NO_THROW(uptane_client1->initialize());
52 auto uptane_client2 = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf_2, storage_2, http2);
53 ASSERT_NO_THROW(uptane_client2->initialize());
56 EcuSerials ecu_serials_1;
57 EcuSerials ecu_serials_2;
58 ASSERT_TRUE(storage_1->loadEcuSerials(&ecu_serials_1));
59 ASSERT_TRUE(storage_2->loadEcuSerials(&ecu_serials_2));
60 ASSERT_EQ(ecu_serials_1.size(), 2);
61 ASSERT_EQ(ecu_serials_2.size(), 2);
62 EXPECT_FALSE(ecu_serials_1[0].first.ToString().empty());
63 EXPECT_FALSE(ecu_serials_1[1].first.ToString().empty());
64 EXPECT_FALSE(ecu_serials_2[0].first.ToString().empty());
65 EXPECT_FALSE(ecu_serials_2[1].first.ToString().empty());
66 EXPECT_NE(ecu_serials_1[0].first, ecu_serials_2[0].first);
67 EXPECT_NE(ecu_serials_1[1].first, ecu_serials_2[1].first);
68 EXPECT_NE(ecu_serials_1[0].first, ecu_serials_1[1].first);
69 EXPECT_NE(ecu_serials_2[0].first, ecu_serials_2[1].first);
77 TEST(
Uptane, ReloadSerial) {
78 RecordProperty(
"zephyr_key",
"OTA-989,TST-156");
80 EcuSerials ecu_serials_1;
81 EcuSerials ecu_serials_2;
83 Config conf(
"tests/config/basic.toml");
84 conf.storage.path = temp_dir.Path();
85 conf.provision.primary_ecu_serial =
"";
86 UptaneTestCommon::addDefaultSecondary(conf, temp_dir,
"",
"secondary_hardware",
false);
90 auto storage = INvStorage::newStorage(conf.storage);
91 auto http = std::make_shared<HttpFake>(temp_dir.Path());
92 auto uptane_client = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf, storage, http);
94 ASSERT_NO_THROW(uptane_client->initialize());
95 ASSERT_TRUE(storage->loadEcuSerials(&ecu_serials_1));
96 ASSERT_EQ(ecu_serials_1.size(), 2);
97 EXPECT_FALSE(ecu_serials_1[0].first.ToString().empty());
98 EXPECT_FALSE(ecu_serials_1[1].first.ToString().empty());
104 auto storage = INvStorage::newStorage(conf.storage);
105 auto http = std::make_shared<HttpFake>(temp_dir.Path());
106 auto uptane_client = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf, storage, http);
108 ASSERT_NO_THROW(uptane_client->initialize());
109 ASSERT_TRUE(storage->loadEcuSerials(&ecu_serials_2));
110 ASSERT_EQ(ecu_serials_2.size(), 2);
111 EXPECT_FALSE(ecu_serials_2[0].first.ToString().empty());
112 EXPECT_FALSE(ecu_serials_2[1].first.ToString().empty());
116 EXPECT_EQ(ecu_serials_1[0].first, ecu_serials_2[0].first);
117 EXPECT_EQ(ecu_serials_1[1].first, ecu_serials_2[1].first);
119 EXPECT_NE(ecu_serials_1[0].first, ecu_serials_1[1].first);
120 EXPECT_NE(ecu_serials_2[0].first, ecu_serials_2[1].first);
124 int main(
int argc,
char** argv) {
125 ::testing::InitGoogleTest(&argc, argv);
126 logger_set_threshold(boost::log::trivial::trace);
128 return RUN_ALL_TESTS();
Configuration object for an aktualizr instance running on a Primary ECU.
Base data types that are used in The Update Framework (TUF), part of Uptane.