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

Build out of tree #2183

Closed
wants to merge 4 commits into from
Closed

Build out of tree #2183

wants to merge 4 commits into from

Conversation

bb010g
Copy link

@bb010g bb010g commented Sep 20, 2020

Tests weren't happy with a setup like mkdir -p build && cd build && ../configure && make. make check now works on out-of-tree-builds.

While I was making tests work, one of them failed for me due to Valgrind output, so that's fixed (I think with virtually no runtime costs; the biggest cost would be strncpy() instead of strcpy(), with lengths we already were computing).

While I was making that test work, I noticed a function pointer cast error, so that's also received what should be a zero-cost patch (always_inlined function that exists solely to cast a parameter type and tail call the actual function).

Another test failed due to my normal environment exporting JQ_COLORS, so that's now unset before all tests that try to use it.


This change is Reviewable

Autoconf & Automake support builds that aren't in-tree! Tests failed
with them though, so that's fixed now.

To facilitate testing out-of-tree, Autoconf preset output variables are
set for test runners.

Also, switch from setting the user-reserved TESTS_ENVRIONMENT to the
developer-reserved AM_TESTS_ENVIRONMENT in Makefile.am.

JQ_COLORS is now unset before testing, for reproducibility.
Making the C standard happy is a pretty good thing.
Also some setup for Clang tools use. GCC doesn't have an equivalent to
Clang's -Wconditional-uninitialized; clang-tidy gets around that.

(I used https://github.com/rizsotto/Bear to generate
compile_commands.json, and ran with
`clang-check --extra-arg=-Wconditional-uninitialized src/(^decNumber)**.c`
in Zsh. Turns out `-Wconditional-uninitialized` has a lot of false
positives, and we probably wouldn't want it on by default.)

Spurred from a tests/mantest Valgrind failure:

    Conditional jump or move depends on uninitialised value(s)
       at 0x40A578: checkfail (jq_test.c:50)
       by 0x40A578: run_jq_tests (jq_test.c:91)
       by 0x40AFD3: jq_testsuite (jq_test.c:34)
       by 0x405360: main (main.c:545)

    Conditional jump or move depends on uninitialised value(s)
       at 0x40A5A1: checkfail (jq_test.c:50)
       by 0x40A5A1: run_jq_tests (jq_test.c:91)
       by 0x40AFD3: jq_testsuite (jq_test.c:34)
       by 0x405360: main (main.c:545)

The offending flow:

1. `static void run_jq_tests(…, FILE *testdata, …) {`
2. `  char prog[4096];`
3. `  while (1) {`
4. `    if (!fgets(prog, sizeof(prog), testdata)) break;`
5. `    if (skipline(prog)) continue;`
  (This does not modify `prog`.)
6. `    if (checkfail(prog)) {`
7. `static int checkfail(const char *buf) {`
8. `  return strcmp(buf, "%%FAIL\n") == 0 || …`
  This is the first Valgrind output.
9. `  return … || strcmp(buf, "%%FAIL IGNORE MSG\n") == 0;`
    This is the second Valgrind output.

My hypothesis is that strcmp() is examining characters past EOF.

fgets() returns whether it errored or immediately hit EOF, not how many
characters it has read, so that's not helpful to us. skipline() stops on
an EOF character (NUL byte). Nothing else modifies prog.

Computing strlen(prog) earlier and passing it to relevant strncmp()
(instead of strcmp()) calls fixes the error.

Similar precautions are taken for run_jq_tests()'s `char buf[4096];`.
@bb010g
Copy link
Author

bb010g commented Sep 20, 2020

(AppVeyor is experiencing pacman mingw32.db issues, unrelated to this patchset.)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 84.12% when pulling e2ffd22 on bb010g:build-out-of-tree into a17dd32 on stedolan:master.

@itchyny
Copy link
Contributor

itchyny commented Jul 21, 2023

The main issue of this PR make check in sub-directory works now (maybe fixed in #2700), so closing this PR. This PR contains various fixes to be separated into multiple PRs.

@itchyny itchyny closed this Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants