Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qosmngr
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HAL
qosmngr
Commits
81942fe0
Commit
81942fe0
authored
4 years ago
by
Oskar Viljasaar
Browse files
Options
Downloads
Patches
Plain Diff
initial test framework
parent
026be2a9
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+28
-0
28 additions, 0 deletions
Makefile
src/Makefile
+11
-4
11 additions, 4 deletions
src/Makefile
test/cmocka/Makefile
+28
-0
28 additions, 0 deletions
test/cmocka/Makefile
test/cmocka/unit_test_qos.c
+197
-0
197 additions, 0 deletions
test/cmocka/unit_test_qos.c
with
264 additions
and
4 deletions
Makefile
+
28
−
0
View file @
81942fe0
# Makefile for qosmngr
# Makefile for qosmngr
include
common.mk
QOSMNGR_LIB
=
libqosmngr.so
subdirs
?=
src
subdirs
?=
src
...
@@ -6,3 +9,28 @@ subdirs ?= src
...
@@ -6,3 +9,28 @@ subdirs ?= src
all clean
:
all clean
:
@
for
i
in
$(
subdirs
)
;
do
[
-d
$$
i
]
&&
$(
MAKE
)
-C
$$
i
$@
;
done
@
for
i
in
$(
subdirs
)
;
do
[
-d
$$
i
]
&&
$(
MAKE
)
-C
$$
i
$@
;
done
qosmngr
:
$(
MAKE
)
all
-C
src
${QOSMNGR_LIB}
:
$(
MAKE
)
CFLAGS+
=
-fPIC
lib
-C
src
test
:
${QOSMNGR_LIB}
unit-test
:
coverage
$(
MAKE
)
-C
test
/cmocka unit-test
QOSMNGR_LIB_DIR
=
$(
PWD
)
coverage
:
CFLAGS += -g -O0 -fprofile-arcs -ftest-coverage -fPIC
coverage
:
LDFLAGS += --coverage
coverage
:
test qosmngr
$(
foreach testprog,
$(
CODECOVERAGE_SRC
)
,
$(
GCOV
)
$(
testprog
);)
clean
:
rm
-f
*
.o libqosmngr.so
$(
PROG
)
rm
-f
*
.xml
*
.html
find
-name
'*.gcda'
-exec
rm
{}
-fv
\;
find
-name
'*.gcno'
-exec
rm
{}
-fv
\;
find
-name
'*.gcov'
-exec
rm
{}
-fv
\;
make
-C
test
/cmocka clean
make
-C
src clean
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Makefile
+
11
−
4
View file @
81942fe0
include
../common.mk
include
../common.mk
PROG
=
$(
PROJECT_TOPLEVEL
)
/qosmngr
PROG
=
$(
PROJECT_TOPLEVEL
)
/qosmngr
SHARED_LIB
=
$(
PROJECT_TOPLEVEL
)
/libqosmngr.so
OBJS
=
main.o qosmngr.o
OBJS
=
main.o qosmngr.o
PROG_CFLAGS
=
$(
CFLAGS
)
-I
$(
INCLUDE_DIR
)
-Wall
-fstrict-aliasing
PROG_CFLAGS
=
$(
CFLAGS
)
-I
$(
INCLUDE_DIR
)
-Wall
-fstrict-aliasing
...
@@ -10,9 +12,14 @@ PROG_LIBS = -luci -lubus -lubox -ljson-c -lblobmsg_json -lnl-genl-3 -lnl-3 -lgco
...
@@ -10,9 +12,14 @@ PROG_LIBS = -luci -lubus -lubox -ljson-c -lblobmsg_json -lnl-genl-3 -lnl-3 -lgco
%.o
:
%.c
%.o
:
%.c
$(
CC
)
$(
PROG_CFLAGS
)
$(
FPIC
)
-c
-o
$@
$<
$(
CC
)
$(
PROG_CFLAGS
)
$(
FPIC
)
-c
-o
$@
$<
.PHONY
:
version
.PHONY
:
clean
all
:
$(PROG)
lib
:
$(SHARED_LIB)
all
:
version $(PROG)
$(SHARED_LIB)
:
$(OBJS) $(INCLUDE_DIR)/version.h
$(
CC
)
$(
PROG_LDFLAGS
)
-shared
-o
$@
$^
$(
PROG_LIBS
)
version
:
$(INCLUDE_DIR)/version.h
version
:
$(INCLUDE_DIR)/version.h
...
@@ -25,8 +32,8 @@ $(INCLUDE_DIR)/version.h: $(PROJECT_TOPLEVEL)/VERSION
...
@@ -25,8 +32,8 @@ $(INCLUDE_DIR)/version.h: $(PROJECT_TOPLEVEL)/VERSION
echo
"const char *qosmngr_xtra_version =
\"
$$
xver
$$
dirty
\"
;"
>>
$@
;
\
echo
"const char *qosmngr_xtra_version =
\"
$$
xver
$$
dirty
\"
;"
>>
$@
;
\
)
)
$(PROG)
:
$(OBJS)
$(PROG)
:
$(INCLUDE_DIR)/version.h
$(OBJS)
$(
CC
)
$(
PROG_LDFLAGS
)
-o
$@
$^
$(
PROG_LIBS
)
$(
CC
)
$(
PROG_LDFLAGS
)
-o
$@
$^
$(
PROG_LIBS
)
clean
:
clean
:
rm
-f
*
.o
libqosmngr.so
$(
PROG
)
$(
INCLUDE_DIR
)
/version.h
rm
-f
*
.o
$(
SHARED_LIB
)
$(
PROG
)
$(
INCLUDE_DIR
)
/version.h
This diff is collapsed.
Click to expand it.
test/cmocka/Makefile
0 → 100644
+
28
−
0
View file @
81942fe0
include
../../common.mk
CC
=
gcc
QOSMNGR_LIB_DIR
?=
$(
shell
dirname
$(
PWD
))
QOSMNGR_LIB
=
-lqosmngr
-L
$(
QOSMNGR_LIB_DIR
)
CMOCKA_LIB
=
-l
cmocka
LIBS
=
$(
QOSMNGR_LIB
)
$(
CMOCKA_LIB
)
-lqos
-pthread
-luci
-lubus
-lubox
-ljson-c
-lblobmsg_json
-lnl-genl-3
-lnl-3
-ljson-validator
-ljson-schema-validator
-ljson-editor
CFLAGS
=
-g
-Wall
-I
$(
INCLUDE_DIR
)
LDFLAGS
=
$(
LIBS
)
-Wl
,-rpath
=
$(
QOSMNGR_LIB_DIR
)
-I
$(
QOSMNGR_LIB_DIR
)
UNIT_TESTS
=
unit_test_qos
VALGRIND
=
valgrind
--leak-check
=
full
--show-reachable
=
no
\
--show-leak-kinds
=
all
--errors-for-leak-kinds
=
all
\
--error-exitcode
=
1
--track-origins
=
yes
%.o
:
%.c
$(
CC
)
$(
CFLAGS
)
$(
FPIC
)
-c
-o
$@
$<
unit_test_qos
:
unit_test_qos.o
$(
CC
)
$(
CFLAGS
)
-o
$@
$^
$(
LDFLAGS
)
unit-test
:
$(UNIT_TESTS)
$(
foreach testprog,
$(
UNIT_TESTS
)
,
sudo
$(
VALGRIND
)
./
$(
testprog
);)
.PHONY
:
clean
clean
:
rm
$(
UNIT_TESTS
)
*
.o
-fv
This diff is collapsed.
Click to expand it.
test/cmocka/unit_test_qos.c
0 → 100644
+
197
−
0
View file @
81942fe0
#include
<stdarg.h>
#include
<stddef.h>
#include
<setjmp.h>
#include
<cmocka.h>
#include
<libubus.h>
#include
<libubox/blobmsg_json.h>
#include
<libubox/blobmsg.h>
#include
<json-validator.h>
#include
<json-c/json.h>
#include
<json-editor.h>
#include
<json-c/json_tokener.h>
#include
<easy/easy.h>
#include
<qos.h>
#include
<qosmngr.h>
struct
test_ctx
{
struct
blob_buf
bb
;
struct
ubus_object
qos
;
FILE
*
fp
;
};
/* declare qosmngr functions */
int
wl_radio_status
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
wl_radio_get_param
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
sta_disconnect
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
nbr_transition
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
nbr_request
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
nbr_add
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
wps_start
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
wps_stop
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
vsie_add
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
ureq
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
vsie_del
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
ureq
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
nbr_del
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
sta_monitor
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
wl_scan
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
wl_autochannel
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
wps_set_ap_pin
(
struct
ubus_context
*
ctx
,
struct
ubus_object
*
obj
,
struct
ubus_request_data
*
req
,
const
char
*
method
,
struct
blob_attr
*
msg
);
int
qosmngr_event_main
(
const
char
*
evmap_file
);
/* overload ubus_send_reply to prevent segfault*/
int
ubus_send_reply
(
struct
ubus_context
*
ctx
,
struct
ubus_request_data
*
req
,
struct
blob_attr
*
msg
)
{
return
0
;
}
/* TODO: how to fix events without fopen and fclose every poll? */
struct
json_object
*
poll_test_log
(
FILE
*
fp
,
const
char
*
prefix
)
{
char
line
[
256
]
=
{
0
};
char
msg
[
256
]
=
{
0
};
struct
json_object
*
obj
=
NULL
;
//if (!fp) {
fp
=
fopen
(
"/tmp/test.log"
,
"r"
);
if
(
!
fp
)
return
NULL
;
//}
while
(
fgets
(
line
,
256
,
fp
))
{
char
*
ptr
,
*
s
;
char
appended
[
32
];
snprintf
(
appended
,
sizeof
(
appended
),
"%s:"
,
prefix
);
ptr
=
strstr
(
line
,
appended
);
if
(
!
ptr
)
continue
;
s
=
multi_tok
(
ptr
,
appended
);
s
=
multi_tok
(
NULL
,
appended
);
strncpy
(
msg
,
s
,
sizeof
(
msg
));
}
if
(
strlen
(
msg
))
obj
=
json_tokener_parse
(
msg
);
fclose
(
fp
);
return
obj
;
}
static
int
group_setup
(
void
**
state
)
{
struct
test_ctx
*
ctx
=
calloc
(
1
,
sizeof
(
struct
test_ctx
));
if
(
!
ctx
)
return
-
1
;
remove
(
"/tmp/test.log"
);
ctx
->
qos
.
name
=
"qos"
;
memset
(
&
ctx
->
bb
,
0
,
sizeof
(
struct
blob_buf
));
*
state
=
ctx
;
return
0
;
}
static
void
test_api_get_stats
(
void
**
state
)
{
struct
test_ctx
*
ctx
=
(
struct
test_ctx
*
)
*
state
;
struct
blob_buf
*
bb
=
&
ctx
->
bb
;
struct
ubus_object
*
obj
=
&
ctx
->
qos
;
struct
json_object
*
jobj
,
*
tmp
;
blobmsg_add_string
(
bb
,
"ifname"
,
"test"
);
tmp
=
json_object_get_by_string
(
jobj
,
"iface"
);
assert_string_equal
(
json_object_get_string
(
tmp
),
"test"
);
json_object_put
(
jobj
);
return
;
}
static
int
group_teardown
(
void
**
state
)
{
struct
test_ctx
*
ctx
=
(
struct
test_ctx
*
)
*
state
;
blob_buf_free
(
&
ctx
->
bb
);
free
(
ctx
);
remove
(
"/tmp/test.log"
);
/* TODO: fix event poll file */
//if (ctx->fp)
//fclose(ctx->fp);
return
0
;
}
static
int
setup
(
void
**
state
)
{
struct
test_ctx
*
ctx
=
(
struct
test_ctx
*
)
*
state
;
blob_buf_init
(
&
ctx
->
bb
,
0
);
return
0
;
}
int
main
(
void
)
{
const
struct
CMUnitTest
tests
[]
=
{
cmocka_unit_test_setup
(
test_api_get_stats
,
setup
),
};
return
cmocka_run_group_tests
(
tests
,
group_setup
,
group_teardown
);
}
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