Skip to content

Commit

Permalink
Regression test tweaks and other minor things
Browse files Browse the repository at this point in the history
Notable changes:

src/cmd/ksh93/tests/select.sh:
- Rename to loop.sh.
- Add missing regression tests for 'break' and 'continue'.
  • Loading branch information
McDutchie committed Jan 27, 2024
1 parent 4e979ec commit be6b5e9
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/cmd/ksh93/bltins/typeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ int b_typeset(int argc,char *argv[],Shbltin_t *context)

memset(&tdata,0,sizeof(tdata));
troot = sh.var_tree;
if(ntp) /* custom declaration command added using enum */
if(ntp) /* type declaration command added using 'typeset -T' or 'enum' */
{
tdata.tp = ntp->tp;
opt_info.disc = (Optdisc_t*)ntp->optinfof;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/data/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* Copyright (c) 2020-2023 Contributors to ksh 93u+m *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down
24 changes: 16 additions & 8 deletions src/cmd/ksh93/tests/arith.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@

. "${SHTESTS_COMMON:-${0%/*}/_common}"

integer hasposix=0
(set -o posix) 2>/dev/null && ((hasposix++)) # not using [[ -o ?posix ]] as it's broken on 93v-
enum bool=(false true)

bool HAVE_signbit=false
if typeset -f .sh.math.signbit >/dev/null && (( signbit(-NaN) ))
then HAVE_signbit=true
else warning "-lm does not support signbit(-NaN)"
fi

bool HAVE_posix=false
(set -o posix) 2>/dev/null && HAVE_posix=true # not using [[ -o ?posix ]] as it's broken on 93v-

trap '' FPE # NOTE: osf.alpha requires this (no ieee math)

Expand Down Expand Up @@ -351,7 +359,7 @@ unset x
x=010
(( x == 10 )) || err_exit 'leading zeros in x treated as octal arithmetic with ((x))'
(( $x == 10 )) || err_exit 'leading zeros in x treated as octal arithmetic with (($x))'
if ((hasposix))
if ((HAVE_posix))
then set --posix
((x == 8)) || err_exit 'posix: leading zeros in x not treated as octal arithmetic with ((x))'
(($x == 8)) || err_exit 'posix: leading zeros in x not treated as octal arithmetic with (($x))'
Expand Down Expand Up @@ -454,8 +462,8 @@ then set \
Inf inf \
-Inf -inf \
Nan nan \
-Nan -nan \
1.0/0.0 inf
((HAVE_signbit)) && set -- "$@" -Nan -nan
while (( $# >= 2 ))
do x=$(printf "%g\n" $(($1)))
[[ $x == $2 ]] || err_exit "printf '%g\\n' \$(($1)) failed -- expected $2, got $x"
Expand Down Expand Up @@ -746,7 +754,7 @@ print -- -020 | read x
((x == -20)) || err_exit 'numbers with leading -0 treated as octal outside ((...))'
print -- -8#20 | read x
((x == -16)) || err_exit 'numbers with leading -8# should be treated as octal'
if ((hasposix))
if ((HAVE_posix))
then set --posix
(($r == 16)) || err_exit 'posix: leading 0 not treated as octal inside ((...))'
x=$(($r))
Expand All @@ -772,7 +780,7 @@ let "$x==10" || err_exit 'arithmetic with $x where $x is 010 should be decimal i
x010=99
((x$x == 99 )) || err_exit 'arithmetic with x$x where x=010 should be $x010'
(( 3+$x == 13 )) || err_exit '3+$x where x=010 should be 13 in ((...))'
if ((hasposix))
if ((HAVE_posix))
then set --posix
(( 3+$x == 11 )) || err_exit 'posix: 3+$x where x=010 should be 11 in ((...))'
set --noposix
Expand Down Expand Up @@ -904,7 +912,7 @@ unset got

# ======
# https://github.com/ksh93/ksh/issues/326
((hasposix)) && for m in u d i o x X
((HAVE_posix)) && for m in u d i o x X
do
set --posix
case $m in
Expand All @@ -923,7 +931,7 @@ done
# BUG_ARITHNAN: In ksh <= 93u+m 2021-11-15 and zsh 5.6 - 5.8, the case-insensitive
# floating point constants Inf and NaN are recognised in arithmetic evaluation,
# overriding any variables with the names Inf, NaN, INF, nan, etc.
if ((hasposix))
if ((HAVE_posix))
then set --posix
Inf=42 NaN=13
inf=421 nan=137
Expand Down
5 changes: 3 additions & 2 deletions src/cmd/ksh93/tests/comvario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

. "${SHTESTS_COMMON:-${0%/*}/_common}"

typeset -is HAVE_signbit=0
enum bool=(false true)
bool HAVE_signbit=false

if typeset -f .sh.math.signbit >/dev/null && (( signbit(-NaN) ))
then HAVE_signbit=1
then HAVE_signbit=true
else warning "-lm does not support signbit(-NaN)"
fi

Expand Down
10 changes: 5 additions & 5 deletions src/cmd/ksh93/tests/libcmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,16 @@ if builtin cat 2> /dev/null; then
if [[ $'\n'${ builtin; }$'\n' == *$'\n/opt/ast/bin/cat\n'* ]]
then exp=' version cat (*) ????-??-??'
got=$(/opt/ast/bin/cat --version 2>&1)
[[ $got == $exp ]] || err_exit "path-bound builtin not executable by literal canonical path" \
[[ $got == $exp && $got != *$'\n'* ]] || err_exit "path-bound builtin not executable by literal canonical path" \
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
got=$(PATH=/opt/ast/bin:$PATH; "${ whence -p cat; }" --version 2>&1)
[[ $got == $exp ]] || err_exit "path-bound builtin not executable by canonical path resulting from expansion" \
[[ $got == $exp && $got != *$'\n'* ]] || err_exit "path-bound builtin not executable by canonical path resulting from expansion" \
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
got=$(PATH=/opt/ast/bin:$PATH; "$SHELL" -o restricted -c 'cat --version' 2>&1)
[[ $got == $exp ]] || err_exit "restricted shells do not recognize path-bound builtins" \
[[ $got == $exp && $got != *$'\n'* ]] || err_exit "restricted shells do not recognize path-bound builtins" \
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
got=$(set +x; PATH=/opt/ast/bin cat --version 2>&1)
[[ $got == $exp ]] || err_exit "path-bound builtin not found on PATH in preceding assignment" \
got=$(set +x; PATH=/dev/null; PATH=/opt/ast/bin cat --version 2>&1)
[[ $got == $exp && $got != *$'\n'* ]] || err_exit "path-bound builtin on PATH in preceding assignment" \
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
else warning 'skipping path-bound builtin tests: builtin /opt/ast/bin/cat not found'
fi
Expand Down
22 changes: 21 additions & 1 deletion src/cmd/ksh93/tests/select.sh → src/cmd/ksh93/tests/loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property #
# Copyright (c) 2020-2022 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down Expand Up @@ -50,4 +50,24 @@ done 3>&2 2> $tmp/2 <<!
foo
!

# ======
# break, continue

got=$(for i in a b c; do print -n $i; for j in 1 2 3; do print -n $j; break 2; done; done)
exp=a1
[[ $got == "$exp" ]] || err_exit "'break 2' broken (expected '$exp', got '$got')"

got=$(for i in a b c; do print -n $i; for j in 1 2 3; do print -n $j; continue 2; done; done)
exp=a1b1c1
[[ $got == "$exp" ]] || err_exit "'continue 2' broken (expected '$exp', got '$got')"

got=$(for i in a b c; do print -n $i; for j in 1 2 3; do print -n $j; for k in x y z; do print -n $k; break 3; done; done; done)
exp=a1x
[[ $got == "$exp" ]] || err_exit "'break 3' broken (expected '$exp', got '$got')"

got=$(for i in a b c; do print -n $i; for j in 1 2 3; do print -n $j; for k in x y z; do print -n $k; continue 3; done; done; done)
exp=a1xb1xc1x
[[ $got == "$exp" ]] || err_exit "'continue 3' broken (expected '$exp', got '$got')"

# ======
exit $((Errors<125?Errors:125))
5 changes: 3 additions & 2 deletions src/cmd/ksh93/tests/path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down Expand Up @@ -534,7 +534,8 @@ trap 'kill $sleep_pid; while kill -9 $pid; do :; done 2>/dev/null; trap - INT; k
sleep 5
# if it's slow, display a counter
for ((i=35; i>0; i--))
do printf '\t%s[%d]: command -x: %2ds...\r' "$Command" LINENO i
do kill -s 0 "$$" 2>/dev/null || exit # parent shell exited
printf '\t%s[%d]: command -x: %2ds...\r' "$Command" LINENO i
sleep 1
done
# if this subshell is not killed yet, give up and kill the test by triggering the TERM trap in parent
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/tests/sh_match.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# Copyright (c) 2012 Roland Mainz #
# Copyright (c) 2020-2023 Contributors to ksh 93u+m #
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
# and is licensed under the #
# Eclipse Public License, Version 2.0 #
# #
Expand Down
5 changes: 3 additions & 2 deletions src/lib/libast/vmalloc/vmbest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,15 +1172,16 @@ static void* mmapmem(void* caddr, size_t csize, size_t nsize, Mmdisc_t* mmdc)
}
#endif /* _mem_map_anon || _mem_mmap_zero */

#if _std_malloc /* using native malloc as a last resource */
#if _std_malloc /* using native malloc as a last resort */
static void* mallocmem(void* caddr, size_t csize, size_t nsize)
{
/**/ASSERT(csize > 0 || nsize > 0);
if(csize == 0)
return malloc(nsize);
else if(nsize == 0)
{ free(caddr);
#if !__clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#if !__clang__ && __GNUC__ >= 12
/* ...one hopes the AT&T guys knew what they were doing here... */
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
return caddr;
Expand Down

0 comments on commit be6b5e9

Please sign in to comment.