1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/*****************************************************************************\
* prog7.11.prog.c - SPANK plugin for testing purposes
*****************************************************************************
* Copyright (C) 2008-2009 Lawrence Livermore National Security.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Morris Jette <jette1@llnl.gov>
* CODE-OCEC-09-009. All rights reserved.
*
* This file is part of Slurm, a resource management program.
* For details, see <https://slurm.schedmd.com/>.
* Please also read the included file: DISCLAIMER.
*
* Slurm is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* Slurm 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 Slurm; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <slurm/spank.h>
#define SPANK_JOB_ENV_TESTS 0
/*
* All spank plugins must define this macro for the Slurm plugin loader.
*/
SPANK_PLUGIN(test_suite, 1);
static int opt_arg_srun = 0;
static int opt_arg_sbatch = 0;
static char *opt_out_file = NULL;
static int _test_opt_process_srun(int val, const char *optarg, int remote);
static int _test_opt_process_sbatch(int val, const char *optarg, int remote);
/*
* Provide a --test_suite=[opt_arg] option to srun:
*/
struct spank_option spank_options[] =
{
{ "test_suite_srun",
"[opt_arg_srun]",
"Component of slurm test suite.",
2,
0,
_test_opt_process_srun
},
SPANK_OPTIONS_TABLE_END
};
struct spank_option spank_options_reg[] =
{
{ "test_suite_sbatch",
"[opt_arg_sbatch]",
"Registered component of slurm test suite. Has to be non-zero int",
2,
0,
_test_opt_process_sbatch
},
SPANK_OPTIONS_TABLE_END
};
static int _test_opt_process_srun(int val, const char *optarg, int remote)
{
opt_arg_srun = atoi(optarg);
if (!remote)
slurm_info("%s: opt_arg_srun=%d", __func__, opt_arg_srun);
return (0);
}
static int _test_opt_process_sbatch(int val, const char *optarg, int remote)
{
opt_arg_sbatch = atoi(optarg);
/* Verify if option is a non-zero number */
if (!opt_arg_sbatch) {
slurm_error("Non-zero argument required");
return -1;
}
if (!remote)
slurm_info("%s: opt_arg_sbatch=%d", __func__, opt_arg_sbatch);
return (0);
}
/* Called from both srun and slurmd */
int slurm_spank_init(spank_t sp, int ac, char **av)
{
spank_context_t context;
context = spank_context();
if ((context != S_CTX_LOCAL) && (context != S_CTX_REMOTE) &&
(context != S_CTX_ALLOCATOR))
slurm_error("spank_context error");
if (SPANK_JOB_ENV_TESTS &&
((context == S_CTX_LOCAL) || (context == S_CTX_ALLOCATOR))) {
/* Testing logic for spank_job_control_env options */
char test_value[200];
spank_err_t err;
spank_job_control_setenv(sp, "DUMMY", "DV", 1);
spank_job_control_setenv(sp, "NAME", "VALUE", 1);
spank_job_control_setenv(sp, "name", "value", 1);
/* spank_job_control_setenv(sp, "PATH", "/", 1); */
memset(test_value, 0, sizeof(test_value));
err = spank_job_control_getenv(
sp, "NAME", test_value, sizeof(test_value));
if (err != ESPANK_SUCCESS)
slurm_error("spank_get_job_env error, NULL");
else if (strcmp(test_value, "VALUE"))
slurm_error("spank_get_job_env error, bad value");
spank_job_control_unsetenv(sp, "DUMMY");
}
if (spank_option_register(sp, spank_options_reg) != ESPANK_SUCCESS)
slurm_error("spank_option_register error");
if (spank_remote(sp) && (ac == 1))
opt_out_file = strdup(av[0]);
return (0);
}
/* Called from both srun and slurmd, not tested here
int slurm_spank_init_post_opt(spank_t sp, int ac, char **av) */
/* Called from srun only */
int slurm_spank_local_user_init(spank_t sp, int ac, char **av)
{
slurm_info("slurm_spank_local_user_init");
return (0);
}
/* Called from slurmd only */
int slurm_spank_task_init(spank_t sp, int ac, char **av)
{
uid_t my_uid;
int argc, i;
char **argv;
if (opt_out_file) {
FILE *fp = NULL;
for (i = 0; (i < 10) && !fp; i++)
fp = fopen(opt_out_file, "a");
if (!fp)
return -1;
fprintf(fp, "%s: opt_arg_sbatch=%d opt_arg_srun=%d\n",
__func__, opt_arg_sbatch, opt_arg_srun);
if (spank_get_item(sp, S_JOB_UID, &my_uid) == ESPANK_SUCCESS)
fprintf(fp, "spank_get_item: my_uid=%d\n", my_uid);
if (spank_get_item(sp, S_JOB_ARGV, &argc, &argv) ==
ESPANK_SUCCESS) {
for (i = 0; i < argc; i++) {
fprintf(fp, "spank_get_item: argv[%d]=%s\n",
i, argv[i]);
}
}
fclose(fp);
}
return 0;
}
/* Called from slurmd only, not tested here
int slurm_spank_task_post_fork(spank_t sp, int ac, char **av) */
/* Called from slurmd only, not tested here
int slurm_spank_task_exit(spank_t sp, int ac, char **av) */
/* Called from both srun and slurmd */
int slurm_spank_exit(spank_t sp, int ac, char **av)
{
int i;
if (opt_out_file) {
FILE *fp = NULL;
for (i = 0; (i < 10) && !fp; i++)
fp = fopen(opt_out_file, "a");
if (!fp)
return -1;
fprintf(fp, "%s: opt_arg_sbatch=%d opt_arg_srun=%d\n",
__func__, opt_arg_sbatch, opt_arg_srun);
fclose(fp);
} else
slurm_info("%s: opt_arg_sbatch=%d opt_arg_srun=%d",
__func__, opt_arg_sbatch, opt_arg_srun);
return 0;
}
|