1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2020 Facebook */
3
4#include <test_progs.h>
5#include "test_endian.skel.h"
6
7static int duration;
8
9#define IN16 0x1234
10#define IN32 0x12345678U
11#define IN64 0x123456789abcdef0ULL
12
13#define OUT16 0x3412
14#define OUT32 0x78563412U
15#define OUT64 0xf0debc9a78563412ULL
16
17void test_endian(void)
18{
19	struct test_endian* skel;
20	struct test_endian__bss *bss;
21	int err;
22
23	skel = test_endian__open_and_load();
24	if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
25		return;
26	bss = skel->bss;
27
28	bss->in16 = IN16;
29	bss->in32 = IN32;
30	bss->in64 = IN64;
31
32	err = test_endian__attach(skel);
33	if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
34		goto cleanup;
35
36	usleep(1);
37
38	CHECK(bss->out16 != OUT16, "out16", "got 0x%llx != exp 0x%llx\n",
39	      (__u64)bss->out16, (__u64)OUT16);
40	CHECK(bss->out32 != OUT32, "out32", "got 0x%llx != exp 0x%llx\n",
41	      (__u64)bss->out32, (__u64)OUT32);
42	CHECK(bss->out64 != OUT64, "out16", "got 0x%llx != exp 0x%llx\n",
43	      (__u64)bss->out64, (__u64)OUT64);
44
45	CHECK(bss->const16 != OUT16, "const16", "got 0x%llx != exp 0x%llx\n",
46	      (__u64)bss->const16, (__u64)OUT16);
47	CHECK(bss->const32 != OUT32, "const32", "got 0x%llx != exp 0x%llx\n",
48	      (__u64)bss->const32, (__u64)OUT32);
49	CHECK(bss->const64 != OUT64, "const64", "got 0x%llx != exp 0x%llx\n",
50	      (__u64)bss->const64, (__u64)OUT64);
51cleanup:
52	test_endian__destroy(skel);
53}
54