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
c767cdd0
Commit
c767cdd0
authored
6 years ago
by
Matthew Blue
Browse files
Options
Downloads
Patches
Plain Diff
tests/cb_mux: initial test routine
parent
02697faf
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/cb_mux/Makefile
+10
-0
10 additions, 0 deletions
tests/cb_mux/Makefile
tests/cb_mux/main.c
+135
-0
135 additions, 0 deletions
tests/cb_mux/main.c
tests/cb_mux/tests/01-run.py
+44
-0
44 additions, 0 deletions
tests/cb_mux/tests/01-run.py
with
189 additions
and
0 deletions
tests/cb_mux/Makefile
0 → 100644
+
10
−
0
View file @
c767cdd0
include
../Makefile.tests_common
USEMODULE
+=
cb_mux
TEST_ON_CI_WHITELIST
+=
all
include
$(RIOTBASE)/Makefile.include
test
:
./tests/01-run.py
This diff is collapsed.
Click to expand it.
tests/cb_mux/main.c
0 → 100644
+
135
−
0
View file @
c767cdd0
/*
* Copyright (C) 2018 Acutam Automation, LLC
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief cb_mux test application
*
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
* @}
*/
#include
<stdio.h>
#include
"cb_mux.h"
/* Head of cb_mux list */
cb_mux_t
*
cb_mux_head
;
/* Flags for mux_iter */
enum
{
ITER_TEST
=
1
};
/* Function to iterate over cb_mux list */
void
mux_iter
(
cb_mux_t
*
entry
,
void
*
arg
)
{
(
void
)
arg
;
entry
->
info
=
(
void
*
)((
uintptr_t
)
entry
->
info
|
(
1
<<
ITER_TEST
));
}
/* Test callback */
void
cb
(
void
*
arg
)
{
printf
(
"Callback %u executed
\n
"
,
(
uint8_t
)(
uintptr_t
)
arg
);
}
int
main
(
void
)
{
cb_mux_t
entries
[
5
];
cb_mux_cbid_t
num
;
cb_mux_t
*
entry
;
puts
(
"cb_mux test routine"
);
for
(
num
=
0
;
num
<
5
;
num
++
)
{
entries
[
num
].
cb
=
cb
;
entries
[
num
].
arg
=
(
void
*
)
num
;
entries
[
num
].
cbid
=
num
;
}
puts
(
"Test list addition, retrieval, execution of 5 CBs"
);
for
(
num
=
0
;
num
<
5
;
num
++
)
{
cb_mux_add
(
&
cb_mux_head
,
&
(
entries
[
num
]));
}
for
(
num
=
0
;
num
<
5
;
num
++
)
{
entry
=
cb_mux_find_cbid
(
cb_mux_head
,
num
);
if
(
entry
->
cb
==
NULL
)
{
puts
(
"[FAILED] Unexpected NULL pointer"
);
return
1
;
}
entry
->
cb
(
entry
->
arg
);
}
puts
(
"Test list deletion of CB 0, 2, 4, execution of 1, 3"
);
cb_mux_del
(
&
cb_mux_head
,
&
(
entries
[
0
]));
cb_mux_del
(
&
cb_mux_head
,
&
(
entries
[
2
]));
cb_mux_del
(
&
cb_mux_head
,
&
(
entries
[
4
]));
for
(
num
=
0
;
num
<
5
;
num
++
)
{
entry
=
cb_mux_find_cbid
(
cb_mux_head
,
num
);
if
(
entry
==
NULL
)
{
continue
;
}
entry
->
cb
(
entry
->
arg
);
}
puts
(
"Test execution of CB with lowest ID (1)"
);
entry
=
cb_mux_find_low
(
cb_mux_head
);
if
(
entry
->
cb
==
NULL
)
{
puts
(
"[FAILED] Unexpected NULL pointer"
);
return
1
;
}
entry
->
cb
(
entry
->
arg
);
puts
(
"Test execution of CB with highest ID (3)"
);
entry
=
cb_mux_find_high
(
cb_mux_head
);
if
(
entry
->
cb
==
NULL
)
{
puts
(
"[FAILED] Unexpected NULL pointer"
);
return
1
;
}
entry
->
cb
(
entry
->
arg
);
puts
(
"Re-adding list entries (0, 2, 4) by finding next free ID"
);
num
=
cb_mux_find_free_id
(
cb_mux_head
);
while
(
num
<
5
)
{
cb_mux_add
(
&
cb_mux_head
,
&
(
entries
[
num
]));
printf
(
"Added entry %i
\n
"
,
num
);
num
=
cb_mux_find_free_id
(
cb_mux_head
);
}
puts
(
"Test iteration of a function over list"
);
cb_mux_iter
(
cb_mux_head
,
mux_iter
,
NULL
);
for
(
num
=
0
;
num
<
5
;
num
++
)
{
if
((
uintptr_t
)
entries
[
num
].
info
&
(
1
<<
ITER_TEST
))
{
printf
(
"Entry %i was updated correctly
\n
"
,
num
);
}
}
puts
(
"Tests complete!"
);
return
0
;
}
This diff is collapsed.
Click to expand it.
tests/cb_mux/tests/01-run.py
0 → 100755
+
44
−
0
View file @
c767cdd0
#!/usr/bin/env python3
# Copyright (C) 2018 Acutam Automation, LLC
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import
os
import
sys
def
testfunc
(
child
):
child
.
expect_exact
(
"
cb_mux test routine
"
)
child
.
expect_exact
(
"
Test list addition, retrieval, execution of 5 CBs
"
)
child
.
expect_exact
(
"
Callback 0 executed
"
)
child
.
expect_exact
(
"
Callback 1 executed
"
)
child
.
expect_exact
(
"
Callback 2 executed
"
)
child
.
expect_exact
(
"
Callback 3 executed
"
)
child
.
expect_exact
(
"
Callback 4 executed
"
)
child
.
expect_exact
(
"
Test list deletion of CB 0, 2, 4, execution of 1, 3
"
)
child
.
expect_exact
(
"
Callback 1 executed
"
)
child
.
expect_exact
(
"
Callback 3 executed
"
)
child
.
expect_exact
(
"
Test execution of CB with lowest ID (1)
"
)
child
.
expect_exact
(
"
Callback 1 executed
"
)
child
.
expect_exact
(
"
Test execution of CB with highest ID (3)
"
)
child
.
expect_exact
(
"
Callback 3 executed
"
)
child
.
expect_exact
(
"
Re-adding list entries (0, 2, 4) by finding next free ID
"
)
child
.
expect_exact
(
"
Added entry 0
"
)
child
.
expect_exact
(
"
Added entry 2
"
)
child
.
expect_exact
(
"
Added entry 4
"
)
child
.
expect_exact
(
"
Test iteration of a function over list
"
)
child
.
expect_exact
(
"
Entry 0 was updated correctly
"
)
child
.
expect_exact
(
"
Entry 1 was updated correctly
"
)
child
.
expect_exact
(
"
Entry 2 was updated correctly
"
)
child
.
expect_exact
(
"
Entry 3 was updated correctly
"
)
child
.
expect_exact
(
"
Entry 4 was updated correctly
"
)
child
.
expect_exact
(
"
Tests complete!
"
)
if
__name__
==
"
__main__
"
:
sys
.
path
.
append
(
os
.
path
.
join
(
os
.
environ
[
'
RIOTBASE
'
],
'
dist/tools/testrunner
'
))
from
testrunner
import
run
sys
.
exit
(
run
(
testfunc
))
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