提交 b08e986e 编写于 作者: L LiFeng

iSulad: add testcases for specs_extend

Signed-off-by: NLiFeng <lifeng68@huawei.com>
上级 af92f7ea
...@@ -18,8 +18,16 @@ ...@@ -18,8 +18,16 @@
# include "oci_runtime_spec.h" # include "oci_runtime_spec.h"
#ifdef __cplusplus
extern "C" {
#endif
oci_runtime_spec_hooks *oci_runtime_spec_hooks_parse_file(const char *filename, oci_runtime_spec_hooks *oci_runtime_spec_hooks_parse_file(const char *filename,
const struct parser_context *ctx, parser_error *err); const struct parser_context *ctx, parser_error *err);
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -88,6 +88,10 @@ MERGE_HOOKS_ITEM_DEF(poststop) ...@@ -88,6 +88,10 @@ MERGE_HOOKS_ITEM_DEF(poststop)
int merge_hooks(oci_runtime_spec_hooks *dest, oci_runtime_spec_hooks *src) int merge_hooks(oci_runtime_spec_hooks *dest, oci_runtime_spec_hooks *src)
{ {
if (dest == NULL || src == NULL) {
return -1;
}
if (merge_prestart_conf(dest, src) || merge_poststart_conf(dest, src) || merge_poststop_conf(dest, src)) { if (merge_prestart_conf(dest, src) || merge_poststart_conf(dest, src) || merge_poststop_conf(dest, src)) {
return -1; return -1;
} }
......
project(iSulad_LLT) project(iSulad_LLT)
add_subdirectory(specs) add_subdirectory(specs)
add_subdirectory(specs_extend)
project(iSulad_LLT)
SET(EXE specs_extend_llt)
add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_regex.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_verify.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_array.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_string.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_convert.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils/util_atomic.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/log.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256/sha256.c
${CMAKE_BINARY_DIR}/json/json_common.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/path.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec/specs.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec/specs_mount.c
${CMAKE_BINARY_DIR}/json/host_config.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec/specs_extend.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec/specs_security.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/libisulad.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json/oci_runtime_hooks.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json/parse_common.c
${CMAKE_BINARY_DIR}/json/defs.c
${CMAKE_BINARY_DIR}/json/container_config_v2.c
${CMAKE_BINARY_DIR}/json/container_config.c
${CMAKE_BINARY_DIR}/json/oci_runtime_spec.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec/sysinfo.c
${CMAKE_BINARY_DIR}/json/oci_runtime_config_linux.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/commander.c
${CMAKE_BINARY_DIR}/json/isulad_daemon_configs.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json/schema/src/read_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd/isulad/arguments.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/image/oci/oci_llt_common.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/containers_store_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/namespace_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/container_unix_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/engine_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/selinux_label_mock.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/isulad_config_mock.cc
${CMAKE_BINARY_DIR}/json/imagetool_image.c
${CMAKE_BINARY_DIR}/json/oci_image_spec.c
${CMAKE_BINARY_DIR}/json/docker_seccomp.c
specs_extend_llt.cc)
target_include_directories(${EXE} PUBLIC
${GTEST_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/image/oci
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/image
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
${CMAKE_CURRENT_SOURCE_DIR}/../../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/map
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/spec
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/manager
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/events
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/execution/execute
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/tar
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/plugin
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/http
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/engines
${ENGINES_INCS}
${RUNTIME_INCS}
${IMAGE_INCS}
${CMAKE_BINARY_DIR}/json
${CMAKE_BINARY_DIR}/conf
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/sha256
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/config
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cmd
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/services/graphdriver
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/json/schema/src
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/console
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/image/oci
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
{
"prestart": [
{
"path": "/home/hooks/start.bash",
"args": ["arg0", "arg1", "arg2"],
"timeout": 40,
"env": [ "key1=value1"]
}
],
"poststart": [
{
"path": "/home/hooks/post1.bash",
"args": ["arg5", "arg6", "arg7"],
"timeout": 60,
"env": [ "key2=value221"]
},
{
"path": "/home/hooks/post2.bash",
"args": ["arg51", "arg61", "arg71"],
"timeout": 61,
"env": [ "key3=value3"]
}
],
"poststop": [
{
"path": "/home/hooks/stop1.bash",
"args": ["arg11", "arg12", "arg13"],
"timeout": 60,
"env": [ "key2=value221"]
},
{
"path": "/home/hooks/stop2.bash",
"args": ["arg52", "arg62", "arg72"],
"timeout": 62,
"env": [ "key4=value4"]
}
]
}
{
"ShmSize": 67108864,
"RestartPolicy": {
"Name": "no"
}
}
{
"ociVersion": "1.0.0-rc5-dev",
"hooks": {
},
"annotations": {
"log.console.file": "none",
"log.console.filerotate": "7",
"log.console.filesize": "1MB",
"rootfs.mount": "/var/lib/lcrd/mnt/rootfs",
"native.umask": "secure"
},
"hostname": "localhost",
"mounts": [
{
"source": "proc",
"destination": "/proc",
"options": [
"nosuid",
"noexec",
"nodev"
],
"type": "proc"
},
{
"source": "tmpfs",
"destination": "/dev",
"options": [
"nosuid",
"strictatime",
"mode=755",
"size=65536k"
],
"type": "tmpfs"
},
{
"source": "devpts",
"destination": "/dev/pts",
"options": [
"nosuid",
"noexec",
"newinstance",
"ptmxmode=0666",
"mode=0620",
"gid=5"
],
"type": "devpts"
},
{
"source": "sysfs",
"destination": "/sys",
"options": [
"nosuid",
"noexec",
"nodev",
"ro"
],
"type": "sysfs"
},
{
"source": "shm",
"destination": "/dev/shm",
"options": [
"nosuid",
"noexec",
"nodev",
"mode=1777",
"size=67108864"
],
"type": "tmpfs"
},
{
"source": "cgroup",
"destination": "/sys/fs/cgroup",
"options": [
"nosuid",
"noexec",
"nodev",
"ro"
],
"type": "cgroup"
},
{
"source": "mqueue",
"destination": "/dev/mqueue",
"options": [
"nosuid",
"noexec",
"nodev"
],
"type": "mqueue"
},
{
"source": "/var/lib/lcrd/engines/lcr/ad6c3f33518ed7e17a6d889a1327aa386f8b869927e2540821fb02310f567310/hostname",
"destination": "/etc/hostname",
"options": [
"rbind",
"rprivate"
],
"type": "bind"
},
{
"source": "/var/lib/lcrd/engines/lcr/ad6c3f33518ed7e17a6d889a1327aa386f8b869927e2540821fb02310f567310/resolv.conf",
"destination": "/etc/resolv.conf",
"options": [
"rbind",
"rprivate"
],
"type": "bind"
},
{
"source": "/var/lib/lcrd/engines/lcr/ad6c3f33518ed7e17a6d889a1327aa386f8b869927e2540821fb02310f567310/hosts",
"destination": "/etc/hosts",
"options": [
"rbind",
"rprivate"
],
"type": "bind"
}
],
"root": {
"path": "/var/lib/lcrd/storage/overlay/40c51530fc1b4610f7f56633ef78fc5e4ad1a6f14cad59d5a1d012ff800c4289/merged"
},
"process": {
"args": [
"sh"
],
"consoleSize": {
},
"cwd": "/",
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"terminal": true,
"user": {
},
"capabilities": {
"bounding": [
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_FSETID",
"CAP_FOWNER",
"CAP_MKNOD",
"CAP_NET_RAW",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETFCAP",
"CAP_SETPCAP",
"CAP_NET_BIND_SERVICE",
"CAP_SYS_CHROOT",
"CAP_KILL",
"CAP_AUDIT_WRITE"
]
}
},
"linux": {
"namespaces": [
{
"type": "pid"
},
{
"type": "network"
},
{
"type": "ipc"
},
{
"type": "uts"
},
{
"type": "mount"
}
],
"resources": {
"devices": [
{
"type": "a",
"major": -1,
"minor": -1,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": -1,
"minor": -1,
"access": "m"
},
{
"allow": true,
"type": "b",
"major": -1,
"minor": -1,
"access": "m"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 3,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 5,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 7,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 5,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 5,
"minor": 1,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 5,
"minor": 2,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 8,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 1,
"minor": 9,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 136,
"minor": -1,
"access": "rwm"
},
{
"allow": true,
"type": "c",
"major": 10,
"minor": 200,
"access": "rwm"
},
{
"type": "c",
"major": 10,
"minor": 229,
"access": "rwm"
}
]
},
"seccomp": {
"defaultAction": "SCMP_ACT_ERRNO",
"architectures": [
"SCMP_ARCH_X86_64",
"SCMP_ARCH_X86",
"SCMP_ARCH_X32",
"SCMP_ARCH_AARCH64",
"SCMP_ARCH_ARM"
],
"syscalls": [
{
"names": [
"accept",
"accept4",
"access",
"adjtimex",
"alarm",
"bind",
"brk",
"capget",
"capset",
"chdir",
"chmod",
"chown",
"chown32",
"clock_getres",
"clock_gettime",
"clock_nanosleep",
"close",
"connect",
"copy_file_range",
"creat",
"dup",
"dup2",
"dup3",
"epoll_create",
"epoll_create1",
"epoll_ctl",
"epoll_ctl_old",
"epoll_pwait",
"epoll_wait",
"epoll_wait_old",
"eventfd",
"eventfd2",
"execve",
"execveat",
"exit",
"exit_group",
"faccessat",
"fadvise64",
"fadvise64_64",
"fallocate",
"fanotify_mark",
"fchdir",
"fchmod",
"fchmodat",
"fchown",
"fchown32",
"fchownat",
"fcntl",
"fcntl64",
"fdatasync",
"fgetxattr",
"flistxattr",
"flock",
"fork",
"fremovexattr",
"fsetxattr",
"fstat",
"fstat64",
"fstatat64",
"fstatfs",
"fstatfs64",
"fsync",
"ftruncate",
"ftruncate64",
"futex",
"futimesat",
"getcpu",
"getcwd",
"getdents",
"getdents64",
"getegid",
"getegid32",
"geteuid",
"geteuid32",
"getgid",
"getgid32",
"getgroups",
"getgroups32",
"getitimer",
"getpeername",
"getpgid",
"getpgrp",
"getpid",
"getppid",
"getpriority",
"getrandom",
"getresgid",
"getresgid32",
"getresuid",
"getresuid32",
"getrlimit",
"get_robust_list",
"getrusage",
"getsid",
"getsockname",
"getsockopt",
"get_thread_area",
"gettid",
"gettimeofday",
"getuid",
"getuid32",
"getxattr",
"inotify_add_watch",
"inotify_init",
"inotify_init1",
"inotify_rm_watch",
"io_cancel",
"ioctl",
"io_destroy",
"io_getevents",
"ioprio_get",
"ioprio_set",
"io_setup",
"io_submit",
"ipc",
"kill",
"lchown",
"lchown32",
"lgetxattr",
"link",
"linkat",
"listen",
"listxattr",
"llistxattr",
"_llseek",
"lremovexattr",
"lseek",
"lsetxattr",
"lstat",
"lstat64",
"madvise",
"memfd_create",
"mincore",
"mkdir",
"mkdirat",
"mknod",
"mknodat",
"mlock",
"mlock2",
"mlockall",
"mmap",
"mmap2",
"mprotect",
"mq_getsetattr",
"mq_notify",
"mq_open",
"mq_timedreceive",
"mq_timedsend",
"mq_unlink",
"mremap",
"msgctl",
"msgget",
"msgrcv",
"msgsnd",
"msync",
"munlock",
"munlockall",
"munmap",
"nanosleep",
"newfstatat",
"_newselect",
"open",
"openat",
"pause",
"pipe",
"pipe2",
"poll",
"ppoll",
"prctl",
"pread64",
"preadv",
"preadv2",
"prlimit64",
"pselect6",
"pwrite64",
"pwritev",
"pwritev2",
"read",
"readahead",
"readlink",
"readlinkat",
"readv",
"recv",
"recvfrom",
"recvmmsg",
"recvmsg",
"remap_file_pages",
"removexattr",
"rename",
"renameat",
"renameat2",
"restart_syscall",
"rmdir",
"rt_sigaction",
"rt_sigpending",
"rt_sigprocmask",
"rt_sigqueueinfo",
"rt_sigreturn",
"rt_sigsuspend",
"rt_sigtimedwait",
"rt_tgsigqueueinfo",
"sched_getaffinity",
"sched_getattr",
"sched_getparam",
"sched_get_priority_max",
"sched_get_priority_min",
"sched_getscheduler",
"sched_rr_get_interval",
"sched_setaffinity",
"sched_setattr",
"sched_setparam",
"sched_setscheduler",
"sched_yield",
"seccomp",
"select",
"semctl",
"semget",
"semop",
"semtimedop",
"send",
"sendfile",
"sendfile64",
"sendmmsg",
"sendmsg",
"sendto",
"setfsgid",
"setfsgid32",
"setfsuid",
"setfsuid32",
"setgid",
"setgid32",
"setgroups",
"setgroups32",
"setitimer",
"setpgid",
"setpriority",
"setregid",
"setregid32",
"setresgid",
"setresgid32",
"setresuid",
"setresuid32",
"setreuid",
"setreuid32",
"setrlimit",
"set_robust_list",
"setsid",
"setsockopt",
"set_thread_area",
"set_tid_address",
"setuid",
"setuid32",
"setxattr",
"shmat",
"shmctl",
"shmdt",
"shmget",
"shutdown",
"sigaltstack",
"signalfd",
"signalfd4",
"sigreturn",
"socket",
"socketcall",
"socketpair",
"splice",
"stat",
"stat64",
"statfs",
"statfs64",
"statx",
"symlink",
"symlinkat",
"sync",
"sync_file_range",
"syncfs",
"sysinfo",
"tee",
"tgkill",
"time",
"timer_create",
"timer_delete",
"timerfd_create",
"timerfd_gettime",
"timerfd_settime",
"timer_getoverrun",
"timer_gettime",
"timer_settime",
"times",
"tkill",
"truncate",
"truncate64",
"ugetrlimit",
"umask",
"uname",
"unlink",
"unlinkat",
"utime",
"utimensat",
"utimes",
"vfork",
"vmsplice",
"wait4",
"waitid",
"waitpid",
"write",
"writev"
],
"action": "SCMP_ACT_ALLOW"
},
{
"names": [
"ptrace"
],
"action": "SCMP_ACT_ALLOW"
},
{
"names": [
"personality"
],
"action": "SCMP_ACT_ALLOW",
"args": [
{
"op": "SCMP_CMP_EQ"
}
]
},
{
"names": [
"personality"
],
"action": "SCMP_ACT_ALLOW",
"args": [
{
"value": 8,
"op": "SCMP_CMP_EQ"
}
]
},
{
"names": [
"personality"
],
"action": "SCMP_ACT_ALLOW",
"args": [
{
"value": 131072,
"op": "SCMP_CMP_EQ"
}
]
},
{
"names": [
"personality"
],
"action": "SCMP_ACT_ALLOW",
"args": [
{
"value": 131080,
"op": "SCMP_CMP_EQ"
}
]
},
{
"names": [
"personality"
],
"action": "SCMP_ACT_ALLOW",
"args": [
{
"value": 4294967295,
"op": "SCMP_CMP_EQ"
}
]
},
{
"names": [
"arm_fadvise64_64",
"arm_sync_file_range",
"sync_file_range2",
"breakpoint",
"cacheflush",
"set_tls"
],
"action": "SCMP_ACT_ALLOW"
},
{
"names": [
"arch_prctl"
],
"action": "SCMP_ACT_ALLOW"
},
{
"names": [
"modify_ldt"
],
"action": "SCMP_ACT_ALLOW"
},
{
"names": [
"clone"
],
"action": "SCMP_ACT_ALLOW",
"args": [
{
"value": 2080505856,
"op": "SCMP_CMP_MASKED_EQ"
}
]
},
{
"names": [
"chroot"
],
"action": "SCMP_ACT_ALLOW"
}
]
},
"maskedPaths": [
"/proc/acpi",
"/proc/config.gz",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/proc/signo",
"/proc/sig_catch",
"/proc/kbox",
"/proc/oom_extend",
"/proc/fdthreshold",
"/proc/fdstat",
"/proc/fdenable",
"/proc/files_panic_enable",
"/sys/firmware",
"/proc/cpuirqstat",
"/proc/memstat",
"/proc/iomem_ext",
"/proc/livepatch"
],
"readonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger",
"/proc/sysrq-region-size"
]
}
}
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v1.
* You can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
* Description: specs extend llt
* Author: lifeng
* Create: 2020-02-18
*/
#include <stdlib.h>
#include <stdio.h>
#include <gtest/gtest.h>
#include "mock.h"
#include "oci_runtime_spec.h"
#include "specs.h"
#include "host_config.h"
#include "container_config.h"
#include "oci_llt_common.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "isulad_config_mock.h"
#include "oci_runtime_hooks.h"
#include "utils.h"
#include "specs_extend.h"
using ::testing::Args;
using ::testing::ByRef;
using ::testing::SetArgPointee;
using ::testing::DoAll;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::NotNull;
using ::testing::AtLeast;
using ::testing::Invoke;
using ::testing::_;
using namespace std;
#define HOOKS_CONFIG_FILE "specs/specs_extend/hooks.json"
TEST(make_sure_oci_spec_linux_llt, test_make_sure_oci_spec_linux)
{
oci_runtime_spec *oci_spec = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
ASSERT_EQ(make_sure_oci_spec_linux(oci_spec), 0);
ASSERT_TRUE(oci_spec->linux != NULL);
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(make_sure_oci_spec_process_llt, test_make_sure_oci_spec_process)
{
oci_runtime_spec *oci_spec = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
ASSERT_EQ(make_sure_oci_spec_process(oci_spec), 0);
ASSERT_TRUE(oci_spec->process != NULL);
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(make_sure_oci_spec_linux_resources_llt, test_make_sure_oci_spec_linux_resources)
{
oci_runtime_spec *oci_spec = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
ASSERT_EQ(make_sure_oci_spec_linux_resources(oci_spec), 0);
ASSERT_TRUE(oci_spec->linux != NULL);
ASSERT_TRUE(oci_spec->linux->resources != NULL);
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(make_sure_oci_spec_linux_resources_blkio_llt, test_make_sure_oci_spec_linux_resources_blkio)
{
oci_runtime_spec *oci_spec = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
ASSERT_EQ(make_sure_oci_spec_linux_resources_blkio(oci_spec), 0);
ASSERT_TRUE(oci_spec->linux != NULL);
ASSERT_TRUE(oci_spec->linux->resources != NULL);
ASSERT_TRUE(oci_spec->linux->resources->block_io != NULL);
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(merge_hooks_llt, test_merge_hooks_invalid)
{
ASSERT_NE(merge_hooks(nullptr, nullptr), 0);
}
TEST(merge_hooks_llt, test_merge_hooks_llt_2)
{
oci_runtime_spec *oci_spec = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks));
ASSERT_NE(merge_hooks(oci_spec->hooks, NULL), 0);
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(merge_hooks_llt, test_merge_hooks_llt_3)
{
char *hooks_config_file = NULL;
oci_runtime_spec_hooks *hooks_spec = NULL;
char *err = NULL;
hooks_config_file = json_path(HOOKS_CONFIG_FILE);
ASSERT_TRUE(hooks_config_file != NULL);
hooks_spec = oci_runtime_spec_hooks_parse_file(hooks_config_file, NULL, &err);
ASSERT_TRUE(hooks_spec != NULL);
free(err);
err = NULL;
free(hooks_config_file);
hooks_config_file = NULL;
ASSERT_NE(merge_hooks(NULL, hooks_spec), 0);
free_oci_runtime_spec_hooks(hooks_spec);
hooks_spec = NULL;
}
TEST(merge_hooks_llt, test_merge_hooks_llt_4)
{
char *hooks_config_file = NULL;
oci_runtime_spec_hooks *hooks_spec = NULL;
oci_runtime_spec *oci_spec = NULL;
char *err = NULL;
// All parameter correct
hooks_config_file = json_path(HOOKS_CONFIG_FILE);
ASSERT_TRUE(hooks_config_file != NULL);
hooks_spec = oci_runtime_spec_hooks_parse_file(hooks_config_file, NULL, &err);
ASSERT_TRUE(hooks_spec != NULL);
free(err);
err = NULL;
free(hooks_config_file);
hooks_config_file = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks));
ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0);
free_oci_runtime_spec_hooks(hooks_spec);
hooks_spec = NULL;
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(merge_hooks_llt, test_merge_hooks_llt_prestart)
{
char *hooks_config_file = NULL;
oci_runtime_spec_hooks *hooks_spec = NULL;
oci_runtime_spec *oci_spec = NULL;
char *err = NULL;
// All parameter correct
hooks_config_file = json_path(HOOKS_CONFIG_FILE);
ASSERT_TRUE(hooks_config_file != NULL);
hooks_spec = oci_runtime_spec_hooks_parse_file(hooks_config_file, NULL, &err);
ASSERT_TRUE(hooks_spec != NULL);
free(err);
err = NULL;
free(hooks_config_file);
hooks_config_file = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks));
ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0);
ASSERT_EQ(oci_spec->hooks->prestart_len, 1);
ASSERT_STREQ(oci_spec->hooks->prestart[0]->path, "/home/hooks/start.bash");
ASSERT_EQ(oci_spec->hooks->prestart[0]->args_len, 3);
ASSERT_STREQ(oci_spec->hooks->prestart[0]->args[0], "arg0");
ASSERT_STREQ(oci_spec->hooks->prestart[0]->args[1], "arg1");
ASSERT_STREQ(oci_spec->hooks->prestart[0]->args[2], "arg2");
ASSERT_EQ(oci_spec->hooks->prestart[0]->env_len, 1);
ASSERT_STREQ(oci_spec->hooks->prestart[0]->env[0], "key1=value1");
ASSERT_EQ(oci_spec->hooks->prestart[0]->timeout, 40);
free_oci_runtime_spec_hooks(hooks_spec);
hooks_spec = NULL;
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(merge_hooks_llt, test_merge_hooks_llt_poststart)
{
char *hooks_config_file = NULL;
oci_runtime_spec_hooks *hooks_spec = NULL;
oci_runtime_spec *oci_spec = NULL;
char *err = NULL;
// All parameter correct
hooks_config_file = json_path(HOOKS_CONFIG_FILE);
ASSERT_TRUE(hooks_config_file != NULL);
hooks_spec = oci_runtime_spec_hooks_parse_file(hooks_config_file, NULL, &err);
ASSERT_TRUE(hooks_spec != NULL);
free(err);
err = NULL;
free(hooks_config_file);
hooks_config_file = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks));
ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0);
ASSERT_EQ(oci_spec->hooks->poststart_len, 2);
ASSERT_STREQ(oci_spec->hooks->poststart[0]->path, "/home/hooks/post1.bash");
ASSERT_EQ(oci_spec->hooks->poststart[0]->args_len, 3);
ASSERT_STREQ(oci_spec->hooks->poststart[0]->args[0], "arg5");
ASSERT_STREQ(oci_spec->hooks->poststart[0]->args[1], "arg6");
ASSERT_STREQ(oci_spec->hooks->poststart[0]->args[2], "arg7");
ASSERT_EQ(oci_spec->hooks->poststart[0]->env_len, 1);
ASSERT_STREQ(oci_spec->hooks->poststart[0]->env[0], "key2=value221");
ASSERT_EQ(oci_spec->hooks->poststart[0]->timeout, 60);
ASSERT_STREQ(oci_spec->hooks->poststart[1]->path, "/home/hooks/post2.bash");
ASSERT_EQ(oci_spec->hooks->poststart[1]->args_len, 3);
ASSERT_STREQ(oci_spec->hooks->poststart[1]->args[0], "arg51");
ASSERT_STREQ(oci_spec->hooks->poststart[1]->args[1], "arg61");
ASSERT_STREQ(oci_spec->hooks->poststart[1]->args[2], "arg71");
ASSERT_EQ(oci_spec->hooks->poststart[1]->env_len, 1);
ASSERT_STREQ(oci_spec->hooks->poststart[1]->env[0], "key3=value3");
ASSERT_EQ(oci_spec->hooks->poststart[1]->timeout, 61);
free_oci_runtime_spec_hooks(hooks_spec);
hooks_spec = NULL;
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
TEST(merge_hooks_llt, test_merge_hooks_llt_poststop)
{
char *hooks_config_file = NULL;
oci_runtime_spec_hooks *hooks_spec = NULL;
oci_runtime_spec *oci_spec = NULL;
char *err = NULL;
// All parameter correct
hooks_config_file = json_path(HOOKS_CONFIG_FILE);
ASSERT_TRUE(hooks_config_file != NULL);
hooks_spec = oci_runtime_spec_hooks_parse_file(hooks_config_file, NULL, &err);
ASSERT_TRUE(hooks_spec != NULL);
free(err);
err = NULL;
free(hooks_config_file);
hooks_config_file = NULL;
oci_spec = (oci_runtime_spec *) util_common_calloc_s(sizeof(oci_runtime_spec));
ASSERT_TRUE(oci_spec != NULL);
oci_spec->hooks = (oci_runtime_spec_hooks*)util_common_calloc_s(sizeof(oci_runtime_spec_hooks));
ASSERT_EQ(merge_hooks(oci_spec->hooks, hooks_spec), 0);
ASSERT_EQ(oci_spec->hooks->poststop_len, 2);
ASSERT_STREQ(oci_spec->hooks->poststop[0]->path, "/home/hooks/stop1.bash");
ASSERT_EQ(oci_spec->hooks->poststop[0]->args_len, 3);
ASSERT_STREQ(oci_spec->hooks->poststop[0]->args[0], "arg11");
ASSERT_STREQ(oci_spec->hooks->poststop[0]->args[1], "arg12");
ASSERT_STREQ(oci_spec->hooks->poststop[0]->args[2], "arg13");
ASSERT_EQ(oci_spec->hooks->poststop[0]->env_len, 1);
ASSERT_STREQ(oci_spec->hooks->poststop[0]->env[0], "key2=value221");
ASSERT_EQ(oci_spec->hooks->poststop[0]->timeout, 60);
ASSERT_STREQ(oci_spec->hooks->poststop[1]->path, "/home/hooks/stop2.bash");
ASSERT_EQ(oci_spec->hooks->poststop[1]->args_len, 3);
ASSERT_STREQ(oci_spec->hooks->poststop[1]->args[0], "arg52");
ASSERT_STREQ(oci_spec->hooks->poststop[1]->args[1], "arg62");
ASSERT_STREQ(oci_spec->hooks->poststop[1]->args[2], "arg72");
ASSERT_EQ(oci_spec->hooks->poststop[1]->env_len, 1);
ASSERT_STREQ(oci_spec->hooks->poststop[1]->env[0], "key4=value4");
ASSERT_EQ(oci_spec->hooks->poststop[1]->timeout, 62);
free_oci_runtime_spec_hooks(hooks_spec);
hooks_spec = NULL;
free_oci_runtime_spec(oci_spec);
oci_spec = NULL;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册