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
2aa12318
Commit
2aa12318
authored
Oct 01, 2013
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add reboot test
It's really more of a kernel check, but worth having. Signed-off-by:
Serge Hallyn
<
serge.hallyn@ubuntu.com
>
parent
8111adfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
1 deletion
+142
-1
Makefile.am
src/tests/Makefile.am
+3
-1
reboot.c
src/tests/reboot.c
+139
-0
No files found.
src/tests/Makefile.am
View file @
2aa12318
...
@@ -20,6 +20,7 @@ lxc_usernic_test_CFLAGS = -DISTEST
...
@@ -20,6 +20,7 @@ lxc_usernic_test_CFLAGS = -DISTEST
lxc_test_snapshot_SOURCES
=
snapshot.c
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
AM_CFLAGS
=
-I
$(top_srcdir)
/src
\
AM_CFLAGS
=
-I
$(top_srcdir)
/src
\
-DLXCROOTFSMOUNT
=
\"
$(LXCROOTFSMOUNT)
\"
\
-DLXCROOTFSMOUNT
=
\"
$(LXCROOTFSMOUNT)
\"
\
...
@@ -32,7 +33,8 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
...
@@ -32,7 +33,8 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
lxc-test-destroytest lxc-test-saveconfig lxc-test-createtest
\
lxc-test-destroytest lxc-test-saveconfig lxc-test-createtest
\
lxc-test-shutdowntest lxc-test-get_item lxc-test-getkeys lxc-test-lxcpath
\
lxc-test-shutdowntest lxc-test-get_item lxc-test-getkeys lxc-test-lxcpath
\
lxc-test-cgpath lxc-test-clonetest lxc-test-console lxc-usernic-test
\
lxc-test-cgpath lxc-test-clonetest lxc-test-console lxc-usernic-test
\
lxc-test-snapshot lxc-test-concurrent lxc-test-may-control
lxc-test-snapshot lxc-test-concurrent lxc-test-may-control
\
lxc-test-reboot
bin_SCRIPTS
=
lxc-test-usernic
bin_SCRIPTS
=
lxc-test-usernic
...
...
src/tests/reboot.c
0 → 100644
View file @
2aa12318
/*
* Copyright 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
* Copyright 2012 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; 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 <sys/reboot.h>
#include <sys/types.h>
#include <sys/wait.h>
#define _GNU_SOURCE
#include <sched.h>
#include <linux/sched.h>
#include <linux/reboot.h>
int
clone
(
int
(
*
fn
)(
void
*
),
void
*
child_stack
,
int
flags
,
void
*
arg
);
static
int
do_reboot
(
void
*
arg
)
{
int
*
cmd
=
arg
;
if
(
reboot
(
*
cmd
))
printf
(
"failed to reboot(%d): %m
\n
"
,
*
cmd
);
return
0
;
}
int
test_reboot
(
int
cmd
,
int
sig
)
{
long
stack_size
=
4096
;
void
*
stack
=
alloca
(
stack_size
)
+
stack_size
;
int
status
;
pid_t
ret
;
ret
=
clone
(
do_reboot
,
stack
,
CLONE_NEWPID
|
SIGCHLD
,
&
cmd
);
if
(
ret
<
0
)
{
printf
(
"failed to clone: %m
\n
"
);
return
-
1
;
}
if
(
wait
(
&
status
)
<
0
)
{
printf
(
"unexpected wait error: %m
\n
"
);
return
-
1
;
}
if
(
!
WIFSIGNALED
(
status
))
{
if
(
sig
!=
-
1
)
printf
(
"child process exited but was not signaled
\n
"
);
return
-
1
;
}
if
(
WTERMSIG
(
status
)
!=
sig
)
{
printf
(
"signal termination is not the one expected
\n
"
);
return
-
1
;
}
return
0
;
}
static
int
have_reboot_patch
(
void
)
{
FILE
*
f
=
fopen
(
"/proc/sys/kernel/ctrl-alt-del"
,
"r"
);
int
ret
;
int
v
;
if
(
!
f
)
return
0
;
ret
=
fscanf
(
f
,
"%d"
,
&
v
);
fclose
(
f
);
if
(
ret
!=
1
)
return
0
;
ret
=
reboot
(
v
?
LINUX_REBOOT_CMD_CAD_ON
:
LINUX_REBOOT_CMD_CAD_OFF
);
if
(
ret
!=
-
1
)
return
0
;
return
1
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
status
;
if
(
getuid
()
!=
0
)
{
printf
(
"Must run as root.
\n
"
);
return
1
;
}
status
=
have_reboot_patch
();
if
(
status
!=
0
)
{
printf
(
"Your kernel does not have the container reboot patch
\n
"
);
return
1
;
}
status
=
test_reboot
(
LINUX_REBOOT_CMD_CAD_ON
,
-
1
);
if
(
status
>=
0
)
{
printf
(
"reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed
\n
"
);
return
1
;
}
printf
(
"reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected
\n
"
);
status
=
test_reboot
(
LINUX_REBOOT_CMD_RESTART
,
SIGHUP
);
if
(
status
<
0
)
return
1
;
printf
(
"reboot(LINUX_REBOOT_CMD_RESTART) succeed
\n
"
);
status
=
test_reboot
(
LINUX_REBOOT_CMD_RESTART2
,
SIGHUP
);
if
(
status
<
0
)
return
1
;
printf
(
"reboot(LINUX_REBOOT_CMD_RESTART2) succeed
\n
"
);
status
=
test_reboot
(
LINUX_REBOOT_CMD_HALT
,
SIGINT
);
if
(
status
<
0
)
return
1
;
printf
(
"reboot(LINUX_REBOOT_CMD_HALT) succeed
\n
"
);
status
=
test_reboot
(
LINUX_REBOOT_CMD_POWER_OFF
,
SIGINT
);
if
(
status
<
0
)
return
1
;
printf
(
"reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed
\n
"
);
printf
(
"All tests passed
\n
"
);
return
0
;
}
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