testing/nxdiag: Move to "system" and improve info generated

Move the application to the "System" category. Improve host OS info by using platform.uname() and get current config file using CONFIG_BASE_DEFCONFIG
This commit is contained in:
Lucas Saavedra Vaz 2023-05-26 19:50:04 -03:00 committed by Xiang Xiao
parent df418bea81
commit 9cc710e954
6 changed files with 55 additions and 49 deletions

View File

@ -1,4 +1,4 @@
config TESTING_NXDIAG menuconfig SYSTEM_NXDIAG
bool "System information and diagnostic (nxdiag)" bool "System information and diagnostic (nxdiag)"
default n default n
---help--- ---help---
@ -6,19 +6,19 @@ config TESTING_NXDIAG
and target system information. It can also perform some and target system information. It can also perform some
diagnostic checks on the host and target systems. diagnostic checks on the host and target systems.
if TESTING_NXDIAG if SYSTEM_NXDIAG
config TESTING_NXDIAG_PRIORITY config SYSTEM_NXDIAG_PRIORITY
int "Nxdiag task priority" int "Nxdiag task priority"
default 100 default 100
config TESTING_NXDIAG_STACKSIZE config SYSTEM_NXDIAG_STACKSIZE
int "Nxdiag stack size" int "Nxdiag stack size"
default DEFAULT_TASK_STACKSIZE default DEFAULT_TASK_STACKSIZE
comment "NuttX system information" comment "NuttX system information"
config TESTING_NXDIAG_CONF config SYSTEM_NXDIAG_CONF
bool "Get NuttX configuration" bool "Get NuttX configuration"
default n default n
---help--- ---help---
@ -26,7 +26,7 @@ config TESTING_NXDIAG_CONF
used to compile NuttX. This is useful for debugging the host and used to compile NuttX. This is useful for debugging the host and
target systems. Enables the "-c" and "--nuttx-config" options. target systems. Enables the "-c" and "--nuttx-config" options.
config TESTING_NXDIAG_COMP_FLAGS config SYSTEM_NXDIAG_COMP_FLAGS
bool "Get NuttX compilation flags" bool "Get NuttX compilation flags"
default n default n
---help--- ---help---
@ -36,7 +36,7 @@ config TESTING_NXDIAG_COMP_FLAGS
comment "Host system infromation" comment "Host system infromation"
config TESTING_NXDIAG_HOST_PATH config SYSTEM_NXDIAG_HOST_PATH
bool "Get host system PATH" bool "Get host system PATH"
default n default n
---help--- ---help---
@ -44,7 +44,7 @@ config TESTING_NXDIAG_HOST_PATH
variable. This is useful for debugging the host system. variable. This is useful for debugging the host system.
Enables the "-p" and "--host-path" options. Enables the "-p" and "--host-path" options.
config TESTING_NXDIAG_HOST_PACKAGES config SYSTEM_NXDIAG_HOST_PACKAGES
bool "Get host system packages" bool "Get host system packages"
default n default n
---help--- ---help---
@ -52,7 +52,7 @@ config TESTING_NXDIAG_HOST_PACKAGES
on the host system. This is useful for debugging the host on the host system. This is useful for debugging the host
system. Enables the "-k" and "--host-packages" options. system. Enables the "-k" and "--host-packages" options.
config TESTING_NXDIAG_HOST_MODULES config SYSTEM_NXDIAG_HOST_MODULES
bool "Get host system python modules" bool "Get host system python modules"
default n default n
---help--- ---help---
@ -62,10 +62,10 @@ config TESTING_NXDIAG_HOST_MODULES
comment "Vendor specific information" comment "Vendor specific information"
config TESTING_NXDIAG_ESPRESSIF config SYSTEM_NXDIAG_ESPRESSIF
bool "Espressif" bool "Espressif"
default n default n
---help--- ---help---
Enable Espressif-specific information and checks. Enable Espressif-specific information and checks.
endif endif # SYSTEM_NXDIAG

View File

@ -1,5 +1,5 @@
############################################################################ ############################################################################
# apps/testing/nxdiag/Make.defs # apps/system/nxdiag/Make.defs
# #
# Licensed to the Apache Software Foundation (ASF) under one or more # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # contributor license agreements. See the NOTICE file distributed with
@ -18,6 +18,6 @@
# #
############################################################################ ############################################################################
ifneq ($(CONFIG_TESTING_NXDIAG),) ifneq ($(CONFIG_SYSTEM_NXDIAG),)
CONFIGURED_APPS += $(APPDIR)/testing/nxdiag CONFIGURED_APPS += $(APPDIR)/system/nxdiag
endif endif

View File

@ -1,5 +1,5 @@
############################################################################ ############################################################################
# apps/testing/nxdiag/Makefile # apps/system/nxdiag/Makefile
# #
# Licensed to the Apache Software Foundation (ASF) under one or more # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with # contributor license agreements. See the NOTICE file distributed with
@ -25,40 +25,40 @@ NXTOOLSDIR = $(APPDIR)/tools
# Sysinfo application info # Sysinfo application info
PROGNAME = nxdiag PROGNAME = nxdiag
PRIORITY = $(CONFIG_TESTING_NXDIAG_PRIORITY) PRIORITY = $(CONFIG_SYSTEM_NXDIAG_PRIORITY)
STACKSIZE = $(CONFIG_TESTING_NXDIAG_STACKSIZE) STACKSIZE = $(CONFIG_SYSTEM_NXDIAG_STACKSIZE)
MODULE = $(CONFIG_TESTING_NXDIAG) MODULE = $(CONFIG_SYSTEM_NXDIAG)
# Sysinfo application # Sysinfo application
MAINSRC = nxdiag.c MAINSRC = nxdiag.c
NXDIAG_FLAGS = "$(realpath $(TOPDIR))" NXDIAG_FLAGS = "$(realpath $(TOPDIR))"
ifeq ($(CONFIG_TESTING_NXDIAG_CONF),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_CONF),y)
NXDIAG_FLAGS += --config NXDIAG_FLAGS += --config
endif endif
ifeq ($(CONFIG_TESTING_NXDIAG_COMP_FLAGS),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_COMP_FLAGS),y)
NXDIAG_FLAGS += --flags \""$(shell echo '$(CFLAGS)' | sed 's/"/\\\\\\"/g')"\" NXDIAG_FLAGS += --flags \""$(shell echo '$(CFLAGS)' | sed 's/"/\\\\\\"/g')"\"
NXDIAG_FLAGS += \""$(shell echo '$(CXXFLAGS)' | sed 's/"/\\\\\\"/g')"\" NXDIAG_FLAGS += \""$(shell echo '$(CXXFLAGS)' | sed 's/"/\\\\\\"/g')"\"
NXDIAG_FLAGS += \""$(shell echo '$(LDFLAGS)' | sed 's/"/\\\\\\"/g')"\" NXDIAG_FLAGS += \""$(shell echo '$(LDFLAGS)' | sed 's/"/\\\\\\"/g')"\"
endif endif
ifeq ($(CONFIG_TESTING_NXDIAG_HOST_PACKAGES),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_HOST_PACKAGES),y)
NXDIAG_FLAGS += --packages NXDIAG_FLAGS += --packages
endif endif
ifeq ($(CONFIG_TESTING_NXDIAG_HOST_MODULES),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_HOST_MODULES),y)
NXDIAG_FLAGS += --modules NXDIAG_FLAGS += --modules
endif endif
ifeq ($(CONFIG_TESTING_NXDIAG_HOST_PATH),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_HOST_PATH),y)
NXDIAG_FLAGS += --path NXDIAG_FLAGS += --path
endif endif
# Vendor-specific checks # Vendor-specific checks
ifeq ($(CONFIG_TESTING_NXDIAG_ESPRESSIF),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_ESPRESSIF),y)
ifdef ESPTOOL_BINDIR ifdef ESPTOOL_BINDIR
NXDIAG_FLAGS += --espressif "$(ESPTOOL_BINDIR)" NXDIAG_FLAGS += --espressif "$(ESPTOOL_BINDIR)"
else else

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* apps/testing/nxdiag/nxdiag.c * apps/system/nxdiag/nxdiag.c
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
@ -29,6 +29,7 @@
#include <unistd.h> #include <unistd.h>
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/info.h>
#include <nuttx/version.h> #include <nuttx/version.h>
#include "sysinfo.h" #include "sysinfo.h"
@ -45,25 +46,25 @@ static const char *g_valid_args[] =
"--help", "--help",
"-n", "-n",
"--nuttx", "--nuttx",
#ifdef CONFIG_TESTING_NXDIAG_COMP_FLAGS #ifdef CONFIG_SYSTEM_NXDIAG_COMP_FLAGS
"-f", "-f",
"--flags", "--flags",
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_CONF #ifdef CONFIG_SYSTEM_NXDIAG_CONF
"-c", "-c",
"--config", "--config",
#endif #endif
"-o", "-o",
"--host-os", "--host-os",
#ifdef CONFIG_TESTING_NXDIAG_HOST_PATH #ifdef CONFIG_SYSTEM_NXDIAG_HOST_PATH
"-p", "-p",
"--host-path", "--host-path",
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_HOST_PACKAGES #ifdef CONFIG_SYSTEM_NXDIAG_HOST_PACKAGES
"-k", "-k",
"--host-packages", "--host-packages",
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_HOST_MODULES #ifdef CONFIG_SYSTEM_NXDIAG_HOST_MODULES
"-m", "-m",
"--host-modules", "--host-modules",
#endif #endif
@ -189,25 +190,25 @@ static void print_usage(char *prg)
Show this message\n"); Show this message\n");
fprintf(stderr, " -n, --nuttx \ fprintf(stderr, " -n, --nuttx \
Output the NuttX operational system information.\n"); Output the NuttX operational system information.\n");
#ifdef CONFIG_TESTING_NXDIAG_COMP_FLAGS #ifdef CONFIG_SYSTEM_NXDIAG_COMP_FLAGS
fprintf(stderr, " -f, --flags \ fprintf(stderr, " -f, --flags \
Output the NuttX compilation and linker flags used.\n"); Output the NuttX compilation and linker flags used.\n");
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_CONF #ifdef CONFIG_SYSTEM_NXDIAG_CONF
fprintf(stderr, " -c, --config \ fprintf(stderr, " -c, --config \
Output the NuttX configuration options used.\n"); Output the NuttX configuration options used.\n");
#endif #endif
fprintf(stderr, " -o, --host-os \ fprintf(stderr, " -o, --host-os \
Output the host system operational system information.\n"); Output the host system operational system information.\n");
#ifdef CONFIG_TESTING_NXDIAG_HOST_PATH #ifdef CONFIG_SYSTEM_NXDIAG_HOST_PATH
fprintf(stderr, " -p, --host-path \ fprintf(stderr, " -p, --host-path \
Output the host PATH environment variable.\n"); Output the host PATH environment variable.\n");
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_HOST_PACKAGES #ifdef CONFIG_SYSTEM_NXDIAG_HOST_PACKAGES
fprintf(stderr, " -k, --host-packages \ fprintf(stderr, " -k, --host-packages \
Output the host installed system packages.\n"); Output the host installed system packages.\n");
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_HOST_MODULES #ifdef CONFIG_SYSTEM_NXDIAG_HOST_MODULES
fprintf(stderr, " -m, --host-modules \ fprintf(stderr, " -m, --host-modules \
Output the host installed Python modules.\n"); Output the host installed Python modules.\n");
#endif #endif
@ -258,10 +259,11 @@ int main(int argc, char *argv[])
#else #else
printf("\tBuild: %s\n", CONFIG_VERSION_BUILD); printf("\tBuild: %s\n", CONFIG_VERSION_BUILD);
#endif #endif
printf("\tArch: %s\n\n", CONFIG_ARCH); printf("\tArch: %s\n", CONFIG_ARCH);
printf("\tConfig: %s\n\n", CONFIG_BASE_DEFCONFIG);
} }
#ifdef CONFIG_TESTING_NXDIAG_COMP_FLAGS #ifdef CONFIG_SYSTEM_NXDIAG_COMP_FLAGS
if (search_str_in_arr(argc, argv, "-f") || if (search_str_in_arr(argc, argv, "-f") ||
search_str_in_arr(argc, argv, "--flags") || search_str_in_arr(argc, argv, "--flags") ||
search_str_in_arr(argc, argv, "--all")) search_str_in_arr(argc, argv, "--all"))
@ -275,7 +277,7 @@ int main(int argc, char *argv[])
} }
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_CONF #ifdef CONFIG_SYSTEM_NXDIAG_CONF
if (search_str_in_arr(argc, argv, "-c") || if (search_str_in_arr(argc, argv, "-c") ||
search_str_in_arr(argc, argv, "--config") || search_str_in_arr(argc, argv, "--config") ||
search_str_in_arr(argc, argv, "--all")) search_str_in_arr(argc, argv, "--all"))
@ -295,7 +297,7 @@ int main(int argc, char *argv[])
printf("\t%s\n\n", OS_VERSION); printf("\t%s\n\n", OS_VERSION);
} }
#ifdef CONFIG_TESTING_NXDIAG_HOST_PATH #ifdef CONFIG_SYSTEM_NXDIAG_HOST_PATH
if (search_str_in_arr(argc, argv, "-p") || if (search_str_in_arr(argc, argv, "-p") ||
search_str_in_arr(argc, argv, "--host-path") || search_str_in_arr(argc, argv, "--host-path") ||
search_str_in_arr(argc, argv, "--all")) search_str_in_arr(argc, argv, "--all"))
@ -305,7 +307,7 @@ int main(int argc, char *argv[])
} }
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_HOST_PACKAGES #ifdef CONFIG_SYSTEM_NXDIAG_HOST_PACKAGES
if (search_str_in_arr(argc, argv, "-k") || if (search_str_in_arr(argc, argv, "-k") ||
search_str_in_arr(argc, argv, "--host-packages") || search_str_in_arr(argc, argv, "--host-packages") ||
search_str_in_arr(argc, argv, "--all")) search_str_in_arr(argc, argv, "--all"))
@ -315,7 +317,7 @@ int main(int argc, char *argv[])
} }
#endif #endif
#ifdef CONFIG_TESTING_NXDIAG_HOST_MODULES #ifdef CONFIG_SYSTEM_NXDIAG_HOST_MODULES
if (search_str_in_arr(argc, argv, "-m") || if (search_str_in_arr(argc, argv, "-m") ||
search_str_in_arr(argc, argv, "--host-modules") || search_str_in_arr(argc, argv, "--host-modules") ||
search_str_in_arr(argc, argv, "--all")) search_str_in_arr(argc, argv, "--all"))
@ -336,7 +338,7 @@ int main(int argc, char *argv[])
* in Documentation/applications/nxdiag * in Documentation/applications/nxdiag
*/ */
#ifdef CONFIG_TESTING_NXDIAG_ESPRESSIF #ifdef CONFIG_SYSTEM_NXDIAG_ESPRESSIF
printf("Espressif specific information:\n\n"); printf("Espressif specific information:\n\n");
printf("Bootloader version:\n"); printf("Bootloader version:\n");
print_array(ESPRESSIF_BOOTLOADER, ESPRESSIF_BOOTLOADER_ARRAY_SIZE); print_array(ESPRESSIF_BOOTLOADER, ESPRESSIF_BOOTLOADER_ARRAY_SIZE);

View File

@ -181,8 +181,7 @@ def get_os_version():
""" """
Gets the OS distribution and version. This function works on Linux, Windows, Gets the OS distribution and version. This function works on Linux, Windows,
and macOS. On Linux, if the distro package is installed, it will be used to and macOS. On Linux, if the distro package is installed, it will be used to
get the OS distribution. Otherwise, the platform.system() function will be get the OS distribution.
used.
Args: Args:
None. None.
@ -192,24 +191,29 @@ def get_os_version():
""" """
os_name = platform.system() os_name = platform.system()
os_version = platform.release() sys_id = ""
os_distro = ""
if os_name == "Windows": if os_name == "Windows":
os_distro = "Windows" os_distro = "Windows"
os_version = platform.win32_ver()[0] os_version = platform.win32_ver()[0]
sys_id = f"{os_distro} {os_version}"
elif os_name == "Darwin": elif os_name == "Darwin":
os_distro = "macOS" os_distro = "macOS"
os_uname = " ".join(platform.uname())
os_version = platform.mac_ver()[0] os_version = platform.mac_ver()[0]
sys_id = f"{os_distro} {os_version} {os_uname}"
elif os_name == "Linux": elif os_name == "Linux":
os_uname = " ".join(platform.uname())
try: try:
import distro import distro
return distro.name(pretty=True) sys_id = distro.name(pretty=True) + " " + os_uname
except ImportError: except ImportError:
os_distro = platform.system() sys_id = os_uname
return f"{os_distro} {os_version}" return sys_id
def get_compilation_flags(flags): def get_compilation_flags(flags):