On 20/02/2025 20:24, Eduard Zingerman wrote:
On Wed, 2025-02-19 at 23:30 +0000, Mykyta Yatsenko wrote:
From: Mykyta Yatsenko <yatsenko@xxxxxxxx>
Introducing test for veristat, part of test_progs.
Test cases cover functionality of setting global variables in BPF
program.
Signed-off-by: Mykyta Yatsenko <yatsenko@xxxxxxxx>
---
Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
[...]
diff --git a/tools/testing/selftests/bpf/prog_tests/test_veristat.c b/tools/testing/selftests/bpf/prog_tests/test_veristat.c
new file mode 100644
index 000000000000..eff79bf55fe3
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/test_veristat.c
[...]
+static struct fixture *init_fixture(void)
+{
+ struct fixture *fix = malloc(sizeof(struct fixture));
+
+ if (access("./veristat", F_OK) == 0)
+ strcpy(fix->veristat, "./veristat");
+ /* for no_alu32 and cpuv4 veristat is in parent folder */
+ if (access("../veristat", F_OK) == 0)
+ strcpy(fix->veristat, "../veristat");
Nit: 'else PRINT_FAIL("Can't find veristat binary");' ?
+
+ snprintf(fix->tmpfile, sizeof(fix->tmpfile), "/tmp/test_veristat.XXXXXX");
+ fix->fd = mkstemp(fix->tmpfile);
+ fix->sz = 1000000;
+ fix->output = malloc(fix->sz);
+ return fix;
+}
[...]
+static void test_set_global_vars_from_file_succeeds(void)
+{
+ struct fixture *fix = init_fixture();
+ char input_file[80];
+ const char *vars = "var_s16 = -32768\nvar_u16 = 60652";
+ int fd;
+
+ snprintf(input_file, sizeof(input_file), "/tmp/veristat_input.XXXXXX");
+ fd = mkstemp(input_file);
+ if (!ASSERT_GE(fd, 0, "valid fd"))
+ goto out;
+
+ write(fd, vars, strlen(vars));
Nit: 'syncfs(fd);' ?
Thanks, makes sense. I'll include these in the next version, along with
CI failures fixes.
+ SYS(out, "%s set_global_vars.bpf.o -G \"@%s\" -vl2 > %s",
+ fix->veristat, input_file, fix->tmpfile);
+ read(fix->fd, fix->output, fix->sz);
+ __CHECK_STR("_w=0x8000 ", "var_s16 = -32768");
+ __CHECK_STR("_w=0xecec ", "var_u16 = 60652");
+
+out:
+ close(fd);
+ remove(input_file);
+ teardown_fixture(fix);
+}
[...]