Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
OTA-3766: repo generation was moved to build stage. Fixtures were rem…
Browse files Browse the repository at this point in the history
…oved as unnecessary.

Signed-off-by: Chekhovoi, Mykola <ext-mykola.chekhovoi@here.com>
  • Loading branch information
Chekhovoi, Mykola committed Nov 22, 2019
1 parent 00ed305 commit 1c5618b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 94 deletions.
15 changes: 12 additions & 3 deletions src/libaktualizr-c/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ SET(SOURCES api-test.c)

SET(CMAKE_SKIP_RPATH TRUE)

SET(REPO_PATH ${PROJECT_BINARY_DIR}/uptane_repos/c-api-test-repo)

add_custom_target(api-test-resources-generation
COMMAND ${PROJECT_SOURCE_DIR}/tests/uptane_repo_generation/generate_repo.sh
${PROJECT_BINARY_DIR}/src/uptane_generator/uptane-generator
${REPO_PATH}
--add_campaigns)
add_dependencies(api-test-resources-generation uptane-generator)

add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL ${SOURCES})
add_dependencies(build_tests ${TARGET_NAME})
target_link_libraries(${TARGET_NAME} aktualizr-c api-test-utils)
add_dependencies(${TARGET_NAME} api-test-resources-generation)

aktualizr_source_file_checks(${SOURCES})

add_test(NAME t_c_api_test COMMAND ${TARGET_NAME}
${PROJECT_SOURCE_DIR}/tests/fake_http_server/fake_test_server.py
${PROJECT_BINARY_DIR}/c-api-test-repo
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
set_tests_properties(t_c_api_test PROPERTIES FIXTURES_REQUIRED c_api_test)
${REPO_PATH}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
set_tests_properties(t_c_api_test PROPERTIES
ENVIRONMENT LD_PRELOAD=${PROJECT_BINARY_DIR}/src/libaktualizr-c/test/api-test-utils/libapi-test-utils.so:${PROJECT_BINARY_DIR}/src/libaktualizr-c/libaktualizr-c.so)

Expand Down
23 changes: 0 additions & 23 deletions src/libaktualizr-c/test/api-test-utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,3 @@ target_link_libraries(${TARGET_NAME} testutilities)
add_dependencies(build_tests ${TARGET_NAME})

aktualizr_source_file_checks(${SOURCES} ${HEADERS})



add_executable(uptane_generator_utils uptane-generator-utils.cc)
target_include_directories(uptane_generator_utils PUBLIC ${PROJECT_SOURCE_DIR}/tests)
target_link_libraries(uptane_generator_utils
aktualizr_static_lib
testutilities
uptane_generator_lib
${TEST_LIBS})
add_dependencies(build_tests uptane_generator_utils)

aktualizr_source_file_checks(uptane-generator-utils.cc)

add_test(NAME t_uptane_generator_setup COMMAND uptane_generator_utils
${PROJECT_BINARY_DIR}/src/uptane_generator/uptane-generator
${PROJECT_BINARY_DIR}/c-api-test-repo
${PROJECT_SOURCE_DIR}/tests/test_data/firmware.txt)
set_tests_properties(t_uptane_generator_setup PROPERTIES FIXTURES_SETUP c_api_test)

add_test(NAME t_uptane_generator_cleanup COMMAND uptane_generator_utils
${PROJECT_BINARY_DIR}/c-api-test-repo)
set_tests_properties(t_uptane_generator_cleanup PROPERTIES FIXTURES_CLEANUP c_api_test)
14 changes: 11 additions & 3 deletions src/libaktualizr-c/test/api-test-utils/api-test-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "test_utils.h"

std::string serverAddress;
TemporaryDirectory *temp_dir;

FakeHttpServer *Run_fake_http_server(const char *serverPath, const char *metaPath) {
std::string port = TestUtils::getFreePort();
Expand All @@ -22,7 +23,7 @@ void Stop_fake_http_server(FakeHttpServer *server) {
}
}

Config *Get_test_config(const char *storagePath) {
Config *Get_test_config() {
auto *config = new Config();

config->tls.server = serverAddress;
Expand All @@ -32,11 +33,18 @@ Config *Get_test_config(const char *storagePath) {
config->provision.server = serverAddress;
config->provision.provision_path = "tests/test_data/cred.zip";

config->storage.path = storagePath;
temp_dir = new TemporaryDirectory;
config->storage.path = temp_dir->Path();
config->pacman.type = PackageManager::kNone;

config->postUpdateValues();
return config;
}

void Remove_test_config(Config *config) { delete config; }
void Remove_test_config(Config *config) {
if (temp_dir != nullptr && config->storage.path == temp_dir->Path()) {
delete temp_dir;
temp_dir = nullptr;
}
delete config;
}
2 changes: 1 addition & 1 deletion src/libaktualizr-c/test/api-test-utils/api-test-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef struct FakeHttpServer FakeHttpServer;
FakeHttpServer* Run_fake_http_server(const char* serverPath, const char* metaPath);
void Stop_fake_http_server(FakeHttpServer* server);

Config* Get_test_config(const char* storagePath);
Config* Get_test_config();
void Remove_test_config(Config* config);

#ifdef __cplusplus
Expand Down
55 changes: 0 additions & 55 deletions src/libaktualizr-c/test/api-test-utils/uptane-generator-utils.cc

This file was deleted.

2 changes: 1 addition & 1 deletion src/libaktualizr-c/test/api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char **argv) {
const char *metaPath = argv[2];
server = Run_fake_http_server(serverPath, metaPath);

cfg = Get_test_config(/* storagePath = */ metaPath);
cfg = Get_test_config();
a = Aktualizr_create_from_cfg(cfg);
if (!a) {
printf("Aktualizr_create_from_cfg failed\n");
Expand Down
4 changes: 2 additions & 2 deletions tests/uptane_repo_generation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_custom_target(uptane_repo_full_no_correlation_id
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/full_no_correlation_id.sh
${UPTANE_GENERATOR} ${PROJECT_BINARY_DIR}/uptane_repos/full_no_correlation_id)
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generate_repo.sh
${UPTANE_GENERATOR} ${PROJECT_BINARY_DIR}/uptane_repos/full_no_correlation_id --add_default_secondary)
add_dependencies(uptane_repo_full_no_correlation_id uptane-generator)
40 changes: 34 additions & 6 deletions tests/uptane_repo_generation/generate_repo.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
#! /bin/bash
set -eEuo pipefail

if [ "$#" -ne 2 ]; then
echo "Usage: $0 <uptane-generator> <output directory>"
if [ "$#" -eq 0 ]; then
echo "Usage: $0 <uptane-generator> <output directory> [options]"
echo "Options:"
echo " -s|--add_default_secondary"
echo " -c|--add_campaigns"
exit 1
fi

ADD_DEFAULT_SECONDARY=false
ADD_CAMPAIGNS=false

for arg in "$@"
do
case $arg in
-s|--add_default_secondary)
ADD_DEFAULT_SECONDARY=true
;;
-c|--add_campaigns)
ADD_CAMPAIGNS=true
;;
esac
done

UPTANE_GENERATOR="$1"
DEST_DIR="$2"

Expand All @@ -25,12 +43,22 @@ IMAGES=$(mktemp -d)
trap 'rm -rf "$IMAGES"' exit
PRIMARY_FIRMWARE="$IMAGES/primary.txt"
echo "primary" > "$PRIMARY_FIRMWARE"
SECONDARY_FIRMWARE="$IMAGES/secondary.txt"
echo "secondary" > "$SECONDARY_FIRMWARE"

uptane_gen --command generate --expires 2021-07-04T16:33:27Z
uptane_gen --command image --filename "$PRIMARY_FIRMWARE" --targetname primary.txt --hwid primary_hw
uptane_gen --command image --filename "$SECONDARY_FIRMWARE" --targetname secondary.txt --hwid secondary_hw
uptane_gen --command addtarget --hwid primary_hw --serial CA:FE:A6:D2:84:9D --targetname primary.txt
uptane_gen --command addtarget --hwid secondary_hw --serial secondary_ecu_serial --targetname secondary.txt

if [ "$ADD_DEFAULT_SECONDARY" = true ]
then
SECONDARY_FIRMWARE="$IMAGES/secondary.txt"
echo "secondary" > "$SECONDARY_FIRMWARE"
uptane_gen --command image --filename "$SECONDARY_FIRMWARE" --targetname secondary.txt --hwid secondary_hw
uptane_gen --command addtarget --hwid secondary_hw --serial secondary_ecu_serial --targetname secondary.txt
fi

uptane_gen --command signtargets

if [ "$ADD_CAMPAIGNS" = true ]
then
uptane_gen --command addcampaigns
fi

0 comments on commit 1c5618b

Please sign in to comment.