Merge pull request #25732 from enr0n/unit-test-machine-id-initialized
unit tests: do not fail when `/etc/machine-id` is empty
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
#include "sd-journal.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
@@ -262,22 +263,26 @@ static void test_sequence_numbers_one(void) {
|
||||
|
||||
test_close(one);
|
||||
|
||||
/* restart server */
|
||||
seqnum = 0;
|
||||
/* If the machine-id is not initialized, the header file verification
|
||||
* (which happens when re-opening a journal file) will fail. */
|
||||
if (sd_id128_get_machine(NULL) >= 0) {
|
||||
/* restart server */
|
||||
seqnum = 0;
|
||||
|
||||
assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0,
|
||||
UINT64_MAX, NULL, m, NULL, NULL, &two) == 0);
|
||||
assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0,
|
||||
UINT64_MAX, NULL, m, NULL, NULL, &two) == 0);
|
||||
|
||||
assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id));
|
||||
assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id));
|
||||
|
||||
append_number(two, 7, &seqnum);
|
||||
printf("seqnum=%"PRIu64"\n", seqnum);
|
||||
assert_se(seqnum == 5);
|
||||
append_number(two, 7, &seqnum);
|
||||
printf("seqnum=%"PRIu64"\n", seqnum);
|
||||
assert_se(seqnum == 5);
|
||||
|
||||
/* So..., here we have the same seqnum in two files with the
|
||||
* same seqnum_id. */
|
||||
/* So..., here we have the same seqnum in two files with the
|
||||
* same seqnum_id. */
|
||||
|
||||
test_close(two);
|
||||
test_close(two);
|
||||
}
|
||||
|
||||
log_info("Done...");
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ TEST(chase_symlinks) {
|
||||
assert_se(symlink("/usr/../etc/./machine-id", p) >= 0);
|
||||
|
||||
r = chase_symlinks(p, NULL, 0, NULL, &pfd);
|
||||
if (r != -ENOENT) {
|
||||
if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
sd_id128_t a, b;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST(id128) {
|
||||
assert_se(!sd_id128_in_set(id, ID128_WALDI));
|
||||
assert_se(!sd_id128_in_set(id, ID128_WALDI, ID128_WALDI));
|
||||
|
||||
if (sd_booted() > 0 && access("/etc/machine-id", F_OK) >= 0) {
|
||||
if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) {
|
||||
assert_se(sd_id128_get_machine(&id) == 0);
|
||||
printf("machine: %s\n", sd_id128_to_string(id, t));
|
||||
|
||||
@@ -170,7 +170,7 @@ TEST(id128) {
|
||||
assert_se(lseek(fd, 0, SEEK_SET) == 0);
|
||||
assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -EUCLEAN);
|
||||
|
||||
if (sd_booted() > 0 && access("/etc/machine-id", F_OK) >= 0) {
|
||||
if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) {
|
||||
assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0);
|
||||
assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id2) >= 0);
|
||||
assert_se(sd_id128_equal(id, id2));
|
||||
@@ -195,8 +195,8 @@ TEST(benchmark_sd_id128_get_machine_app_specific) {
|
||||
unsigned iterations = slow_tests_enabled() ? 1000000 : 1000;
|
||||
usec_t t, q;
|
||||
|
||||
if (access("/etc/machine-id", F_OK) < 0 && errno == ENOENT)
|
||||
return (void) log_tests_skipped("/etc/machine-id does not exist");
|
||||
if (sd_id128_get_machine(NULL) < 0)
|
||||
return (void) log_tests_skipped("/etc/machine-id is not initialized");
|
||||
|
||||
log_info("/* %s (%u iterations) */", __func__, iterations);
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "all-units.h"
|
||||
#include "alloc-util.h"
|
||||
#include "capability-util.h"
|
||||
@@ -518,7 +520,7 @@ TEST(install_printf, .sd_booted = true) {
|
||||
|
||||
_cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *gid = NULL, *group = NULL, *uid = NULL, *user = NULL;
|
||||
|
||||
if (access("/etc/machine-id", F_OK) >= 0)
|
||||
if (sd_id128_get_machine(NULL) >= 0)
|
||||
assert_se(specifier_machine_id('m', NULL, NULL, NULL, &mid) >= 0 && mid);
|
||||
if (sd_booted() > 0)
|
||||
assert_se(specifier_boot_id('b', NULL, NULL, NULL, &bid) >= 0 && bid);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "all-units.h"
|
||||
#include "glob-util.h"
|
||||
@@ -261,7 +263,7 @@ TEST_RET(unit_printf, .sd_booted = true) {
|
||||
assert_se(short_hostname);
|
||||
assert_se(specifier_pretty_hostname('q', NULL, NULL, NULL, &pretty_hostname) == 0);
|
||||
assert_se(pretty_hostname);
|
||||
if (access("/etc/machine-id", F_OK) >= 0) {
|
||||
if (sd_id128_get_machine(NULL) >= 0) {
|
||||
assert_se(specifier_machine_id('m', NULL, NULL, NULL, &machine_id) >= 0);
|
||||
assert_se(machine_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user