Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@ ecutuned_SOURCES = $(SRC_FILES) src/ecutuned.c
ecutuned_CFLAGS = -DUSESSL -DTHREADED $(INCLUDE_ALL_DIRS) $(COMPILER_FLAGS) $(LOG_FLAGS)
ecutuned_LDFLAGS = $(LD_FLAG) $(EXTERNAL_LIBS)

TESTS = check_j2534
check_PROGRAMS = check_j2534
TESTS = check_j2534 check_passthru_open
check_PROGRAMS = check_j2534 check_passthru_open
check_j2534_SOURCES = $(ECUTOOLS_TEST_FILES)
check_j2534_LDFLAGS = $(LD_FLAG) -lcheck -lj2534

check_passthru_open_SOURCES = tests/check_passthru_open.c src/j2534.c
check_passthru_open_CFLAGS = $(AM_CFLAGS) -ffunction-sections -fdata-sections
check_passthru_open_LDFLAGS = -Wl,--gc-sections
check_passthru_open_LDADD = -lcheck -lsubunit

bundle-install:
cd bindings/ruby && bundle install && cd -
cd cli && bundle install && cd -
Expand Down
11 changes: 5 additions & 6 deletions src/j2534.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,20 @@ long PassThruGetNextDevice(SDEVICE *psDevice) {
* STATUS_NOERROR Function call was successful
*/
long PassThruOpen(const char *pName, unsigned long *pDeviceID) {
j2534_current_api_call = J2534_PassThruOpen;

syslog(LOG_ERR, "PassThruOpen: pName=%s, pDeviceID=%d", pName, *pDeviceID);
if(pName == NULL || pDeviceID == NULL) {
return unless_concurrent_call(ERR_NULL_PARAMETER, J2534_PassThruOpen);
}

j2534_current_api_call = J2534_PassThruOpen;
syslog(LOG_ERR, "PassThruOpen: pName=%s, pDeviceID=%d", pName, *pDeviceID);

unsigned int shadow_update_topic_len = PASSTHRU_SHADOW_UPDATE_TOPIC + strlen(pName) + 1;
unsigned int shadow_update_accepted_topic_len = PASSTHRU_SHADOW_UPDATE_ACCEPTED_TOPIC + strlen(pName) + 1;
unsigned int shadow_error_topic_len = J2534_ERROR_TOPIC + strlen(pName) + 1;
unsigned int msg_rx_topic_len = J2534_MSG_RX_TOPIC + strlen(pName) + 1;
unsigned int msg_tx_topic_len = J2534_MSG_TX_TOPIC + strlen(pName) + 1;

if(pName == NULL || pDeviceID == NULL) {
return unless_concurrent_call(ERR_NULL_PARAMETER, J2534_PassThruOpen);
}

if(!j2534_initialized) {
vector_init(&j2534_client_vector);
vector_init(&j2534_selected_channels);
Expand Down
97 changes: 97 additions & 0 deletions tests/check_passthru_open.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include <stdlib.h>
#include <check.h>

#include "j2534.h"

/* PassThruOpen dependencies that are not exercised by NULL validation. */
void vector_init(vector *items) { (void)items; }
void vector_add(vector *items, void *item) { (void)items; (void)item; }
void *vector_get(vector *items, int index) { (void)items; (void)index; return NULL; }

unsigned int awsiot_client_connect(awsiot_client *client)
{
(void)client;
return 0;
}

unsigned int awsiot_client_subscribe(awsiot_client *client,
const char *topic,
void *handler,
void *data)
{
(void)client;
(void)topic;
(void)handler;
(void)data;
return 0;
}

unsigned int awsiot_client_publish(awsiot_client *client,
const char *topic,
char *payload)
{
(void)client;
(void)topic;
(void)payload;
return 0;
}

IoT_Error_t aws_iot_mqtt_yield(AWS_IoT_Client *client, uint32_t timeout_ms)
{
(void)client;
(void)timeout_ms;
return SUCCESS;
}

int MYINT_LEN(int *num)
{
(void)num;
return 1;
}

shadow_message *passthru_shadow_parser_parse_state(const char *json)
{
(void)json;
return NULL;
}

void passthru_shadow_parser_free_message(shadow_message *message)
{
(void)message;
}

START_TEST(test_passthru_open_rejects_null_name)
{
unsigned long device_id = 1;

ck_assert_int_eq(PassThruOpen(NULL, &device_id), ERR_NULL_PARAMETER);
}
END_TEST

START_TEST(test_passthru_open_rejects_null_device_id)
{
ck_assert_int_eq(
PassThruOpen("J2534-1:ecutools", NULL),
ERR_NULL_PARAMETER
);
}
END_TEST

int main(void)
{
int failed;
Suite *suite = suite_create("PassThruOpen");
TCase *null_parameters = tcase_create("null_parameters");
SRunner *runner;

tcase_add_test(null_parameters, test_passthru_open_rejects_null_name);
tcase_add_test(null_parameters, test_passthru_open_rejects_null_device_id);
suite_add_tcase(suite, null_parameters);

runner = srunner_create(suite);
srunner_run_all(runner, CK_NORMAL);
failed = srunner_ntests_failed(runner);
srunner_free(runner);

return failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}