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
9b937486
Unverified
Commit
9b937486
authored
Jul 03, 2018
by
Christian Brauner
Committed by
GitHub
Jul 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2445 from 2xsec/bugfix
tests: cleanup source codes.
parents
5221c891
6ea8a436
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
190 additions
and
14 deletions
+190
-14
api_reboot.c
src/tests/api_reboot.c
+3
-0
clonetest.c
src/tests/clonetest.c
+11
-0
concurrent.c
src/tests/concurrent.c
+0
-0
config_jump_table.c
src/tests/config_jump_table.c
+1
-1
console.c
src/tests/console.c
+17
-0
containertests.c
src/tests/containertests.c
+22
-0
createtest.c
src/tests/createtest.c
+4
-0
criu_check_feature.c
src/tests/criu_check_feature.c
+1
-0
destroytest.c
src/tests/destroytest.c
+7
-0
device_add_remove.c
src/tests/device_add_remove.c
+2
-0
get_item.c
src/tests/get_item.c
+0
-0
getkeys.c
src/tests/getkeys.c
+1
-0
list.c
src/tests/list.c
+10
-0
locktests.c
src/tests/locktests.c
+14
-0
lxc-test-utils.c
src/tests/lxc-test-utils.c
+24
-0
lxc_raw_clone.c
src/tests/lxc_raw_clone.c
+1
-4
lxcpath.c
src/tests/lxcpath.c
+2
-0
may_control.c
src/tests/may_control.c
+4
-0
reboot.c
src/tests/reboot.c
+4
-0
saveconfig.c
src/tests/saveconfig.c
+8
-0
shortlived.c
src/tests/shortlived.c
+14
-0
shutdowntest.c
src/tests/shutdowntest.c
+7
-4
snapshot.c
src/tests/snapshot.c
+17
-4
startone.c
src/tests/startone.c
+15
-1
state_server.c
src/tests/state_server.c
+1
-0
No files found.
src/tests/api_reboot.c
View file @
9b937486
...
@@ -59,6 +59,7 @@ int main(int argc, char *argv[])
...
@@ -59,6 +59,7 @@ int main(int argc, char *argv[])
lxc_error
(
"%s
\n
"
,
"Container
\"
reboot
\"
is not defined"
);
lxc_error
(
"%s
\n
"
,
"Container
\"
reboot
\"
is not defined"
);
goto
on_error_put
;
goto
on_error_put
;
}
}
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
NULL
))
{
if
(
!
c
->
load_config
(
c
,
NULL
))
{
...
@@ -118,7 +119,9 @@ on_error_stop:
...
@@ -118,7 +119,9 @@ on_error_stop:
on_error_put:
on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All reboot tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All reboot tests passed"
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/clonetest.c
View file @
9b937486
...
@@ -41,6 +41,7 @@ int main(int argc, char *argv[])
...
@@ -41,6 +41,7 @@ int main(int argc, char *argv[])
lxc_container_put
(
c
);
lxc_container_put
(
c
);
c
=
NULL
;
c
=
NULL
;
}
}
if
(
c2
)
{
if
(
c2
)
{
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
...
@@ -52,11 +53,14 @@ int main(int argc, char *argv[])
...
@@ -52,11 +53,14 @@ int main(int argc, char *argv[])
ret
=
1
;
ret
=
1
;
goto
out
;
goto
out
;
}
}
c
->
save_config
(
c
,
NULL
);
c
->
save_config
(
c
,
NULL
);
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
...
@@ -92,12 +96,14 @@ int main(int argc, char *argv[])
...
@@ -92,12 +96,14 @@ int main(int argc, char *argv[])
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
}
}
c2
=
lxc_container_new
(
"clonetest-o1"
,
NULL
);
c2
=
lxc_container_new
(
"clonetest-o1"
,
NULL
);
if
(
c2
)
{
if
(
c2
)
{
if
(
c2
->
is_defined
(
c2
))
if
(
c2
->
is_defined
(
c2
))
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
}
}
c2
=
lxc_container_new
(
"clonetest-o2"
,
NULL
);
c2
=
lxc_container_new
(
"clonetest-o2"
,
NULL
);
if
(
c2
)
{
if
(
c2
)
{
if
(
c2
->
is_defined
(
c2
))
if
(
c2
->
is_defined
(
c2
))
...
@@ -112,6 +118,7 @@ int main(int argc, char *argv[])
...
@@ -112,6 +118,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"failed loading clonetestlvm1
\n
"
);
fprintf
(
stderr
,
"failed loading clonetestlvm1
\n
"
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
fprintf
(
stderr
,
"clonetestlvm1 does not exist, skipping lvm tests
\n
"
);
fprintf
(
stderr
,
"clonetestlvm1 does not exist, skipping lvm tests
\n
"
);
ret
=
0
;
ret
=
0
;
...
@@ -138,6 +145,7 @@ int main(int argc, char *argv[])
...
@@ -138,6 +145,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"lvm clone failed
\n
"
);
fprintf
(
stderr
,
"lvm clone failed
\n
"
);
goto
out
;
goto
out
;
}
}
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
c
=
c2
=
NULL
;
c
=
c2
=
NULL
;
...
@@ -166,13 +174,16 @@ out:
...
@@ -166,13 +174,16 @@ out:
if
(
c3
)
{
if
(
c3
)
{
lxc_container_put
(
c3
);
lxc_container_put
(
c3
);
}
}
if
(
c2
)
{
if
(
c2
)
{
c2
->
destroy
(
c2
);
c2
->
destroy
(
c2
);
lxc_container_put
(
c2
);
lxc_container_put
(
c2
);
}
}
if
(
c
)
{
if
(
c
)
{
c
->
destroy
(
c
);
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/concurrent.c
View file @
9b937486
This diff is collapsed.
Click to expand it.
src/tests/config_jump_table.c
View file @
9b937486
...
@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
...
@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
for
(
key
=
strtok_r
(
keys
,
"
\n
"
,
&
saveptr
);
key
!=
NULL
;
for
(
key
=
strtok_r
(
keys
,
"
\n
"
,
&
saveptr
);
key
!=
NULL
;
key
=
strtok_r
(
NULL
,
"
\n
"
,
&
saveptr
))
{
key
=
strtok_r
(
NULL
,
"
\n
"
,
&
saveptr
))
{
struct
lxc_config_t
*
config
;
struct
lxc_config_t
*
config
;
config
=
lxc_get_config
(
key
);
config
=
lxc_get_config
(
key
);
if
(
!
config
)
{
if
(
!
config
)
{
lxc_error
(
"configuration key
\"
%s
\"
not implemented in "
lxc_error
(
"configuration key
\"
%s
\"
not implemented in "
...
@@ -90,5 +91,4 @@ on_error:
...
@@ -90,5 +91,4 @@ on_error:
free
(
keys
);
free
(
keys
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/console.c
View file @
9b937486
...
@@ -46,6 +46,7 @@ static void test_console_close_all(int ttyfd[MAXCONSOLES],
...
@@ -46,6 +46,7 @@ static void test_console_close_all(int ttyfd[MAXCONSOLES],
close
(
masterfd
[
i
]);
close
(
masterfd
[
i
]);
masterfd
[
i
]
=
-
1
;
masterfd
[
i
]
=
-
1
;
}
}
if
(
ttyfd
[
i
]
!=
-
1
)
{
if
(
ttyfd
[
i
]
!=
-
1
)
{
close
(
ttyfd
[
i
]);
close
(
ttyfd
[
i
]);
ttyfd
[
i
]
=
-
1
;
ttyfd
[
i
]
=
-
1
;
...
@@ -64,11 +65,13 @@ static int test_console_running_container(struct lxc_container *c)
...
@@ -64,11 +65,13 @@ static int test_console_running_container(struct lxc_container *c)
ttynum
[
i
]
=
ttyfd
[
i
]
=
masterfd
[
i
]
=
-
1
;
ttynum
[
i
]
=
ttyfd
[
i
]
=
masterfd
[
i
]
=
-
1
;
ttynum
[
0
]
=
1
;
ttynum
[
0
]
=
1
;
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
masterfd
[
0
]);
ret
=
c
->
console_getfd
(
c
,
&
ttynum
[
0
],
&
masterfd
[
0
]);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
TSTERR
(
"console allocate failed"
);
TSTERR
(
"console allocate failed"
);
goto
err1
;
goto
err1
;
}
}
ttyfd
[
0
]
=
ret
;
ttyfd
[
0
]
=
ret
;
if
(
ttynum
[
0
]
!=
1
)
{
if
(
ttynum
[
0
]
!=
1
)
{
TSTERR
(
"console allocate got bad ttynum %d"
,
ttynum
[
0
]);
TSTERR
(
"console allocate got bad ttynum %d"
,
ttynum
[
0
]);
...
@@ -94,16 +97,20 @@ static int test_console_running_container(struct lxc_container *c)
...
@@ -94,16 +97,20 @@ static int test_console_running_container(struct lxc_container *c)
break
;
break
;
ttyfd
[
nrconsoles
]
=
ret
;
ttyfd
[
nrconsoles
]
=
ret
;
}
}
if
(
nrconsoles
!=
TTYCNT
)
{
if
(
nrconsoles
!=
TTYCNT
)
{
TSTERR
(
"didn't allocate all consoles %d != %d"
,
nrconsoles
,
TTYCNT
);
TSTERR
(
"didn't allocate all consoles %d != %d"
,
nrconsoles
,
TTYCNT
);
goto
err2
;
goto
err2
;
}
}
test_console_close_all
(
ttyfd
,
masterfd
);
test_console_close_all
(
ttyfd
,
masterfd
);
}
}
ret
=
0
;
ret
=
0
;
err2:
err2:
test_console_close_all
(
ttyfd
,
masterfd
);
test_console_close_all
(
ttyfd
,
masterfd
);
err1:
err1:
return
ret
;
return
ret
;
}
}
...
@@ -135,20 +142,24 @@ static int test_console(const char *lxcpath,
...
@@ -135,20 +142,24 @@ static int test_console(const char *lxcpath,
TSTERR
(
"instantiating container %s"
,
name
);
TSTERR
(
"instantiating container %s"
,
name
);
goto
out1
;
goto
out1
;
}
}
if
(
c
->
is_defined
(
c
))
{
if
(
c
->
is_defined
(
c
))
{
c
->
stop
(
c
);
c
->
stop
(
c
);
c
->
destroy
(
c
);
c
->
destroy
(
c
);
c
=
lxc_container_new
(
name
,
lxcpath
);
c
=
lxc_container_new
(
name
,
lxcpath
);
}
}
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
TSTERR
(
"creating container %s"
,
name
);
TSTERR
(
"creating container %s"
,
name
);
goto
out2
;
goto
out2
;
}
}
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
c
->
set_config_item
(
c
,
"lxc.tty.max"
,
TTYCNT_STR
);
c
->
set_config_item
(
c
,
"lxc.tty.max"
,
TTYCNT_STR
);
c
->
set_config_item
(
c
,
"lxc.pty.max"
,
"1024"
);
c
->
set_config_item
(
c
,
"lxc.pty.max"
,
"1024"
);
c
->
save_config
(
c
,
NULL
);
c
->
save_config
(
c
,
NULL
);
c
->
want_daemonize
(
c
,
true
);
c
->
want_daemonize
(
c
,
true
);
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
TSTERR
(
"starting container %s"
,
name
);
TSTERR
(
"starting container %s"
,
name
);
goto
out3
;
goto
out3
;
...
@@ -157,10 +168,13 @@ static int test_console(const char *lxcpath,
...
@@ -157,10 +168,13 @@ static int test_console(const char *lxcpath,
ret
=
test_console_running_container
(
c
);
ret
=
test_console_running_container
(
c
);
c
->
stop
(
c
);
c
->
stop
(
c
);
out3:
out3:
c
->
destroy
(
c
);
c
->
destroy
(
c
);
out2:
out2:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
out1:
out1:
return
ret
;
return
ret
;
}
}
...
@@ -168,6 +182,7 @@ out1:
...
@@ -168,6 +182,7 @@ out1:
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
ret
;
int
ret
;
ret
=
test_console
(
NULL
,
NULL
,
TSTNAME
,
"busybox"
);
ret
=
test_console
(
NULL
,
NULL
,
TSTNAME
,
"busybox"
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
err1
;
goto
err1
;
...
@@ -175,7 +190,9 @@ int main(int argc, char *argv[])
...
@@ -175,7 +190,9 @@ int main(int argc, char *argv[])
ret
=
test_console
(
"/var/lib/lxctest2"
,
NULL
,
TSTNAME
,
"busybox"
);
ret
=
test_console
(
"/var/lib/lxctest2"
,
NULL
,
TSTNAME
,
"busybox"
);
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
err1
;
goto
err1
;
printf
(
"All tests passed
\n
"
);
printf
(
"All tests passed
\n
"
);
err1:
err1:
return
ret
;
return
ret
;
}
}
src/tests/containertests.c
View file @
9b937486
...
@@ -39,10 +39,12 @@ static int destroy_busybox(void)
...
@@ -39,10 +39,12 @@ static int destroy_busybox(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -51,12 +53,15 @@ again:
...
@@ -51,12 +53,15 @@ again:
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -69,10 +74,12 @@ static int create_busybox(void)
...
@@ -69,10 +74,12 @@ static int create_busybox(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -81,12 +88,15 @@ again:
...
@@ -81,12 +88,15 @@ again:
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -99,25 +109,30 @@ int main(int argc, char *argv[])
...
@@ -99,25 +109,30 @@ int main(int argc, char *argv[])
char
*
str
;
char
*
str
;
ret
=
1
;
ret
=
1
;
/* test refcounting */
/* test refcounting */
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"%d: error creating lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: error creating lxc_container %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
}
}
if
(
!
lxc_container_get
(
c
))
{
if
(
!
lxc_container_get
(
c
))
{
fprintf
(
stderr
,
"%d: error getting refcount
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: error getting refcount
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
/* peek in, inappropriately, make sure refcount is a we'd like */
/* peek in, inappropriately, make sure refcount is a we'd like */
if
(
c
->
numthreads
!=
2
)
{
if
(
c
->
numthreads
!=
2
)
{
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
2
);
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
2
);
goto
out
;
goto
out
;
}
}
if
(
strcmp
(
c
->
name
,
MYNAME
)
!=
0
)
{
if
(
strcmp
(
c
->
name
,
MYNAME
)
!=
0
)
{
fprintf
(
stderr
,
"%d: container has wrong name (%s not %s)
\n
"
,
__LINE__
,
c
->
name
,
MYNAME
);
fprintf
(
stderr
,
"%d: container has wrong name (%s not %s)
\n
"
,
__LINE__
,
c
->
name
,
MYNAME
);
goto
out
;
goto
out
;
}
}
str
=
c
->
config_file_name
(
c
);
str
=
c
->
config_file_name
(
c
);
#define CONFIGFNAM LXCPATH "/" MYNAME "/config"
#define CONFIGFNAM LXCPATH "/" MYNAME "/config"
if
(
!
str
||
strcmp
(
str
,
CONFIGFNAM
))
{
if
(
!
str
||
strcmp
(
str
,
CONFIGFNAM
))
{
...
@@ -127,19 +142,23 @@ int main(int argc, char *argv[])
...
@@ -127,19 +142,23 @@ int main(int argc, char *argv[])
free
(
str
);
free
(
str
);
free
(
c
->
configfile
);
free
(
c
->
configfile
);
c
->
configfile
=
NULL
;
c
->
configfile
=
NULL
;
str
=
c
->
config_file_name
(
c
);
str
=
c
->
config_file_name
(
c
);
if
(
str
)
{
if
(
str
)
{
fprintf
(
stderr
,
"%d: config file name was not NULL as it should have been
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: config file name was not NULL as it should have been
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
lxc_container_put
(
c
)
!=
0
)
{
if
(
lxc_container_put
(
c
)
!=
0
)
{
fprintf
(
stderr
,
"%d: c was freed on non-final put
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: c was freed on non-final put
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
if
(
c
->
numthreads
!=
1
)
{
if
(
c
->
numthreads
!=
1
)
{
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
1
);
fprintf
(
stderr
,
"%d: refcount is %d, not %d
\n
"
,
__LINE__
,
c
->
numthreads
,
1
);
goto
out
;
goto
out
;
}
}
if
(
lxc_container_put
(
c
)
!=
1
)
{
if
(
lxc_container_put
(
c
)
!=
1
)
{
fprintf
(
stderr
,
"%d: c was not freed on final put
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: c was not freed on final put
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -202,9 +221,11 @@ int main(int argc, char *argv[])
...
@@ -202,9 +221,11 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: lxc_get_wait_states gave %d not %d
\n
"
,
__LINE__
,
numstates
,
MAX_STATE
);
fprintf
(
stderr
,
"%d: lxc_get_wait_states gave %d not %d
\n
"
,
__LINE__
,
numstates
,
MAX_STATE
);
goto
out
;
goto
out
;
}
}
const
char
**
sstr
=
malloc
(
numstates
*
sizeof
(
const
char
*
));
const
char
**
sstr
=
malloc
(
numstates
*
sizeof
(
const
char
*
));
numstates
=
lxc_get_wait_states
(
sstr
);
numstates
=
lxc_get_wait_states
(
sstr
);
int
i
;
int
i
;
for
(
i
=
0
;
i
<
numstates
;
i
++
)
{
for
(
i
=
0
;
i
<
numstates
;
i
++
)
{
fprintf
(
stderr
,
"got state %d %s
\n
"
,
i
,
sstr
[
i
]);
fprintf
(
stderr
,
"got state %d %s
\n
"
,
i
,
sstr
[
i
]);
}
}
...
@@ -237,6 +258,7 @@ out:
...
@@ -237,6 +258,7 @@ out:
c
->
stop
(
c
);
c
->
stop
(
c
);
destroy_busybox
();
destroy_busybox
();
}
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/createtest.c
View file @
9b937486
...
@@ -48,8 +48,10 @@ int main(int argc, char *argv[])
...
@@ -48,8 +48,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a trusty container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -63,6 +65,7 @@ int main(int argc, char *argv[])
...
@@ -63,6 +65,7 @@ int main(int argc, char *argv[])
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
c
->
want_daemonize
(
c
,
true
);
c
->
want_daemonize
(
c
,
true
);
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
...
@@ -85,6 +88,7 @@ int main(int argc, char *argv[])
...
@@ -85,6 +88,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/criu_check_feature.c
View file @
9b937486
...
@@ -86,5 +86,6 @@ on_error_put:
...
@@ -86,5 +86,6 @@ on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All criu feature check tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All criu feature check tests passed"
);
exit
(
ret
);
exit
(
ret
);
}
}
src/tests/destroytest.c
View file @
9b937486
...
@@ -37,24 +37,30 @@ static int create_container(void)
...
@@ -37,24 +37,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -96,6 +102,7 @@ int main(int argc, char *argv[])
...
@@ -96,6 +102,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/device_add_remove.c
View file @
9b937486
...
@@ -50,6 +50,7 @@ int main(int argc, char *argv[])
...
@@ -50,6 +50,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"Adding %s to the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
fprintf
(
stderr
,
"Adding %s to the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
remove_device_node
(
c
,
DEVICE
,
DEVICE
))
{
if
(
!
c
->
remove_device_node
(
c
,
DEVICE
,
DEVICE
))
{
fprintf
(
stderr
,
"Removing %s from the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
fprintf
(
stderr
,
"Removing %s from the container (%s) failed...
\n
"
,
DEVICE
,
NAME
);
goto
out
;
goto
out
;
...
@@ -64,6 +65,7 @@ int main(int argc, char *argv[])
...
@@ -64,6 +65,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"Destroying the container (%s) failed...
\n
"
,
NAME
);
fprintf
(
stderr
,
"Destroying the container (%s) failed...
\n
"
,
NAME
);
goto
out
;
goto
out
;
}
}
ret
=
0
;
ret
=
0
;
out:
out:
...
...
src/tests/get_item.c
View file @
9b937486
This diff is collapsed.
Click to expand it.
src/tests/getkeys.c
View file @
9b937486
...
@@ -51,6 +51,7 @@ int main(int argc, char *argv[])
...
@@ -51,6 +51,7 @@ int main(int argc, char *argv[])
ret
=
1
;
ret
=
1
;
goto
out
;
goto
out
;
}
}
ret
=
c
->
get_keys
(
c
,
NULL
,
v3
,
len
+
1
);
ret
=
c
->
get_keys
(
c
,
NULL
,
v3
,
len
+
1
);
if
(
ret
!=
len
)
{
if
(
ret
!=
len
)
{
fprintf
(
stderr
,
"%d: failed to get keys (%d)
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: failed to get keys (%d)
\n
"
,
__LINE__
,
ret
);
...
...
src/tests/list.c
View file @
9b937486
...
@@ -31,17 +31,21 @@ static void test_list_func(const char *lxcpath, const char *type,
...
@@ -31,17 +31,21 @@ static void test_list_func(const char *lxcpath, const char *type,
char
**
names
;
char
**
names
;
printf
(
"%-10s Counting containers
\n
"
,
type
);
printf
(
"%-10s Counting containers
\n
"
,
type
);
n
=
func
(
lxcpath
,
NULL
,
NULL
);
n
=
func
(
lxcpath
,
NULL
,
NULL
);
printf
(
"%-10s Counted %d containers
\n
"
,
type
,
n
);
printf
(
"%-10s Counted %d containers
\n
"
,
type
,
n
);
printf
(
"%-10s Get container struct only
\n
"
,
type
);
printf
(
"%-10s Get container struct only
\n
"
,
type
);
n2
=
func
(
lxcpath
,
NULL
,
&
clist
);
n2
=
func
(
lxcpath
,
NULL
,
&
clist
);
if
(
n2
!=
n
)
if
(
n2
!=
n
)
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
struct
lxc_container
*
c
=
clist
[
i
];
struct
lxc_container
*
c
=
clist
[
i
];
printf
(
"%-10s Got container struct %s
\n
"
,
type
,
c
->
name
);
printf
(
"%-10s Got container struct %s
\n
"
,
type
,
c
->
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
if
(
n2
>
0
)
{
if
(
n2
>
0
)
{
free
(
clist
);
free
(
clist
);
clist
=
NULL
;
clist
=
NULL
;
...
@@ -51,10 +55,12 @@ static void test_list_func(const char *lxcpath, const char *type,
...
@@ -51,10 +55,12 @@ static void test_list_func(const char *lxcpath, const char *type,
n2
=
func
(
lxcpath
,
&
names
,
NULL
);
n2
=
func
(
lxcpath
,
&
names
,
NULL
);
if
(
n2
!=
n
)
if
(
n2
!=
n
)
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
printf
(
"%-10s Got container name %s
\n
"
,
type
,
names
[
i
]);
printf
(
"%-10s Got container name %s
\n
"
,
type
,
names
[
i
]);
free
(
names
[
i
]);
free
(
names
[
i
]);
}
}
if
(
n2
>
0
)
{
if
(
n2
>
0
)
{
free
(
names
);
free
(
names
);
names
=
NULL
;
names
=
NULL
;
...
@@ -64,14 +70,18 @@ static void test_list_func(const char *lxcpath, const char *type,
...
@@ -64,14 +70,18 @@ static void test_list_func(const char *lxcpath, const char *type,
n2
=
func
(
lxcpath
,
&
names
,
&
clist
);
n2
=
func
(
lxcpath
,
&
names
,
&
clist
);
if
(
n2
!=
n
)
if
(
n2
!=
n
)
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
printf
(
"Warning: first call returned %d, second %d
\n
"
,
n
,
n2
);
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
for
(
i
=
0
;
i
<
n2
;
i
++
)
{
struct
lxc_container
*
c
=
clist
[
i
];
struct
lxc_container
*
c
=
clist
[
i
];
printf
(
"%-10s Got container struct %s, name %s
\n
"
,
type
,
c
->
name
,
names
[
i
]);
printf
(
"%-10s Got container struct %s, name %s
\n
"
,
type
,
c
->
name
,
names
[
i
]);
if
(
strcmp
(
c
->
name
,
names
[
i
]))
if
(
strcmp
(
c
->
name
,
names
[
i
]))
fprintf
(
stderr
,
"ERROR: name mismatch!
\n
"
);
fprintf
(
stderr
,
"ERROR: name mismatch!
\n
"
);
free
(
names
[
i
]);
free
(
names
[
i
]);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
if
(
n2
>
0
)
{
if
(
n2
>
0
)
{
free
(
names
);
free
(
names
);
free
(
clist
);
free
(
clist
);
...
...
src/tests/locktests.c
View file @
9b937486
...
@@ -38,39 +38,49 @@ static void test_two_locks(void)
...
@@ -38,39 +38,49 @@ static void test_two_locks(void)
if
(
pipe
(
p
)
<
0
)
if
(
pipe
(
p
)
<
0
)
exit
(
1
);
exit
(
1
);
if
((
pid
=
fork
())
<
0
)
if
((
pid
=
fork
())
<
0
)
exit
(
1
);
exit
(
1
);
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
if
(
read
(
p
[
0
],
&
c
,
1
)
<
0
)
{
if
(
read
(
p
[
0
],
&
c
,
1
)
<
0
)
{
perror
(
"read"
);
perror
(
"read"
);
exit
(
1
);
exit
(
1
);
}
}
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
if
(
!
l
)
{
if
(
!
l
)
{
fprintf
(
stderr
,
"%d: child: failed to create lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: child: failed to create lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
if
(
lxclock
(
l
,
0
)
<
0
)
{
if
(
lxclock
(
l
,
0
)
<
0
)
{
fprintf
(
stderr
,
"%d: child: failed to grab lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: child: failed to grab lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
fprintf
(
stderr
,
"%d: child: grabbed lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: child: grabbed lock
\n
"
,
__LINE__
);
exit
(
0
);
exit
(
0
);
}
}
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
l
=
lxc_newlock
(
"/tmp"
,
"lxctest-sem"
);
if
(
!
l
)
{
if
(
!
l
)
{
fprintf
(
stderr
,
"%d: failed to create lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
if
(
lxclock
(
l
,
0
)
<
0
)
{
if
(
lxclock
(
l
,
0
)
<
0
)
{
fprintf
(
stderr
,
"%d; failed to get lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d; failed to get lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
if
(
write
(
p
[
1
],
"a"
,
1
)
<
0
)
{
if
(
write
(
p
[
1
],
"a"
,
1
)
<
0
)
{
perror
(
"write"
);
perror
(
"write"
);
exit
(
1
);
exit
(
1
);
}
}
sleep
(
3
);
sleep
(
3
);
ret
=
waitpid
(
pid
,
&
status
,
WNOHANG
);
ret
=
waitpid
(
pid
,
&
status
,
WNOHANG
);
if
(
ret
==
pid
)
{
// task exited
if
(
ret
==
pid
)
{
// task exited
if
(
WIFEXITED
(
status
))
{
if
(
WIFEXITED
(
status
))
{
...
@@ -85,6 +95,7 @@ static void test_two_locks(void)
...
@@ -85,6 +95,7 @@ static void test_two_locks(void)
perror
(
"waitpid"
);
perror
(
"waitpid"
);
exit
(
1
);
exit
(
1
);
}
}
kill
(
pid
,
SIGKILL
);
kill
(
pid
,
SIGKILL
);
wait
(
&
status
);
wait
(
&
status
);
close
(
p
[
1
]);
close
(
p
[
1
]);
...
@@ -103,6 +114,7 @@ int main(int argc, char *argv[])
...
@@ -103,6 +114,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to get unnamed lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to get unnamed lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
ret
=
lxclock
(
lock
,
0
);
ret
=
lxclock
(
lock
,
0
);
if
(
ret
)
{
if
(
ret
)
{
fprintf
(
stderr
,
"%d: failed to take unnamed lock (%d)
\n
"
,
__LINE__
,
ret
);
fprintf
(
stderr
,
"%d: failed to take unnamed lock (%d)
\n
"
,
__LINE__
,
ret
);
...
@@ -121,8 +133,10 @@ int main(int argc, char *argv[])
...
@@ -121,8 +133,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to get lock
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to get lock
\n
"
,
__LINE__
);
exit
(
1
);
exit
(
1
);
}
}
struct
stat
sb
;
struct
stat
sb
;
char
*
pathname
=
RUNTIME_PATH
"/lxc/lock/var/lib/lxc/"
;
char
*
pathname
=
RUNTIME_PATH
"/lxc/lock/var/lib/lxc/"
;
ret
=
stat
(
pathname
,
&
sb
);
ret
=
stat
(
pathname
,
&
sb
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%d: filename %s not created
\n
"
,
__LINE__
,
fprintf
(
stderr
,
"%d: filename %s not created
\n
"
,
__LINE__
,
...
...
src/tests/lxc-test-utils.c
View file @
9b937486
...
@@ -49,6 +49,7 @@ void test_lxc_deslashify(void)
...
@@ -49,6 +49,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A/B/C/D/E"
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A/B/C/D/E"
)
==
0
);
free
(
t
);
free
(
t
);
...
@@ -57,6 +58,7 @@ void test_lxc_deslashify(void)
...
@@ -57,6 +58,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A"
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A"
)
==
0
);
free
(
t
);
free
(
t
);
...
@@ -64,6 +66,7 @@ void test_lxc_deslashify(void)
...
@@ -64,6 +66,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
""
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
""
)
==
0
);
free
(
t
);
free
(
t
);
...
@@ -72,6 +75,7 @@ void test_lxc_deslashify(void)
...
@@ -72,6 +75,7 @@ void test_lxc_deslashify(void)
t
=
lxc_deslashify
(
s
);
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
if
(
!
t
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/"
)
==
0
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/"
)
==
0
);
free
(
t
);
free
(
t
);
}
}
...
@@ -188,6 +192,7 @@ void test_detect_ramfs_rootfs(void)
...
@@ -188,6 +192,7 @@ void test_detect_ramfs_rootfs(void)
for
(
i
=
0
;
i
<
sizeof
(
mountinfo
)
/
sizeof
(
mountinfo
[
0
]);
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
mountinfo
)
/
sizeof
(
mountinfo
[
0
]);
i
++
)
{
if
(
strcmp
(
mountinfo
[
i
],
"24 0 8:2 / / rw - rootfs rootfs rw,size=1004396k,nr_inodes=251099"
)
==
0
)
if
(
strcmp
(
mountinfo
[
i
],
"24 0 8:2 / / rw - rootfs rootfs rw,size=1004396k,nr_inodes=251099"
)
==
0
)
continue
;
continue
;
if
(
fprintf
(
fp2
,
"%s
\n
"
,
mountinfo
[
i
])
<
0
)
{
if
(
fprintf
(
fp2
,
"%s
\n
"
,
mountinfo
[
i
])
<
0
)
{
lxc_error
(
"Could not write
\"
%s
\"
to temporary file."
,
mountinfo
[
i
]);
lxc_error
(
"Could not write
\"
%s
\"
to temporary file."
,
mountinfo
[
i
]);
goto
non_test_error
;
goto
non_test_error
;
...
@@ -217,6 +222,7 @@ non_test_error:
...
@@ -217,6 +222,7 @@ non_test_error:
fclose
(
fp1
);
fclose
(
fp1
);
else
if
(
fd1
>
0
)
else
if
(
fd1
>
0
)
close
(
fd1
);
close
(
fd1
);
if
(
fp2
)
if
(
fp2
)
fclose
(
fp2
);
fclose
(
fp2
);
else
if
(
fd2
>
0
)
else
if
(
fd2
>
0
)
...
@@ -229,8 +235,10 @@ non_test_error:
...
@@ -229,8 +235,10 @@ non_test_error:
}
}
close
(
init_ns
);
close
(
init_ns
);
}
}
if
(
fret
==
EXIT_SUCCESS
)
if
(
fret
==
EXIT_SUCCESS
)
return
;
return
;
exit
(
fret
);
exit
(
fret
);
}
}
...
@@ -246,11 +254,13 @@ void test_lxc_safe_uint(void)
...
@@ -246,11 +254,13 @@ void test_lxc_safe_uint(void)
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
numstr
,
&
n
))
&&
n
==
UINT_MAX
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
numstr
,
&
n
))
&&
n
==
UINT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
+
1
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
UINT_MAX
+
1
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_uint
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
lxc_test_assert_abort
((
0
==
lxc_safe_uint
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
...
@@ -277,21 +287,25 @@ void test_lxc_safe_int(void)
...
@@ -277,21 +287,25 @@ void test_lxc_safe_int(void)
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MAX
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MAX
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
+
1
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRIu64
,
(
uint64_t
)
INT_MAX
+
1
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MIN
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
numstr
,
&
n
))
&&
n
==
INT_MIN
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
-
1
);
ret
=
snprintf
(
numstr
,
LXC_NUMSTRLEN64
,
"%"
PRId64
,
(
int64_t
)
INT_MIN
-
1
);
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
if
(
ret
<
0
||
ret
>=
LXC_NUMSTRLEN64
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
-
ERANGE
==
lxc_safe_int
(
numstr
,
&
n
)));
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
lxc_test_assert_abort
((
0
==
lxc_safe_int
(
"1234345"
,
&
n
))
&&
n
==
1234345
);
...
@@ -394,6 +408,7 @@ void test_parse_byte_size_string(void)
...
@@ -394,6 +408,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
0
)
{
if
(
n
!=
0
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
0
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -404,6 +419,7 @@ void test_parse_byte_size_string(void)
...
@@ -404,6 +419,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1
)
{
if
(
n
!=
1
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -420,6 +436,7 @@ void test_parse_byte_size_string(void)
...
@@ -420,6 +436,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1
)
{
if
(
n
!=
1
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -430,6 +447,7 @@ void test_parse_byte_size_string(void)
...
@@ -430,6 +447,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1024
)
{
if
(
n
!=
1024
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -440,6 +458,7 @@ void test_parse_byte_size_string(void)
...
@@ -440,6 +458,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1048576
)
{
if
(
n
!=
1048576
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -456,6 +475,7 @@ void test_parse_byte_size_string(void)
...
@@ -456,6 +475,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1
)
{
if
(
n
!=
1
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 B
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -466,6 +486,7 @@ void test_parse_byte_size_string(void)
...
@@ -466,6 +486,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1024
)
{
if
(
n
!=
1024
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 kB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -476,6 +497,7 @@ void test_parse_byte_size_string(void)
...
@@ -476,6 +497,7 @@ void test_parse_byte_size_string(void)
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
n
!=
1048576
)
{
if
(
n
!=
1048576
)
{
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to parse
\"
1 MB
\"
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -503,8 +525,10 @@ void test_lxc_config_net_hwaddr(void)
...
@@ -503,8 +525,10 @@ void test_lxc_config_net_hwaddr(void)
if
(
lxc_config_net_hwaddr
(
"lxc.net"
))
if
(
lxc_config_net_hwaddr
(
"lxc.net"
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net."
))
if
(
lxc_config_net_hwaddr
(
"lxc.net."
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net.0."
))
if
(
lxc_config_net_hwaddr
(
"lxc.net.0."
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
...
src/tests/lxc_raw_clone.c
View file @
9b937486
...
@@ -125,6 +125,7 @@ int main(int argc, char *argv[])
...
@@ -125,6 +125,7 @@ int main(int argc, char *argv[])
flags
|=
CLONE_NEWIPC
;
flags
|=
CLONE_NEWIPC
;
flags
|=
CLONE_NEWPID
;
flags
|=
CLONE_NEWPID
;
flags
|=
CLONE_NEWUTS
;
flags
|=
CLONE_NEWUTS
;
pid
=
lxc_raw_clone
(
flags
);
pid
=
lxc_raw_clone
(
flags
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
lxc_error
(
"%s
\n
"
,
"Failed to call lxc_raw_clone(CLONE_NEWUSER "
lxc_error
(
"%s
\n
"
,
"Failed to call lxc_raw_clone(CLONE_NEWUSER "
...
@@ -172,7 +173,6 @@ int main(int argc, char *argv[])
...
@@ -172,7 +173,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
...
@@ -190,7 +190,6 @@ int main(int argc, char *argv[])
...
@@ -190,7 +190,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -208,7 +207,6 @@ int main(int argc, char *argv[])
...
@@ -208,7 +207,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_SUCCESS)"
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
...
@@ -226,7 +224,6 @@ int main(int argc, char *argv[])
...
@@ -226,7 +224,6 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
lxc_error
(
"%s
\n
"
,
"Child will exit(EXIT_FAILURE)"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
...
src/tests/lxcpath.c
View file @
9b937486
...
@@ -44,6 +44,7 @@ int main()
...
@@ -44,6 +44,7 @@ int main()
TSTERR
(
"create using default path"
);
TSTERR
(
"create using default path"
);
goto
err
;
goto
err
;
}
}
p1
=
c
->
get_config_path
(
c
);
p1
=
c
->
get_config_path
(
c
);
p2
=
c
->
config_file_name
(
c
);
p2
=
c
->
config_file_name
(
c
);
if
(
!
p1
||
!
p2
||
strncmp
(
p1
,
p2
,
strlen
(
p1
)))
{
if
(
!
p1
||
!
p2
||
strncmp
(
p1
,
p2
,
strlen
(
p1
)))
{
...
@@ -57,6 +58,7 @@ int main()
...
@@ -57,6 +58,7 @@ int main()
TSTERR
(
"Error setting custom path"
);
TSTERR
(
"Error setting custom path"
);
goto
err
;
goto
err
;
}
}
p1
=
c
->
get_config_path
(
c
);
p1
=
c
->
get_config_path
(
c
);
p2
=
c
->
config_file_name
(
c
);
p2
=
c
->
config_file_name
(
c
);
if
(
strcmp
(
p1
,
CPATH
)
||
strcmp
(
p2
,
FPATH
))
{
if
(
strcmp
(
p1
,
CPATH
)
||
strcmp
(
p2
,
FPATH
))
{
...
...
src/tests/may_control.c
View file @
9b937486
...
@@ -35,12 +35,16 @@ int main(int argc, char *argv[])
...
@@ -35,12 +35,16 @@ int main(int argc, char *argv[])
if
(
argc
<
2
)
if
(
argc
<
2
)
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
name
=
argv
[
1
];
name
=
argv
[
1
];
if
(
argc
==
3
)
if
(
argc
==
3
)
lxcpath
=
argv
[
2
];
lxcpath
=
argv
[
2
];
c
=
lxc_container_new
(
name
,
lxcpath
);
c
=
lxc_container_new
(
name
,
lxcpath
);
if
(
c
)
if
(
c
)
may
=
c
->
may_control
(
c
);
may
=
c
->
may_control
(
c
);
printf
(
"You may%s control %s
\n
"
,
may
?
""
:
" not"
,
name
);
printf
(
"You may%s control %s
\n
"
,
may
?
""
:
" not"
,
name
);
exit
(
may
?
0
:
1
);
exit
(
may
?
0
:
1
);
}
}
src/tests/reboot.c
View file @
9b937486
...
@@ -41,6 +41,7 @@ static int do_reboot(void *arg)
...
@@ -41,6 +41,7 @@ static int do_reboot(void *arg)
if
(
reboot
(
*
cmd
))
if
(
reboot
(
*
cmd
))
printf
(
"failed to reboot(%d): %s
\n
"
,
*
cmd
,
strerror
(
errno
));
printf
(
"failed to reboot(%d): %s
\n
"
,
*
cmd
,
strerror
(
errno
));
return
0
;
return
0
;
}
}
...
@@ -65,6 +66,7 @@ static int test_reboot(int cmd, int sig)
...
@@ -65,6 +66,7 @@ static int test_reboot(int cmd, int sig)
if
(
!
WIFSIGNALED
(
status
))
{
if
(
!
WIFSIGNALED
(
status
))
{
if
(
sig
!=
-
1
)
if
(
sig
!=
-
1
)
printf
(
"child process exited but was not signaled
\n
"
);
printf
(
"child process exited but was not signaled
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -89,9 +91,11 @@ static int have_reboot_patch(void)
...
@@ -89,9 +91,11 @@ static int have_reboot_patch(void)
fclose
(
f
);
fclose
(
f
);
if
(
ret
!=
1
)
if
(
ret
!=
1
)
return
0
;
return
0
;
ret
=
reboot
(
v
?
LINUX_REBOOT_CMD_CAD_ON
:
LINUX_REBOOT_CMD_CAD_OFF
);
ret
=
reboot
(
v
?
LINUX_REBOOT_CMD_CAD_ON
:
LINUX_REBOOT_CMD_CAD_OFF
);
if
(
ret
!=
-
1
)
if
(
ret
!=
-
1
)
return
0
;
return
0
;
return
1
;
return
1
;
}
}
...
...
src/tests/saveconfig.c
View file @
9b937486
...
@@ -37,24 +37,30 @@ static int create_container(void)
...
@@ -37,24 +37,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -90,6 +96,7 @@ int main(int argc, char *argv[])
...
@@ -90,6 +96,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed writing config file /tmp/lxctest1
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed writing config file /tmp/lxctest1
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
rename
(
LXCPATH
"/"
MYNAME
"/config"
,
LXCPATH
"/"
MYNAME
"/config.bak"
);
rename
(
LXCPATH
"/"
MYNAME
"/config"
,
LXCPATH
"/"
MYNAME
"/config.bak"
);
if
(
!
c
->
save_config
(
c
,
NULL
))
{
if
(
!
c
->
save_config
(
c
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed writing config file
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed writing config file
\n
"
,
__LINE__
);
...
@@ -108,6 +115,7 @@ int main(int argc, char *argv[])
...
@@ -108,6 +115,7 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/shortlived.c
View file @
9b937486
...
@@ -46,10 +46,12 @@ static int destroy_container(void)
...
@@ -46,10 +46,12 @@ static int destroy_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
...
@@ -58,12 +60,15 @@ again:
...
@@ -58,12 +60,15 @@ again:
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -76,24 +81,30 @@ static int create_container(void)
...
@@ -76,24 +81,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -124,6 +135,7 @@ int main(int argc, char *argv[])
...
@@ -124,6 +135,7 @@ int main(int argc, char *argv[])
log
.
prefix
=
"shortlived"
;
log
.
prefix
=
"shortlived"
;
log
.
quiet
=
false
;
log
.
quiet
=
false
;
log
.
lxcpath
=
NULL
;
log
.
lxcpath
=
NULL
;
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
@@ -256,11 +268,13 @@ out:
...
@@ -256,11 +268,13 @@ out:
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
char
buf
[
4096
];
char
buf
[
4096
];
ssize_t
buflen
;
ssize_t
buflen
;
while
((
buflen
=
read
(
fd
,
buf
,
1024
))
>
0
)
{
while
((
buflen
=
read
(
fd
,
buf
,
1024
))
>
0
)
{
buflen
=
write
(
STDERR_FILENO
,
buf
,
buflen
);
buflen
=
write
(
STDERR_FILENO
,
buf
,
buflen
);
if
(
buflen
<=
0
)
if
(
buflen
<=
0
)
break
;
break
;
}
}
close
(
fd
);
close
(
fd
);
}
}
}
}
...
...
src/tests/shutdowntest.c
View file @
9b937486
...
@@ -49,8 +49,10 @@ int main(int argc, char *argv[])
...
@@ -49,8 +49,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to set network type
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
}
}
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.link"
,
"lxcbr0"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
c
->
set_config_item
(
c
,
"lxc.net.0.flags"
,
"up"
);
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: failed to create a container
\n
"
,
__LINE__
);
goto
out
;
goto
out
;
...
@@ -64,6 +66,7 @@ int main(int argc, char *argv[])
...
@@ -64,6 +66,7 @@ int main(int argc, char *argv[])
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
c
->
want_daemonize
(
c
,
true
);
c
->
want_daemonize
(
c
,
true
);
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to start %s
\n
"
,
__LINE__
,
MYNAME
);
goto
out
;
goto
out
;
...
@@ -74,9 +77,9 @@ int main(int argc, char *argv[])
...
@@ -74,9 +77,9 @@ int main(int argc, char *argv[])
if
(
!
c
->
shutdown
(
c
,
120
))
{
if
(
!
c
->
shutdown
(
c
,
120
))
{
fprintf
(
stderr
,
"%d: failed to shut down %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to shut down %s
\n
"
,
__LINE__
,
MYNAME
);
if
(
!
c
->
stop
(
c
))
{
if
(
!
c
->
stop
(
c
))
fprintf
(
stderr
,
"%d: failed to kill %s
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: failed to kill %s
\n
"
,
__LINE__
,
MYNAME
);
}
goto
out
;
goto
out
;
}
}
...
@@ -92,10 +95,10 @@ int main(int argc, char *argv[])
...
@@ -92,10 +95,10 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
fprintf
(
stderr
,
"all lxc_container tests passed for %s
\n
"
,
c
->
name
);
ret
=
0
;
ret
=
0
;
out:
out:
if
(
c
&&
c
->
is_defined
(
c
))
{
if
(
c
&&
c
->
is_defined
(
c
))
c
->
destroy
(
c
);
c
->
destroy
(
c
);
}
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
ret
);
exit
(
ret
);
...
...
src/tests/snapshot.c
View file @
9b937486
...
@@ -32,23 +32,28 @@
...
@@ -32,23 +32,28 @@
static
void
try_to_remove
(
void
)
static
void
try_to_remove
(
void
)
{
{
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
c
=
lxc_container_new
(
RESTNAME
,
NULL
);
c
=
lxc_container_new
(
RESTNAME
,
NULL
);
if
(
c
)
{
if
(
c
)
{
c
->
snapshot_destroy_all
(
c
);
c
->
snapshot_destroy_all
(
c
);
if
(
c
->
is_defined
(
c
))
if
(
c
->
is_defined
(
c
))
c
->
destroy
(
c
);
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
c
=
lxc_container_new
(
MYNAME2
,
NULL
);
c
=
lxc_container_new
(
MYNAME2
,
NULL
);
if
(
c
)
{
if
(
c
)
{
c
->
destroy_with_snapshots
(
c
);
c
->
destroy_with_snapshots
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
c
)
{
if
(
c
)
{
c
->
snapshot_destroy_all
(
c
);
c
->
snapshot_destroy_all
(
c
);
if
(
c
->
is_defined
(
c
))
if
(
c
->
is_defined
(
c
))
c
->
destroy
(
c
);
c
->
destroy
(
c
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
}
}
}
}
...
@@ -66,6 +71,7 @@ int main(int argc, char *argv[])
...
@@ -66,6 +71,7 @@ int main(int argc, char *argv[])
template
=
argv
[
1
];
template
=
argv
[
1
];
try_to_remove
();
try_to_remove
();
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"%s: %d: failed to load first container
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed to load first container
\n
"
,
__FILE__
,
__LINE__
);
...
@@ -76,15 +82,19 @@ int main(int argc, char *argv[])
...
@@ -76,15 +82,19 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%d: %s thought it was defined
\n
"
,
__LINE__
,
MYNAME
);
fprintf
(
stderr
,
"%d: %s thought it was defined
\n
"
,
__LINE__
,
MYNAME
);
(
void
)
c
->
destroy_with_snapshots
(
c
);
(
void
)
c
->
destroy_with_snapshots
(
c
);
}
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.type"
,
"empty"
))
{
if
(
!
c
->
set_config_item
(
c
,
"lxc.net.0.type"
,
"empty"
))
{
fprintf
(
stderr
,
"%s: %d: failed to set network type
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed to set network type
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
c
->
save_config
(
c
,
NULL
);
c
->
save_config
(
c
,
NULL
);
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
if
(
!
c
->
createl
(
c
,
template
,
NULL
,
NULL
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%s: %d: failed to create %s container
\n
"
,
__FILE__
,
__LINE__
,
template
);
fprintf
(
stderr
,
"%s: %d: failed to create %s container
\n
"
,
__FILE__
,
__LINE__
,
template
);
goto
err
;
goto
err
;
}
}
c
->
load_config
(
c
,
NULL
);
c
->
load_config
(
c
,
NULL
);
if
(
c
->
snapshot
(
c
,
NULL
)
!=
0
)
{
if
(
c
->
snapshot
(
c
,
NULL
)
!=
0
)
{
...
@@ -110,13 +120,14 @@ int main(int argc, char *argv[])
...
@@ -110,13 +120,14 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
s
[
i
].
free
(
&
s
[
i
]);
s
[
i
].
free
(
&
s
[
i
]);
}
free
(
s
);
free
(
s
);
if
(
!
c
->
snapshot_restore
(
c
,
"snap0"
,
RESTNAME
))
{
if
(
!
c
->
snapshot_restore
(
c
,
"snap0"
,
RESTNAME
))
{
...
@@ -152,13 +163,14 @@ int main(int argc, char *argv[])
...
@@ -152,13 +163,14 @@ int main(int argc, char *argv[])
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: failed listing containers
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
if
(
strcmp
(
s
->
name
,
"snap0"
)
!=
0
)
{
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
fprintf
(
stderr
,
"%s: %d: snapshot had bad name
\n
"
,
__FILE__
,
__LINE__
);
goto
err
;
goto
err
;
}
}
for
(
i
=
0
;
i
<
n
;
i
++
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
s
[
i
].
free
(
&
s
[
i
]);
s
[
i
].
free
(
&
s
[
i
]);
}
free
(
s
);
free
(
s
);
if
(
!
c2
->
snapshot_restore
(
c2
,
"snap0"
,
NULL
))
{
if
(
!
c2
->
snapshot_restore
(
c2
,
"snap0"
,
NULL
))
{
...
@@ -177,6 +189,7 @@ good:
...
@@ -177,6 +189,7 @@ good:
printf
(
"All tests passed
\n
"
);
printf
(
"All tests passed
\n
"
);
exit
(
0
);
exit
(
0
);
err:
err:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
try_to_remove
();
try_to_remove
();
...
...
src/tests/startone.c
View file @
9b937486
...
@@ -39,24 +39,30 @@ static int destroy_container(void)
...
@@ -39,24 +39,30 @@ static int destroy_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-destroy"
,
"lxc-destroy"
,
"-f"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -69,24 +75,30 @@ static int create_container(void)
...
@@ -69,24 +75,30 @@ static int create_container(void)
perror
(
"fork"
);
perror
(
"fork"
);
return
-
1
;
return
-
1
;
}
}
if
(
pid
==
0
)
{
if
(
pid
==
0
)
{
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
execlp
(
"lxc-create"
,
"lxc-create"
,
"-t"
,
"busybox"
,
"-n"
,
MYNAME
,
NULL
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
again:
again:
ret
=
waitpid
(
pid
,
&
status
,
0
);
ret
=
waitpid
(
pid
,
&
status
,
0
);
if
(
ret
==
-
1
)
{
if
(
ret
==
-
1
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
perror
(
"waitpid"
);
perror
(
"waitpid"
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
!=
pid
)
if
(
ret
!=
pid
)
goto
again
;
goto
again
;
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
if
(
!
WIFEXITED
(
status
))
{
// did not exit normally
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
fprintf
(
stderr
,
"%d: lxc-create exited abnormally
\n
"
,
__LINE__
);
return
-
1
;
return
-
1
;
}
}
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
...
@@ -100,6 +112,7 @@ int main(int argc, char *argv[])
...
@@ -100,6 +112,7 @@ int main(int argc, char *argv[])
int
len
;
int
len
;
ret
=
1
;
ret
=
1
;
/* test a real container */
/* test a real container */
c
=
lxc_container_new
(
MYNAME
,
NULL
);
c
=
lxc_container_new
(
MYNAME
,
NULL
);
if
(
!
c
)
{
if
(
!
c
)
{
...
@@ -167,6 +180,7 @@ int main(int argc, char *argv[])
...
@@ -167,6 +180,7 @@ int main(int argc, char *argv[])
}
}
sleep
(
3
);
sleep
(
3
);
s
=
c
->
state
(
c
);
s
=
c
->
state
(
c
);
if
(
!
s
||
strcmp
(
s
,
"RUNNING"
))
{
if
(
!
s
||
strcmp
(
s
,
"RUNNING"
))
{
fprintf
(
stderr
,
"%d: %s is in state %s, not in RUNNING.
\n
"
,
__LINE__
,
c
->
name
,
s
?
s
:
"undefined"
);
fprintf
(
stderr
,
"%d: %s is in state %s, not in RUNNING.
\n
"
,
__LINE__
,
c
->
name
,
s
?
s
:
"undefined"
);
...
@@ -192,7 +206,7 @@ int main(int argc, char *argv[])
...
@@ -192,7 +206,7 @@ int main(int argc, char *argv[])
goto
out
;
goto
out
;
}
}
sprintf
(
buf
,
"XXX"
);
sprintf
(
buf
,
"XXX"
);
len
=
c
->
get_cgroup_item
(
c
,
"freezer.state"
,
buf
,
200
);
len
=
c
->
get_cgroup_item
(
c
,
"freezer.state"
,
buf
,
200
);
if
(
len
<=
0
||
(
strcmp
(
buf
,
"FREEZING
\n
"
)
&&
strcmp
(
buf
,
"FROZEN
\n
"
)))
{
if
(
len
<=
0
||
(
strcmp
(
buf
,
"FREEZING
\n
"
)
&&
strcmp
(
buf
,
"FROZEN
\n
"
)))
{
fprintf
(
stderr
,
"%d: not able to get freezer.state (len %d buf %s)
\n
"
,
__LINE__
,
len
,
buf
);
fprintf
(
stderr
,
"%d: not able to get freezer.state (len %d buf %s)
\n
"
,
__LINE__
,
len
,
buf
);
...
...
src/tests/state_server.c
View file @
9b937486
...
@@ -149,5 +149,6 @@ on_error_put:
...
@@ -149,5 +149,6 @@ on_error_put:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All state server tests passed"
);
lxc_debug
(
"%s
\n
"
,
"All state server tests passed"
);
exit
(
ret
);
exit
(
ret
);
}
}
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