test-journal-interleaving.c revision cf0fbc49e67b55f8d346fc94de28c90113505297
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Marius Vollmer
Copyright 2013 Zbigniew Jędrzejewski-Szmek
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <unistd.h>
#include "sd-journal.h"
#include "alloc-util.h"
#include "journal-file.h"
#include "journal-vacuum.h"
#include "log.h"
#include "parse-util.h"
#include "rm-rf.h"
#include "util.h"
/* This program tests skipping around in a multi-file journal.
*/
static bool arg_keep = false;
noreturn static void log_assert_errno(const char *text, int eno, const char *file, int line, const char *func) {
"'%s' failed at %s:%u (%s): %s.",
abort();
}
#define assert_ret(expr) \
do { \
if (_unlikely_(_r_ < 0)) \
} while (false)
JournalFile *f;
return f;
}
static void test_close(JournalFile *f) {
journal_file_close (f);
}
char *p;
static dual_timestamp previous_ts = {};
previous_ts = ts;
free(p);
}
static void test_check_number (sd_journal *j, int n) {
const void *d;
_cleanup_free_ char *k;
size_t l;
int x;
printf("%s\n", k);
assert_se(n == x);
}
int i;
for (i = 1; i <= count; i++) {
int r;
test_check_number(j, i);
assert_ret(r = sd_journal_next(j));
if (i == count)
assert_se(r == 0);
else
assert_se(r == 1);
}
}
for (int i = count; i >= 1; i--) {
int r;
test_check_number(j, i);
assert_ret(r = sd_journal_previous(j));
if (i == 1)
assert_se(r == 0);
else
assert_se(r == 1);
}
}
static void setup_sequential(void) {
}
static void setup_interleaved(void) {
}
char t[] = "/tmp/journal-skip-XXXXXX";
sd_journal *j;
int r;
setup();
/* Seek to head, iterate down.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
test_check_numbers_down(j, 4);
sd_journal_close(j);
/* Seek to tail, iterate up.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
test_check_numbers_up(j, 4);
sd_journal_close(j);
/* Seek to tail, skip to head, iterate down.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_se(r == 4);
test_check_numbers_down(j, 4);
sd_journal_close(j);
/* Seek to head, skip to tail, iterate up.
*/
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_se(r == 4);
test_check_numbers_up(j, 4);
sd_journal_close(j);
log_info("Done...");
if (arg_keep)
log_info("Not removing %s", t);
else {
}
puts("------------------------------------------------------------");
}
static void test_sequence_numbers(void) {
char t[] = "/tmp/journal-seq-XXXXXX";
/* restart server */
seqnum = 0;
/* So..., here we have the same seqnum in two files with the
* same seqnum_id. */
log_info("Done...");
if (arg_keep)
log_info("Not removing %s", t);
else {
}
}
/* journal_file_open requires a valid machine id */
return EXIT_TEST_SKIP;
return 0;
}