freeze: add freeze_thaw test
Change-Id: I31db80b89adca9ac354a96ad21073b269d8a0e24
This commit is contained in:
committed by
Masamichi Takagi
parent
83ade5cdcd
commit
ec31d72483
25
test/freeze_thaw/cmd/Makefile
Normal file
25
test/freeze_thaw/cmd/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
# Makefile COPYRIGHT FUJITSU LIMITED 2019
|
||||
CC=$(CROSS_COMPILE)gcc
|
||||
CPPFLAGS:=$(CPPFLAGS) -I/usr/local/include/ihk -I/usr/local/include/ihk
|
||||
CFLAGS:=-O0 -ggdb3 -Wall
|
||||
LDFLAGS:=
|
||||
|
||||
all: helloworld fork pthread_create freeze thaw
|
||||
|
||||
helloworld: helloworld.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) helloworld.c -o helloworld
|
||||
|
||||
fork: fork.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) fork.c -o fork
|
||||
|
||||
pthread_create: pthread_create.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lpthread pthread_create.c -o pthread_create
|
||||
|
||||
freeze: freeze.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) freeze.c -o freeze
|
||||
|
||||
thaw: thaw.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) thaw.c -o thaw
|
||||
|
||||
clean:
|
||||
rm -rf helloworld fork pthread_create freeze thaw
|
||||
54
test/freeze_thaw/cmd/fork.c
Normal file
54
test/freeze_thaw/cmd/fork.c
Normal file
@ -0,0 +1,54 @@
|
||||
/* fork.c COPYRIGHT FUJITSU LIMITED 2019 */
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void waitChildren(void)
|
||||
{
|
||||
for (;;) {
|
||||
int status = 0;
|
||||
pid_t pid = wait(&status);
|
||||
|
||||
if (pid == -1) {
|
||||
const char msg[] = "wait fail\n";
|
||||
|
||||
if (errno == ECHILD) {
|
||||
return;
|
||||
} else if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
write(STDERR_FILENO, msg, sizeof(msg));
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
int nr_fork;
|
||||
int i;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <nr_fork>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
nr_fork = atoi(argv[1]);
|
||||
|
||||
for (i = 0; i < nr_fork; i++) {
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
ret = -1;
|
||||
break;
|
||||
} else if (pid == 0) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
waitChildren();
|
||||
return ret;
|
||||
}
|
||||
44
test/freeze_thaw/cmd/freeze.c
Normal file
44
test/freeze_thaw/cmd/freeze.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* freeze.c COPYRIGHT FUJITSU LIMITED 2019 */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "ihk_host_user.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
int fd = -1;
|
||||
char dev[128];
|
||||
int mcosid;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage %s <osnum>\n", argv[0]);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
mcosid = atoi(argv[1]);
|
||||
|
||||
sprintf(dev, "/dev/mcos%d", mcosid);
|
||||
fd = open(dev, O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open /dev/mcosN");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, IHK_OS_FREEZE, 0);
|
||||
if (ret) {
|
||||
perror("ioctl(freeze)");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
15
test/freeze_thaw/cmd/helloworld.c
Normal file
15
test/freeze_thaw/cmd/helloworld.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int num;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <num>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
num = atoi(argv[1]);
|
||||
printf("hello world[%d]\n", num);
|
||||
return 0;
|
||||
}
|
||||
49
test/freeze_thaw/cmd/pthread_create.c
Normal file
49
test/freeze_thaw/cmd/pthread_create.c
Normal file
@ -0,0 +1,49 @@
|
||||
/* pthread_create.c COPYRIGHT FUJITSU LIMITED 2019 */
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define MAX_THREAD 1000
|
||||
static pthread_t thread[MAX_THREAD];
|
||||
|
||||
static void *child_thread(void *arg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
int nr_thread;
|
||||
int i, j;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage: %s <nr_thread>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
nr_thread = atoi(argv[1]);
|
||||
if (nr_thread >= MAX_THREAD) {
|
||||
printf("err: MAX_THREAD=%d\n", MAX_THREAD);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < nr_thread; i++) {
|
||||
ret = pthread_create(&thread[i], NULL, child_thread, NULL);
|
||||
if (ret) {
|
||||
perror("pthread_create");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
int join = pthread_join(thread[j], NULL);
|
||||
|
||||
if (join) {
|
||||
ret = join;
|
||||
perror("pthread_join");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
44
test/freeze_thaw/cmd/thaw.c
Normal file
44
test/freeze_thaw/cmd/thaw.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* thaw.c COPYRIGHT FUJITSU LIMITED 2019 */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "ihk_host_user.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0;
|
||||
int fd = -1;
|
||||
char dev[128];
|
||||
int mcosid;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("usage %s <osnum>\n", argv[0]);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
mcosid = atoi(argv[1]);
|
||||
|
||||
sprintf(dev, "/dev/mcos%d", mcosid);
|
||||
fd = open(dev, O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open /dev/mcosN");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, IHK_OS_THAW, 0);
|
||||
if (ret) {
|
||||
perror("ioctl(thaw)");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user