From: Thomas Weißschuh Date: Thu, 24 Nov 2022 16:38:58 +0000 (+0100) Subject: lscpu: test endianess X-Git-Tag: v2.39-rc1~367^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f145492fa871a5a08f466aae27886c2ddccec402;p=thirdparty%2Futil-linux.git lscpu: test endianess --- diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index f706b34291..3f28db61cb 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -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"); diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index 8cb0d630ce..ac73ea762a 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -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; diff --git a/tests/ts/lscpu/lscpu b/tests/ts/lscpu/lscpu index 5c4b28ec00..03249c335d 100755 --- a/tests/ts/lscpu/lscpu +++ b/tests/ts/lscpu/lscpu @@ -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 diff --git a/tests/ts/lscpu/mk-input.sh b/tests/ts/lscpu/mk-input.sh index 65e3d20f58..a19bad3739 100644 --- a/tests/ts/lscpu/mk-input.sh +++ b/tests/ts/lscpu/mk-input.sh @@ -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