Skip to content

Commit

Permalink
tests: use assert_se instead of assert
Browse files Browse the repository at this point in the history
Otherwise they can be optimized away with -DNDEBUG
  • Loading branch information
ronnychevalier committed Jan 22, 2015
1 parent 714af6a commit 0c0cdb0
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 147 deletions.
18 changes: 9 additions & 9 deletions src/journal/test-compress-benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static char* make_buf(size_t count) {
size_t i;

buf = malloc(count);
assert(buf);
assert_se(buf);

for (i = 0; i < count; i++)
buf[i] = 'a' + i % ('z' - 'a' + 1);
Expand All @@ -52,7 +52,7 @@ static void test_compress_decompress(const char* label,

text = make_buf(MAX_SIZE);
buf = calloc(MAX_SIZE + 1, 1);
assert(text && buf);
assert_se(text && buf);

n = now(CLOCK_MONOTONIC);

Expand All @@ -62,24 +62,24 @@ static void test_compress_decompress(const char* label,

r = compress(text, i, buf, &j);
/* assume compression must be successful except for small inputs */
assert(r == 0 || (i < 2048 && r == -ENOBUFS));
assert_se(r == 0 || (i < 2048 && r == -ENOBUFS));
/* check for overwrites */
assert(buf[i] == 0);
assert_se(buf[i] == 0);
if (r != 0) {
skipped += i;
continue;
}

assert(j > 0);
assert_se(j > 0);
if (j >= i)
log_error("%s \"compressed\" %zu -> %zu", label, i, j);

r = decompress(buf, j, &buf2, &buf2_allocated, &k, 0);
assert(r == 0);
assert(buf2_allocated >= k);
assert(k == i);
assert_se(r == 0);
assert_se(buf2_allocated >= k);
assert_se(k == i);

assert(memcmp(text, buf2, i) == 0);
assert_se(memcmp(text, buf2, i) == 0);

total += i;
compressed += j;
Expand Down
4 changes: 2 additions & 2 deletions src/journal/test-compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static void test_compress_stream(int compression,

assert_se(lseek(dst, 0, SEEK_SET) == 0);
r = decompress(dst, dst2, st.st_size);
assert(r == 0);
assert_se(r == 0);

assert_se(asprintf(&cmd2, "diff %s %s", srcfile, pattern2) > 0);
assert_se(system(cmd2) == 0);
Expand All @@ -189,7 +189,7 @@ static void test_compress_stream(int compression,
assert_se(lseek(dst, 0, SEEK_SET) == 0);
assert_se(lseek(dst2, 0, SEEK_SET) == 0);
r = decompress(dst, dst2, st.st_size - 1);
assert(r == -EFBIG);
assert_se(r == -EFBIG);

assert_se(unlink(pattern) == 0);
assert_se(unlink(pattern2) == 0);
Expand Down
7 changes: 4 additions & 3 deletions src/journal/test-journal-flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fcntl.h>

#include "sd-journal.h"
#include "macro.h"
#include "journal-file.h"
#include "journal-internal.h"

Expand Down Expand Up @@ -49,13 +50,13 @@ int main(int argc, char *argv[]) {
JournalFile *f;

f = j->current_file;
assert(f && f->current_offset > 0);
assert_se(f && f->current_offset > 0);

r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
assert(r >= 0);
assert_se(r >= 0);

r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL);
assert(r >= 0);
assert_se(r >= 0);

n++;
if (n > 10000)
Expand Down
34 changes: 17 additions & 17 deletions src/journal/test-journal-interleaving.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,43 +212,43 @@ static void test_sequence_numbers(void) {

append_number(one, 1, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 1);
assert_se(seqnum == 1);
append_number(one, 2, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 2);
assert_se(seqnum == 2);

assert(one->header->state == STATE_ONLINE);
assert(!sd_id128_equal(one->header->file_id, one->header->machine_id));
assert(!sd_id128_equal(one->header->file_id, one->header->boot_id));
assert(sd_id128_equal(one->header->file_id, one->header->seqnum_id));
assert_se(one->header->state == STATE_ONLINE);
assert_se(!sd_id128_equal(one->header->file_id, one->header->machine_id));
assert_se(!sd_id128_equal(one->header->file_id, one->header->boot_id));
assert_se(sd_id128_equal(one->header->file_id, one->header->seqnum_id));

memcpy(&seqnum_id, &one->header->seqnum_id, sizeof(sd_id128_t));

assert_se(journal_file_open("two.journal", O_RDWR|O_CREAT, 0644,
true, false, NULL, NULL, one, &two) == 0);

assert(two->header->state == STATE_ONLINE);
assert(!sd_id128_equal(two->header->file_id, one->header->file_id));
assert(sd_id128_equal(one->header->machine_id, one->header->machine_id));
assert(sd_id128_equal(one->header->boot_id, one->header->boot_id));
assert(sd_id128_equal(one->header->seqnum_id, one->header->seqnum_id));
assert_se(two->header->state == STATE_ONLINE);
assert_se(!sd_id128_equal(two->header->file_id, one->header->file_id));
assert_se(sd_id128_equal(one->header->machine_id, one->header->machine_id));
assert_se(sd_id128_equal(one->header->boot_id, one->header->boot_id));
assert_se(sd_id128_equal(one->header->seqnum_id, one->header->seqnum_id));

append_number(two, 3, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 3);
assert_se(seqnum == 3);
append_number(two, 4, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 4);
assert_se(seqnum == 4);

test_close(two);

append_number(one, 5, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 5);
assert_se(seqnum == 5);

append_number(one, 6, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 6);
assert_se(seqnum == 6);

test_close(one);

Expand All @@ -258,11 +258,11 @@ static void test_sequence_numbers(void) {
assert_se(journal_file_open("two.journal", O_RDWR, 0,
true, false, NULL, NULL, NULL, &two) == 0);

assert(sd_id128_equal(two->header->seqnum_id, seqnum_id));
assert_se(sd_id128_equal(two->header->seqnum_id, seqnum_id));

append_number(two, 7, &seqnum);
printf("seqnum=%"PRIu64"\n", seqnum);
assert(seqnum == 5);
assert_se(seqnum == 5);

/* So..., here we have the same seqnum in two files with the
* same seqnum_id. */
Expand Down
3 changes: 2 additions & 1 deletion src/journal/test-journal-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
#include "journal-internal.h"
#include "util.h"
#include "log.h"
#include "macro.h"

#define N_ENTRIES 200

static void verify_contents(sd_journal *j, unsigned skip) {
unsigned i;

assert(j);
assert_se(j);

i = 0;
SD_JOURNAL_FOREACH(j) {
Expand Down
7 changes: 3 additions & 4 deletions src/libsystemd/sd-bus/test-bus-chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/

#include <assert.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
Expand All @@ -44,7 +43,7 @@ static int match_callback(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus
static int object_callback(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
int r;

assert(bus);
assert_se(bus);

if (sd_bus_message_is_method_error(m, NULL))
return 0;
Expand All @@ -68,7 +67,7 @@ static int server_init(sd_bus **_bus) {
int r;
const char *unique;

assert(_bus);
assert_se(_bus);

r = sd_bus_open_user(&bus);
if (r < 0) {
Expand Down Expand Up @@ -299,7 +298,7 @@ static void* client1(void*p) {
goto finish;
}

assert(streq(hello, "hello"));
assert_se(streq(hello, "hello"));

if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) {
log_error_errno(errno, "Failed to allocate pipe: %m");
Expand Down
Loading

0 comments on commit 0c0cdb0

Please sign in to comment.