1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 
4 #include <test_progs.h>
5 #include <time.h>
6 #include "test_autoload.skel.h"
7 
8 void test_autoload(void)
9 {
10 	int duration = 0, err;
11 	struct test_autoload* skel;
12 
13 	skel = test_autoload__open_and_load();
14 	/* prog3 should be broken */
15 	if (CHECK(skel, "skel_open_and_load", "unexpected success\n"))
16 		goto cleanup;
17 
18 	skel = test_autoload__open();
19 	if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
20 		goto cleanup;
21 
22 	/* don't load prog3 */
23 	bpf_program__set_autoload(skel->progs.prog3, false);
24 
25 	err = test_autoload__load(skel);
26 	if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err))
27 		goto cleanup;
28 
29 	err = test_autoload__attach(skel);
30 	if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
31 		goto cleanup;
32 
33 	usleep(1);
34 
35 	CHECK(!skel->bss->prog1_called, "prog1", "not called\n");
36 	CHECK(!skel->bss->prog2_called, "prog2", "not called\n");
37 	CHECK(skel->bss->prog3_called, "prog3", "called?!\n");
38 
39 cleanup:
40 	test_autoload__destroy(skel);
41 }
42