Ticket refs #5379: icwmp: backupsession, session, events, download unit tests

This commit is contained in:
Omar Kallel 2021-07-05 10:53:41 +01:00
parent 153f265761
commit 40b08ae2f1
9 changed files with 534 additions and 5 deletions

View file

@ -46,9 +46,15 @@ startretries=0
priority=8
command=/bin/bash -c "/usr/sbin/genieacs-ui --ui-jwt-secret secret"
[program:icwmpd]
[program:lighttpd]
autorestart=false
startretries=0
priority=9
command=service lighttpd restart
[program:icwmpd]
autorestart=false
startretries=0
priority=10
command=/bin/bash -c "/usr/bin/valgrind --xml=yes --xml-file=/builds/iopsys/icwmp/memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 --track-origins=yes /builds/iopsys/icwmp/bin/icwmpd"

View file

@ -57,6 +57,7 @@ function configure_genieacs()
echo "upload firmware image to genieacs server"
exec_cmd dd if=/dev/zero of=/builds/iopsys/icwmp/firmware_v1.0.bin bs=25MB count=1
echo "Valid" > /builds/iopsys/icwmp/firmware_v1.0.bin
curl -X PUT 'http://localhost:7557/files/firmware_v1.0.bin' --data-binary '@/builds/iopsys/icwmp/firmware_v1.0.bin' --header "fileType: 1 Firmware Upgrade Image" --header "oui: XXX" --header "productClass: FirstClass" --header "version: 000000001" >/dev/null 2>&1
check_ret $?
}

View file

@ -7,6 +7,16 @@ source ./gitlab-ci/shared.sh
trap cleanup EXIT
trap cleanup SIGINT
echo "Install lighttpd"
apt-get update
apt-get install -y lighttpd
exec_cmd dd if=/dev/zero of=/builds/iopsys/icwmp/firmware_v1.0.bin bs=25MB count=1
echo "Valid" > /builds/iopsys/icwmp/firmware_v1.0.bin
exec_cmd cp /builds/iopsys/icwmp/firmware_v1.0.bin /var/www/html
exec_cmd dd if=/dev/zero of=/builds/iopsys/icwmp/invalid_firmware_v1.0.bin bs=25MB count=1
echo "Invalid" > /builds/iopsys/icwmp/invalid_firmware_v1.0.bin
exec_cmd cp /builds/iopsys/icwmp/invalid_firmware_v1.0.bin /var/www/html
echo "Starting dependent services"
supervisorctl status all
supervisorctl update

View file

@ -32,4 +32,5 @@ int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session, struct
void *thread_cwmp_rpc_cpe_download(void *v);
void *thread_cwmp_rpc_cpe_schedule_download(void *v);
void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v);
int cwmp_launch_download(struct download *pdownload, enum load_type ltype, struct transfer_complete **ptransfer_complete);
#endif

View file

@ -6,11 +6,9 @@ CFLAGS = -g -Wall -I./inc
LDFLAGS = -lmicroxml -luci -lblobmsg_json -lubox -ljson-c -lubus -lpthread -lcurl -lssl -lcrypto
LIBCFLAGS = -g -Wall -fPIC -c -I../../inc
LIBOBJ = libobj
UNIT_TESTS = icwmp_datamodel_interface_unit_testd icwmp_soap_msg_unit_testd
UNIT_TESTS = icwmp_datamodel_interface_unit_testd icwmp_soap_msg_unit_testd icwmp_backup_session_unit_testd icwmp_download_unit_testd
VALGRIND = valgrind --xml=yes --xml-file=/builds/iopsys/icwmp/memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all
libobj:
$(CC) $(LIBCFLAGS) ../../download.c ../../upload.c ../../log.c ../../md5.c ../../digestauth.c ../../netlink.c ../../cwmp_cli.c ../../cwmp_du_state.c ../../sched_inform.c \
../../diagnostic.c ../../reboot.c ../../notifications.c ../../cwmp_zlib.c ../../datamodel_interface.c ../../http.c ../../backupSession.c \
@ -38,6 +36,12 @@ icwmp_datamodel_interface_unit_testd: icwmp_datamodel_interface_unit_test.o
icwmp_soap_msg_unit_testd: icwmp_soap_msg_unit_test.o
$(CC) -o $@ $^ -lcmocka -licwmp $(LDFLAGS) $(CFLAGS)
icwmp_backup_session_unit_testd: icwmp_backup_session_unit_test.o
$(CC) -o $@ $^ -lcmocka -licwmp $(LDFLAGS) $(CFLAGS)
icwmp_download_unit_testd: icwmp_download_unit_test.o
$(CC) -o $@ $^ -lcmocka -licwmp $(LDFLAGS) $(CFLAGS)
unit-test: $(UNIT_TESTS)
$(foreach testprog, $(UNIT_TESTS), sudo $(VALGRIND) ./$(testprog);)

View file

@ -0,0 +1,305 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <dirent.h>
#include <libicwmp/common.h>
#include <libicwmp/backupSession.h>
#include <libicwmp/xml.h>
#include <libicwmp/config.h>
#include <libicwmp/cwmp_time.h>
#include <libicwmp/event.h>
struct cwmp cwmp_main_test = { 0 };
static int bkp_session_unit_tests_clean(void **state)
{
icwmp_cleanmem();
return 0;
}
static void cwmp_backup_session_unit_test(void **state)
{
remove(CWMP_BKP_FILE);
struct cwmp *cwmp_test = &cwmp_main_test;
mxml_node_t *backup_tree = NULL, *n = NULL;
/*
* Init backup session
*/
int error = cwmp_init_backup_session(cwmp_test, NULL, ALL);
assert_int_equal(error, 0);
bkp_session_save();
FILE *pFile;
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(backup_tree);
assert_string_equal(backup_tree->value.element.name, "cwmp");
assert_null(backup_tree->child);
MXML_DELETE(backup_tree);
/*
* Insert Event
*/
mxml_node_t *bkp_event1 = NULL, *bkp_event2 = NULL, *queue_tree1 = NULL, *queue_tree2 = NULL;
// Case of one event
bkp_event1 = bkp_session_insert_event(EVENT_IDX_4VALUE_CHANGE, "4 VALUE CHANGE", 0, "queue");
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(bkp_event1);
queue_tree1 = mxmlFindElement(backup_tree, backup_tree, "queue_event", NULL, NULL, MXML_DESCEND);
assert_non_null(queue_tree1);
n = mxmlFindElement(queue_tree1, queue_tree1, "index", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), EVENT_IDX_4VALUE_CHANGE);
n = mxmlFindElement(queue_tree1, queue_tree1, "id", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), 0);
n = mxmlFindElement(queue_tree1, queue_tree1, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "4 VALUE CHANGE");
MXML_DELETE(bkp_event1);
bkp_session_save();
MXML_DELETE(backup_tree);
//case of two events with different ids under the same queue
bkp_event1 = bkp_session_insert_event(EVENT_IDX_1BOOT, "1 BOOT", 0, "queue");
bkp_event2 = bkp_session_insert_event(EVENT_IDX_4VALUE_CHANGE, "4 VALUE CHANGE", 1, "queue");
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(bkp_event1);
assert_non_null(bkp_event2);
queue_tree1 = mxmlFindElement(backup_tree, backup_tree, "queue_event", NULL, NULL, MXML_DESCEND);
queue_tree2 = mxmlFindElement(queue_tree1, backup_tree, "queue_event", NULL, NULL, MXML_DESCEND);
assert_non_null(queue_tree1);
n = mxmlFindElement(queue_tree1, queue_tree1, "index", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), EVENT_IDX_1BOOT);
n = mxmlFindElement(queue_tree1, queue_tree1, "id", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), 0);
n = mxmlFindElement(queue_tree1, queue_tree1, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "1 BOOT");
assert_non_null(queue_tree2);
n = mxmlFindElement(queue_tree2, queue_tree2, "index", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), EVENT_IDX_4VALUE_CHANGE);
n = mxmlFindElement(queue_tree2, queue_tree2, "id", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), 1);
n = mxmlFindElement(queue_tree2, queue_tree2, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "4 VALUE CHANGE");
MXML_DELETE(bkp_event1);
MXML_DELETE(bkp_event2);
bkp_session_save();
MXML_DELETE(backup_tree);
bkp_event1 = NULL;
bkp_event2 = NULL;
//case of two events with same id under the same queue
#if 0
bkp_event1 = bkp_session_insert_event(EVENT_IDX_1BOOT, "1 BOOT", 0, "queue");
bkp_event2 = bkp_session_insert_event(EVENT_IDX_4VALUE_CHANGE, "4 VALUE CHANGE", 0, "queue");
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(bkp_event1);
assert_non_null(bkp_event2);
queue_tree1 = mxmlFindElement(backup_tree, backup_tree, "queue_event", NULL, NULL, MXML_DESCEND);
queue_tree2 = mxmlFindElement(queue_tree1, backup_tree, "queue_event", NULL, NULL, MXML_DESCEND);
n = mxmlFindElement(queue_tree1, queue_tree1, "index", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), EVENT_IDX_1BOOT);
n = mxmlFindElement(queue_tree1, queue_tree1, "id", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), 0);
n = mxmlFindElement(queue_tree1, queue_tree1, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "1 BOOT");
assert_null(queue_tree2);
MXML_DELETE(bkp_event1);
MXML_DELETE(bkp_event2);
bkp_session_save();
MXML_DELETE(backup_tree);
#endif
//case of two events with same id under different queues
bkp_event1 = bkp_session_insert_event(EVENT_IDX_1BOOT, "1 BOOT", 0, "queue1");
bkp_event2 = bkp_session_insert_event(EVENT_IDX_4VALUE_CHANGE, "4 VALUE CHANGE", 0, "queue2");
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(bkp_event1);
assert_non_null(bkp_event2);
queue_tree1 = mxmlFindElement(backup_tree, backup_tree, "queue1_event", NULL, NULL, MXML_DESCEND);
queue_tree2 = mxmlFindElement(queue_tree1, backup_tree, "queue2_event", NULL, NULL, MXML_DESCEND);
assert_non_null(queue_tree1);
n = mxmlFindElement(queue_tree1, queue_tree1, "index", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), EVENT_IDX_1BOOT);
n = mxmlFindElement(queue_tree1, queue_tree1, "id", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), 0);
n = mxmlFindElement(queue_tree1, queue_tree1, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "1 BOOT");
assert_non_null(queue_tree2);
n = mxmlFindElement(queue_tree2, queue_tree2, "index", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), EVENT_IDX_4VALUE_CHANGE);
n = mxmlFindElement(queue_tree2, queue_tree2, "id", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), 0);
n = mxmlFindElement(queue_tree2, queue_tree2, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "4 VALUE CHANGE");
MXML_DELETE(bkp_event1);
MXML_DELETE(bkp_event2);
bkp_session_save();
MXML_DELETE(backup_tree);
/*
* Insert Download
*/
struct download *download = NULL;
download = icwmp_calloc(1, sizeof(struct download));
download->command_key = icwmp_strdup("download_key");
download->file_size = 0;
download->file_type = icwmp_strdup("1 Firmware Upgrade Image");
download->password = icwmp_strdup("iopsys");
download->username = icwmp_strdup("iopsys");
download->url = icwmp_strdup("http://192.168.1.160:8080/openacs/acs");
bkp_session_insert_download(download);
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
mxml_node_t *download_tree = NULL;
download_tree = mxmlFindElement(backup_tree, backup_tree, "download", NULL, NULL, MXML_DESCEND);
assert_non_null(download_tree);
n = mxmlFindElement(download_tree, download_tree, "url", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "http://192.168.1.160:8080/openacs/acs");
n = mxmlFindElement(download_tree, download_tree, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "download_key");
n = mxmlFindElement(download_tree, download_tree, "file_type", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "1 Firmware Upgrade Image");
n = mxmlFindElement(download_tree, download_tree, "username", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "iopsys");
n = mxmlFindElement(download_tree, download_tree, "password", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "iopsys");
n = mxmlFindElement(download_tree, download_tree, "file_size", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "0");
n = mxmlFindElement(download_tree, download_tree, "time", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
MXML_DELETE(backup_tree);
/*
* Delete download
*/
bkp_session_delete_download(download);
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(backup_tree);
assert_string_equal(backup_tree->value.element.name, "cwmp");
assert_null(backup_tree->child);
MXML_DELETE(backup_tree);
/*
* Insert TransferComplete bkp_session_delete_transfer_complete
*/
struct transfer_complete *p;
p = icwmp_calloc(1, sizeof(struct transfer_complete));
p->command_key = icwmp_strdup("transfer_complete_key");
p->start_time = icwmp_strdup(mix_get_time());
p->complete_time = icwmp_strdup(mix_get_time());
p->old_software_version = icwmp_strdup("iopsys_img_old");
p->type = TYPE_DOWNLOAD;
p->fault_code = FAULT_CPE_NO_FAULT;
bkp_session_insert_transfer_complete(p);
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
mxml_node_t *transfer_complete_tree = NULL;
transfer_complete_tree = mxmlFindElement(backup_tree, backup_tree, "transfer_complete", NULL, NULL, MXML_DESCEND);
assert_non_null(transfer_complete_tree);
n = mxmlFindElement(transfer_complete_tree, transfer_complete_tree, "command_key", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "transfer_complete_key");
n = mxmlFindElement(transfer_complete_tree, transfer_complete_tree, "start_time", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
n = mxmlFindElement(transfer_complete_tree, transfer_complete_tree, "complete_time", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
n = mxmlFindElement(transfer_complete_tree, transfer_complete_tree, "old_software_version", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_string_equal(n->child->value.opaque, "iopsys_img_old");
n = mxmlFindElement(transfer_complete_tree, transfer_complete_tree, "fault_code", NULL, NULL, MXML_DESCEND);
assert_non_null(n);
assert_int_equal(atoi(n->child->value.opaque), FAULT_CPE_NO_FAULT);
MXML_DELETE(backup_tree);
/*
* Delete TransferComplete
*/
bkp_session_delete_transfer_complete(p);
bkp_session_save();
pFile = fopen(CWMP_BKP_FILE, "r");
backup_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);
assert_non_null(backup_tree);
assert_string_equal(backup_tree->value.element.name, "cwmp");
assert_null(backup_tree->child);
MXML_DELETE(backup_tree);
bkp_tree_clean();
}
int main(void)
{
const struct CMUnitTest tests[] = { //
cmocka_unit_test(cwmp_backup_session_unit_test),
};
return cmocka_run_group_tests(tests, NULL, bkp_session_unit_tests_clean);
}

View file

@ -0,0 +1,193 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <dirent.h>
#include <unistd.h>
#include <libicwmp/xml.h>
#include <libicwmp/event.h>
#include <libicwmp/session.h>
#include <libicwmp/config.h>
#include <libicwmp/backupSession.h>
#include <libicwmp/log.h>
#include <libicwmp/download.h>
struct transfer_complete *transfer_complete_test = NULL;
void free_transfer_complete(struct transfer_complete *p)
{
FREE(p->command_key);
FREE(p->start_time);
FREE(p->complete_time);
FREE(p->old_software_version);
FREE(p);
}
void free_download(struct download *p)
{
if (p==NULL)
return;
icwmp_free(p->command_key);
icwmp_free(p->file_type);
icwmp_free(p->username);
icwmp_free(p->password);
icwmp_free(p->url);
icwmp_free(p);
p = NULL;
}
static int download_unit_tests_clean(void **state)
{
icwmp_cleanmem();
if (transfer_complete_test != NULL)
free_transfer_complete(transfer_complete_test);
remove(ICWMP_DOWNLOAD_FILE);
remove(FIRMWARE_UPGRADE_IMAGE);
return 0;
}
static void cwmp_download_file_unit_test(void **state)
{
remove(ICWMP_DOWNLOAD_FILE);
/*
* Valid URL
*/
int http_code = download_file(ICWMP_DOWNLOAD_FILE, "http://127.0.0.1/firmware_v1.0.bin", NULL, NULL);
assert_int_equal(http_code, 200);
assert_int_equal(access( ICWMP_DOWNLOAD_FILE, F_OK ), 0);
remove(ICWMP_DOWNLOAD_FILE);
/*
* Not Valid URL
*/
http_code = download_file(ICWMP_DOWNLOAD_FILE, "http://127.0.0.1/firmware.bin", NULL, NULL);
assert_int_equal(http_code, 404);
assert_int_equal(access( ICWMP_DOWNLOAD_FILE, F_OK ), 0);
remove(ICWMP_DOWNLOAD_FILE);
}
static void cwmp_launch_download_unit_test(void **state)
{
struct transfer_complete *ptransfer_complete = NULL;
struct download *pdownload;
remove(FIRMWARE_UPGRADE_IMAGE);
/*
* All arguments are valid
*/
pdownload = icwmp_calloc(1, sizeof(struct download));
pdownload->command_key = icwmp_strdup("download_key");
pdownload->file_size = 0;
pdownload->file_type = icwmp_strdup("1 Firmware Upgrade Image");
pdownload->username = icwmp_strdup("iopsys");
pdownload->password = icwmp_strdup("iopsys");
pdownload->url = icwmp_strdup("http://127.0.0.1/firmware_v1.0.bin");
int error = cwmp_launch_download(pdownload, TYPE_DOWNLOAD, &ptransfer_complete);
transfer_complete_test = ptransfer_complete;
assert_int_equal(error, FAULT_CPE_NO_FAULT);
assert_int_equal(access( FIRMWARE_UPGRADE_IMAGE, F_OK ), 0);
assert_int_equal(ptransfer_complete->fault_code, FAULT_CPE_NO_FAULT);
assert_string_equal(ptransfer_complete->command_key, "download_key");
assert_non_null(ptransfer_complete->start_time);
assert_non_null(ptransfer_complete->complete_time);
free_transfer_complete(ptransfer_complete);
free_download(pdownload);
remove(FIRMWARE_UPGRADE_IMAGE);
/*
* Not valid url
*/
pdownload = icwmp_calloc(1, sizeof(struct download));
pdownload->command_key = icwmp_strdup("download_key");
pdownload->file_size = 0;
pdownload->file_type = icwmp_strdup("1 Firmware Upgrade Image");
pdownload->username = icwmp_strdup("iopsys");
pdownload->password = icwmp_strdup("iopsys");
pdownload->url = icwmp_strdup("http://127.0.0.1/firmware.bin");
error = cwmp_launch_download(pdownload, TYPE_DOWNLOAD, &ptransfer_complete);
transfer_complete_test = ptransfer_complete;
assert_int_equal(error, FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER);
assert_int_equal(ptransfer_complete->fault_code, FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER);
assert_string_equal(ptransfer_complete->command_key, "download_key");
assert_non_null(ptransfer_complete->start_time);
assert_non_null(ptransfer_complete->complete_time);
free_transfer_complete(ptransfer_complete);
free_download(pdownload);
remove(FIRMWARE_UPGRADE_IMAGE);
/*
* Not valid FileType
*/
pdownload = icwmp_calloc(1, sizeof(struct download));
pdownload->command_key = icwmp_strdup("download_key");
pdownload->file_size = 0;
pdownload->file_type = icwmp_strdup("7 New File Type");
pdownload->username = icwmp_strdup("iopsys");
pdownload->password = icwmp_strdup("iopsys");
pdownload->url = icwmp_strdup("http://127.0.0.1/firmware_v1.0.bin");
error = cwmp_launch_download(pdownload, TYPE_DOWNLOAD, &ptransfer_complete);
transfer_complete_test = ptransfer_complete;
assert_int_equal(error, FAULT_CPE_INVALID_ARGUMENTS);
assert_int_equal(ptransfer_complete->fault_code, FAULT_CPE_INVALID_ARGUMENTS);
assert_string_equal(ptransfer_complete->command_key, "download_key");
assert_non_null(ptransfer_complete->start_time);
assert_non_null(ptransfer_complete->complete_time);
free_transfer_complete(ptransfer_complete);
free_download(pdownload);
remove(FIRMWARE_UPGRADE_IMAGE);
/*
* Not valid image
*/
pdownload = icwmp_calloc(1, sizeof(struct download));
pdownload->command_key = icwmp_strdup("download_key");
pdownload->file_size = 0;
pdownload->file_type = icwmp_strdup("1 Firmware Upgrade Image");
pdownload->username = icwmp_strdup("iopsys");
pdownload->password = icwmp_strdup("iopsys");
pdownload->url = icwmp_strdup("http://127.0.0.1/invalid_firmware_v1.0.bin");
error = cwmp_launch_download(pdownload, TYPE_DOWNLOAD, &ptransfer_complete);
transfer_complete_test = ptransfer_complete;
assert_int_equal(error, FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED);
assert_int_equal(ptransfer_complete->fault_code, FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED);
assert_string_equal(ptransfer_complete->command_key, "download_key");
assert_non_null(ptransfer_complete->start_time);
assert_non_null(ptransfer_complete->complete_time);
free_transfer_complete(ptransfer_complete);
free_download(pdownload);
remove(FIRMWARE_UPGRADE_IMAGE);
}
int main(void)
{
const struct CMUnitTest tests[] = { //
cmocka_unit_test(cwmp_download_file_unit_test),
cmocka_unit_test(cwmp_launch_download_unit_test)
};
return cmocka_run_group_tests(tests, NULL, download_unit_tests_clean);
}

View file

@ -0,0 +1,4 @@
{
"code": 1,
"stderr": "FATAL ERROR: could not read header from: /tmp/firmware.bin\nNot an IOPSYS image\nImage check failed.\n"
}

View file

@ -9,7 +9,12 @@ case "$1" in
call)
case "$2" in
upgrade_test)
cat /tmp/rpc_sys.data 2>/dev/null
invalid=`cat /tmp/firmware.bin`
if [ $invalid = "Invalid" ]; then
cat /tmp/rpc_sys_fail.data 2>/dev/null
else
cat /tmp/rpc_sys.data 2>/dev/null
fi
;;
upgrade_start)
cat /tmp/rpc_sys.data 2>/dev/null