test-unit-file.c revision 46a0d98ac0fb5b507a6423e60058a2483830b432
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
Copyright 2013 Zbigniew Jędrzejewski-Szmek
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.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "install.h"
#include "install-printf.h"
#include "specifier.h"
#include "util.h"
#include "macro.h"
#include "hashmap.h"
#include "load-fragment.h"
#include "strv.h"
#include "fileio.h"
#include "test-helper.h"
#include "hostname-util.h"
static int test_unit_file_get_set(void) {
int r;
Hashmap *h;
Iterator i;
UnitFileList *p;
h = hashmap_new(&string_hash_ops);
assert_se(h);
return EXIT_TEST_SKIP;
}
"unit_file_get_list: %s", strerror(-r));
if (r < 0)
return EXIT_FAILURE;
HASHMAP_FOREACH(p, h, i)
return 0;
}
static void check_execcommand(ExecCommand *c,
const char* path,
const char* argv0,
const char* argv1,
const char* argv2,
bool ignore) {
size_t n;
assert_se(c);
log_info("expect: \"%s\" [\"%s\" \"%s\" \"%s\"]",
n = strv_length(c->argv);
log_info("actual: \"%s\" [\"%s\" \"%s\" \"%s\"]",
if (n > 0)
if (n > 1)
}
static void test_config_parse_exec(void) {
/* int config_parse_exec(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) */
int r;
const char *ccc;
log_info("/* basic test */");
"LValue", 0, "/RValue r1",
&c, NULL);
assert_se(r >= 0);
"LValue", 0, "/RValue///slashes r1///",
&c, NULL);
log_info("/* test slashes */");
assert_se(r >= 0);
c1 = c->command_next;
log_info("/* trailing slash */");
"LValue", 0, "/RValue/ argv0 r1",
&c, NULL);
assert_se(r == 0);
log_info("/* honour_argv0 */");
"LValue", 0, "@/RValue///slashes2 ///argv0 r1",
&c, NULL);
assert_se(r >= 0);
log_info("/* honour_argv0, no args */");
"LValue", 0, "@/RValue",
&c, NULL);
assert_se(r == 0);
log_info("/* no command, check for bad memory access */");
"LValue", 0, " ",
&c, NULL);
assert_se(r == 0);
log_info("/* ignore && honour_argv0 */");
"LValue", 0, "-@/RValue///slashes3 argv0a r1",
&c, NULL);
assert_se(r >= 0);
log_info("/* ignore && honour_argv0 */");
"LValue", 0, "@-/RValue///slashes4 argv0b r1",
&c, NULL);
assert_se(r >= 0);
log_info("/* ignore && ignore */");
"LValue", 0, "--/RValue argv0 r1",
&c, NULL);
assert_se(r == 0);
log_info("/* ignore && ignore (2) */");
"LValue", 0, "-@-/RValue argv0 r1",
&c, NULL);
assert_se(r == 0);
log_info("/* semicolon */");
"LValue", 0,
"-@/RValue argv0 r1 ; "
&c, NULL);
assert_se(r >= 0);
log_info("/* two semicolons in a row */");
"LValue", 0,
"-@/RValue argv0 r1 ; ; "
&c, NULL);
assert_se(r >= 0);
/* second command fails because the executable name is ";" */
log_info("/* trailing semicolon */");
"LValue", 0,
"-@/RValue argv0 r1 ; ",
&c, NULL);
assert_se(r >= 0);
log_info("/* trailing semicolon, no whitespace */");
"LValue", 0,
"-@/RValue argv0 r1 ;",
&c, NULL);
assert_se(r >= 0);
log_info("/* trailing semicolon in single quotes */");
"LValue", 0,
"-@/RValue argv0 r1 ';'",
&c, NULL);
assert_se(r >= 0);
log_info("/* escaped semicolon */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* escaped semicolon with following arg */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* escaped semicolon as part of an expression */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* encoded semicolon */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* quoted semicolon */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* quoted semicolon with following arg */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* spaces in the filename */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* spaces in the filename, no args */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* spaces in the filename, everything quoted */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* escaped spaces in the filename */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* escaped spaces in the filename (2) */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
/* \\x is an incomplete hexadecimal sequence, invalid because of the slash */
char path[] = "/path\\X";
"LValue", 0, path,
&c, NULL);
assert_se(r == 0);
}
log_info("/* valid character: \\s */");
"LValue", 0, "/path\\s",
&c, NULL);
assert_se(r >= 0);
log_info("/* quoted backslashes */");
"LValue", 0,
&c, NULL);
assert_se(r >= 0);
log_info("/* trailing backslash: \\ */");
/* backslash is invalid */
"LValue", 0, "/path\\",
&c, NULL);
assert_se(r == 0);
log_info("/* missing ending ' */");
"LValue", 0, "/path 'foo",
&c, NULL);
assert_se(r == 0);
log_info("/* missing ending ' with trailing backslash */");
"LValue", 0, "/path 'foo\\",
&c, NULL);
assert_se(r == 0);
log_info("/* invalid space between modifiers */");
"LValue", 0, "- /path",
&c, NULL);
assert_se(r == 0);
log_info("/* only modifiers, no path */");
"LValue", 0, "-",
&c, NULL);
assert_se(r == 0);
log_info("/* empty argument, reset */");
"LValue", 0, "",
&c, NULL);
assert_se(r == 0);
}
#define env_file_1 \
"a=a\n" \
"b=b\\\n" \
"c\n" \
"d=d\\\n" \
"e\\\n" \
"f\n" \
"g=g\\ \n" \
"h=h\n" \
"i=i\\"
#define env_file_2 \
"a=a\\\n"
#define env_file_3 \
"#--nouser-config \\\n" \
"normal=line"
#define env_file_4 \
"# Generated\n" \
"\n" \
"HWMON_MODULES=\"coretemp f71882fg\"\n" \
"\n" \
"# For compatibility reasons\n" \
"\n" \
"MODULE_0=coretemp\n" \
"MODULE_1=f71882fg"
#define env_file_5 \
"a=\n" \
"b="
static void test_load_env_file_1(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
_cleanup_close_ int fd;
assert_se(r == 0);
}
static void test_load_env_file_2(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
_cleanup_close_ int fd;
assert_se(r == 0);
}
static void test_load_env_file_3(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
_cleanup_close_ int fd;
assert_se(r == 0);
}
static void test_load_env_file_4(void) {
char name[] = "/tmp/test-load-env-file.XXXXXX";
_cleanup_close_ int fd;
int r;
assert_se(r == 0);
}
static void test_load_env_file_5(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
_cleanup_close_ int fd;
assert_se(r == 0);
}
static void test_install_printf(void) {
path[] = "/run/systemd/system/name.service",
user[] = "xxxx-no-such-user";
char name3[] = "name@inst.service",
path3[] = "/run/systemd/system/name.service";
do { \
_cleanup_free_ char *t = NULL; \
_cleanup_free_ char \
if (result) { \
printf("%s\n", t); \
} while(false)
}
int r;
log_open();
r = test_unit_file_get_set();
return r;
}