]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: test endianess
authorThomas Weißschuh <thomas@t-8ch.de>
Thu, 24 Nov 2022 16:38:58 +0000 (17:38 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 27 Nov 2022 15:11:29 +0000 (16:11 +0100)
sys-utils/lscpu.c
sys-utils/lscpu.h
tests/ts/lscpu/lscpu
tests/ts/lscpu/mk-input.sh

index f706b342915d11db89c4bb17930b5e1d76589136..3f28db61cbc32fbb240f93973dade80c0e1937e5 100644 (file)
@@ -221,6 +221,15 @@ static void lscpu_context_init_paths(struct lscpu_cxt *cxt)
        DBG(MISC, ul_debugobj(cxt, "initialize paths"));
        ul_path_init_debug();
 
+       /* / */
+       cxt->rootfs = NULL;
+       if (cxt->prefix) {
+               cxt->rootfs = ul_new_path("/");
+               if (!cxt->rootfs)
+                       err(EXIT_FAILURE, _("failed to initialize rootfs handler"));
+               ul_path_set_prefix(cxt->rootfs, cxt->prefix);
+       }
+
        /* /sys/devices/system/cpu */
        cxt->syscpu = ul_new_path(_PATH_SYS_CPU);
        if (!cxt->syscpu)
@@ -253,6 +262,7 @@ static void lscpu_free_context(struct lscpu_cxt *cxt)
        DBG(MISC, ul_debugobj(cxt, " de-initialize paths"));
        ul_unref_path(cxt->syscpu);
        ul_unref_path(cxt->procfs);
+       ul_unref_path(cxt->rootfs);
 
        DBG(MISC, ul_debugobj(cxt, " freeing cpus"));
        for (i = 0; i < cxt->npossibles; i++) {
@@ -1000,7 +1010,7 @@ static void print_summary(struct lscpu_cxt *cxt)
        if (ct && ct->addrsz)
                add_summary_s(tb, sec, _("Address sizes:"), ct->addrsz);
 
-       if (sysfs_get_byteorder(NULL) == SYSFS_BYTEORDER_LITTLE)
+       if (sysfs_get_byteorder(cxt->rootfs) == SYSFS_BYTEORDER_LITTLE)
                add_summary_s(tb, sec, _("Byte Order:"), "Little Endian");
        else
                add_summary_s(tb, sec, _("Byte Order:"), "Big Endian");
index 8cb0d630ce88cfcaf4c41c56a78652b4cf80605c..ac73ea762abd899123dc0784ce356aa9ce99a9ca 100644 (file)
@@ -206,6 +206,7 @@ struct lscpu_cxt {
 
        struct path_cxt *syscpu; /* _PATH_SYS_CPU path handler */
        struct path_cxt *procfs; /* /proc path handler */
+       struct path_cxt *rootfs; /* / path handler */
 
        size_t ncputypes;
        struct lscpu_cputype **cputypes;
index 5c4b28ec000672aaf1bdf07048e5b5ea588b23aa..03249c335df40933f9da5e00b7de9fbfac39e70d 100755 (executable)
@@ -49,8 +49,10 @@ for dump in $(ls $TS_SELF/dumps/*.tar.gz | sort); do
        "${TS_CMD_LSCPU}" -p -y -s "${dumpdir}/${name}" \
                 >> ${TS_OUTPUT} 2>> $TS_ERRLOG
 
-       # LE/BE depends on binary
-       sed -i -e '/Byte Order:.*/d' $TS_OUTPUT
+       if [[ ! -e "${dumpdir}/${name}/sys/kernel/cpu_byteorder" ]]; then
+               # LE/BE depends on binary if we can't read it from the dump
+               sed -i -e '/Byte Order:.*/d' $TS_OUTPUT
+       fi
 
        ts_finalize_subtest
 done
index 65e3d20f58d583cfeaec81a15a42e1d1db303e8e..a19bad3739beae3218eb9f26467db96b266887f8 100644 (file)
@@ -37,6 +37,11 @@ fi
 $CP /sys/devices/system/cpu/* $TS_DUMP
 $CP /sys/devices/system/node/*/cpumap $TS_DUMP
 
+if [ -e "/sys/kernel/cpu_byteorder" ]; then
+       $CP /sys/kernel/cpu_byteorder $TS_DUMP
+fi
+
+
 tar zcvf $TS_NAME.tar.gz $TS_DUMP
 rm -rf $TS_DUMP