Ejemplo n.º 1
0
TEST_F(FooFixture, ClassFunT) {
    SUBSTITUTE(Class::FunTemp<int>, fake_Class_mf);
    Class c;
    int p = 13;
    auto res = c.FunTemp(p);
    EXPECT_EQ(res, 39);
}
Ejemplo n.º 2
0
TEST_F(FooFixture, ClassTFunT) {
    SUBSTITUTE(TemplateS2<int>::barT<int>, fake_bar_mem_fun);
    TemplateS2<int> t;
    int p = 13;
    auto res = t.barT(p);
    EXPECT_EQ(res, 39);
    res = t.fooT(p);
    EXPECT_EQ(res, 39);
}
Ejemplo n.º 3
0
TEST(handleMessage, reloadConfig_shall_be_called_on_timeout) {
    SUBSTITUTE(time, fake_time);
    SUBSTITUTE(reloadConfig, mock_reloadConfig);
    handleMessage(Message());
    EXPECT_EQ(reloadConfigCalled, true);
}
Ejemplo n.º 4
0
Archivo: proc.c Proyecto: matrach/PRoot
/**
 * This function emulates the @result of readlink("@base/@component")
 * with respect to @tracee, where @base belongs to "/proc" (according
 * to @comparison).  This function returns -errno on error, an enum
 * @action otherwise (c.f. above).
 *
 * Unlike readlink(), this function includes the nul terminating byte
 * to @result.
 */
Action readlink_proc(const Tracee *tracee, char result[PATH_MAX],
			const char base[PATH_MAX], const char component[NAME_MAX],
			Comparison comparison)
{
	const Tracee *known_tracee;
	char proc_path[64]; /* 64 > sizeof("/proc//fd/") + 2 * sizeof(#ULONG_MAX) */
	int status;
	pid_t pid;

	assert(comparison == compare_paths("/proc", base));

	/* Remember: comparison = compare_paths("/proc", base)  */
	switch (comparison) {
	case PATHS_ARE_EQUAL:
		/* Substitute "/proc/self" with "/proc/<PID>".  */
		if (strcmp(component, "self") != 0)
			return DEFAULT;

		status = snprintf(result, PATH_MAX, "/proc/%d", tracee->pid);
		if (status < 0 || status >= PATH_MAX)
			return -EPERM;

		return CANONICALIZE;

	case PATH1_IS_PREFIX:
		/* Handle "/proc/<PID>" below, where <PID> is process
		 * monitored by PRoot.  */
		break;

	default:
		return DEFAULT;
	}

	pid = atoi(base + strlen("/proc/"));
	if (pid == 0)
		return DEFAULT;

	known_tracee = get_tracee(pid, false);
	if (!known_tracee)
		return DEFAULT;

	/* Handle links in "/proc/<PID>/".  */
	status = snprintf(proc_path, sizeof(proc_path), "/proc/%d", pid);
	if (status < 0 || status >= sizeof(proc_path))
		return -EPERM;

	comparison = compare_paths(proc_path, base);
	switch (comparison) {
	case PATHS_ARE_EQUAL:
#define SUBSTITUTE(name, field)					\
		do {						\
			if (strcmp(component, #name) != 0)	\
				break;				\
								\
			status = strlen(known_tracee->field);	\
			if (status >= PATH_MAX)			\
				return -EPERM;			\
								\
			strncpy(result, known_tracee->field, status + 1); \
			return CANONICALIZE;			\
		} while (0)

		/* Substitute link "/proc/<PID>/???" with the content
		 * of tracee->???.  */
		SUBSTITUTE(exe, exe);
		SUBSTITUTE(cwd, fs->cwd);
		//SUBSTITUTE(root);
#undef SUBSTITUTE
		return DEFAULT;

	case PATH1_IS_PREFIX:
		/* Handle "/proc/<PID>/???" below.  */
		break;

	default:
		return DEFAULT;
	}

	/* Handle links in "/proc/<PID>/fd/".  */
	status = snprintf(proc_path, sizeof(proc_path), "/proc/%d/fd", pid);
	if (status < 0 || status >= sizeof(proc_path))
		return -EPERM;

	comparison = compare_paths(proc_path, base);
	switch (comparison) {
		char *end_ptr;

	case PATHS_ARE_EQUAL:
		/* Sanity check: a number is expected.  */
		errno = 0;
		(void) strtol(component, &end_ptr, 10);
		if (errno != 0 || end_ptr == component)
			return -EPERM;

		/* Don't dereference "/proc/<PID>/fd/???" now: they
		 * can point to anonymous pipe, socket, ...  otherwise
		 * they point to a path already canonicalized by the
		 * kernel.
		 *
		 * Note they are still correctly detranslated in
		 * syscall/exit.c if a monitored process uses
		 * readlink() against any of them.  */
		status = snprintf(result, PATH_MAX, "%s/%s", base, component);
		if (status < 0 || status >= PATH_MAX)
			return -EPERM;

		return DONT_CANONICALIZE;

	default:
		return DEFAULT;
	}

	return DEFAULT;
}
Ejemplo n.º 5
0
TEST_F(FooFixture, ClassT) {
    SUBSTITUTE(TemplateS<int>::bar, fake_bar_mem_fun);
    TemplateS<int> t;
    auto res = t.foo(13);
    EXPECT_EQ(res, 39);
}
Ejemplo n.º 6
0
TEST_F(FooFixture, CallFunT) {
    SUBSTITUTE(FunTemp<int>, fake_FunTemp);
    int p = 13;
    auto res = foo(p);
    EXPECT_EQ(res, 39);
}