int main(int argc, char *argv[]) { int a, v; v = detect_virtualization(); if (v == -EPERM || v == -EACCES) return EXIT_TEST_SKIP; assert_se(v >= 0); log_info("virtualization=%s id=%s", VIRTUALIZATION_IS_CONTAINER(v) ? "container" : VIRTUALIZATION_IS_VM(v) ? "vm" : "n/a", virtualization_to_string(v)); a = uname_architecture(); assert_se(a >= 0); log_info("uname architecture=%s", architecture_to_string(a)); a = native_architecture(); assert_se(a >= 0); log_info("native architecture=%s", architecture_to_string(a)); log_info("primary library architecture=" LIB_ARCH_TUPLE); return 0; }
int main(int argc, char *argv[]) { int a, v; const char *p; assert_se(architecture_from_string("") < 0); assert_se(architecture_from_string(NULL) < 0); assert_se(architecture_from_string("hoge") < 0); assert_se(architecture_to_string(-1) == NULL); assert_se(architecture_from_string(architecture_to_string(0)) == 0); assert_se(architecture_from_string(architecture_to_string(1)) == 1); v = detect_virtualization(); if (IN_SET(v, -EPERM, -EACCES)) return EXIT_TEST_SKIP; assert_se(v >= 0); log_info("virtualization=%s id=%s", VIRTUALIZATION_IS_CONTAINER(v) ? "container" : VIRTUALIZATION_IS_VM(v) ? "vm" : "n/a", virtualization_to_string(v)); a = uname_architecture(); assert_se(a >= 0); p = architecture_to_string(a); assert_se(p); log_info("uname architecture=%s", p); assert_se(architecture_from_string(p) == a); a = native_architecture(); assert_se(a >= 0); p = architecture_to_string(a); assert_se(p); log_info("native architecture=%s", p); assert_se(architecture_from_string(p) == a); log_info("primary library architecture=" LIB_ARCH_TUPLE); return 0; }
static void test_personality(void) { assert_se(personality_to_string(PER_LINUX)); assert_se(!personality_to_string(PERSONALITY_INVALID)); assert_se(streq(personality_to_string(PER_LINUX), architecture_to_string(native_architecture()))); assert_se(personality_from_string(personality_to_string(PER_LINUX)) == PER_LINUX); assert_se(personality_from_string(architecture_to_string(native_architecture())) == PER_LINUX); #ifdef __x86_64__ assert_se(streq_ptr(personality_to_string(PER_LINUX), "x86-64")); assert_se(streq_ptr(personality_to_string(PER_LINUX32), "x86")); assert_se(personality_from_string("x86-64") == PER_LINUX); assert_se(personality_from_string("x86") == PER_LINUX32); assert_se(personality_from_string("ia64") == PERSONALITY_INVALID); assert_se(personality_from_string(NULL) == PERSONALITY_INVALID); assert_se(personality_from_string(personality_to_string(PER_LINUX32)) == PER_LINUX32); #endif }
static void test_condition_test_architecture(void) { Condition *condition; const char *sa; int a; a = uname_architecture(); assert_se(a >= 0); sa = architecture_to_string(a); assert_se(sa); condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false); assert_se(condition_test(condition)); condition_free(condition); condition = condition_new(CONDITION_ARCHITECTURE, "garbage value", false, false); assert_se(condition_test(condition) < 0); condition_free(condition); condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true); assert_se(!condition_test(condition)); condition_free(condition); }
int main(int argc, char *argv[]) { _cleanup_(loop_device_unrefp) LoopDevice *d = NULL; _cleanup_(decrypted_image_unrefp) DecryptedImage *di = NULL; _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL; int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = loop_device_make_by_path(arg_image, (arg_flags & DISSECT_IMAGE_READ_ONLY) ? O_RDONLY : O_RDWR, &d); if (r < 0) { log_error_errno(r, "Failed to set up loopback device: %m"); goto finish; } if (!arg_root_hash) { r = root_hash_load(arg_image, &arg_root_hash, &arg_root_hash_size); if (r < 0) { log_error_errno(r, "Failed to read root hash file for %s: %m", arg_image); goto finish; } } r = dissect_image(d->fd, arg_root_hash, arg_root_hash_size, arg_flags, &m); if (r == -ENOPKG) { log_error_errno(r, "Couldn't identify a suitable partition table or file system in %s.", arg_image); goto finish; } if (r == -EADDRNOTAVAIL) { log_error_errno(r, "No root partition for specified root hash found in %s.", arg_image); goto finish; } if (r == -ENOTUNIQ) { log_error_errno(r, "Multiple suitable root partitions found in image %s.", arg_image); goto finish; } if (r == -ENXIO) { log_error_errno(r, "No suitable root partition found in image %s.", arg_image); goto finish; } if (r == -EPROTONOSUPPORT) { log_error_errno(r, "Device %s is loopback block device with partition scanning turned off, please turn it on.", arg_image); goto finish; } if (r < 0) { log_error_errno(r, "Failed to dissect image: %m"); goto finish; } switch (arg_action) { case ACTION_DISSECT: { unsigned i; for (i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) { DissectedPartition *p = m->partitions + i; int k; if (!p->found) continue; printf("Found %s '%s' partition", p->rw ? "writable" : "read-only", partition_designator_to_string(i)); if (!sd_id128_is_null(p->uuid)) printf(" (UUID " SD_ID128_FORMAT_STR ")", SD_ID128_FORMAT_VAL(p->uuid)); if (p->fstype) printf(" of type %s", p->fstype); if (p->architecture != _ARCHITECTURE_INVALID) printf(" for %s", architecture_to_string(p->architecture)); k = PARTITION_VERITY_OF(i); if (k >= 0) printf(" %s verity", m->partitions[k].found ? "with" : "without"); if (p->partno >= 0) printf(" on partition #%i", p->partno); if (p->node) printf(" (%s)", p->node); putchar('\n'); } r = dissected_image_acquire_metadata(m); if (r < 0) { log_error_errno(r, "Failed to acquire image metadata: %m"); goto finish; } if (m->hostname) printf(" Hostname: %s\n", m->hostname); if (!sd_id128_is_null(m->machine_id)) printf("Machine ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(m->machine_id)); if (!strv_isempty(m->machine_info)) { char **p, **q; STRV_FOREACH_PAIR(p, q, m->machine_info) printf("%s %s=%s\n", p == m->machine_info ? "Mach. Info:" : " ", *p, *q); } if (!strv_isempty(m->os_release)) { char **p, **q; STRV_FOREACH_PAIR(p, q, m->os_release) printf("%s %s=%s\n", p == m->os_release ? "OS Release:" : " ", *p, *q); } break; } case ACTION_MOUNT: r = dissected_image_decrypt_interactively(m, NULL, arg_root_hash, arg_root_hash_size, arg_flags, &di); if (r < 0) goto finish; r = dissected_image_mount(m, arg_path, UID_INVALID, arg_flags); if (r < 0) { log_error_errno(r, "Failed to mount image: %m"); goto finish; } if (di) { r = decrypted_image_relinquish(di); if (r < 0) { log_error_errno(r, "Failed to relinquish DM devices: %m"); goto finish; } } loop_device_relinquish(d); break; default: assert_not_reached("Unknown action."); } finish: free(arg_root_hash); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }