-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests to test private functions which implement the
RSP protocol and deal with the string buffer.
- Loading branch information
Showing
5 changed files
with
215 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Copyright 2018 The Open SoC Debug Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef OSD_GDBSERVER_PRIVATE_H | ||
#define OSD_GDBSERVER_PRIVATE_H | ||
|
||
#include <osd/hostmod.h> | ||
#include <osd/osd.h> | ||
|
||
#include <stdlib.h> | ||
|
||
/** | ||
* Return packet-data from the received data buffer by validating the checksum | ||
* | ||
* @param buf_p the pointer to the received packet buffer data | ||
* @param ver_checksum '1' indicates valid checksum | ||
* @param len the length of the packet-data | ||
* @param buffer the packet-data received | ||
* | ||
*/ | ||
osd_result validate_rsp_packet(char *buf_p, bool *ver_checksum, int *len, | ||
char *buffer); | ||
|
||
|
||
/** | ||
* Set packet-data into the RSP format: $packet-data#checksum | ||
* | ||
* @param buffer the packet-data buffer | ||
* @param len the length of the packet-data | ||
* @param packet_buffer the packet buffer in RSP format | ||
*/ | ||
osd_result configure_rsp_packet(char *buffer, int len, char *packet_buffer); | ||
|
||
#endif // OSD_GDBSERVER_PRIVATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* Copyright 2018 The Open SoC Debug Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#define TEST_SUITE_NAME "check_gdbserver" | ||
|
||
#include "testutil.h" | ||
|
||
#include <../../src/libosd/gdbserver-private.h> | ||
#include <osd/osd.h> | ||
#include <osd/reg.h> | ||
|
||
#include "mock_host_controller.h" | ||
|
||
struct osd_gdbserver_ctx *gdbserver_ctx; | ||
struct osd_log_ctx *log_ctx; | ||
|
||
const unsigned int target_subnet_addr = 0; | ||
unsigned int mock_hostmod_diaddr; | ||
unsigned int mock_scm_diaddr; | ||
|
||
START_TEST(test_validate_rsp_packet) | ||
{ | ||
osd_result rv; | ||
char packet_buffer[11] = "swbreak#ef"; | ||
char *buf_p = packet_buffer; | ||
bool ver_checksum; | ||
int len; | ||
char buffer[1024]; | ||
char packet_data[1024] = "swbreak"; | ||
|
||
rv = validate_rsp_packet(buf_p, &ver_checksum, &len, buffer); | ||
ck_assert(OSD_SUCCEEDED(rv)); | ||
ck_assert_uint_eq(len, 7); | ||
ck_assert_str_eq(buffer, packet_data); | ||
} | ||
END_TEST | ||
|
||
START_TEST(test_configure_rsp_packet) | ||
{ | ||
char buffer[8] = "swbreak"; | ||
int buf_cnt = 11; | ||
int packet_checksum; | ||
int len = 7; | ||
char packet_buffer[len + 3]; | ||
|
||
configure_rsp_packet(buffer, len, packet_buffer); | ||
ck_assert_str_eq(packet_buffer, "$swbreak#ef"); | ||
} | ||
END_TEST | ||
|
||
Suite *suite(void) | ||
{ | ||
Suite *s; | ||
TCase *tc_testing; | ||
|
||
s = suite_create(TEST_SUITE_NAME); | ||
|
||
tc_testing = tcase_create("Testing"); | ||
|
||
tcase_add_test(tc_testing, test_validate_rsp_packet); | ||
tcase_add_test(tc_testing, test_configure_rsp_packet); | ||
suite_add_tcase(s, tc_testing); | ||
|
||
return s; | ||
} |