Skip to content

Commit a19f9d8

Browse files
authored
Merge 7d0efe2 into ee388a7
2 parents ee388a7 + 7d0efe2 commit a19f9d8

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

NEWS.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ https://github.com/networkupstools/nut/milestone/12
286286
to bumping the debug verbosity of `upsdrvctl` tool. [#3276]
287287
* If we fail to stop a driver by signal (e.g. PID file was not saved),
288288
retry to `INSTCMD driver.exit` it by socket protocol. [#3277]
289+
* The NUT Integration Testing suite now also involves `upsdrvctl` to
290+
run one driver instance indirectly, helping make check-NIT` catch
291+
portability issues with different builds of the tool. [#2800, #3292]
289292

290293
- `upslog` tool updates:
291294
* Updated `help()` and failure messages to suggest `-m '*,-'` for logging

configure.ac

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6708,10 +6708,13 @@ AS_CASE([${target_os}],
67086708
AC_MSG_NOTICE([FWIW, assuming ABS_TOP_SRCDIR="$ABS_TOP_SRCDIR" and ABS_TOP_BUILDDIR="$ABS_TOP_BUILDDIR"])
67096709
])
67106710

6711-
dnl Use these at best for tests (e.g. nutconf), not production code:
6711+
dnl Use these at best for tests (e.g. nutconf, NIT), not production code:
67126712
AC_DEFINE_UNQUOTED([ABS_TOP_SRCDIR], ["${ABS_TOP_SRCDIR}"], [NUT source directory when the build was configured])
67136713
AC_DEFINE_UNQUOTED([ABS_TOP_BUILDDIR], ["${ABS_TOP_BUILDDIR}"], [NUT build directory when the build was configured])
67146714

6715+
AC_SUBST(ABS_TOP_SRCDIR)
6716+
AC_SUBST(ABS_TOP_BUILDDIR)
6717+
67156718
dnl ---------------------------------------------------------------------
67166719
AC_MSG_CHECKING([whether to install External API integration script: Enphase Monitor])
67176720
nut_with_extapi_enphase="no"

drivers/upsdrvctl.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -943,23 +943,38 @@ static void forkexec(char *const argv[], const ups_t *ups)
943943
BOOL ret;
944944
DWORD res;
945945
DWORD exit_code = 0;
946-
char commandline[SMALLBUF];
946+
char commandline[LARGEBUF];
947947
STARTUPINFO StartupInfo;
948948
PROCESS_INFORMATION ProcessInformation;
949949
int i = 1;
950950

951951
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
952952

953953
/* the command line is made of the driver name followed by args */
954-
snprintf(commandline, sizeof(commandline), "%s", ups->driver);
954+
if (strstr(argv[0], ups->driver)) {
955+
/* We already know whom to call (got a pointer to needle in the haystack) */
956+
snprintf(commandline, sizeof(commandline), "%s", argv[0]);
957+
} else {
958+
/* Hope for the PATH based resolution to work, perhaps the
959+
* driver program is located nearby (depends on configure
960+
* options). Note that for builds tested in the workspace
961+
* this may be misleading ("nearby" is under ".libs/" and
962+
* fails to run directly without the tweaks of libtool
963+
* wrapper provided in the directory just above).
964+
*/
965+
snprintf(commandline, sizeof(commandline), "%s%s", ups->driver, EXEEXT);
966+
}
967+
955968
while (argv[i] != NULL) {
956969
snprintfcat(commandline, sizeof(commandline), " %s", argv[i]);
957970
i++;
958971
}
959972

973+
upsdebugx(1, "%s[WIN32]: CreateProcess(argv0='%s' cmdline='%s')...",
974+
__func__, argv[0], commandline);
960975
ret = CreateProcess(
961-
argv[0],
962-
commandline,
976+
argv[0], /* Application/Module name, often the program to run */
977+
commandline, /* Full command line including the program to run and its args */
963978
NULL,
964979
NULL,
965980
FALSE,
@@ -1237,7 +1252,10 @@ static void start_driver(const ups_t *ups)
12371252
#ifndef WIN32
12381253
snprintf(dfn, sizeof(dfn), "%s/%s", driverpath, ups->driver);
12391254
#else /* WIN32 */
1240-
snprintf(dfn, sizeof(dfn), "%s/%s.exe", driverpath, ups->driver);
1255+
if (driverpath && *driverpath == '/')
1256+
snprintf(dfn, sizeof(dfn), "%s/%s.exe", driverpath, ups->driver);
1257+
else /* Assume windows-style path with backslashes */
1258+
snprintf(dfn, sizeof(dfn), "%s\\%s.exe", driverpath, ups->driver);
12411259
#endif /* WIN32 */
12421260
ret = stat(dfn, &fs);
12431261

tests/NIT/Makefile.am

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ EXTRA_DIST = nit.sh README.adoc
1313

1414
if WITH_CHECK_NIT
1515
check: check-NIT
16-
else
16+
else !WITH_CHECK_NIT
1717
check:
1818
@echo "NO-OP: $@ in `pwd` is inactive by default. Run 'configure --enable-check-NIT' or 'make check-NIT' explicitly" >&2
19-
endif
19+
endif !WITH_CHECK_NIT
20+
21+
# Paths possibly different from what automake provides (POSIXish)
22+
# when building on/for e.g. Windows. Matters where system() is used,
23+
# such as NIT suite using/testing upsdrvctl:
24+
ABS_TOP_SRCDIR = @ABS_TOP_SRCDIR@
25+
ABS_TOP_BUILDDIR = @ABS_TOP_BUILDDIR@
2026

2127
# Run in builddir, use script from srcdir
2228
# Avoid running "$<" - not all make implementations handle that
@@ -25,6 +31,7 @@ check-NIT: $(abs_srcdir)/nit.sh
2531
BUILTIN_RUN_AS_USER='$(RUN_AS_USER)' BUILTIN_RUN_AS_GROUP='$(RUN_AS_GROUP)' \
2632
abs_srcdir='$(abs_srcdir)' abs_builddir='$(abs_builddir)' \
2733
abs_top_srcdir='$(abs_top_srcdir)' abs_top_builddir='$(abs_top_builddir)' \
34+
ABS_TOP_SRCDIR='$(ABS_TOP_SRCDIR)' ABS_TOP_BUILDDIR='$(ABS_TOP_BUILDDIR)' \
2835
EXEEXT='$(EXEEXT)' \
2936
"$(abs_srcdir)/nit.sh"
3037

@@ -48,6 +55,7 @@ check-NIT-sandbox: $(abs_srcdir)/nit.sh
4855
BUILTIN_RUN_AS_USER='$(RUN_AS_USER)' BUILTIN_RUN_AS_GROUP='$(RUN_AS_GROUP)' \
4956
abs_srcdir='$(abs_srcdir)' abs_builddir='$(abs_builddir)' \
5057
abs_top_srcdir='$(abs_top_srcdir)' abs_top_builddir='$(abs_top_builddir)' \
58+
ABS_TOP_SRCDIR='$(ABS_TOP_SRCDIR)' ABS_TOP_BUILDDIR='$(ABS_TOP_BUILDDIR)' \
5159
EXEEXT='$(EXEEXT)' \
5260
"$(abs_srcdir)/nit.sh"
5361

tests/NIT/nit.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# different value like "nobody" or "nogroup" would be defaulted for test.
5454
#
5555
# Copyright
56-
# 2022-2025 Jim Klimov <jimklimov+nut@gmail.com>
56+
# 2022-2026 Jim Klimov <jimklimov+nut@gmail.com>
5757
#
5858
# License: GPLv2+
5959

@@ -427,7 +427,7 @@ else
427427
fi
428428

429429
log_info "Locating NUT programs to test:"
430-
for PROG in upsd upsc dummy-ups upsmon upslog upssched ; do
430+
for PROG in upsd upsc dummy-ups upsdrvctl upsmon upslog upssched ; do
431431
(command -v ${PROG}) || (command -v ${PROG}${EXEEXT-}) || die "Useless setup: ${PROG} not found in PATH: ${PATH}"
432432
done
433433

@@ -1000,9 +1000,24 @@ generatecfg_upsmon_secondary() {
10001000
generatecfg_ups_trivial() {
10011001
# Populate the configs for the run
10021002
( echo 'maxretry = 3' > "$NUT_CONFPATH/ups.conf" || exit
1003-
if [ x"${TOP_BUILDDIR}" != x ]; then
1004-
echo "driverpath = \"${TOP_BUILDDIR}/drivers\"" >> "$NUT_CONFPATH/ups.conf" || exit
1003+
if [ x"${ABS_TOP_BUILDDIR}" != x ]; then
1004+
# NOTE: Windows backslashes are pre-escaped in the configure-generated value
1005+
case "${ABS_TOP_BUILDDIR}" in
1006+
?":\\"*) PATHSEP='\\' ;;
1007+
*) PATHSEP="/" ;;
1008+
esac
1009+
echo "driverpath = \"${ABS_TOP_BUILDDIR}${PATHSEP}drivers\"" >> "$NUT_CONFPATH/ups.conf" || exit
1010+
else
1011+
# NOTE: Escaping presumed needed below, so for PATHSEP too
1012+
if [ x"${TOP_BUILDDIR}" != x ]; then
1013+
case "${TOP_BUILDDIR}" in
1014+
?":\"*) PATHSEP='\' ;;
1015+
*) PATHSEP="/" ;;
1016+
esac
1017+
echo "driverpath = \"${TOP_BUILDDIR}${PATHSEP}drivers\"" | sed 's,\\,\\\\,g' >> "$NUT_CONFPATH/ups.conf" || exit
1018+
fi
10051019
fi
1020+
unset PATHSEP
10061021
if [ -n "${NUT_DEBUG_MIN-}" ] ; then
10071022
echo "debug_min = ${NUT_DEBUG_MIN}" >> "$NUT_CONFPATH/ups.conf" || exit
10081023
fi
@@ -1359,8 +1374,9 @@ sandbox_start_drivers() {
13591374
if [ -n "${NUT_DEBUG_LEVEL_DRIVERS-}" ]; then
13601375
NUT_DEBUG_LEVEL="${NUT_DEBUG_LEVEL_DRIVERS}"
13611376
fi
1362-
#execcmd upsdrvctl ${ARG_FG} ${ARG_USER} start dummy &
1363-
execcmd dummy-ups -a dummy ${ARG_USER} ${ARG_FG} &
1377+
# Run one driver instance indirectly, to test the upsdrvctl tool too:
1378+
execcmd upsdrvctl ${ARG_FG} ${ARG_USER} start dummy &
1379+
#execcmd dummy-ups -a dummy ${ARG_USER} ${ARG_FG} &
13641380
PID_DUMMYUPS="$!"
13651381
log_debug "Tried to start dummy-ups driver for 'dummy' as PID $PID_DUMMYUPS"
13661382

0 commit comments

Comments
 (0)