1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
3
4#include <linux/bpf.h>
5#include <time.h>
6#include <errno.h>
7#include <bpf/bpf_helpers.h>
8#include "bpf_misc.h"
9#include "bpf_tcp_helpers.h"
10
11char _license[] SEC("license") = "GPL";
12
13struct elem {
14	struct bpf_timer t;
15};
16
17struct {
18	__uint(type, BPF_MAP_TYPE_ARRAY);
19	__uint(max_entries, 1);
20	__type(key, int);
21	__type(value, struct elem);
22} timer_map SEC(".maps");
23
24static int timer_cb_ret1(void *map, int *key, struct bpf_timer *timer)
25{
26	if (bpf_get_smp_processor_id() % 2)
27		return 1;
28	else
29		return 0;
30}
31
32SEC("fentry/bpf_fentry_test1")
33__failure __msg("should have been in (0x0; 0x0)")
34int BPF_PROG2(test_ret_1, int, a)
35{
36	int key = 0;
37	struct bpf_timer *timer;
38
39	timer = bpf_map_lookup_elem(&timer_map, &key);
40	if (timer) {
41		bpf_timer_init(timer, &timer_map, CLOCK_BOOTTIME);
42		bpf_timer_set_callback(timer, timer_cb_ret1);
43		bpf_timer_start(timer, 1000, 0);
44	}
45
46	return 0;
47}
48