support unit test cases of worker related

This commit is contained in:
Rongsong Shen 2025-11-25 16:52:03 +08:00
parent de090dce35
commit cf425dfa56
11 changed files with 87 additions and 6084 deletions

View file

@ -25,8 +25,8 @@ controller_src = [
incdir = include_directories('.', '../include', '../lib', incdir = include_directories('.', '../include', '../lib',
'include') 'include')
cc = meson.get_compiler('c') # cc = meson.get_compiler('c')
math_dep = cc.find_library('m', required : false) # math_dep = cc.find_library('m', required : false)
controller_deps = [libxce_dep, math_dep] controller_deps = [libxce_dep, math_dep]

View file

@ -33,6 +33,10 @@ endif
include_dir = include_directories('include', 'include/xce') include_dir = include_directories('include', 'include/xce')
cc = meson.get_compiler('c')
math_dep = cc.find_library('m', required: false)
rt_dep = cc.find_library('rt', required: false)
libcjson_dep = dependency('libcjson') libcjson_dep = dependency('libcjson')
libcyaml_dep = dependency('libcyaml') libcyaml_dep = dependency('libcyaml')
libyaml_dep = dependency('yaml-0.1') libyaml_dep = dependency('yaml-0.1')

View file

@ -49,6 +49,7 @@ stdenv.mkDerivation {
unity_test_with_color unity_test_with_color
libcyaml libcyaml
libyaml libyaml
libcgroup
]; ];
build-system = [ pkgs.meson ]; build-system = [ pkgs.meson ];

View file

@ -12,10 +12,11 @@ incdir = include_directories('.', 'include', '../include', '../lib')
libuv_dep = dependency('libuv') libuv_dep = dependency('libuv')
elogind_dep = dependency('libelogind') elogind_dep = dependency('libelogind')
sqlite3_dep = dependency('sqlite3') sqlite3_dep = dependency('sqlite3')
libcgroup_dep = dependency('libcgroup')
xcecd_worker_deps = [ xcecd_worker_deps = [
libxce_dep, libxce_dep,
libcgroup_dep,
libuv_dep, libuv_dep,
elogind_dep, elogind_dep,
sqlite3_dep, sqlite3_dep,
@ -53,7 +54,7 @@ xcecd_srcs = [
'src/xcecd_exdata.c', 'src/xcecd_exdata.c',
'src/xcecd_cgroups.c', 'src/xcecd_cgroups.c',
'src/xcecd_dbus_manager.c', 'src/xcecd_dbus_manager.c',
'src/main.c', # 'src/main.c',
'src/xcecd.c', 'src/xcecd.c',
'src/thread_pool.c', 'src/thread_pool.c',
'src/system_monitor.c', 'src/system_monitor.c',
@ -72,15 +73,59 @@ hwloc_dep = dependency('hwloc')
xcecd_deps = [xcecd_worker_deps,hwloc_dep] xcecd_deps = [xcecd_worker_deps,hwloc_dep]
xcecd = executable('xcecd', xcecd = executable('xcecd',
xcecd_srcs, [xcecd_srcs,'src/main.c'],
c_args: ['-DDBUS_MANAGER'], c_args: ['-DDBUS_MANAGER'],
include_directories: [incdir], include_directories: [incdir],
dependencies: [xcecd_deps], dependencies: [xcecd_deps],
install: true) install: true)
xcecd_virtual = executable('xcecd_virtual', xcecd_virtual = executable('xcecd_virtual',
xcecd_srcs, [xcecd_srcs,'src/main.c'],
c_args: ['-DVIRTUAL_CLUSTER', '-DDBUS_MANAGER'], c_args: ['-DVIRTUAL_CLUSTER', '-DDBUS_MANAGER'],
include_directories: [incdir], include_directories: [incdir],
dependencies:[xcecd_deps], dependencies:[xcecd_deps],
install:true) install:true)
include_dir_test = include_directories('test')
xce_test_deps = xcecd_deps
xce_sched_test = executable('xce_sched_test',
[xcecd_srcs, 'test/xce_sched_test.c'],
include_directories: [incdir,include_dir_test],
dependencies: [xce_test_deps],
install: true)
unity_deps = dependency('unity')
xcecd_daemon_test = executable('xcecd_daemon_test',
[xcecd_srcs, 'test/xcecd_daemon_test.c'],
include_directories: [incdir, include_dir_test],
dependencies: [xce_test_deps, unity_deps],
install: true)
xcecd_worker_test = executable('xcecd_worker_test',
[xcecd_srcs, 'test/xcecd_worker_test.c'],
include_directories: [incdir, include_dir_test],
dependencies: [xce_test_deps, unity_deps],
install: true)
# cgroup_srcs = [
# 'src/xcecd_cgroups.c',
# 'test/cgroup_test.c'
# ]
# cgroup_test = executable('cgroup_test',
# cgroup_srcs,
# include_directories: [incdir, include_dir_test],
# dependencies: [xce_test_deps, unity_deps],
# install: true)
limit_test_srcs = [
'test/limit_test.c'
]
limit_test = executable('limit_test',
limit_test_srcs,
include_directories: [incdir, include_dir_test],
dependencies: [xce_test_deps, unity_deps, math_dep],
install: true)

View file

@ -18,6 +18,10 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#if !defined(DBUS_MANAGER)
#include "process_worker_manager.h"
#endif
/* TEMP SOLUTION: use config later */ /* TEMP SOLUTION: use config later */
#define LOG_SIZE (1024 * 1024 * 100) // 100 MB #define LOG_SIZE (1024 * 1024 * 100) // 100 MB
#define LOG_LEVEL 2 // DEBUG level #define LOG_LEVEL 2 // DEBUG level

View file

@ -12,6 +12,8 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include "process_worker_manager.h"
xcecd_context_t xcecd_ctx = { 0 }; xcecd_context_t xcecd_ctx = { 0 };
hostattrs_t host_attrs = { 0 }; hostattrs_t host_attrs = { 0 };
@ -68,7 +70,7 @@ void xcecd_process_command(void* arg)
} }
/* adding worker to worker list,and update worker pid */ /* adding worker to worker list,and update worker pid */
int pid = get_current_process_pid(ctx->manager); pid = get_current_process_pid(ctx->manager);
if (pid != -1) { if (pid != -1) {
add_worker(&xcecd_ctx.worker_list, pid, WORKER_RUNNING, ctx->xce_jobid, add_worker(&xcecd_ctx.worker_list, pid, WORKER_RUNNING, ctx->xce_jobid,
@ -726,4 +728,4 @@ bool xcecd_check_restart_type(void)
return true; return true;
} }
} }
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,10 +3,10 @@
#include "../include/system_monitor.h" #include "../include/system_monitor.h"
#include "../include/thread_pool.h" #include "../include/thread_pool.h"
#include "../include/xcecd.h" #include "../include/xcecd.h"
#include "unity.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unity.h>
// Mock function declarations // Mock function declarations
static int mock_network_start_called = 0; static int mock_network_start_called = 0;
@ -29,9 +29,9 @@ void test_xcecd_init_success(void)
.resource_update_interval = 5, .resource_update_interval = 5,
.job_status_update_interval = 1, .job_status_update_interval = 1,
.port = 8080, .port = 8080,
.acct_file_path = "/tmp/xcecd.acct", .acct_file = "/tmp/xcecd.acct",
.log_file_path = "/tmp/xcecd.log", .log_file = "/tmp/xcecd.log",
.domain_sock_path = "/tmp/xcecd.sock", .domain_sock_file = "/tmp/xcecd.sock",
.remote_host = "localhost", .remote_host = "localhost",
.remote_port = 6789, .remote_port = 6789,
.update_interval = 2 }; .update_interval = 2 };
@ -53,9 +53,9 @@ void test_xcecd_init_invalid_params(void)
.resource_update_interval = 0, .resource_update_interval = 0,
.job_status_update_interval = 0, .job_status_update_interval = 0,
.port = 0, .port = 0,
.acct_file_path = NULL, .acct_file = NULL,
.log_file_path = NULL, .log_file = NULL,
.domain_sock_path = NULL, .domain_sock_file = NULL,
.remote_host = NULL, .remote_host = NULL,
.remote_port = 0, .remote_port = 0,
.update_interval = 0 }; .update_interval = 0 };
@ -77,9 +77,9 @@ void test_xcecd_stop(void)
.resource_update_interval = 5, .resource_update_interval = 5,
.job_status_update_interval = 1, .job_status_update_interval = 1,
.port = 8080, .port = 8080,
.acct_file_path = "/tmp/xcecd.acct", .acct_file = "/tmp/xcecd.acct",
.log_file_path = "/tmp/xcecd.log", .log_file = "/tmp/xcecd.log",
.domain_sock_path = "/tmp/xcecd.sock", .domain_sock_file = "/tmp/xcecd.sock",
.remote_host = "localhost", .remote_host = "localhost",
.remote_port = 6789, .remote_port = 6789,
.update_interval = 2 }; .update_interval = 2 };
@ -97,9 +97,9 @@ void test_xcecd_cleanup(void)
.resource_update_interval = 5, .resource_update_interval = 5,
.job_status_update_interval = 1, .job_status_update_interval = 1,
.port = 8080, .port = 8080,
.acct_file_path = "/tmp/xcecd.acct", .acct_file = "/tmp/xcecd.acct",
.log_file_path = "/tmp/xcecd.log", .log_file = "/tmp/xcecd.log",
.domain_sock_path = "/tmp/xcecd.sock", .domain_sock_file = "/tmp/xcecd.sock",
.remote_host = "localhost", .remote_host = "localhost",
.remote_port = 6789, .remote_port = 6789,
.update_interval = 2 }; .update_interval = 2 };
@ -117,9 +117,9 @@ void test_xcecd_multiple_init_cleanup(void)
.resource_update_interval = 5, .resource_update_interval = 5,
.job_status_update_interval = 1, .job_status_update_interval = 1,
.port = 8080, .port = 8080,
.acct_file_path = "/tmp/xcecd.acct", .acct_file = "/tmp/xcecd.acct",
.log_file_path = "/tmp/xcecd.log", .log_file = "/tmp/xcecd.log",
.domain_sock_path = "/tmp/xcecd.sock", .domain_sock_file = "/tmp/xcecd.sock",
.remote_host = "localhost", .remote_host = "localhost",
.remote_port = 6789, .remote_port = 6789,
.update_interval = 2 }; .update_interval = 2 };
@ -138,9 +138,9 @@ void test_xcecd_init_minimum_values(void)
.resource_update_interval = 1, .resource_update_interval = 1,
.job_status_update_interval = 1, .job_status_update_interval = 1,
.port = 1024, .port = 1024,
.acct_file_path = "/tmp/xcecd.acct", .acct_file = "/tmp/xcecd.acct",
.log_file_path = "/tmp/xcecd.log", .log_file = "/tmp/xcecd.log",
.domain_sock_path = "/tmp/xcecd.sock", .domain_sock_file = "/tmp/xcecd.sock",
.remote_host = "localhost", .remote_host = "localhost",
.remote_port = 6789, .remote_port = 6789,
.update_interval = 1 }; .update_interval = 1 };
@ -162,4 +162,4 @@ int main(void)
RUN_TEST(test_xcecd_init_minimum_values); RUN_TEST(test_xcecd_init_minimum_values);
return UNITY_END(); return UNITY_END();
} }

View file

@ -1,7 +1,6 @@
#include "../include/process_manager.h" #include "../include/process_manager.h"
#include "../include/xcecd.h" #include "../include/xcecd.h"
#include "../include/xcecd_utils.h" #include "../include/xcecd_utils.h"
#include "../include/xcecd_worker.h"
#include "unity.h" #include "unity.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -35,6 +34,8 @@ static int mock_select_return = 0;
static int mock_waitpid_return = 0; static int mock_waitpid_return = 0;
static int mock_process_manager_start_process_return = 0; static int mock_process_manager_start_process_return = 0;
extern int main(void);
void setUp(void) void setUp(void)
{ {
mock_socket_fd = -1; mock_socket_fd = -1;
@ -318,4 +319,4 @@ int main(void)
RUN_TEST(test_xcecd_worker_main); RUN_TEST(test_xcecd_worker_main);
return UNITY_END(); return UNITY_END();
} }