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
c02c49ee
Unverified
Commit
c02c49ee
authored
Nov 21, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add test for reboot2() API extension
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
d39b10eb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
5 deletions
+129
-5
Makefile.am
src/tests/Makefile.am
+3
-1
api_reboot.c
src/tests/api_reboot.c
+125
-0
livepatch.c
src/tests/livepatch.c
+1
-4
No files found.
src/tests/Makefile.am
View file @
c02c49ee
...
@@ -20,6 +20,7 @@ lxc_test_snapshot_SOURCES = snapshot.c
...
@@ -20,6 +20,7 @@ lxc_test_snapshot_SOURCES = snapshot.c
lxc_test_concurrent_SOURCES
=
concurrent.c
lxc_test_concurrent_SOURCES
=
concurrent.c
lxc_test_may_control_SOURCES
=
may_control.c
lxc_test_may_control_SOURCES
=
may_control.c
lxc_test_reboot_SOURCES
=
reboot.c
lxc_test_reboot_SOURCES
=
reboot.c
lxc_test_api_reboot_SOURCES
=
api_reboot.c
lxc_test_list_SOURCES
=
list.c
lxc_test_list_SOURCES
=
list.c
lxc_test_attach_SOURCES
=
attach.c
lxc_test_attach_SOURCES
=
attach.c
lxc_test_device_add_remove_SOURCES
=
device_add_remove.c
lxc_test_device_add_remove_SOURCES
=
device_add_remove.c
...
@@ -57,7 +58,8 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
...
@@ -57,7 +58,8 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
lxc-test-snapshot lxc-test-concurrent lxc-test-may-control
\
lxc-test-snapshot lxc-test-concurrent lxc-test-may-control
\
lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove
\
lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove
\
lxc-test-apparmor lxc-test-utils lxc-test-parse-config-file
\
lxc-test-apparmor lxc-test-utils lxc-test-parse-config-file
\
lxc-test-config-jump-table lxc-test-shortlived lxc-test-livepatch
lxc-test-config-jump-table lxc-test-shortlived lxc-test-livepatch
\
lxc-test-api-reboot
bin_SCRIPTS
=
lxc-test-automount
\
bin_SCRIPTS
=
lxc-test-automount
\
lxc-test-autostart
\
lxc-test-autostart
\
...
...
src/tests/api_reboot.c
0 → 100644
View file @
c02c49ee
/* liblxcapi
*
* Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <alloca.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <sys/reboot.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "lxc/lxccontainer.h"
#include "lxctest.h"
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
struct
lxc_container
*
c
;
int
ret
=
EXIT_FAILURE
;
/* Test that the reboot() API function properly waits for containers to
* restart.
*/
c
=
lxc_container_new
(
"reboot"
,
NULL
);
if
(
!
c
)
{
lxc_error
(
"%s"
,
"Failed to create container
\"
reboot
\"
"
);
exit
(
ret
);
}
if
(
c
->
is_defined
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Container
\"
reboot
\"
is defined"
);
goto
on_error_put
;
}
if
(
!
c
->
createl
(
c
,
"busybox"
,
NULL
,
NULL
,
0
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to create busybox container
\"
reboot
\"
"
);
goto
on_error_put
;
}
if
(
!
c
->
is_defined
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Container
\"
reboot
\"
is not defined"
);
goto
on_error_put
;
}
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to load config for container
\"
reboot
\"
"
);
goto
on_error_stop
;
}
if
(
!
c
->
want_daemonize
(
c
,
true
))
{
lxc_error
(
"%s
\n
"
,
"Failed to mark container
\"
reboot
\"
daemonized"
);
goto
on_error_stop
;
}
if
(
!
c
->
startl
(
c
,
0
,
NULL
))
{
lxc_error
(
"%s
\n
"
,
"Failed to start container
\"
reboot
\"
daemonized"
);
goto
on_error_stop
;
}
/* reboot 10 times */
for
(
i
=
0
;
i
<
10
;
i
++
)
{
/* Give the init system some time to setup it's signal handlers
* otherwise we will hang indefinitely.
*/
sleep
(
5
);
if
(
!
c
->
reboot2
(
c
,
-
1
))
{
lxc_error
(
"%s
\n
"
,
"Failed to reboot container
\"
reboot
\"
"
);
goto
on_error_stop
;
}
if
(
!
c
->
is_running
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Failed to reboot container
\"
reboot
\"
"
);
goto
on_error_stop
;
}
lxc_debug
(
"%s
\n
"
,
"Container
\"
reboot
\"
rebooted successfully"
);
}
/* Give the init system some time to setup it's signal handlers
* otherwise we will hang indefinitely.
*/
sleep
(
5
);
/* Test non-blocking reboot2() */
if
(
!
c
->
reboot2
(
c
,
0
))
{
lxc_error
(
"%s
\n
"
,
"Failed to request non-blocking reboot of container
\"
reboot
\"
"
);
goto
on_error_stop
;
}
lxc_debug
(
"%s
\n
"
,
"Non-blocking reboot of container
\"
reboot
\"
succeeded"
);
ret
=
EXIT_SUCCESS
;
on_error_stop:
if
(
c
->
is_running
(
c
)
&&
!
c
->
stop
(
c
))
lxc_error
(
"%s
\n
"
,
"Failed to stop container
\"
reboot
\"
"
);
if
(
!
c
->
destroy
(
c
))
lxc_error
(
"%s
\n
"
,
"Failed to destroy container
\"
reboot
\"
"
);
on_error_put:
lxc_container_put
(
c
);
if
(
ret
==
EXIT_SUCCESS
)
lxc_debug
(
"%s
\n
"
,
"All reboot tests passed"
);
exit
(
ret
);
}
src/tests/livepatch.c
View file @
c02c49ee
...
@@ -203,14 +203,11 @@ int main(int argc, char *argv[])
...
@@ -203,14 +203,11 @@ int main(int argc, char *argv[])
}
}
free
(
value
);
free
(
value
);
if
(
!
c
->
reboot
(
c
))
{
if
(
!
c
->
reboot
2
(
c
,
-
1
))
{
lxc_error
(
"%s"
,
"Failed to create container
\"
livepatch
\"
"
);
lxc_error
(
"%s"
,
"Failed to create container
\"
livepatch
\"
"
);
goto
on_error_stop
;
goto
on_error_stop
;
}
}
/* Busybox shouldn't take long to reboot. Sleep for 5s. */
sleep
(
5
);
if
(
!
c
->
is_running
(
c
))
{
if
(
!
c
->
is_running
(
c
))
{
lxc_error
(
"%s
\n
"
,
"Failed to reboot container
\"
livepatch
\"
"
);
lxc_error
(
"%s
\n
"
,
"Failed to reboot container
\"
livepatch
\"
"
);
goto
on_error_destroy
;
goto
on_error_destroy
;
...
...
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