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;
24 boost::filesystem::path build_dir;
30 TEST(
Uptane, RandomSerial) {
31 RecordProperty(
"zephyr_key",
"OTA-989,TST-155");
34 Config conf_1(
"tests/config/basic.toml");
35 conf_1.storage.path = temp_dir1.Path();
36 Config conf_2(
"tests/config/basic.toml");
37 conf_2.storage.path = temp_dir2.Path();
39 conf_1.provision.primary_ecu_serial =
"";
40 conf_2.provision.primary_ecu_serial =
"";
42 UptaneTestCommon::addDefaultSecondary(conf_1, temp_dir1,
"",
"secondary_hardware",
false);
43 UptaneTestCommon::addDefaultSecondary(conf_2, temp_dir2,
"",
"secondary_hardware",
false);
46 auto storage_1 = INvStorage::newStorage(conf_1.storage);
47 auto storage_2 = INvStorage::newStorage(conf_2.storage);
48 auto http1 = std::make_shared<HttpFake>(temp_dir1.Path());
49 auto http2 = std::make_shared<HttpFake>(temp_dir2.Path());
51 auto uptane_client1 = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf_1, storage_1, http1);
52 ASSERT_NO_THROW(uptane_client1->initialize());
54 auto uptane_client2 = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf_2, storage_2, http2);
55 ASSERT_NO_THROW(uptane_client2->initialize());
58 EcuSerials ecu_serials_1;
59 EcuSerials ecu_serials_2;
60 ASSERT_TRUE(storage_1->loadEcuSerials(&ecu_serials_1));
61 ASSERT_TRUE(storage_2->loadEcuSerials(&ecu_serials_2));
62 ASSERT_EQ(ecu_serials_1.size(), 2);
63 ASSERT_EQ(ecu_serials_2.size(), 2);
64 EXPECT_FALSE(ecu_serials_1[0].first.ToString().empty());
65 EXPECT_FALSE(ecu_serials_1[1].first.ToString().empty());
66 EXPECT_FALSE(ecu_serials_2[0].first.ToString().empty());
67 EXPECT_FALSE(ecu_serials_2[1].first.ToString().empty());
68 EXPECT_NE(ecu_serials_1[0].first, ecu_serials_2[0].first);
69 EXPECT_NE(ecu_serials_1[1].first, ecu_serials_2[1].first);
70 EXPECT_NE(ecu_serials_1[0].first, ecu_serials_1[1].first);
71 EXPECT_NE(ecu_serials_2[0].first, ecu_serials_2[1].first);
79 TEST(
Uptane, ReloadSerial) {
80 RecordProperty(
"zephyr_key",
"OTA-989,TST-156");
82 EcuSerials ecu_serials_1;
83 EcuSerials ecu_serials_2;
87 Config conf(
"tests/config/basic.toml");
88 conf.storage.path = temp_dir.Path();
89 conf.provision.primary_ecu_serial =
"";
91 auto storage = INvStorage::newStorage(conf.storage);
92 auto http = std::make_shared<HttpFake>(temp_dir.Path());
94 UptaneTestCommon::addDefaultSecondary(conf, temp_dir,
"",
"secondary_hardware",
false);
95 auto uptane_client = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf, storage, http);
97 ASSERT_NO_THROW(uptane_client->initialize());
98 ASSERT_TRUE(storage->loadEcuSerials(&ecu_serials_1));
99 ASSERT_EQ(ecu_serials_1.size(), 2);
100 EXPECT_FALSE(ecu_serials_1[0].first.ToString().empty());
101 EXPECT_FALSE(ecu_serials_1[1].first.ToString().empty());
107 Config conf(
"tests/config/basic.toml");
108 conf.storage.path = temp_dir.Path();
109 conf.provision.primary_ecu_serial =
"";
111 auto storage = INvStorage::newStorage(conf.storage);
112 auto http = std::make_shared<HttpFake>(temp_dir.Path());
113 UptaneTestCommon::addDefaultSecondary(conf, temp_dir,
"",
"secondary_hardware",
false);
114 auto uptane_client = std_::make_unique<UptaneTestCommon::TestUptaneClient>(conf, storage, http);
116 ASSERT_NO_THROW(uptane_client->initialize());
117 ASSERT_TRUE(storage->loadEcuSerials(&ecu_serials_2));
118 ASSERT_EQ(ecu_serials_2.size(), 2);
119 EXPECT_FALSE(ecu_serials_2[0].first.ToString().empty());
120 EXPECT_FALSE(ecu_serials_2[1].first.ToString().empty());
124 EXPECT_EQ(ecu_serials_1[0].first, ecu_serials_2[0].first);
125 EXPECT_EQ(ecu_serials_1[1].first, ecu_serials_2[1].first);
127 EXPECT_NE(ecu_serials_1[0].first, ecu_serials_1[1].first);
128 EXPECT_NE(ecu_serials_2[0].first, ecu_serials_2[1].first);
132 int main(
int argc,
char** argv) {
133 ::testing::InitGoogleTest(&argc, argv);
134 logger_set_threshold(boost::log::trivial::trace);
137 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the build directory as an input argument.\n";
141 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.