test_values: Avoid most double-evaluation

Most of these TEST_*() macros may evaluate the expression twice when
they fail. When used with a complex stateful evaluation, such as when
waiting for a condition, this can produce very confusing output such as
the following:

BAD: wrong value for timed_waitpid (upstart_pid, 1+TEST_QUIESCE_KILL_PHASE), expected 4537 got 4537
        at tests/test_initctl.c:11851 (test_quiesce).
FAIL test_initctl (exit status: 134)

This is because the printed value ("got 4537") is from a second
evaluation of the timed_waitpid() function, and by the time we wait a
second time, it produces the expected result.

The standard practice with function-like macros is to nest a context
where we assign the expression to a local variable, and use that
variable in both the comparison and the printed output (if failed).

This exposes a few typing issues, where we can't assign functions to a
variable (such as, `const typeof(my_function) __a = my_function`), but
we *can* assign a pointer to the function (`const typeof(&my_function)
__a = &my_function`).

I also avoid TEST_EQ_MEM() and a few others, since those are often used
with arrays, which similarly can't be assigned the same way as a
pointer.

BUG=b:232122437
TEST=cros_run_unit_tests

Change-Id: I528948fac48995e01f82d677e4b6c8d91ae4d9f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/libnih/+/5623190
Commit-Queue: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
15 files changed