1 #include <gtest/gtest.h> 11 #include "config/config.h" 12 #include "http/httpclient.h" 13 #include "logging/logging.h" 14 #include "primary/sotauptaneclient.h" 15 #include "storage/invstorage.h" 16 #include "utilities/utils.h" 31 std::cout <<
"name: " << e.getName() << std::endl;
32 std::cout <<
"e.what: " << e.what() << std::endl;
33 std::cout <<
"1: " << error[
"director"][
"update"][
"err_msg"].asString() << std::endl;
34 std::cout <<
"2: " << error[
"director"][
"targets"][e.getName()][
"err_msg"].asString() << std::endl;
35 std::cout <<
"3: " << error[
"image_repo"][
"update"][
"err_msg"].asString() << std::endl;
36 std::cout <<
"4: " << error[
"image_repo"][
"targets"][e.getName()][
"err_msg"].asString() << std::endl;
37 if (error[
"director"][
"update"][
"err_msg"].asString() == e.what() ||
38 error[
"director"][
"targets"][e.getName()][
"err_msg"].asString() == e.what() ||
39 error[
"image_repo"][
"update"][
"err_msg"].asString() == e.what() ||
40 error[
"image_repo"][
"targets"][e.getName()][
"err_msg"].asString() == e.what()) {
43 std::cout <<
"aktualizr failed with unmatched exception " <<
typeid(e).name() <<
": " << e.what() <<
"\n";
48 static bool run_test(
const std::string& test_name,
const Json::Value& vector,
const std::string& port) {
49 std::cout <<
"VECTOR: " << vector;
52 config.provision.primary_ecu_serial =
"test_primary_ecu_serial";
53 config.provision.primary_ecu_hardware_id =
"test_primary_hardware_id";
54 config.uptane.director_server =
"http://127.0.0.1:" + port +
"/" + test_name +
"/director";
55 config.uptane.repo_server =
"http://127.0.0.1:" + port +
"/" + test_name +
"/image_repo";
56 config.storage.path = temp_dir.Path();
57 config.storage.uptane_metadata_path =
BasedPath(port +
"/aktualizr_repos");
58 config.pacman.type = PackageManager::kNone;
59 logger_set_threshold(boost::log::trivial::trace);
62 auto storage = INvStorage::newStorage(config.storage);
64 auto uptane_client = SotaUptaneClient::newDefaultClient(config, storage);
67 uptane_client->hw_ids.insert(std::make_pair(ecu_serial, hw_id));
68 uptane_client->installed_images[ecu_serial] =
"test_filename";
69 if (!uptane_client->uptaneIteration()) {
70 throw uptane_client->getLastException();
74 return match_error(vector, e);
75 }
catch (
const std::exception& e) {
76 std::cout <<
"aktualizr failed with unrecognized exception " <<
typeid(e).name() <<
": " << e.what() <<
"\n";
80 if (vector[
"director"][
"update"][
"is_success"].asBool() && vector[
"image_repo"][
"update"][
"is_success"].asBool()) {
81 for (Json::ValueConstIterator it = vector[
"director"][
"targets"].begin();
82 it != vector[
"director"][
"targets"].end(); ++it) {
83 if (!(*it)[
"is_success"].asBool()) {
84 std::cout <<
"aktualizr did not fail as expected.\n";
88 for (Json::ValueConstIterator it = vector[
"image_repo"][
"targets"].begin();
89 it != vector[
"image_repo"][
"targets"].end(); ++it) {
90 if (!(*it)[
"is_success"].asBool()) {
91 std::cout <<
"aktualizr did not fail as expected.\n";
98 std::cout <<
"No exceptions happen, but expects ";
99 if (!vector[
"director"][
"update"][
"is_success"].asBool()) {
100 std::cout <<
"exception from director: '" << vector[
"director"][
"update"][
"err"]
101 <<
" with message: " << vector[
"director"][
"update"][
"err_msg"] <<
"\n";
102 }
else if (!vector[
"image_repo"][
"update"][
"is_success"].asBool()) {
103 std::cout <<
"exception from image_repo: '" << vector[
"image_repo"][
"update"][
"err"]
104 <<
" with message: " << vector[
"image_repo"][
"update"][
"err_msg"] <<
"\n";
112 int main(
int argc,
char* argv[]) {
113 ::testing::InitGoogleTest(&argc, argv);
115 logger_set_threshold(boost::log::trivial::trace);
118 std::cerr <<
"This program is intended to be run from run_vector_tests.sh!\n";
126 const std::string port = argv[1];
127 const std::string address =
"http://127.0.0.1:" + port +
"/";
128 const Json::Value json_vectors = http_client.get(address, HttpInterface::kNoLimit).getJson();
131 for (Json::ValueConstIterator it = json_vectors.begin(); it != json_vectors.end(); it++) {
132 std::cout <<
"Running test vector " << (*it).asString() <<
"\n";
134 HttpResponse response = http_client.post(address + (*it).asString() +
"/step", Json::Value());
135 if (response.http_status_code == 204) {
139 bool pass = Uptane_Vector_Test::run_test((*it).asString(), response.getJson(), port);
140 std::cout <<
"Finished test vector " << (*it).asString() <<
"\n";
143 std::cout <<
"TEST: PASS\n";
146 std::cout <<
"TEST: FAIL\n";
150 std::cout <<
"\n\n\nPASSED TESTS: " << passed <<
"\n";
151 std::cout <<
"FAILED TESTS: " << failed <<
"\n";
Configuration object for an aktualizr instance running on a primary ECU.