Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EXPECT_JSON runtime test directive #2841

Closed
danobi opened this issue Nov 21, 2023 · 1 comment · Fixed by #2847
Closed

Add EXPECT_JSON runtime test directive #2841

danobi opened this issue Nov 21, 2023 · 1 comment · Fixed by #2847
Labels
enhancement New feature or request, changes on existing features good first issue Good for newcomers tests Issues with our tests or test framework; missing tests; invalid tests

Comments

@danobi
Copy link
Member

danobi commented Nov 21, 2023

Runtime tests have quite a few available directives (see https://github.com/iovisor/bpftrace/blob/master/tests/README.md#runtime-test-directives).

A bunch of json output tests (see https://github.com/iovisor/bpftrace/blob/master/tests/runtime/json-output) pipe output from bpftrace to python like this:

NAME complex
RUN {{BPFTRACE}} -q -f json -e 'BEGIN { @complex[comm,2] = 5; exit(); }' | python3 -c 'import sys,json; print(json.load(sys.stdin) == json.load(open("runtime/outputs/complex.json")))'
EXPECT ^True$
TIMEOUT 5

Would be good to add a EXPECT_JSON directive to simplify all those tests. So something like:

NAME complex
RUN {{BPFTRACE}} -q -f json -e 'BEGIN { @complex[comm,2] = 5; exit(); }'
EXPECT_JSON runtime/outputs/complex.json
TIMEOUT 5

It needs to be done in python (and not an exact string match) to ignore dict reorderings. Cuz in json those kinds of reorderings are not semantically relevant.

@danobi danobi added enhancement New feature or request, changes on existing features good first issue Good for newcomers tests Issues with our tests or test framework; missing tests; invalid tests labels Nov 21, 2023
@luigirizzo
Copy link
Contributor

see #2845 for a possible implementation of this directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request, changes on existing features good first issue Good for newcomers tests Issues with our tests or test framework; missing tests; invalid tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants