File: test_hooks.c

package info (click to toggle)
redis 5%3A8.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,304 kB
  • sloc: ansic: 216,903; tcl: 51,562; sh: 4,625; perl: 4,214; cpp: 3,568; python: 2,954; makefile: 2,055; ruby: 639; javascript: 30; csh: 7
file content (38 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (6)
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
#include "test/jemalloc_test.h"

static bool hook_called = false;

static void
hook() {
	hook_called = true;
}

static int
func_to_hook(int arg1, int arg2) {
	return arg1 + arg2;
}

#define func_to_hook JEMALLOC_TEST_HOOK(func_to_hook, test_hooks_libc_hook)

TEST_BEGIN(unhooked_call) {
	test_hooks_libc_hook = NULL;
	hook_called = false;
	expect_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
	expect_false(hook_called, "Nulling out hook didn't take.");
}
TEST_END

TEST_BEGIN(hooked_call) {
	test_hooks_libc_hook = &hook;
	hook_called = false;
	expect_d_eq(3, func_to_hook(1, 2), "Hooking changed return value.");
	expect_true(hook_called, "Hook should have executed.");
}
TEST_END

int
main(void) {
	return test(
	    unhooked_call,
	    hooked_call);
}