Skip to content

Commit

Permalink
mv PR#18555-tests to new "check-devel only" file and make target; + S…
Browse files Browse the repository at this point in the history
…ys.sleep(timeout)

git-svn-id: https://svn.r-project.org/R/trunk@84692 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Jul 14, 2023
1 parent 0cbbfcb commit e337066
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 46 deletions.
15 changes: 12 additions & 3 deletions tests/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test-src-regexp = utf8-regex.R PCRE.R
test-src-segfault = no-segfault.R
test-src-tz = timezone.R
test-src-cond = conditions.R
test-src-misc-dev = misc-devel.R

test-src-reg-1 = array-subset.R \
reg-tests-1a.R reg-tests-1b.R reg-tests-1c.R reg-tests-1d.R \
Expand Down Expand Up @@ -89,6 +90,7 @@ test-out-reg3 = $(test-src-reg3:.R=.Rout)
test-out-segfault = $(test-src-segfault:.R=.Rout)
test-out-tz = $(test-src-tz:.R=.Rout)
test-out-cond = $(test-src-cond:.R=.Rout)
test-out-misc-dev = $(test-src-misc-dev:.R=.Rout)

## This macro is used only for dependencies and for distclean
test-out = $(test-out-strict) $(test-out-sloppy) $(test-out-demo) $(test-out-gct) \
Expand All @@ -97,7 +99,7 @@ test-out = $(test-out-strict) $(test-out-sloppy) $(test-out-demo) $(test-out-gct
$(test-out-segfault) $(test-out-isas) \
$(test-out-internet2) $(test-out-internet-dev) \
$(test-out-CRANtools) $(test-out-large) $(test-out-primitive) $(test-out-dt) \
$(test-out-regexp) $(test-out-tz) $(test-out-cond) \
$(test-out-regexp) $(test-out-tz) $(test-out-cond) $(test-out-misc-dev) \
utf8.Rout reg-translation.Rout iconv.Rout

.SUFFIXES:
Expand Down Expand Up @@ -192,10 +194,11 @@ test-all-basics:
$(MK) test-$${name} || exit 1; \
done

## if you change this, also edit Makefile.install
## if you change this, also edit *both* Makefile.install{,.win}
## The definitions for Standalone are in Makefile.{in,win}.
## 'Packages' slow ==> last
all-devel-tests = DateTime Docs IsAs Random Demo Primitive Regexp Translation \
Internet2 CRANtools Segfault Standalone Conditions Packages
Internet2 CRANtools Segfault Standalone Conditions Misc-dev Packages
test-all-devel:
@for name in $(all-devel-tests); do \
$(MK) test-$${name} || exit 1; \
Expand Down Expand Up @@ -338,6 +341,11 @@ test-Translation:
@$(ECHO) "running tests of translation"
@$(MK) reg-translation.Rout RVAL_IF_DIFF=0

test-Misc-dev:
@$(ECHO) "running other miscellaneous devel tests"
@$(MK) $(test-out-misc-dev) RVAL_IF_DIFF=1


## Not run by any other target
test-UTF-8:
@$(ECHO) "running regression tests for UTF-8 <--> int conversion (slow)"
Expand Down Expand Up @@ -536,4 +544,5 @@ INSTFILES = README \
reg-examples3.Rout.save reg-plot-latin1.pdf.save \
$(test-src-regexp) $(test-src-CRANtools) \
$(test-src-tz) $(test-src-cond) reg-translation.R iconv.R \
$(test-src-misc-dev) \
nanbug.rda WinUnicode.dat arima.rda EmbeddedNuls.csv eval-fns.R
2 changes: 1 addition & 1 deletion tests/Makefile.install
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MK = $(MAKE)
all-basic-tests = BasePackages Specific Reg Internet
## Keep in line with Makefile.common.
## not Docs Standalone Packages
all-devel-tests = DateTime IsAs Random Demo Primitive Regexp Internet2 CRANtools Segfault Conditions
all-devel-tests = DateTime IsAs Random Demo Primitive Regexp Internet2 CRANtools Segfault Conditions Misc-dev


## <NOTE>
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile.install.win
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MK = $(MAKE)
all-basic-tests = BasePackages Specific Reg Internet
## Keep in line with Makefile.common.
## not Docs Standalone Packages
all-devel-tests = DateTime IsAs Random Demo Primitive Regexp Internet2 CRANtools Segfault Conditions
all-devel-tests = DateTime IsAs Random Demo Primitive Regexp Internet2 CRANtools Segfault Conditions Misc-dev


## <NOTE>
Expand Down
57 changes: 57 additions & 0 deletions tests/misc-devel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#### Regression and other checks for 'make check-devel' but *not* for 'make check'

## PR#18555: dummy_fgetc() returning EOF if the connection has an encoding specified
## -------- Based on small change from https://bugs.r-project.org/show_bug.cgi?id=18555#c4
## FIXME: needs a more thorough analysis and fixes (see 'Comment #2' in PR)
sockChk <- function(enc, timeout = 0.25, verbose = TRUE, port = 27182)
{
stopifnot(is.character(enc), length(enc) == 1L)
if(verbose) {
cat(sprintf("enc = '%s', timeout=%g:\n", enc, timeout))
pr <- print
} else
pr <- identity
sock <- serverSocket(port)
outgoing <- socketConnection("localhost", port, encoding=enc)
incoming <- socketAccept(sock, encoding=enc)
on.exit({close(incoming); close(outgoing); close(sock) })
writeLines("hello", outgoing) ; flush(outgoing)
r1 <- readLines(incoming, 1) # "hello"
r2 <- readLines(incoming, 1) # character(0) *and* EOF_signalled gets set
writeLines("again1", outgoing); flush(outgoing)
stopifnot(identical(r2, character(0)), ## now *have* incoming again:
socketSelect(list(incoming)))
r3 <- readLines(incoming, 1) # got character(0) incorrectly
## because of con->EOF_signalled, dummy_fgetc didn't attempt to read more data
if(socketSelect(list(incoming), timeout=0)) # *was* TRUE wrongly
stop("incoming is empty")
writeLines("again2", outgoing)
writeLines("again3", outgoing); flush(outgoing)
if(timeout) Sys.sleep(timeout) # flush not sufficient -> need timeout, platform dependently
r4 <- readLines(incoming, 1) # was character(0), on Mac even after r84624 (timeout=0)
## NB isIncomplete(incoming) being FALSE corresponds to doc
r5 <- suppressWarnings(# Warning "text connection used with readChar(), .."
readChar(incoming, 100))
stopifnot(identical(pr(cbind(r1,r3,r4,r5)[1,]), # print() before possibly reporting ..
c(r1 = "hello", r3 = "again1",
r4 = "again2",r5 = "again3\n")))
invisible(TRUE)
}

## All three failed on (arm64) macOS (with 0 timeout)
timeout <- if(Sys.info()["sysname"] == "Darwin") 0.5 else 0.125
# 0 seemed sufficient for non-Mac
sockChk("ASCII", timeout)
sockChk("UTF-8", timeout)
## The default is getOption("encoding") which defaults to "native.enc"
sockChk("native.enc", timeout)
## only the last already worked in R <= 4.3.1 {for non macOS with 0 timeout}

## stress test w/o sleep
for(i in 1:50) try({ cat(i,":\n---\n")
sockChk("ASCII", 0)
sockChk("UTF-8", 0)
sockChk("native.enc", 0)
})

proc.time()
44 changes: 3 additions & 41 deletions tests/reg-tests-1e.R
Original file line number Diff line number Diff line change
Expand Up @@ -712,54 +712,16 @@ stopifnot(exprs = {
## did partly overrun to invalid strings, nchar(.) giving error in R <= 4.3.1


## PR#18555 : see ---> ./misc-devel.R


## PR#18557 readChar() with large 'nchars'
ch <- "hello\n"; tf <- tempfile(); writeChar(ch, tf)
tools::assertWarning((c2 <- readChar(tf, 4e8)))
stopifnot(identical(c2, "hello\n"))
## had failed w/ cannot allocate memory block of size 16777216 Tb


## PR#18555: dummy_fgetc() returning EOF if the connection has an encoding specified
## All three fail on (arm64) maOS, so skip for now
if(Sys.info()["sysname"] != "Darwin") {
sockChk <- function(enc, port = 27182)
{
stopifnot(is.character(enc), length(enc) == 1L)
sock <- serverSocket(port)
outgoing <- socketConnection("localhost", port, encoding=enc)
incoming <- socketAccept(sock, encoding=enc)
on.exit({close(incoming); close(outgoing); close(sock) })
writeLines("hello", outgoing) ; flush(outgoing)
r1 <- readLines(incoming, 1) # "hello"
r2 <- readLines(incoming, 1) # character(0) *and* EOF_signalled gets set
writeLines("again1", outgoing); flush(outgoing)
stopifnot(identical(r2, character(0)), ## now *have* incoming again:
socketSelect(list(incoming)))
r3 <- readLines(incoming, 1) # got character(0) incorrectly
## because of con->EOF_signalled, dummy_fgetc didn't attempt to read more data
if(socketSelect(list(incoming), timeout=0)) # *was* TRUE wrongly
stop("incoming is empty")
writeLines("again2", outgoing)
writeLines("again3", outgoing); flush(outgoing)
r4 <- readLines(incoming, 1) # was character(0)
cat("isIncomplete(incoming): ", isIncomplete(incoming),
" (should be TRUE - FIXME?)\n") # FALSE wrongly ?
r5 <- suppressWarnings(# Warning "text connection used with readChar(), .."
readChar(incoming, 100))
## print out result before possibly reporting not identical.
print(cbind(r1,r3,r4,r5)[1,])
stopifnot(identical(cbind(r1,r3,r4,r5)[1,],
c(r1 = "hello", r3 = "again1",
r4 = "again2",r5 = "again3\n")))
invisible(TRUE)
}
sockChk("ASCII")
sockChk("UTF-8")
## The default is getOption("encoding") which defaults to "native.enc"
sockChk("native.enc")
## only the last already worked in R <= 4.3.1
}

## Deprecation of *direct* calls to as.data.frame.<someVector>
dpi <- as.data.frame(pi)
d1 <- data.frame(dtime = as.POSIXlt("2023-07-06 11:11")) # gave F.P. warning
Expand Down

0 comments on commit e337066

Please sign in to comment.