Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
0cd5bf9b
Commit
0cd5bf9b
authored
9 years ago
by
Ken Bannister
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for inet_csum_slice()
parent
835a2d8a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unittests/tests-inet_csum/tests-inet_csum.c
+46
-0
46 additions, 0 deletions
tests/unittests/tests-inet_csum/tests-inet_csum.c
with
46 additions
and
0 deletions
tests/unittests/tests-inet_csum/tests-inet_csum.c
+
46
−
0
View file @
0cd5bf9b
...
...
@@ -121,6 +121,50 @@ static void test_inet_csum__odd_len(void)
TEST_ASSERT_EQUAL_INT
(
0xffff
,
inet_csum
(
17
+
39
,
data
,
sizeof
(
data
)));
}
static
void
test_inet_csum__two_app_snips
(
void
)
{
/* CoAP header with Uri-Path and Content-Format options; odd length */
uint8_t
data_hdr
[]
=
{
0x50
,
0x02
,
0x00
,
0x01
,
0xb4
,
0x74
,
0x65
,
0x73
,
0x74
,
0x10
,
0xff
,
};
/* Single character payload, 'a' */
uint8_t
data_pyld
[]
=
{
0x61
,
};
uint16_t
hdr_sum
,
pyld_sum
,
hdr_expected
=
0xdcfc
;
/* result unnormalized:
* initial sum (0) is arbitrary, and incoming length (0) must be even;
* we expect last byte is shifted left for this odd-sized header */
hdr_sum
=
inet_csum_slice
(
0
,
data_hdr
,
sizeof
(
data_hdr
),
0
);
TEST_ASSERT_EQUAL_INT
(
hdr_expected
,
hdr_sum
);
/* Since header was odd length, we expect the single byte in the payload
* snip is not shifted left */
pyld_sum
=
inet_csum_slice
(
hdr_expected
,
data_pyld
,
sizeof
(
data_pyld
),
sizeof
(
data_hdr
));
TEST_ASSERT_EQUAL_INT
(
hdr_expected
+
0x61
,
pyld_sum
);
}
static
void
test_inet_csum__empty_app_buffer
(
void
)
{
/* CoAP header with Uri-Path and Content-Format options; odd length */
uint8_t
data_hdr
[]
=
{
0x50
,
0x02
,
0x00
,
0x01
,
0xb4
,
0x74
,
0x65
,
0x73
,
0x74
,
0x10
,
0xff
,
};
uint16_t
hdr_sum
,
pyld_sum
,
hdr_expected
=
0xdcfc
;
/* result unnormalized:
* explictly using an odd-sized header for the first slice, to setup corner case */
hdr_sum
=
inet_csum_slice
(
0
,
data_hdr
,
sizeof
(
data_hdr
),
0
);
TEST_ASSERT_EQUAL_INT
(
hdr_expected
,
hdr_sum
);
/* expect an empty buffer simply to reflect the incoming checksum */
pyld_sum
=
inet_csum_slice
(
hdr_expected
,
NULL
,
0
,
sizeof
(
data_hdr
));
TEST_ASSERT_EQUAL_INT
(
hdr_expected
,
pyld_sum
);
}
Test
*
tests_inet_csum_tests
(
void
)
{
EMB_UNIT_TESTFIXTURES
(
fixtures
)
{
...
...
@@ -130,6 +174,8 @@ Test *tests_inet_csum_tests(void)
new_TestFixture
(
test_inet_csum__wraps_more_than_once
),
new_TestFixture
(
test_inet_csum__calculate_csum
),
new_TestFixture
(
test_inet_csum__odd_len
),
new_TestFixture
(
test_inet_csum__two_app_snips
),
new_TestFixture
(
test_inet_csum__empty_app_buffer
),
};
EMB_UNIT_TESTCALLER
(
inet_csum_tests
,
NULL
,
NULL
,
fixtures
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment