Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR to close #38 #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
18 changes: 17 additions & 1 deletion test/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ void ENV_RunMillis(uint32_t millis) {
}
}

void ENV_RunMillisForTpRegisteredAt(uint32_t millis, unsigned at) {
uint32_t end = UDSMillis() + millis;
while (UDSMillis() < end) {
assert(at >= 0 && at < MAX_NUM_TP);

UDSTpPoll(registeredTps[at]);
TimeNowMillis++;

// uses vcan, needs delay
if (IsNetworkedTransport(opts.tp_type)) {
// usleep(10);
msleep(1);
}
}
}

UDSTpHandle_t *ENV_TpNew(const char *name) {
ENV_ParseOpts();
UDSTpHandle_t *tp = NULL;
Expand Down Expand Up @@ -183,4 +199,4 @@ void ENV_TpFree(UDSTpHandle_t *tp) {
}
}

const ENV_Opts_t *ENV_GetOpts() { return &opts; }
const ENV_Opts_t *ENV_GetOpts() { return &opts; }
1 change: 1 addition & 0 deletions test/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void ENV_TpFree(UDSTpHandle_t *tp);
void ENV_RegisterServer(UDSServer_t *server);
void ENV_RegisterClient(UDSClient_t *client);
void ENV_RunMillis(uint32_t millis);
void ENV_RunMillisForTpRegisteredAt(uint32_t millis, unsigned at);
const ENV_Opts_t *ENV_GetOpts();

#endif
28 changes: 24 additions & 4 deletions test/test_tp_compliance.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,36 @@ void TestISOTPFlowControlFrameTimeout(void **state) {
skip();
}

// killing server so that no response is sent to client
ENV_TpFree(srv);
int tp_type = ENV_GetOpts()->tp_type;
if (tp_type == ENV_TP_TYPE_ISOTP_SOCK){
// killing server if using ISOTP sockets so that no response is sent to client
ENV_TpFree(srv);
}

// sending multiframe to wait for Flow Control frame
// which will not arrive since no server is running
const uint8_t MSG[] = {1, 2, 3, 4, 5, 6, 7, 8};
ssize_t ret = UDSTpSend(client, MSG, sizeof(MSG), NULL);

// failure is expected as the elapsed 1s timeout raises an error on the ISOTP socket
assert_true(ret < 0);
tp_type = ENV_GetOpts()->tp_type;
if (tp_type == ENV_TP_TYPE_ISOTPC) {
// running poll just for the client to simulate the server not responding
ENV_RunMillisForTpRegisteredAt(1500, 1);
assert(((UDSTpISOTpC_t *)client)->phys_link.send_protocol_result == ISOTP_PROTOCOL_RESULT_TIMEOUT_BS);
assert(((UDSTpISOTpC_t *)client)->phys_link.send_status == ISOTP_SEND_STATUS_ERROR);
} else if (tp_type == ENV_TP_TYPE_ISOTP_SOCK) {
// failure is expected as the elapsed 1s timeout raises an error on the ISOTP socket
assert_true(ret < 0);
} else {
// do no test anything
}

tp_type = ENV_GetOpts()->tp_type;
if (tp_type == ENV_TP_TYPE_ISOTP_SOCK){
// reinitialize the server so the teardown function does not fail because
// of calling free() twice on the server sockets
srv = ENV_TpNew("server");
}
}

int main() {
Expand Down
Loading