Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
77803ee7
Unverified
Commit
77803ee7
authored
Jun 01, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: add unit tests for idmap parser
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
0b843d35
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
1 deletion
+59
-1
conf.c
src/lxc/conf.c
+2
-1
parse_config_file.c
src/tests/parse_config_file.c
+57
-0
No files found.
src/lxc/conf.c
View file @
77803ee7
...
...
@@ -4903,7 +4903,8 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data)
/* idmap will now keep track of that memory. */
container_root_gid
=
NULL
;
if
(
lxc_log_get_level
()
==
LXC_LOG_PRIORITY_TRACE
)
{
if
(
lxc_log_get_level
()
==
LXC_LOG_PRIORITY_TRACE
||
conf
->
loglevel
==
LXC_LOG_PRIORITY_TRACE
)
{
lxc_list_for_each
(
it
,
idmap
)
{
map
=
it
->
elem
;
TRACE
(
"establishing %cid mapping for
\"
%d
\"
in new "
...
...
src/tests/parse_config_file.c
View file @
77803ee7
...
...
@@ -28,6 +28,7 @@
#include <errno.h>
#include <string.h>
#include "confile_utils.h"
#include "lxc/state.h"
#include "lxctest.h"
...
...
@@ -103,6 +104,57 @@ static int set_get_compare_clear_save_load(struct lxc_container *c,
return
0
;
}
int
test_idmap_parser
(
void
)
{
size_t
i
;
struct
idmap_check
{
bool
is_valid
;
const
char
*
idmap
;
};
static
struct
idmap_check
idmaps
[]
=
{
/* valid idmaps */
{
true
,
"u 0 0 1"
},
{
true
,
"g 0 0 1"
},
{
true
,
"u 1 100001 999999999"
},
{
true
,
"g 1 100001 999999999"
},
{
true
,
"u 0 0 0"
},
{
true
,
"g 0 0 0"
},
{
true
,
"u 1000 165536 65536"
},
{
true
,
"g 999 999 1"
},
{
true
,
"u 0 5000 100000"
},
{
true
,
"g 577 789 5"
},
{
true
,
"u 65536 65536 1 "
},
/* invalid idmaps */
{
false
,
"1u 0 0 0"
},
{
false
,
"1g 0 0 0a"
},
{
false
,
"1 u 0 0 0"
},
{
false
,
"1g 0 0 0 1"
},
{
false
,
"1u a0 b0 c0 d1"
},
{
false
,
"1g 0 b0 0 d1"
},
{
false
,
"1u a0 0 c0 1"
},
{
false
,
"g -1 0 -10"
},
{
false
,
"a 1 0 10"
},
{
false
,
"u 1 1 0 10"
},
{
false
,
"g 1 0 10 z "
},
};
for
(
i
=
0
;
i
<
sizeof
(
idmaps
)
/
sizeof
(
struct
idmap_check
);
i
++
)
{
unsigned
long
hostid
,
nsid
,
range
;
char
type
;
int
ret
;
ret
=
parse_idmaps
(
idmaps
[
i
].
idmap
,
&
type
,
&
nsid
,
&
hostid
,
&
range
);
if
((
ret
<
0
&&
idmaps
[
i
].
is_valid
)
||
(
ret
==
0
&&
!
idmaps
[
i
].
is_valid
))
{
lxc_error
(
"failed to parse idmap
\"
%s
\"\n
"
,
idmaps
[
i
].
idmap
);
return
-
1
;
}
}
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
lxc_container
*
c
;
...
...
@@ -489,6 +541,11 @@ int main(int argc, char *argv[])
goto
non_test_error
;
}
if
(
test_idmap_parser
()
<
0
)
{
lxc_error
(
"%s
\n
"
,
"failed to test parser for
\"
lxc.id_map
\"
"
);
goto
non_test_error
;
}
ret
=
EXIT_SUCCESS
;
non_test_error:
c
->
destroy
(
c
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment