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
77f76f31
Unverified
Commit
77f76f31
authored
Dec 06, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: expand tests for shortlived init processes
This adds additional test for app containers. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
fa30091b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
11 deletions
+108
-11
shortlived.c
src/tests/shortlived.c
+108
-11
No files found.
src/tests/shortlived.c
View file @
77f76f31
...
...
@@ -28,6 +28,9 @@
#include <errno.h>
#include <fcntl.h>
#include "lxctest.h"
#include "utils.h"
#define MYNAME "shortlived"
static
int
destroy_container
(
void
)
...
...
@@ -92,12 +95,33 @@ again:
int
main
(
int
argc
,
char
*
argv
[])
{
struct
lxc_container
*
c
;
int
i
;
const
char
*
s
;
bool
b
;
int
i
;
struct
lxc_container
*
c
;
struct
lxc_log
log
;
char
template
[
sizeof
(
P_tmpdir
"/shortlived_XXXXXX"
)];
int
ret
=
0
;
strcpy
(
template
,
P_tmpdir
"/shortlived_XXXXXX"
);
i
=
lxc_make_tmpfile
(
template
,
false
);
if
(
i
<
0
)
{
lxc_error
(
"Failed to create temporary log file for container %s
\n
"
,
MYNAME
);
exit
(
EXIT_FAILURE
);
}
else
{
lxc_debug
(
"Using
\"
%s
\"
as temporary log file for container %s
\n
"
,
template
,
MYNAME
);
close
(
i
);
}
log
.
name
=
MYNAME
;
log
.
file
=
template
;
log
.
level
=
"TRACE"
;
log
.
prefix
=
"shortlived"
;
log
.
quiet
=
false
;
log
.
lxcpath
=
NULL
;
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
ret
=
1
;
/* test a real container */
c
=
lxc_container_new
(
MYNAME
,
NULL
);
...
...
@@ -141,16 +165,51 @@ int main(int argc, char *argv[])
goto
out
;
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.execute.cmd"
,
"echo hello"
))
{
fprintf
(
stderr
,
"%d: failed setting lxc.init.cmd
\n
"
,
__LINE__
);
goto
out
;
}
c
->
want_daemonize
(
c
,
true
);
/* Test whether we can start a really short-lived daemonized container.
*/
/* Test whether we can start a really short-lived daemonized container. */
for
(
i
=
0
;
i
<
10
;
i
++
)
{
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: %s failed to start
\n
"
,
__LINE__
,
c
->
name
);
fprintf
(
stderr
,
"%d: %s failed to start on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
/* The container needs to exit with a successful error code. */
if
(
c
->
error_num
!=
0
)
{
fprintf
(
stderr
,
"%d: %s exited successfully on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
fprintf
(
stderr
,
"%d: %s exited correctly with error code %d on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
c
->
error_num
,
i
);
if
(
!
c
->
wait
(
c
,
"STOPPED"
,
30
))
{
fprintf
(
stderr
,
"%d: %s failed to wait on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
}
/* Test whether we can start a really short-lived daemonized container with lxc-init. */
for
(
i
=
0
;
i
<
10
;
i
++
)
{
if
(
!
c
->
startl
(
c
,
1
,
NULL
))
{
fprintf
(
stderr
,
"%d: %s failed to start on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
/* The container needs to exit with a successful error code. */
if
(
c
->
error_num
!=
0
)
{
fprintf
(
stderr
,
"%d: %s exited successfully on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
fprintf
(
stderr
,
"%d: %s exited correctly with error code %d on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
c
->
error_num
,
i
);
if
(
!
c
->
wait
(
c
,
"STOPPED"
,
30
))
{
fprintf
(
stderr
,
"%d: %s failed to wait on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
sleep
(
1
);
}
if
(
!
c
->
set_config_item
(
c
,
"lxc.init.cmd"
,
"you-shall-fail"
))
{
...
...
@@ -158,15 +217,52 @@ int main(int argc, char *argv[])
goto
out
;
}
/* Test whether we catch the start failure of a really short-lived
* daemonized container.
*/
if
(
!
c
->
set_config_item
(
c
,
"lxc.execute.cmd"
,
"you-shall-fail"
))
{
fprintf
(
stderr
,
"%d: failed setting lxc.init.cmd
\n
"
,
__LINE__
);
goto
out
;
}
/* Test whether we can start a really short-lived daemonized container. */
for
(
i
=
0
;
i
<
10
;
i
++
)
{
if
(
c
->
startl
(
c
,
0
,
NULL
))
{
fprintf
(
stderr
,
"%d: %s failed to start
\n
"
,
__LINE__
,
c
->
name
);
fprintf
(
stderr
,
"%d: %s failed to start on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
/* The container needs to exit with an error code.*/
if
(
c
->
error_num
==
0
)
{
fprintf
(
stderr
,
"%d: %s exited successfully on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
fprintf
(
stderr
,
"%d: %s exited correctly with error code %d on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
c
->
error_num
,
i
);
if
(
!
c
->
wait
(
c
,
"STOPPED"
,
30
))
{
fprintf
(
stderr
,
"%d: %s failed to wait on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
}
/* Test whether we can start a really short-lived daemonized container with lxc-init. */
for
(
i
=
0
;
i
<
10
;
i
++
)
{
/* An container started with lxc-init will always start
* succesfully unless lxc-init has a bug.
*/
if
(
!
c
->
startl
(
c
,
1
,
NULL
))
{
fprintf
(
stderr
,
"%d: %s failed to start on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
/* The container needs to exit with an error code.*/
if
(
c
->
error_num
==
0
)
{
fprintf
(
stderr
,
"%d: %s exited successfully on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
fprintf
(
stderr
,
"%d: %s exited correctly with error code %d on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
c
->
error_num
,
i
);
if
(
!
c
->
wait
(
c
,
"STOPPED"
,
30
))
{
fprintf
(
stderr
,
"%d: %s failed to wait on %dth iteration
\n
"
,
__LINE__
,
c
->
name
,
i
);
goto
out
;
}
sleep
(
1
);
}
c
->
stop
(
c
);
...
...
@@ -180,5 +276,6 @@ out:
destroy_container
();
}
lxc_container_put
(
c
);
unlink
(
template
);
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