From 556b19bf28bb9215736da84b3dcde1bd5293bf50 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 4 Apr 2023 17:14:44 +0000 Subject: Start on tests for large data --- generic/tclTestObj.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 52dd53d..1caa52b 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -25,6 +25,7 @@ #endif #include "tclStringRep.h" +#include /* * Forward declarations for functions defined later in this file: @@ -42,6 +43,7 @@ static Tcl_ObjCmdProc TestintobjCmd; static Tcl_ObjCmdProc TestlistobjCmd; static Tcl_ObjCmdProc TestobjCmd; static Tcl_ObjCmdProc TeststringobjCmd; +static Tcl_ObjCmdProc TestbigdataCmd; #define VARPTR_KEY "TCLOBJTEST_VARPTR" #define NUMBER_OF_OBJECT_VARS 20 @@ -117,6 +119,8 @@ TclObjTest_Init( Tcl_CreateObjCommand(interp, "testobj", TestobjCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "teststringobj", TeststringobjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "testbigdata", TestbigdataCmd, + NULL, NULL); return TCL_OK; } @@ -1519,6 +1523,135 @@ TeststringobjCmd( } /* + *------------------------------------------------------------------------ + * + * TestbigdataCmd -- + * + * Implements the Tcl command testbigdata + * testbigdata string ?LEN? ?SPLIT? + * testbigdata bytearray ?LEN? ?SPLIT? + * If no arguments given, returns the pattern used to generate strings. + * If SPLIT is specified, the character at that position is set to "X". + * + * Results: + * TCL_OK - Success. + * TCL_ERROR - Error. + * + * Side effects: + * Interpreter result holds result or error message. + * + *------------------------------------------------------------------------ + */ +static int +TestbigdataCmd ( + ClientData notUsed, + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + static const char *const subcmds[] = { + "string", "bytearray", "list", NULL + }; + enum options { + BIGDATA_STRING, BIGDATA_BYTEARRAY, BIGDATA_LIST + } idx; + char *s; + unsigned char *p; + Tcl_WideInt i, len, split; + Tcl_DString ds; + Tcl_Obj *objPtr; +#define PATTERN_LEN 10 + Tcl_Obj *patternObjs[PATTERN_LEN]; + + if (objc < 2 || objc > 4) { + Tcl_WrongNumArgs(interp, 1, objv, "command ?len?"); + return TCL_ERROR; + } + if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option", 0, + &idx) != TCL_OK) { + return TCL_ERROR; + } + split = -1; + if (objc == 2) { + len = PATTERN_LEN; + } else { + if (Tcl_GetWideIntFromObj(interp, objv[2], &len) != TCL_OK) { + return TCL_ERROR; + } + if (objc == 4) { + if (Tcl_GetWideIntFromObj(interp, objv[3], &split) != TCL_OK) { + return TCL_ERROR; + } + if (split >= len) { + split = len - 1; /* Last position */ + } + } + } + /* Need one byte for nul terminator */ + Tcl_WideInt limit = + sizeof(Tcl_Size) == sizeof(Tcl_WideInt) ? WIDE_MAX-1 : INT_MAX-1; + if (len < 0 || len > limit) { + Tcl_SetObjResult( + interp, + Tcl_ObjPrintf( + "%s is greater than max permitted length %" TCL_LL_MODIFIER "d", + Tcl_GetString(objv[2]), + limit)); + return TCL_ERROR; + } + + switch (idx) { + case BIGDATA_STRING: + Tcl_DStringInit(&ds); + Tcl_DStringSetLength(&ds, len);/* Also stores \0 at index len+1 */ + s = Tcl_DStringValue(&ds); + for (i = 0; i < len; ++i) { + s[i] = '0' + (i % PATTERN_LEN); + } + if (split >= 0) { + assert(split < len); + s[split] = 'X'; + } + Tcl_DStringResult(interp, &ds); + break; + case BIGDATA_BYTEARRAY: + objPtr = Tcl_NewByteArrayObj(NULL, len); + p = Tcl_GetByteArrayFromObj(objPtr, &len); + for (i = 0; i < len; ++i) { + p[i] = '0' + (i % PATTERN_LEN); + } + if (split >= 0) { + assert(split < len); + p[split] = 'X'; + } + Tcl_SetObjResult(interp, objPtr); + break; + case BIGDATA_LIST: + for (i = 0; i < PATTERN_LEN; ++i) { + patternObjs[i] = Tcl_NewIntObj(i); + Tcl_IncrRefCount(patternObjs[i]); + } + objPtr = Tcl_NewListObj(len, NULL); + for (i = 0; i < len; ++i) { + Tcl_ListObjAppendElement( + interp, objPtr, patternObjs[i % PATTERN_LEN]); + } + if (split >= 0) { + assert(split < len); + Tcl_Obj *splitMarker = Tcl_NewStringObj("X", 1); + Tcl_ListObjReplace(interp, objPtr, split, 1, 1, &splitMarker); + } + for (i = 0; i < PATTERN_LEN; ++i) { + patternObjs[i] = Tcl_NewIntObj(i); + Tcl_DecrRefCount(patternObjs[i]); + } + Tcl_SetObjResult(interp, objPtr); + break; + } + return TCL_OK; +} + +/* *---------------------------------------------------------------------- * * SetVarToObj -- -- cgit v0.12 From eea17e30ab1e9ea8192b0a9910b24842933b7e1c Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 4 Apr 2023 17:16:51 +0000 Subject: Some very initial tests for large data --- tests/bigdata.test | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 tests/bigdata.test diff --git a/tests/bigdata.test b/tests/bigdata.test new file mode 100644 index 0000000..47c81d4 --- /dev/null +++ b/tests/bigdata.test @@ -0,0 +1,202 @@ +# Test cases for large sized data +# +# Copyright © 2023 Ashok P. Nadkarni +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. + +if {"::tcltest" ni [namespace children]} { + package require tcltest + + namespace import -force ::tcltest::* +} + +# +# Hints: +# +# - To save time, when commands do not modify operands, generate the test data +# and run multiple variants of the command in a single test. +# - Do NOT use -setup clauses that generate large data. They seem to be run +# irrespective of whether the test itself is run. + +# Wrapper to generate compiled and uncompiled cases for a test. +# If $args does not contain a -body key, $comment is treated as the test body +proc bigtest {id comment result args} { + if {[dict exists $args -body]} { + set body [dict get $args -body] + dict unset args -body + } else { + set body $comment + } + dict lappend args -constraints bigdata + + uplevel 1 [list test $id.uncompiled "$comment (uncompiled)" \ + -body [list testevalex $body] \ + -result $result \ + {*}$args] + + uplevel 1 [list test $id.compiled-script "$comment (compiled script)" \ + -body [list try $body] \ + -result $result \ + {*}$args] + + return + # TODO - is this required separately from the compile-script above? + dict append args -setup \n[list proc testxproc {} $body] + dict append args -cleanup "\nrename testxproc {}" + uplevel 1 [list test $id.compiled-proc "$comment (compiled proc)" \ + -body {testxproc} \ + -result $result \ + {*}$args] +} + +interp alias {} bigString {} testbigdata string +interp alias {} bigBinary {} testbigdata bytearray +interp alias {} bigList {} testbigdata list +proc bigPatLen {} { + proc bigPatLen {} "return [string length [testbigdata string]]" + bigPatLen +} + +# Returns list of expected elements at the indices specified +proc bigStringIndices {indices} { + set pat [testbigdata string] + set patlen [string length $pat] + lmap idx $indices { + string index $pat [expr {$idx%$patlen}] + } +} + +# Returns the largest multiple of the pattern length that is less than $limit +proc bigPatlenMultiple {limit} { + set patlen [bigPatLen] + return [expr {($limit/$patlen)*$patlen}] +} + +set ::bigLengths(intmax) 0x7fffffff +set ::bigLengths(uintmax) 0xffffffff +# Some tests are more convenient if operands are multiple of pattern length +set ::bigLengths(patlenmultiple) [bigPatlenMultiple $::bigLengths(intmax)] +set ::bigLengths(upatlenmultiple) [bigPatlenMultiple $::bigLengths(uintmax)] + +# +# string cat +bigtest string-cat-bigdata-1 "string cat large small result > INT_MAX" 1 -body { + string equal \ + [string cat [bigString $::bigLengths(patlenmultiple)] [bigString]] \ + [bigString [expr {[bigPatLen]+$::bigLengths(patlenmultiple)}]] +} +bigtest string-cat-bigdata-2 "string cat small large result > INT_MAX" 1 -body { + string equal \ + [string cat [bigString] [bigString $::bigLengths(patlenmultiple)]] \ + [bigString [expr {[bigPatLen]+$::bigLengths(patlenmultiple)}]] +} +bigtest string-cat-bigdata-3 "string cat result > UINT_MAX" 1 -body { + set s [bigString $::bigLengths(patlenmultiple)] + string equal \ + [string cat $s [bigString] $s] \ + [bigString [expr {[bigPatLen]+2*$::bigLengths(patlenmultiple)}]] +} + +# +# string compare/equal +bigtest string-equal/compare-bigdata-1 "string compare/equal equal strings" {0 1} -cleanup { + unset -nocomplain s1 s2 +} -body { + set len [expr {$::bigLengths(intmax)+1}] + set s1 [bigString $len] + set s2 [bigString $len]; # Use separate string to avoid Tcl_Obj * being same + list [string compare $s1 $s2] [string equal $s1 $s2] +} +bigtest string-equal/compare-bigdata-2 "string compare/equal -length unequal strings" {-1 0 0 1 -1 0} -cleanup { + unset -nocomplain s1 s2 +} -body { + # Also tests lengths do not wrap + set len [expr {$::bigLengths(uintmax)+2}] + set s1 [bigString $len] + set s2 [bigString $len $len]; # Differs in last char + set result {} + lappend result [string compare $s1 $s2] + lappend result [string equal $s1 $s2] + # Check lengths > UINT_MAX + # Also that lengths do not truncate to sizeof(int) + lappend result [string compare -length $len $s1 $s2] + lappend result [string equal -length $len $s1 $s2] +} + +# +# string first +test string-first-bigdata-0 "string first > INT_MAX" -result {2147483648 -1 2147483650 1} -cleanup { + unset -nocomplain s +} -body { + set s [bigString 0x8000000a 0x80000000] + list \ + [string first X $s] \ + [string first Y $s] \ + [string first 0 $s 0x80000000] \ + [string first 1 $s end-0x80000010] +} +bigtest string-first-bigdata-1 "string first > INT_MAX" {2147483648 -1 2147483650 1} -cleanup { + unset -nocomplain s +} -body { + set s [bigString 0x8000000a 0x80000000] + list \ + [string first X $s] \ + [string first Y $s] \ + [string first 0 $s 0x80000000] \ + [string first 1 $s end-0x80000010] +} +bigtest xstring-first-bigdata-2 "string first > UINT_MAX" {4294967296 -1 4294967300 1} -cleanup { + unset -nocomplain s +} -body { + set s [bigString 0x10000000a 0x100000000] + list \ + [string first X $s] \ + [string first Y $s] \ + [string first 0 $s 0x100000000] \ + [string first 1 $s end-0x100000010] +} + +# +# string last +bigtest string-last-bigdata-1 "string last > INT_MAX" {2 -1 2147483640 11} -cleanup { + unset -nocomplain s +} -body { + set s [bigString 0x80000010 2] + list \ + [string last X $s] \ + [string last Y $s] \ + [string last 0 $s 0x80000000] \ + [string last 1 $s end-0x80000000] +} +bigtest string-first/last-bigdata-2 "string first > UINT_MAX" {4294967296 -1 4294967300 1} -cleanup { + unset -nocomplain s +} -body { + set s [bigString 0x10000000a 0x100000000] + list \ + [string first X $s] \ + [string first Y $s] \ + [string first 0 $s 0x100000000] \ + [string first 1 $s end-0x100000010] +} + +foreach len {0x7fffffff 0xffffffff 0x800000000} { + break; # Skip for now + set body "string length \[string repeat x $len\]" + bigtest lrepeat-bigdata-1-$len $body $len +} + +foreach len {0x7fffffff 0xffffffff 0x800000000} { + break; # Skip for now + set body "llength \[lrepeat $len x\]" + bigtest lrepeat-bigdata-1-$len $body $len +} + +# cleanup +::tcltest::cleanupTests +return + +# Local Variables: +# mode: tcl +# fill-column: 78 +# End: -- cgit v0.12 From f350cdd7ccb7a3b0e6dda3fccba2787c8946b31c Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sat, 8 Apr 2023 17:19:10 +0000 Subject: A few more bigdata tests for strings --- tests/bigdata.test | 229 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 187 insertions(+), 42 deletions(-) diff --git a/tests/bigdata.test b/tests/bigdata.test index 47c81d4..52aa278 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -41,6 +41,7 @@ proc bigtest {id comment result args} { {*}$args] return + # TODO - is this required separately from the compile-script above? dict append args -setup \n[list proc testxproc {} $body] dict append args -cleanup "\nrename testxproc {}" @@ -50,7 +51,37 @@ proc bigtest {id comment result args} { {*}$args] } +# Like bigtest except that both compiled and uncompiled are combined into one +# test using the same inout argument. This saves considerable time but for +# obvious reasons should only be used when the input argument is not modified. +proc bigtestRO {id comment result args} { + if {[dict exists $args -body]} { + set body [dict get $args -body] + dict unset args -body + } else { + set body $comment + } + dict lappend args -constraints bigdata + + set wrapper "" + set body "{$body}" + append wrapper "set uncompiled_result \[testevalex $body]" \n + append wrapper "set compiled_result \[try $body]" \n + append wrapper {list $uncompiled_result $compiled_result} + uplevel 1 [list test $id {$comment} \ + -body $wrapper \ + -result [list $result $result] \ + {*}$args] + return +} + interp alias {} bigString {} testbigdata string +proc xxbigString args { + puts bigStringEnter:$args + set xx [testbigdata string {*}$args] + puts bigStringExit + return $xx +} interp alias {} bigBinary {} testbigdata bytearray interp alias {} bigList {} testbigdata list proc bigPatLen {} { @@ -100,21 +131,17 @@ bigtest string-cat-bigdata-3 "string cat result > UINT_MAX" 1 -body { # # string compare/equal -bigtest string-equal/compare-bigdata-1 "string compare/equal equal strings" {0 1} -cleanup { - unset -nocomplain s1 s2 -} -body { +bigtestRO string-equal/compare-bigdata-1 "string compare/equal equal strings" {0 1} -body { + list [string compare $s1 $s2] [string equal $s1 $s2] +} -setup { set len [expr {$::bigLengths(intmax)+1}] set s1 [bigString $len] set s2 [bigString $len]; # Use separate string to avoid Tcl_Obj * being same - list [string compare $s1 $s2] [string equal $s1 $s2] -} -bigtest string-equal/compare-bigdata-2 "string compare/equal -length unequal strings" {-1 0 0 1 -1 0} -cleanup { +} -cleanup { unset -nocomplain s1 s2 -} -body { +} +bigtestRO string-equal/compare-bigdata-2 "string compare/equal -length unequal strings" {-1 0 0 1} -body { # Also tests lengths do not wrap - set len [expr {$::bigLengths(uintmax)+2}] - set s1 [bigString $len] - set s2 [bigString $len $len]; # Differs in last char set result {} lappend result [string compare $s1 $s2] lappend result [string equal $s1 $s2] @@ -122,71 +149,189 @@ bigtest string-equal/compare-bigdata-2 "string compare/equal -length unequal str # Also that lengths do not truncate to sizeof(int) lappend result [string compare -length $len $s1 $s2] lappend result [string equal -length $len $s1 $s2] +} -setup { + set len [expr {$::bigLengths(uintmax)+2}] + set s1 [bigString $len] + set s2 [bigString $len $len]; # Differs in last char +} -cleanup { + unset -nocomplain s1 s2 } # # string first -test string-first-bigdata-0 "string first > INT_MAX" -result {2147483648 -1 2147483650 1} -cleanup { - unset -nocomplain s -} -body { - set s [bigString 0x8000000a 0x80000000] +bigtestRO string-first-bigdata-1 "string first > INT_MAX" {2147483648 -1 2147483650 1} -body { list \ [string first X $s] \ [string first Y $s] \ [string first 0 $s 0x80000000] \ [string first 1 $s end-0x80000010] -} -bigtest string-first-bigdata-1 "string first > INT_MAX" {2147483648 -1 2147483650 1} -cleanup { - unset -nocomplain s -} -body { +} -setup { set s [bigString 0x8000000a 0x80000000] - list \ - [string first X $s] \ - [string first Y $s] \ - [string first 0 $s 0x80000000] \ - [string first 1 $s end-0x80000010] -} -bigtest xstring-first-bigdata-2 "string first > UINT_MAX" {4294967296 -1 4294967300 1} -cleanup { +} -cleanup { unset -nocomplain s -} -body { - set s [bigString 0x10000000a 0x100000000] +} -constraints bug-a814ee5bbd + +bigtestRO string-first-bigdata-2 "string first > UINT_MAX" {4294967296 -1 4294967300 1} -body { list \ [string first X $s] \ [string first Y $s] \ [string first 0 $s 0x100000000] \ [string first 1 $s end-0x100000010] -} +} -setup { + set s [bigString 0x10000000a 0x100000000] +} -cleanup { + unset -nocomplain s +} -constraints bug-a814ee5bbd + +bigtestRO string-first-bigdata-3 "string first - long needle" 10 -body { + string first $needle $s +} -setup { + set s [bigString 0x10000000a 0] + set needle [bigString 0x100000000] +} -cleanup { + unset -nocomplain s needle +} -constraints bug-a814ee5bbd # # string last -bigtest string-last-bigdata-1 "string last > INT_MAX" {2 -1 2147483640 11} -cleanup { - unset -nocomplain s -} -body { +bigtestRO string-last-bigdata-1 "string last > INT_MAX" {2 -1 2147483640 11} -body { set s [bigString 0x80000010 2] list \ [string last X $s] \ [string last Y $s] \ [string last 0 $s 0x80000000] \ [string last 1 $s end-0x80000000] -} -bigtest string-first/last-bigdata-2 "string first > UINT_MAX" {4294967296 -1 4294967300 1} -cleanup { +} -setup { + set s [bigString 0x80000010 2] +} -cleanup { + unset -nocomplain s +} -constraints bug-a814ee5bbd + +bigtestRO string-last-bigdata-2 "string last > UINT_MAX" {4294967300 -1 4294967290 1} -body { + list \ + [string last 0 $s] \ + [string last Y $s] \ + [string last 0 $s 0x100000000] \ + [string last 1 $s end-0x100000010] +} -setup { + set s [bigString 0x10000000a 2] +} -cleanup { + unset -nocomplain s +} -constraints bug-a814ee5bbd + +bigtestRO string-last-bigdata-3 "string last - long needle" 0 -body { + string last $needle $s +} -setup { + set s [bigString 0x10000000a 0x10000000a] + set needle [bigString 0x100000000] +} -cleanup { + unset -nocomplain s needle +} -constraints bug-a814ee5bbd + +bigtestRO string-index-bigdata-1 "string index" {6 7 5 {} 5 4 {} 9 {}} -body { + list \ + [string index $s 0x100000000] \ + [string index $s 0x100000000+1] \ + [string index $s 0x100000000-1] \ + [string index $s 0x10000000a] \ + [string index $s end] \ + [string index $s end-1] \ + [string index $s end+1] \ + [string index $s end-0x100000000] \ + [string index $s end-0x10000000a] +} -setup { + set s [bigString 0x10000000a] +} -cleanup { unset -nocomplain s -} -body { +} + +# +# string is +bigtestRO string-is-bigdata-1 "string is" {1 0 0 4294967296} -body { + set result {} + unset -nocomplain failat + lappend result [string is alnum -failindex failat $s] [info exists failat] + lappend result [string is digit -failindex failat $s] $failat +} -setup { set s [bigString 0x10000000a 0x100000000] +} -cleanup { + unset -nocomplain s failat +} + +# +# string length +bigtestRO string-length-bigdata-1 {string length $s} 4294967296 -setup { + set s [bigString 0x100000000] +} -cleanup { + unset -nocomplain s +} + +# +# string map +bigtestRO string-map-bigdata-1 {string map} {5 0 0 5} -body { + set s2 [string map {0 5 5 0} $s] list \ - [string first X $s] \ - [string first Y $s] \ - [string first 0 $s 0x100000000] \ - [string first 1 $s end-0x100000010] + [string index $s2 0] \ + [string index $s2 5] \ + [string index $s2 end] \ + [string index $s2 end-5] +} -setup { + set s [bigString 0x100000000] +} -cleanup { + unset -nocomplain s s2 } -foreach len {0x7fffffff 0xffffffff 0x800000000} { - break; # Skip for now +# +# string match +bigtestR0 string-match-bigdata-1 {string match} {1 0 1} -body { + list \ + [string match 0*5 $s] \ + [string match 0*4 $s] \ + [string match $s $s] +} -setup { + set s [bigString 0x100000000] +} -cleanup { + unset -nocomplain s pat +} + +# +# string range +bigtestRO string-range-bigdata-1 "string range" {6 7 5 {} 5 4 {} 9 {}} -body { + list \ + [string range $s 0x100000000 0x100000000] \ + [string range $s 0x100000000+1 0x100000000+1] \ + [string range $s 0x100000000-1 0x100000000-1] \ + [string range $s 0x10000000a 0x10000000a] \ + [string range $s end end] \ + [string range $s end-1 end-1] \ + [string range $s end+1 end+1] \ + [string range $s end-0x100000000 end-0x100000000] \ + [string range $s end-0x10000000a end-0x10000000a] +} -setup { + set s [bigString 0x10000000a] +} -cleanup { + unset -nocomplain s +} -constraints bug-ad9361fd20f0 +# TODO - once above bug is fixed, add tests for large result range + +# +# string repeat +bigtest string-repeat-bigdata-1 "string repeat single char" {4294967296 0123456789abcdef 0123456789abcdef} -body { + set s [string repeat 0123456789abcdef [expr 0x100000000/16]] + list \ + [string length $s] \ + [string range $s 0 15] \ + [string range $s end-15 end] +} -cleanup { + unset -nocomplain s +} + +foreach len {0x7fffffff 0xffffffff 0x100000000} { set body "string length \[string repeat x $len\]" - bigtest lrepeat-bigdata-1-$len $body $len + bigtest string-repeat-bigdata-1-$len $body $len } -foreach len {0x7fffffff 0xffffffff 0x800000000} { +foreach len {0x7fffffff 0xffffffff 0x100000000} { break; # Skip for now set body "llength \[lrepeat $len x\]" bigtest lrepeat-bigdata-1-$len $body $len -- cgit v0.12 From d90b82d5ceaf993cd0f61ce385c037012a30e3fb Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sun, 9 Apr 2023 16:28:02 +0000 Subject: Sloooow progress on testing bigdata --- tests/bigdata.test | 307 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 266 insertions(+), 41 deletions(-) diff --git a/tests/bigdata.test b/tests/bigdata.test index 52aa278..29ff725 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -193,6 +193,48 @@ bigtestRO string-first-bigdata-3 "string first - long needle" 10 -body { } -constraints bug-a814ee5bbd # +# string index +bigtestRO string-index-bigdata-1 "string index" {6 7 5 {} 5 4 {} 9 {}} -body { + list \ + [string index $s 0x100000000] \ + [string index $s 0x100000000+1] \ + [string index $s 0x100000000-1] \ + [string index $s 0x10000000a] \ + [string index $s end] \ + [string index $s end-1] \ + [string index $s end+1] \ + [string index $s end-0x100000000] \ + [string index $s end-0x10000000a] +} -setup { + set s [bigString 0x10000000a] +} -cleanup { + unset -nocomplain s +} + +# +# string insert +bigtestRO string-insert-bigdata-1 "string insert" 1 -body { + # Note insert at multiple of 10 to enable comparison against generated string + string equal [string insert [bigString 4294967312] 4294967310 "0123456789"] [bigString 4294967322] +} +bigtestRO string-insert-bigdata-2 "string insert" 1 -body { + string equal [string insert [bigString 4294967312] 10 "0123456789"] [bigString 4294967322] +} + +# +# string is +bigtestRO string-is-bigdata-1 "string is" {1 0 0 4294967296} -body { + # TODO - add the other "is" classes + unset -nocomplain failat result + lappend result [string is alnum -failindex failat $s] [info exists failat] + lappend result [string is digit -failindex failat $s] $failat +} -setup { + set s [bigString 0x10000000a 0x100000000] +} -cleanup { + unset -nocomplain s failat +} + +# # string last bigtestRO string-last-bigdata-1 "string last > INT_MAX" {2 -1 2147483640 11} -body { set s [bigString 0x80000010 2] @@ -228,36 +270,6 @@ bigtestRO string-last-bigdata-3 "string last - long needle" 0 -body { unset -nocomplain s needle } -constraints bug-a814ee5bbd -bigtestRO string-index-bigdata-1 "string index" {6 7 5 {} 5 4 {} 9 {}} -body { - list \ - [string index $s 0x100000000] \ - [string index $s 0x100000000+1] \ - [string index $s 0x100000000-1] \ - [string index $s 0x10000000a] \ - [string index $s end] \ - [string index $s end-1] \ - [string index $s end+1] \ - [string index $s end-0x100000000] \ - [string index $s end-0x10000000a] -} -setup { - set s [bigString 0x10000000a] -} -cleanup { - unset -nocomplain s -} - -# -# string is -bigtestRO string-is-bigdata-1 "string is" {1 0 0 4294967296} -body { - set result {} - unset -nocomplain failat - lappend result [string is alnum -failindex failat $s] [info exists failat] - lappend result [string is digit -failindex failat $s] $failat -} -setup { - set s [bigString 0x10000000a 0x100000000] -} -cleanup { - unset -nocomplain s failat -} - # # string length bigtestRO string-length-bigdata-1 {string length $s} 4294967296 -setup { @@ -269,6 +281,9 @@ bigtestRO string-length-bigdata-1 {string length $s} 4294967296 -setup { # # string map bigtestRO string-map-bigdata-1 {string map} {5 0 0 5} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 set s2 [string map {0 5 5 0} $s] list \ [string index $s2 0] \ @@ -279,11 +294,11 @@ bigtestRO string-map-bigdata-1 {string map} {5 0 0 5} -body { set s [bigString 0x100000000] } -cleanup { unset -nocomplain s s2 -} +} -constraints takesTooLong # # string match -bigtestR0 string-match-bigdata-1 {string match} {1 0 1} -body { +bigtestRO string-match-bigdata-1 {string match} {1 0 1} -body { list \ [string match 0*5 $s] \ [string match 0*4 $s] \ @@ -291,7 +306,7 @@ bigtestR0 string-match-bigdata-1 {string match} {1 0 1} -body { } -setup { set s [bigString 0x100000000] } -cleanup { - unset -nocomplain s pat + unset -nocomplain s } # @@ -316,7 +331,10 @@ bigtestRO string-range-bigdata-1 "string range" {6 7 5 {} 5 4 {} 9 {}} -body { # # string repeat -bigtest string-repeat-bigdata-1 "string repeat single char" {4294967296 0123456789abcdef 0123456789abcdef} -body { +bigtest string-repeat-bigdata-1 "string repeat single char length > UINT_MAX" 4294967296 -body { + string length [string repeat x 0x100000000] +} +bigtest string-repeat-bigdata-2 "string repeat multiple char" {4294967296 0123456789abcdef 0123456789abcdef} -body { set s [string repeat 0123456789abcdef [expr 0x100000000/16]] list \ [string length $s] \ @@ -326,17 +344,224 @@ bigtest string-repeat-bigdata-1 "string repeat single char" {4294967296 01234567 unset -nocomplain s } -foreach len {0x7fffffff 0xffffffff 0x100000000} { - set body "string length \[string repeat x $len\]" - bigtest string-repeat-bigdata-1-$len $body $len +# +# string replace +bigtestRO string-replace-bigdata-1 "string replace" {789012345 012345678 XYZ789012345 012345678XYZ} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain result + lappend result [string replace $s 0 0x100000000] + lappend result [string replace $s end-0x100000000 end] + lappend result [string replace $s 0 0x100000000 XYZ] + lappend result [string replace $s end-0x100000000 end XYZ] +} -setup { + set s [bigString 0x10000000a] +} -cleanup { + unset -nocomplain s +} -constraints bug-ad9361fd20f0 +# TODO - once above bug is fixed, add tests for large result range: +# - replacements string is large +# - replace in the middle - string length grows, shrinks +# - last < first + +# +# string reverse +bigtestRO string-reverse-bigdata-1 "string reverse" {5432109876 9876543210} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 result + set s2 [string reverse $s] + list [string range $s2 0 9] [string range $s2 end-9 end] +} -setup { + set s [bigString 0x10000000a] +} -cleanup { + unset -nocomplain s s2 +} + +# +# string tolower +bigtestRO string-tolower-bigdata-1 "string tolower" 1 -body { + string equal [string tolower $s] [string repeat abcd $repts] +} -setup { + set repts [expr 0x100000010/4] + set s [string repeat ABCD $repts] +} -cleanup { + unset -nocomplain s repts +} +bigtestRO string-tolower-bigdata-2 "string tolower first last" {4294967312 ABCDabcdABCD 4294967312 ABCDabcdABCD 4294967312 ABCDabcdABCD} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 result + set s2 [string tolower $s 4 7] + lappend result [string length $s2] [string range $s2 0 11] + + unset s2; #Explicit free to reduce total memory + set s2 [string tolower $s 0x100000008 0x10000000b] + lappend result [string length $s2] [string range $s2 0x100000004 end] + + unset s2; #Explicit free to reduce total memory + set s2 [string tolower $s end-7 end-4] + lappend result [string length $s2] [string range $s2 0x100000004 end] +} -setup { + set repts [expr 0x100000010/4] + set s [string repeat ABCD $repts] +} -cleanup { + unset -nocomplain s s2 repts } -foreach len {0x7fffffff 0xffffffff 0x100000000} { - break; # Skip for now - set body "llength \[lrepeat $len x\]" - bigtest lrepeat-bigdata-1-$len $body $len +# +# string totitle +bigtestRO string-totitle-bigdata-1 "string totitle first last" {4294967312 aBcDAbcdaBcD 4294967312 aBcDAbcdaBcD 4294967312 aBcDAbcdaBcD} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 result + set s2 [string totitle $s 4 7] + lappend result [string length $s2] [string range $s2 0 11] + unset s2; #Explicit free to reduce total memory + set s2 [string totitle $s 0x100000008 0x10000000b] + lappend result [string length $s2] [string range $s2 0x100000004 0x10000000f] + unset s2; #Explicit free to reduce total memory + set s2 [string totitle $s end-7 end-4] + lappend result [string length $s2] [string range $s2 0x100000004 0x10000000f] +} -setup { + set repts [expr 0x100000010/4] + set s [string repeat aBcD $repts] +} -cleanup { + unset -nocomplain s s2 repts } +# +# string toupper +bigtestRO string-toupper-bigdata-1 "string toupper" 1 -body { + string equal [string toupper $s] [string repeat ABCD $repts] +} -setup { + set repts [expr 0x100000010/4] + set s [string repeat abcd $repts] +} -cleanup { + unset -nocomplain s repts +} +bigtestRO string-toupper-bigdata-2 "string toupper first last" {4294967312 abcdABCDabcd 4294967312 abcdABCDabcd 4294967312 abcdABCDabcd} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 result + set s2 [string toupper $s 4 7] + lappend result [string length $s2] [string range $s2 0 11] + unset s2; #Explicit free to reduce total memory + set s2 [string toupper $s 0x100000008 0x10000000b] + lappend result [string length $s2] [string range $s2 0x100000004 0x10000000f] + unset s2; #Explicit free to reduce total memory + set s2 [string toupper $s end-7 end-4] + lappend result [string length $s2] [string range $s2 0x100000004 0x10000000f] +} -setup { + set repts [expr 0x100000010/4] + set s [string repeat abcd $repts] +} -cleanup { + unset -nocomplain s s2 repts +} + +# +# string trim +bigtestRO string-trim-bigdata-1 "string trim" {abcdyxxy yxxyabcd} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 + set s2 [string trim $s xy] + list [string range $s2 0 7] [string range $s2 end-7 end] +} -setup { + set repts [expr 0x100000010/8] + set s [string repeat xyabcdyx $repts] +} -cleanup { + unset -nocomplain s s2 +} + +# +# string trimleft +bigtestRO string-trimleft-bigdata-1 "string trimleft" {abcdyxxy xyabcdyx} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 + set s2 [string trimleft $s xy] + list [string range $s2 0 7] [string range $s2 end-7 end] +} -setup { + set repts [expr 0x100000010/8] + set s [string repeat xyabcdyx $repts] +} -cleanup { + unset -nocomplain s s2 +} + +# +# string trimright +bigtestRO string-trimright-bigdata-1 "string trimright" {xyabcdyx yxxyabcd} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 + set s2 [string trimright $s xy] + list [string range $s2 0 7] [string range $s2 end-7 end] +} -setup { + set repts [expr 0x100000010/8] + set s [string repeat xyabcdyx $repts] +} -cleanup { + unset -nocomplain s s2 +} + +# +# append +bigtestRO append-bigdata-1 "append large to small" 1 -body { + set s 0123456789 + append s [bigString 0x100000000] + string equal $s [bigString 0x10000000a] +} -cleanup { + unset -nocomplain s +} +bigtest append-bigdata-2 "append small to cross UINT_MAX boundary" 1 -body { + append s 0123456789 + string equal $s [bigString 4294967300] +} -setup { + set s [bigString 4294967290] +} -cleanup { + unset -nocomplain s +} +bigtest append-bigdata-3 "append small to cross UINT_MAX boundary" 1 -body { + set s2 "" + append s2 $s $s $s $s + string equal $s2 [bigString 4294967320] +} -setup { + # Make length multiple of 4 AND 10 since the bigString pattern length is 10 + set len [expr 4294967320/4] + set s [bigString $len] +} -cleanup { + unset -nocomplain s +} + +# +# format +bigtestRO format-bigdata-1 "format %s" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain s2 + set s2 [format %s $s] + string equal $s $s2 +} -setup { + set s [bigString 0x100000000] +} -cleanup { + unset -nocomplain s s2 +} -constraints bug-a550f9710b +bigtest format-bigdata-2 "format bigstring%s" 1 -body { + set s [format $s X] + string equal $s [bigString 0x100000001 0x100000000] +} -setup { + set s [bigString 0x100000000] + append s %s +} -cleanup { + unset -nocomplain s s2 +} -constraints bug-a550f9710b +# TODO - once above bugs fixed, add tests for width and precision + +# scan +# regexp +# regsub + + # cleanup ::tcltest::cleanupTests return -- cgit v0.12 From 7b249ac174d6a8a2475588bc916a76e4ed98cff9 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 10 Apr 2023 14:52:44 +0000 Subject: scan, reg*, subst tests --- tests/bigdata.test | 90 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/tests/bigdata.test b/tests/bigdata.test index 29ff725..2bef56a 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -5,6 +5,9 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# These are very rudimentary tests for large size arguments to commands. +# Any more substantive tests are not practical because of the run time. + if {"::tcltest" ni [namespace children]} { package require tcltest @@ -12,12 +15,12 @@ if {"::tcltest" ni [namespace children]} { } # -# Hints: -# -# - To save time, when commands do not modify operands, generate the test data -# and run multiple variants of the command in a single test. -# - Do NOT use -setup clauses that generate large data. They seem to be run -# irrespective of whether the test itself is run. +# bigtest and bigtestRO (RO->read only) generate compiled and uncompiled +# versions of the given test script. The difference between the two is +# that bigtest generates separate test instances for the two cases while +# bigtestRO generates a single test case covering both. The latter can +# only be used when operands are not modified and when combining tests +# does not consume too much additional memory. # Wrapper to generate compiled and uncompiled cases for a test. # If $args does not contain a -body key, $comment is treated as the test body @@ -52,7 +55,7 @@ proc bigtest {id comment result args} { } # Like bigtest except that both compiled and uncompiled are combined into one -# test using the same inout argument. This saves considerable time but for +# test using the same inout argument. This saves time but for # obvious reasons should only be used when the input argument is not modified. proc bigtestRO {id comment result args} { if {[dict exists $args -body]} { @@ -76,12 +79,6 @@ proc bigtestRO {id comment result args} { } interp alias {} bigString {} testbigdata string -proc xxbigString args { - puts bigStringEnter:$args - set xx [testbigdata string {*}$args] - puts bigStringExit - return $xx -} interp alias {} bigBinary {} testbigdata bytearray interp alias {} bigList {} testbigdata list proc bigPatLen {} { @@ -557,9 +554,76 @@ bigtest format-bigdata-2 "format bigstring%s" 1 -body { } -constraints bug-a550f9710b # TODO - once above bugs fixed, add tests for width and precision +# # scan +bigtestRO scan-bigdata-1 "scan %s" {1 1 2 1} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain result digits + lappend result [string equal [scan $s %s] $s] + lappend result [string equal [scan $s {%[0-9X]}] $s] + lappend result [scan $s {%[0-9]%s} digits x] $x + lappend result [string equal $digits [bigString 0x100000008]] +} -setup { + set s [bigString 0x10000000a 0x100000009] +} -cleanup { + unset -nocomplain s digits +} -constraints bug-d4ede611a7 + +# # regexp +bigtestRO regexp-bigdata-1 "regexp" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain result digits + lappend result [regexp {[[:digit:]]*X} $s] +} -setup { + set s [bigString 0x100000000 0x100000000] +} -cleanup { + unset -nocomplain s digits +} +bigtestRO regexp-bigdata-2 "regexp with capture" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain result digits match + lappend result [regexp {([[:digit:]])*X} $s match digits] [string equal $match $s] + puts B + unset match; # Free up memory + lappend result [string equal $digits [bigString 0x100000009]] +} -setup { + set s [bigString 0x10000000a 0x100000009] +} -cleanup { + unset -nocomplain s digits match +} -constraints takesTooLong + +# # regsub +bigtestRO regsub-bigdata-1 "regsub" X -body { + regsub -all \\d $s {} +} -setup { + set s [bigString 0x100000001 0x100000000] +} -cleanup { + unset -nocomplain s +} -constraints takesTooLong +bigtestRO regsub-bigdata-2 "regsub" 1 -body { + string equal [regsub -all \\d $s x] [string cat [string repeat x 0x100000000] X] +} -setup { + set s [bigString 0x100000001 0x100000000] +} -cleanup { + unset -nocomplain s +} -constraints takesTooLong + +# +# subst +bigtestRO subst-bigdata-1 "subst" {1 1} -body { + unset -nocomplain result + lappend result [string equal [subst $s] $s] + lappend result [string equal [subst {$s}] $s] +} -setup { + set s [bigString 0x10000000a] +} -cleanup { + unset -nocomplain s +} # cleanup -- cgit v0.12 From 4acb728d2976b6203a27d5df941f87ea96f41ff0 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 11 Apr 2023 16:52:49 +0000 Subject: Add tests for binary command. Add testlutil command for speeding up list tests. --- generic/tclTest.c | 98 ++++++++++++++++++++++++++++++++++++++++ tests/bigdata.test | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 225 insertions(+), 1 deletion(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index e42d5e6..25e3cf0 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -334,6 +334,7 @@ static Tcl_ObjCmdProc TestFindFirstCmd; static Tcl_ObjCmdProc TestFindLastCmd; static Tcl_ObjCmdProc TestHashSystemHashCmd; static Tcl_ObjCmdProc TestGetIntForIndexCmd; +static Tcl_ObjCmdProc TestLutilCmd; static Tcl_NRPostProc NREUnwind_callback; static Tcl_ObjCmdProc TestNREUnwind; @@ -722,6 +723,8 @@ Tcltest_Init( NULL, NULL); Tcl_CreateObjCommand(interp, "testapplylambda", TestApplyLambdaObjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "testlutil", TestLutilCmd, + NULL, NULL); if (TclObjTest_Init(interp) != TCL_OK) { return TCL_ERROR; @@ -8590,6 +8593,101 @@ int TestApplyLambdaObjCmd ( } /* + *---------------------------------------------------------------------- + * + * TestLutilCmd -- + * + * This procedure implements the "testlequal" command. It is used to + * test compare two lists for equality using the string representation + * of each element. Implemented in C because script level loops are + * too slow for comparing large (GB count) lists. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +TestLutilCmd( + TCL_UNUSED(void *), + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Arguments. */ +{ + Tcl_Size nL1, nL2; + Tcl_Obj *l1Obj = NULL; + Tcl_Obj *l2Obj = NULL; + Tcl_Obj **l1Elems; + Tcl_Obj **l2Elems; + static const char *const subcmds[] = { + "equal", "diffindex", NULL + }; + enum options { + LUTIL_EQUAL, LUTIL_DIFFINDEX + } idx; + + if (objc != 4) { + Tcl_WrongNumArgs(interp, 1, objv, "list1 list2"); + return TCL_ERROR; + } + if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option", 0, + &idx) != TCL_OK) { + return TCL_ERROR; + } + + /* Protect against shimmering, just to be safe */ + l1Obj = Tcl_DuplicateObj(objv[2]); + l2Obj = Tcl_DuplicateObj(objv[3]); + + int ret = TCL_ERROR; + if (Tcl_ListObjGetElements(interp, l1Obj, &nL1, &l1Elems) != TCL_OK) { + goto vamoose; + } + if (Tcl_ListObjGetElements(interp, l2Obj, &nL2, &l2Elems) != TCL_OK) { + goto vamoose; + } + + ret = TCL_OK; + switch (idx) { + case LUTIL_EQUAL: + /* Avoid the loop below if lengths differ */ + if (nL1 != nL2) { + Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + break; + } + /* FALLTHRU */ + case LUTIL_DIFFINDEX: + Tcl_Size i, nCmp; + nCmp = nL1 <= nL2 ? nL1 : nL2; + for (i = 0; i < nCmp; ++i) { + if (strcmp(Tcl_GetString(l1Elems[i]), Tcl_GetString(l2Elems[i]))) { + break; + } + } + if (i == nCmp && nCmp == nL1 && nCmp == nL2) { + nCmp = idx == LUTIL_EQUAL ? 1 : -1; + } else { + nCmp = idx == LUTIL_EQUAL ? 0 : i; + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(nCmp)); + break; + } + +vamoose: + if (l1Obj) { + Tcl_DecrRefCount(l1Obj); + } + if (l2Obj) { + Tcl_DecrRefCount(l2Obj); + } + return ret; +} + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/tests/bigdata.test b/tests/bigdata.test index 2bef56a..13c037e 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -6,7 +6,9 @@ # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # These are very rudimentary tests for large size arguments to commands. -# Any more substantive tests are not practical because of the run time. +# They do not exercise all possible options, shared/unshared Tcl_Objs, +# literal/variable arguments etc. all of which exercise different code +# paths. But more substantive tests are not practical because of the run time. if {"::tcltest" ni [namespace children]} { package require tcltest @@ -625,6 +627,130 @@ bigtestRO subst-bigdata-1 "subst" {1 1} -body { unset -nocomplain s } +# +# binary format +bigtestRO binary-format-bigdata-1 "binary format aN" 4294967296 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain bin + set bin [binary format a4294967296 X] + string length $bin +} -cleanup { + unset -nocomplain bin +} -constraints bug-9369f83649 +# TODO - do string compare and add other format specifiers once above bug is fixed + +bigtestRO binary-format-bigdata-2 "binary format a*" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain bin2 + set bin2 [binary format a* $bin] + string equal $bin $bin2 +} -setup { + set bin [bigBinary 4294967296] +} -cleanup { + unset -nocomplain bin bin2 +} + +# +# binary scan +bigtestRO binary-scan-bigdata-1 "binary scan aN" 4294967296 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain bin2 + binary scan $bin a4294967296 bin2 + string length $bin2 +} -setup { + set bin [bigBinary 4294967296] +} -cleanup { + unset -nocomplain bin bin2 +} -constraints bug-9369f83649 +# TODO - do string compare and add other format specifiers once above bug is fixed + +bigtestRO binary-scan-bigdata-2 "binary scan a*" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain bin2 + binary scan $bin a* bin2 + string equal $bin $bin2 +} -setup { + set bin [bigBinary 4294967296] +} -cleanup { + unset -nocomplain bin bin2 +} +# TODO - do string compare and add other format specifiers once above bug is fixed + +# +# binary encode / decode base64 +bigtestRO binary-encode/decode-base64-bigdata-1 "binary encode/decode base64" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + string equal $bin [binary decode base64 [binary encode base64 $bin]] +} -setup { + set bin [bigBinary 4294967296] +} -cleanup { + unset -nocomplain bin bin2 +} -constraints bug-c719fa8716 + +# +# binary encode / decode hex +bigtestRO binary-encode/decode-hex-bigdata-1 "binary encode/decode hex" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + string equal $bin [binary decode hex [binary encode hex $bin]] +} -setup { + set bin [bigBinary 4294967296] +} -cleanup { + unset -nocomplain bin bin2 +} + +# +# binary encode / decode uuencode +bigtestRO binary-encode/decode-uuencode-bigdata-1 "binary encode/decode uuencode" 1 -body { + string equal $bin [binary decode uuencode [binary encode uuencode $bin]] +} -setup { + set bin [bigBinary 4294967296] +} -cleanup { + unset -nocomplain bin +} -constraints bug-2e3fed53ba + +# +# lassign +bigtestRO lassign-bigdata-1 "lassign" {0 1 2 3 4 5 6 7 8 9 1} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + set l2 [lassign $l a b c d e f g h i j] + list $a $b $c $d $e $f $g $h $i $j [testlutil equal $l2 [bigList 0x100000000]] +} -setup { + set l [bigList 0x10000000a] +} -cleanup { + unset -nocomplain l l2 +} -constraints bug-d90fee06d0 + +# +# TODO +# {*} +# concat +# encoding convertfrom +# encoding convertto +# foreach +# lassign +# list +# lappend +# ledit +# lindex +# linsert +# llength +# lmap +# lrange +# lrepeat +# lreplace +# lsearch +# lsort +# lset +# split + + # cleanup ::tcltest::cleanupTests -- cgit v0.12 From b4542dd058093f1ce4398f8cac12c6490d2df7f6 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Wed, 12 Apr 2023 17:08:02 +0000 Subject: Test cases for more failures --- tests/bigdata.test | 278 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 218 insertions(+), 60 deletions(-) diff --git a/tests/bigdata.test b/tests/bigdata.test index 13c037e..b8d3206 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -24,8 +24,8 @@ if {"::tcltest" ni [namespace children]} { # only be used when operands are not modified and when combining tests # does not consume too much additional memory. -# Wrapper to generate compiled and uncompiled cases for a test. -# If $args does not contain a -body key, $comment is treated as the test body +# Wrapper to generate compiled and uncompiled cases for a test. If $args does +# not contain a -body key, $comment is treated as the test body proc bigtest {id comment result args} { if {[dict exists $args -body]} { set body [dict get $args -body] @@ -57,8 +57,8 @@ proc bigtest {id comment result args} { } # Like bigtest except that both compiled and uncompiled are combined into one -# test using the same inout argument. This saves time but for -# obvious reasons should only be used when the input argument is not modified. +# test using the same inout argument. This saves time but for obvious reasons +# should only be used when the input argument is not modified. proc bigtestRO {id comment result args} { if {[dict exists $args -body]} { set body [dict get $args -body] @@ -73,13 +73,15 @@ proc bigtestRO {id comment result args} { append wrapper "set uncompiled_result \[testevalex $body]" \n append wrapper "set compiled_result \[try $body]" \n append wrapper {list $uncompiled_result $compiled_result} - uplevel 1 [list test $id {$comment} \ + uplevel 1 [list test $id.uncompiled,compiled {$comment} \ -body $wrapper \ -result [list $result $result] \ {*}$args] return } +interp alias {} bigClean {} unset -nocomplain s s1 s2 bin bin1 bin2 l l1 l2 + interp alias {} bigString {} testbigdata string interp alias {} bigBinary {} testbigdata bytearray interp alias {} bigList {} testbigdata list @@ -137,7 +139,7 @@ bigtestRO string-equal/compare-bigdata-1 "string compare/equal equal strings" {0 set s1 [bigString $len] set s2 [bigString $len]; # Use separate string to avoid Tcl_Obj * being same } -cleanup { - unset -nocomplain s1 s2 + bigClean } bigtestRO string-equal/compare-bigdata-2 "string compare/equal -length unequal strings" {-1 0 0 1} -body { # Also tests lengths do not wrap @@ -153,7 +155,7 @@ bigtestRO string-equal/compare-bigdata-2 "string compare/equal -length unequal s set s1 [bigString $len] set s2 [bigString $len $len]; # Differs in last char } -cleanup { - unset -nocomplain s1 s2 + bigClean } # @@ -167,7 +169,7 @@ bigtestRO string-first-bigdata-1 "string first > INT_MAX" {2147483648 -1 2147483 } -setup { set s [bigString 0x8000000a 0x80000000] } -cleanup { - unset -nocomplain s + bigClean } -constraints bug-a814ee5bbd bigtestRO string-first-bigdata-2 "string first > UINT_MAX" {4294967296 -1 4294967300 1} -body { @@ -179,7 +181,7 @@ bigtestRO string-first-bigdata-2 "string first > UINT_MAX" {4294967296 -1 429496 } -setup { set s [bigString 0x10000000a 0x100000000] } -cleanup { - unset -nocomplain s + bigClean } -constraints bug-a814ee5bbd bigtestRO string-first-bigdata-3 "string first - long needle" 10 -body { @@ -188,7 +190,7 @@ bigtestRO string-first-bigdata-3 "string first - long needle" 10 -body { set s [bigString 0x10000000a 0] set needle [bigString 0x100000000] } -cleanup { - unset -nocomplain s needle + bigClean needle } -constraints bug-a814ee5bbd # @@ -207,7 +209,7 @@ bigtestRO string-index-bigdata-1 "string index" {6 7 5 {} 5 4 {} 9 {}} -body { } -setup { set s [bigString 0x10000000a] } -cleanup { - unset -nocomplain s + bigClean } # @@ -230,7 +232,7 @@ bigtestRO string-is-bigdata-1 "string is" {1 0 0 4294967296} -body { } -setup { set s [bigString 0x10000000a 0x100000000] } -cleanup { - unset -nocomplain s failat + bigClean failat } # @@ -245,7 +247,7 @@ bigtestRO string-last-bigdata-1 "string last > INT_MAX" {2 -1 2147483640 11} -bo } -setup { set s [bigString 0x80000010 2] } -cleanup { - unset -nocomplain s + bigClean } -constraints bug-a814ee5bbd bigtestRO string-last-bigdata-2 "string last > UINT_MAX" {4294967300 -1 4294967290 1} -body { @@ -257,7 +259,7 @@ bigtestRO string-last-bigdata-2 "string last > UINT_MAX" {4294967300 -1 42949672 } -setup { set s [bigString 0x10000000a 2] } -cleanup { - unset -nocomplain s + bigClean } -constraints bug-a814ee5bbd bigtestRO string-last-bigdata-3 "string last - long needle" 0 -body { @@ -266,7 +268,7 @@ bigtestRO string-last-bigdata-3 "string last - long needle" 0 -body { set s [bigString 0x10000000a 0x10000000a] set needle [bigString 0x100000000] } -cleanup { - unset -nocomplain s needle + bigClean needle } -constraints bug-a814ee5bbd # @@ -274,7 +276,7 @@ bigtestRO string-last-bigdata-3 "string last - long needle" 0 -body { bigtestRO string-length-bigdata-1 {string length $s} 4294967296 -setup { set s [bigString 0x100000000] } -cleanup { - unset -nocomplain s + bigClean } # @@ -292,7 +294,7 @@ bigtestRO string-map-bigdata-1 {string map} {5 0 0 5} -body { } -setup { set s [bigString 0x100000000] } -cleanup { - unset -nocomplain s s2 + bigClean } -constraints takesTooLong # @@ -305,7 +307,7 @@ bigtestRO string-match-bigdata-1 {string match} {1 0 1} -body { } -setup { set s [bigString 0x100000000] } -cleanup { - unset -nocomplain s + bigClean } # @@ -324,12 +326,12 @@ bigtestRO string-range-bigdata-1 "string range" {6 7 5 {} 5 4 {} 9 {}} -body { } -setup { set s [bigString 0x10000000a] } -cleanup { - unset -nocomplain s + bigClean } -constraints bug-ad9361fd20f0 # TODO - once above bug is fixed, add tests for large result range # -# string repeat +# string repeat - use bigtest, not bigtestRO !! bigtest string-repeat-bigdata-1 "string repeat single char length > UINT_MAX" 4294967296 -body { string length [string repeat x 0x100000000] } @@ -340,7 +342,7 @@ bigtest string-repeat-bigdata-2 "string repeat multiple char" {4294967296 012345 [string range $s 0 15] \ [string range $s end-15 end] } -cleanup { - unset -nocomplain s + bigClean } # @@ -356,7 +358,7 @@ bigtestRO string-replace-bigdata-1 "string replace" {789012345 012345678 XYZ7890 } -setup { set s [bigString 0x10000000a] } -cleanup { - unset -nocomplain s + bigClean } -constraints bug-ad9361fd20f0 # TODO - once above bug is fixed, add tests for large result range: # - replacements string is large @@ -374,7 +376,7 @@ bigtestRO string-reverse-bigdata-1 "string reverse" {5432109876 9876543210} -bod } -setup { set s [bigString 0x10000000a] } -cleanup { - unset -nocomplain s s2 + bigClean } # @@ -385,7 +387,7 @@ bigtestRO string-tolower-bigdata-1 "string tolower" 1 -body { set repts [expr 0x100000010/4] set s [string repeat ABCD $repts] } -cleanup { - unset -nocomplain s repts + bigClean repts } bigtestRO string-tolower-bigdata-2 "string tolower first last" {4294967312 ABCDabcdABCD 4294967312 ABCDabcdABCD 4294967312 ABCDabcdABCD} -body { # Unset explicitly before setting to save memory as bigtestRO runs the @@ -405,7 +407,7 @@ bigtestRO string-tolower-bigdata-2 "string tolower first last" {4294967312 ABCDa set repts [expr 0x100000010/4] set s [string repeat ABCD $repts] } -cleanup { - unset -nocomplain s s2 repts + bigClean repts } # @@ -426,7 +428,7 @@ bigtestRO string-totitle-bigdata-1 "string totitle first last" {4294967312 aBcDA set repts [expr 0x100000010/4] set s [string repeat aBcD $repts] } -cleanup { - unset -nocomplain s s2 repts + bigClean repts } # @@ -437,7 +439,7 @@ bigtestRO string-toupper-bigdata-1 "string toupper" 1 -body { set repts [expr 0x100000010/4] set s [string repeat abcd $repts] } -cleanup { - unset -nocomplain s repts + bigClean repts } bigtestRO string-toupper-bigdata-2 "string toupper first last" {4294967312 abcdABCDabcd 4294967312 abcdABCDabcd 4294967312 abcdABCDabcd} -body { # Unset explicitly before setting to save memory as bigtestRO runs the @@ -455,7 +457,7 @@ bigtestRO string-toupper-bigdata-2 "string toupper first last" {4294967312 abcdA set repts [expr 0x100000010/4] set s [string repeat abcd $repts] } -cleanup { - unset -nocomplain s s2 repts + bigClean repts } # @@ -470,7 +472,7 @@ bigtestRO string-trim-bigdata-1 "string trim" {abcdyxxy yxxyabcd} -body { set repts [expr 0x100000010/8] set s [string repeat xyabcdyx $repts] } -cleanup { - unset -nocomplain s s2 + bigClean } # @@ -485,7 +487,7 @@ bigtestRO string-trimleft-bigdata-1 "string trimleft" {abcdyxxy xyabcdyx} -body set repts [expr 0x100000010/8] set s [string repeat xyabcdyx $repts] } -cleanup { - unset -nocomplain s s2 + bigClean } # @@ -500,7 +502,7 @@ bigtestRO string-trimright-bigdata-1 "string trimright" {xyabcdyx yxxyabcd} -bod set repts [expr 0x100000010/8] set s [string repeat xyabcdyx $repts] } -cleanup { - unset -nocomplain s s2 + bigClean } # @@ -510,7 +512,7 @@ bigtestRO append-bigdata-1 "append large to small" 1 -body { append s [bigString 0x100000000] string equal $s [bigString 0x10000000a] } -cleanup { - unset -nocomplain s + bigClean } bigtest append-bigdata-2 "append small to cross UINT_MAX boundary" 1 -body { append s 0123456789 @@ -518,7 +520,7 @@ bigtest append-bigdata-2 "append small to cross UINT_MAX boundary" 1 -body { } -setup { set s [bigString 4294967290] } -cleanup { - unset -nocomplain s + bigClean } bigtest append-bigdata-3 "append small to cross UINT_MAX boundary" 1 -body { set s2 "" @@ -529,7 +531,7 @@ bigtest append-bigdata-3 "append small to cross UINT_MAX boundary" 1 -body { set len [expr 4294967320/4] set s [bigString $len] } -cleanup { - unset -nocomplain s + bigClean } # @@ -543,7 +545,7 @@ bigtestRO format-bigdata-1 "format %s" 1 -body { } -setup { set s [bigString 0x100000000] } -cleanup { - unset -nocomplain s s2 + bigClean } -constraints bug-a550f9710b bigtest format-bigdata-2 "format bigstring%s" 1 -body { set s [format $s X] @@ -552,7 +554,7 @@ bigtest format-bigdata-2 "format bigstring%s" 1 -body { set s [bigString 0x100000000] append s %s } -cleanup { - unset -nocomplain s s2 + bigClean } -constraints bug-a550f9710b # TODO - once above bugs fixed, add tests for width and precision @@ -569,7 +571,7 @@ bigtestRO scan-bigdata-1 "scan %s" {1 1 2 1} -body { } -setup { set s [bigString 0x10000000a 0x100000009] } -cleanup { - unset -nocomplain s digits + bigClean digits } -constraints bug-d4ede611a7 # @@ -582,7 +584,7 @@ bigtestRO regexp-bigdata-1 "regexp" 1 -body { } -setup { set s [bigString 0x100000000 0x100000000] } -cleanup { - unset -nocomplain s digits + bigClean digits } bigtestRO regexp-bigdata-2 "regexp with capture" 1 -body { # Unset explicitly before setting to save memory as bigtestRO runs the @@ -595,7 +597,7 @@ bigtestRO regexp-bigdata-2 "regexp with capture" 1 -body { } -setup { set s [bigString 0x10000000a 0x100000009] } -cleanup { - unset -nocomplain s digits match + bigClean digits match } -constraints takesTooLong # @@ -605,14 +607,14 @@ bigtestRO regsub-bigdata-1 "regsub" X -body { } -setup { set s [bigString 0x100000001 0x100000000] } -cleanup { - unset -nocomplain s + bigClean } -constraints takesTooLong bigtestRO regsub-bigdata-2 "regsub" 1 -body { string equal [regsub -all \\d $s x] [string cat [string repeat x 0x100000000] X] } -setup { set s [bigString 0x100000001 0x100000000] } -cleanup { - unset -nocomplain s + bigClean } -constraints takesTooLong # @@ -624,7 +626,7 @@ bigtestRO subst-bigdata-1 "subst" {1 1} -body { } -setup { set s [bigString 0x10000000a] } -cleanup { - unset -nocomplain s + bigClean } # @@ -636,7 +638,7 @@ bigtestRO binary-format-bigdata-1 "binary format aN" 4294967296 -body { set bin [binary format a4294967296 X] string length $bin } -cleanup { - unset -nocomplain bin + bigClean } -constraints bug-9369f83649 # TODO - do string compare and add other format specifiers once above bug is fixed @@ -649,7 +651,7 @@ bigtestRO binary-format-bigdata-2 "binary format a*" 1 -body { } -setup { set bin [bigBinary 4294967296] } -cleanup { - unset -nocomplain bin bin2 + bigClean } # @@ -663,7 +665,7 @@ bigtestRO binary-scan-bigdata-1 "binary scan aN" 4294967296 -body { } -setup { set bin [bigBinary 4294967296] } -cleanup { - unset -nocomplain bin bin2 + bigClean } -constraints bug-9369f83649 # TODO - do string compare and add other format specifiers once above bug is fixed @@ -676,7 +678,7 @@ bigtestRO binary-scan-bigdata-2 "binary scan a*" 1 -body { } -setup { set bin [bigBinary 4294967296] } -cleanup { - unset -nocomplain bin bin2 + bigClean } # TODO - do string compare and add other format specifiers once above bug is fixed @@ -689,7 +691,7 @@ bigtestRO binary-encode/decode-base64-bigdata-1 "binary encode/decode base64" 1 } -setup { set bin [bigBinary 4294967296] } -cleanup { - unset -nocomplain bin bin2 + bigClean } -constraints bug-c719fa8716 # @@ -701,7 +703,7 @@ bigtestRO binary-encode/decode-hex-bigdata-1 "binary encode/decode hex" 1 -body } -setup { set bin [bigBinary 4294967296] } -cleanup { - unset -nocomplain bin bin2 + bigClean } # @@ -711,7 +713,7 @@ bigtestRO binary-encode/decode-uuencode-bigdata-1 "binary encode/decode uuencode } -setup { set bin [bigBinary 4294967296] } -cleanup { - unset -nocomplain bin + bigClean } -constraints bug-2e3fed53ba # @@ -719,34 +721,190 @@ bigtestRO binary-encode/decode-uuencode-bigdata-1 "binary encode/decode uuencode bigtestRO lassign-bigdata-1 "lassign" {0 1 2 3 4 5 6 7 8 9 1} -body { # Unset explicitly before setting to save memory as bigtestRO runs the # script below twice. + unset -nocomplain l2 set l2 [lassign $l a b c d e f g h i j] list $a $b $c $d $e $f $g $h $i $j [testlutil equal $l2 [bigList 0x100000000]] } -setup { set l [bigList 0x10000000a] } -cleanup { - unset -nocomplain l l2 + bigClean } -constraints bug-d90fee06d0 # +# lindex +bigtestRO lindex-bigdata-1 "lindex" {6 7 5 {} 5 4 {} 9 {}} -body { + list \ + [lindex $l 0x100000000] \ + [lindex $l 0x100000000+1] \ + [lindex $l 0x100000000-1] \ + [lindex $l 0x10000000a] \ + [lindex $l end] \ + [lindex $l end-1] \ + [lindex $l end+1] \ + [lindex $l end-0x100000000] \ + [lindex $l end-0x10000000a] +} -setup { + set l [bigList 0x10000000a] +} -cleanup { + bigClean +} -constraints bug-dcac54a685 + +# +# linsert +# Cannot use bigtestRO here because 16GB memory not enough to have two 4G sized lists +# Have to throw away source list every time. Also means we cannot compare entire lists +# and instead just compare the affected range +bigtest linsert-bigdata-1 "linsert" {4294967330 1} -body { + # Note insert at multiple of 10 to enable comparison against generated string + set ins [split abcdefghij ""] + set pat [split 0123456789 ""] + set insidx 2000000000 + set l [linsert [bigList 4294967320] $insidx {*}$ins] + list \ + [llength $l] \ + [testlutil equal [lrange $l $insidx-10 $insidx+19] [concat $pat $ins $pat]] +} -cleanup { + bigClean +} + +# +# llength +bigtestRO llength-bigdata-1 {llength} 4294967296 -body { + llength $l +} -setup { + set l [bigList 0x100000000] +} -cleanup { + bigClean +} + +# +# lmap +bigtestRO lmap-bigdata-1 "lmap" 1 -body { + testlutil equal $l [lmap e $l {set e}] +} -setup { + set l [bigList 0x100000000] +} -cleanup { + bigClean +} -constraints bug-6926a21840 + +bigtestRO lrange-bigdata-1 "lrange" {6 7 5 {} 5 4 {} 9 {}} -body { + list \ + [lrange $l 0x100000000 0x100000000] \ + [lrange $l 0x100000000+1 0x100000000+1] \ + [lrange $l 0x100000000-1 0x100000000-1] \ + [lrange $l 0x10000000a 0x10000000a] \ + [lrange $l end end] \ + [lrange $l end-1 end-1] \ + [lrange $l end+1 end+1] \ + [lrange $l end-0x100000000 end-0x100000000] \ + [lrange $l end-0x10000000a end-0x10000000a] +} -setup { + set l [bigList 0x10000000a] +} -cleanup { + bigClean +} -constraints bug-dcac54a685 +# TODO - once above bug is fixed, add tests for large result range + +# +# lrepeat - use bigtest, not bigtestRO !! +bigtest lrepeat-bigdata-1 "lrepeat single element length > UINT_MAX" 4294967296 -body { + # Just to test long lengths are accepted as arguments + llength [lrepeat 0x100000000 x] +} -constraints bug-4ce858a049 + +bigtest lrepeat-bigdata-2 "string repeat multiple char" {4294967296 1} -body { + # Make length multiple of 4 AND 10 since the bigString pattern length is 10 + set len [expr 4294967320/4] + set l [lrepeat $len 0 1 2 3 4 5 6 7 8 9] + list \ + [llength $l] \ + [testlutil equal $l [bigList 4294967320]] +} -cleanup { + bigClean +} -constraints bug-4ce858a049 + +# +# lreplace +bigtestRO lreplace-bigdata-1 "lreplace - small result" [list \ + [split 789012345 ""] \ + [split 012345678 ""] \ + [split XYZ789012345 ""] \ + [split 012345678XYZ ""] \ + ] -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain result + lappend result [lreplace $l 0 0x100000000] + lappend result [lreplace $l end-0x100000000 end] + lappend result [lreplace $l 0 0x100000000 X Y Z] + lappend result [lreplace $l end-0x100000000 end X Y Z] +} -setup { + set l [bigList 0x10000000a] +} -cleanup { + bigClean +} + +bigtest lreplace-bigdata-2 "lreplace - large result" {4294967301 {a b c d e 0 1 2 3 4 5 6}} -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain l2 + set l2 [lreplace [bigList 4294967296] 4294967290 0 a b c d e] + lrange $l2 4294967290 end +} -setup { + #set l [bigList 4294967296] +} -cleanup { + bigClean +} -constraints notenoughmemorypanic + +# +# lsearch +bigtestRO lsearch-bigdata-1 "lsearch" {4294967300 4294967310 -1} -body { + list \ + [lsearch -exact $l X] \ + [lsearch -exact -start 4294967291 $l 0] \ + [lsearch -exact $l Y] +} -setup { + set l [bigList 0x100000010 4294967300] +} -cleanup { + bigClean +} -constraints bug-a4617c8e90 + +# +# lsort +bigtestRO lsort-bigdata-1 "lsort" [list 4294967296 [lrepeat 10 0] [lrepeat 10 9]] -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain l2 + set l2 [lsort $l] + list [llength $l2] [lrange $l2 0 9] [lrange $l2 end-9 end] +} -setup { + set l [bigList 0x100000000] +} -cleanup { + bigClean +} -constraints notenoughmemoryexception + +# +# join +bigtestRO join-bigdata-1 "join" 1 -body { + string equal [join $l ""] $s +} -setup { + set l [bigList 0x100000000] + set s [bigString 0x100000000] +} -cleanup { + bigClean +} + +# # TODO # {*} # concat # encoding convertfrom # encoding convertto # foreach -# lassign # list # lappend # ledit -# lindex -# linsert -# llength -# lmap -# lrange -# lrepeat -# lreplace -# lsearch -# lsort +# lseq # lset # split -- cgit v0.12 From bce26daa76c703d201d5ff0450be57529b236aa3 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Thu, 13 Apr 2023 02:40:00 +0000 Subject: Fix compilation on macos, test loading on mingw --- generic/tclTest.c | 5 +++-- tests/bigdata.test | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 25e3cf0..39246e7 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -8629,7 +8629,7 @@ TestLutilCmd( enum options { LUTIL_EQUAL, LUTIL_DIFFINDEX } idx; - + if (objc != 4) { Tcl_WrongNumArgs(interp, 1, objv, "list1 list2"); return TCL_ERROR; @@ -8651,6 +8651,8 @@ TestLutilCmd( goto vamoose; } + Tcl_Size i, nCmp; + ret = TCL_OK; switch (idx) { case LUTIL_EQUAL: @@ -8661,7 +8663,6 @@ TestLutilCmd( } /* FALLTHRU */ case LUTIL_DIFFINDEX: - Tcl_Size i, nCmp; nCmp = nL1 <= nL2 ? nL1 : nL2; for (i = 0; i < nCmp; ++i) { if (strcmp(Tcl_GetString(l1Elems[i]), Tcl_GetString(l2Elems[i]))) { diff --git a/tests/bigdata.test b/tests/bigdata.test index b8d3206..5c5b75e 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -16,6 +16,10 @@ if {"::tcltest" ni [namespace children]} { namespace import -force ::tcltest::* } +::tcltest::loadTestedCommands +catch [list package require -exact tcl::test [info patchlevel]] +source [file join [file dirname [info script]] tcltests.tcl] + # # bigtest and bigtestRO (RO->read only) generate compiled and uncompiled # versions of the given test script. The difference between the two is @@ -748,6 +752,7 @@ bigtestRO lindex-bigdata-1 "lindex" {6 7 5 {} 5 4 {} 9 {}} -body { } -cleanup { bigClean } -constraints bug-dcac54a685 +# TODO after bug fix - nested index # # linsert -- cgit v0.12 From d8c2bafa2cc1a720d837ffb6a43c2f4d9666ef68 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Thu, 13 Apr 2023 18:05:00 +0000 Subject: Few more bigdata tests --- generic/tclTest.c | 2 +- tests/bigdata.test | 110 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 100 insertions(+), 12 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 39246e7..5c0301a 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -8674,7 +8674,7 @@ TestLutilCmd( } else { nCmp = idx == LUTIL_EQUAL ? 0 : i; } - Tcl_SetObjResult(interp, Tcl_NewIntObj(nCmp)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nCmp)); break; } diff --git a/tests/bigdata.test b/tests/bigdata.test index 5c5b75e..1c107d7 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -299,7 +299,7 @@ bigtestRO string-map-bigdata-1 {string map} {5 0 0 5} -body { set s [bigString 0x100000000] } -cleanup { bigClean -} -constraints takesTooLong +} -constraints bug-takesTooLong # # string match @@ -602,7 +602,7 @@ bigtestRO regexp-bigdata-2 "regexp with capture" 1 -body { set s [bigString 0x10000000a 0x100000009] } -cleanup { bigClean digits match -} -constraints takesTooLong +} -constraints bug-takesTooLong # # regsub @@ -612,14 +612,14 @@ bigtestRO regsub-bigdata-1 "regsub" X -body { set s [bigString 0x100000001 0x100000000] } -cleanup { bigClean -} -constraints takesTooLong +} -constraints bug-takesTooLong bigtestRO regsub-bigdata-2 "regsub" 1 -body { string equal [regsub -all \\d $s x] [string cat [string repeat x 0x100000000] X] } -setup { set s [bigString 0x100000001 0x100000000] } -cleanup { bigClean -} -constraints takesTooLong +} -constraints bug-takesTooLong # # subst @@ -720,6 +720,38 @@ bigtestRO binary-encode/decode-uuencode-bigdata-1 "binary encode/decode uuencode bigClean } -constraints bug-2e3fed53ba +################################################################ +# List commands + +# +# foreach +bigtestRO foreach-bigdata-1 "foreach" 1 -body { + # Unset explicitly before setting to save memory as bigtestRO runs the + # script below twice. + unset -nocomplain l2 + foreach x $l { + lappend l2 $x + } + testlutil equal $l $l2 +} -setup { + set l [bigList 0x100000000] +} -cleanup { + bigClean +} -constraints lengthtruncation + +# +# lappend +bigtest lappend-bigdata-1 "lappend" {0 1 2 3 4 a b c d} -body { + # Do not have enough memory for a full compare. + # Just check end + lappend l a b c d + lrange $l end-8 end +} -setup { + set l [bigList 0xFFFFFFFF] +} -cleanup { + bigClean +} + # # lassign bigtestRO lassign-bigdata-1 "lassign" {0 1 2 3 4 5 6 7 8 9 1} -body { @@ -735,6 +767,33 @@ bigtestRO lassign-bigdata-1 "lassign" {0 1 2 3 4 5 6 7 8 9 1} -body { } -constraints bug-d90fee06d0 # +# ledit +bigtest ledit-bigdata-1 "ledit - small result" {{0 X Y Z 8} {0 X Y Z 8}} -body { + list [ledit l 1 0x100000001 X Y Z] $l +} -setup { + set l [bigList 0x100000003] +} -cleanup { + bigClean +} + +bigtest ledit-bigdata-2 "ledit - large result" {4294967304 4294967304 a b c d e f g 8} -body { + list [llength [ledit l 0x100000000 0x100000000 a b c d e f g]] [llength $l] [lrange $l 0x100000000 end] +} -setup { + set l [bigList 0x100000002] +} -cleanup { + bigClean +} -constraints bug-outofmemorypanic + +bigtest ledit-bigdata-3 "ledit - small -> large result" {2147483651 2147483651} -body { + set l2 {a b c x y z} + list [llength [ledit l2 2 3 {*}$l]] [llength $l2] +} -setup { + set l [bigList 2147483647] +} -cleanup { + bigClean +} -constraints bug-7cddd2845c + +# # lindex bigtestRO lindex-bigdata-1 "lindex" {6 7 5 {} 5 4 {} 9 {}} -body { list \ @@ -773,6 +832,18 @@ bigtest linsert-bigdata-1 "linsert" {4294967330 1} -body { } # +# list and {*} +bigtestRO list-bigdata-1 {list {*} } {4294967296 0 4294967295} -body { + unset -nocomplain l2 + set l2 [list {*}$l] + list [llength $l2] [lindex $l2 0] [lindex $l2 end] +} -setup { + set l [bigList 0x100000000] +} -cleanup { + bigClean +} -constraints bug-7cddd2845c + +# # llength bigtestRO llength-bigdata-1 {llength} 4294967296 -body { llength $l @@ -792,6 +863,8 @@ bigtestRO lmap-bigdata-1 "lmap" 1 -body { bigClean } -constraints bug-6926a21840 +# +# lrange bigtestRO lrange-bigdata-1 "lrange" {6 7 5 {} 5 4 {} 9 {}} -body { list \ [lrange $l 0x100000000 0x100000000] \ @@ -859,7 +932,7 @@ bigtest lreplace-bigdata-2 "lreplace - large result" {4294967301 {a b c d e 0 1 #set l [bigList 4294967296] } -cleanup { bigClean -} -constraints notenoughmemorypanic +} -constraints bug-outofmemorypanic # # lsearch @@ -875,6 +948,16 @@ bigtestRO lsearch-bigdata-1 "lsearch" {4294967300 4294967310 -1} -body { } -constraints bug-a4617c8e90 # +# lset +bigtest lset-bigdata-1 "lset" {4294967297 4294967297 {1 2 3 4 5 X}} -body { + list [llength [lset l 0x100000000 X]] [llength $l] [lrange $l end-5 end] +} -setup { + set l [bigList 0x100000001] +} -cleanup { + bigClean +} -constraints bug-outofmemorypanic + +# # lsort bigtestRO lsort-bigdata-1 "lsort" [list 4294967296 [lrepeat 10 0] [lrepeat 10 9]] -body { # Unset explicitly before setting to save memory as bigtestRO runs the @@ -899,19 +982,24 @@ bigtestRO join-bigdata-1 "join" 1 -body { bigClean } +bigtest split-bigdata-1 "split" {4294967296 {0 1 2 3 4} {1 2 3 4 5}} -body { + # Fill list compare needs too much memory + set l [split $s ""] + list [llength $l] [lrange 0 4] [lrange end-4 end] +} -setup { + set s [bigString 0x100000000] +} -cleanup { + bigClean +} -constraints bug-takesTooLong + # # TODO -# {*} # concat # encoding convertfrom # encoding convertto -# foreach -# list -# lappend -# ledit # lseq -# lset # split +# dict * -- cgit v0.12 From dcd5ea5b916676bf83a5fd3de9ee1d19e1f45c81 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Fri, 14 Apr 2023 03:06:44 +0000 Subject: Finish up list tests. Add testbigdata dict command for generating dicts --- generic/tclTestObj.c | 20 +++++++++++++++----- tests/bigdata.test | 28 +++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 2936345..2e7d70e 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -1528,8 +1528,9 @@ TeststringobjCmd( * TestbigdataCmd -- * * Implements the Tcl command testbigdata - * testbigdata string ?LEN? ?SPLIT? - * testbigdata bytearray ?LEN? ?SPLIT? + * testbigdata string ?LEN? ?SPLIT? - returns 01234567890123... + * testbigdata bytearray ?LEN? ?SPLIT? - returns {0 1 2 3 4 5 6 7 8 9 0 1 ...} + * testbigdata dict ?SIZE? - returns dict mapping integers to themselves * If no arguments given, returns the pattern used to generate strings. * If SPLIT is specified, the character at that position is set to "X". * @@ -1550,10 +1551,10 @@ TestbigdataCmd ( Tcl_Obj *const objv[]) /* Argument objects. */ { static const char *const subcmds[] = { - "string", "bytearray", "list", NULL + "string", "bytearray", "list", "dict", NULL }; enum options { - BIGDATA_STRING, BIGDATA_BYTEARRAY, BIGDATA_LIST + BIGDATA_STRING, BIGDATA_BYTEARRAY, BIGDATA_LIST, BIGDATA_DICT } idx; char *s; unsigned char *p; @@ -1562,9 +1563,10 @@ TestbigdataCmd ( Tcl_Obj *objPtr; #define PATTERN_LEN 10 Tcl_Obj *patternObjs[PATTERN_LEN]; + Tcl_Obj *keyObjs[PATTERN_LEN]; if (objc < 2 || objc > 4) { - Tcl_WrongNumArgs(interp, 1, objv, "command ?len?"); + Tcl_WrongNumArgs(interp, 1, objv, "command ?len? ?split?"); return TCL_ERROR; } if (Tcl_GetIndexFromObj(interp, objv[1], subcmds, "option", 0, @@ -1647,6 +1649,14 @@ TestbigdataCmd ( } Tcl_SetObjResult(interp, objPtr); break; + case BIGDATA_DICT: + objPtr = Tcl_NewDictObj(); + for (i = 0; i < len; ++i) { + Tcl_Obj *objPtr2 = Tcl_NewWideIntObj(i); + Tcl_DictObjPut(interp, objPtr, objPtr2, objPtr2); + } + Tcl_SetObjResult(interp, objPtr); + break; } return TCL_OK; } diff --git a/tests/bigdata.test b/tests/bigdata.test index 1c107d7..d046df2 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -948,6 +948,23 @@ bigtestRO lsearch-bigdata-1 "lsearch" {4294967300 4294967310 -1} -body { } -constraints bug-a4617c8e90 # +# lseq +bigtest lseq-bigdata-1 "lseq" {4294967297 4294967296} -body { + list [llength $l] [lindex $l 0x100000000] +} -setup { + set l [lseq 0x100000001] +} -cleanup { + bigClean +} +bigtest lseq-bigdata-2 "lseq" {9223372036854775807 9223372036854775799} -body { + list [llength $l] [lindex $l 9223372036854775800] +} -setup { + set l [lseq 0x7fffffffffffffff]; llength $l +} -cleanup { + bigClean +} -constraints bug-fa00fbbbab + +# # lset bigtest lset-bigdata-1 "lset" {4294967297 4294967297 {1 2 3 4 5 X}} -body { list [llength [lset l 0x100000000 X]] [llength $l] [lrange $l end-5 end] @@ -992,13 +1009,18 @@ bigtest split-bigdata-1 "split" {4294967296 {0 1 2 3 4} {1 2 3 4 5}} -body { bigClean } -constraints bug-takesTooLong +bigtestRO concat-bigdata-1 "concat" {4294967296 {0 1 2 3 4} {6 7 0 1 2} {3 4 5 6 7}} -body { + unset -nocomplain l2 + set l2 [concat $l $l] + list [llength $l2] [lrange $l2 0 4] [lrange $l2 0x80000000-2 0x80000000+2] [lrange $l2 end-4 end] +} -setup { + set l [bigList 0x80000000] +} + # # TODO -# concat # encoding convertfrom # encoding convertto -# lseq -# split # dict * -- cgit v0.12 From aff6cc914124a4fd2e1a3079a57b58b96b9b6781 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Fri, 14 Apr 2023 15:07:27 +0000 Subject: Fixed bug-a498006438 --- generic/tclListObj.c | 2 +- tests/bigdata.test | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/generic/tclListObj.c b/generic/tclListObj.c index fd06770..b9c830a 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -1852,7 +1852,7 @@ Tcl_ListObjAppendList( : LISTREP_SPACE_ONLY_BACK, &listRep) != TCL_OK) { - return TCL_ERROR; + return MemoryAllocationError(interp, finalLen); } LIST_ASSERT(listRep.storePtr->numAllocated >= finalLen); diff --git a/tests/bigdata.test b/tests/bigdata.test index d046df2..3d4f9bf 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -6,9 +6,9 @@ # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # These are very rudimentary tests for large size arguments to commands. -# They do not exercise all possible options, shared/unshared Tcl_Objs, -# literal/variable arguments etc. all of which exercise different code -# paths. But more substantive tests are not practical because of the run time. +# They do not exercise all possible code paths such as shared/unshared Tcl_Objs, +# literal/variable arguments etc. +# They do however test compiled and uncompiled execution. if {"::tcltest" ni [namespace children]} { package require tcltest @@ -51,7 +51,7 @@ proc bigtest {id comment result args} { return - # TODO - is this required separately from the compile-script above? + # TODO - is this proc compilation required separately from the compile-script above? dict append args -setup \n[list proc testxproc {} $body] dict append args -cleanup "\nrename testxproc {}" uplevel 1 [list test $id.compiled-proc "$comment (compiled proc)" \ @@ -741,13 +741,12 @@ bigtestRO foreach-bigdata-1 "foreach" 1 -body { # # lappend -bigtest lappend-bigdata-1 "lappend" {0 1 2 3 4 a b c d} -body { +bigtest lappend-bigdata-1 "lappend" {4294967300 4294967300 {0 1 2 3 4 a b c d}} -body { + # Do NOT initialize l in a -setup block. That requires more memory and fails. # Do not have enough memory for a full compare. # Just check end - lappend l a b c d - lrange $l end-8 end -} -setup { - set l [bigList 0xFFFFFFFF] + set l [bigList 0x100000000] + list [llength [lappend l a b c d]] [llength $l] [lrange $l end-8 end] } -cleanup { bigClean } @@ -776,13 +775,13 @@ bigtest ledit-bigdata-1 "ledit - small result" {{0 X Y Z 8} {0 X Y Z 8}} -body { bigClean } -bigtest ledit-bigdata-2 "ledit - large result" {4294967304 4294967304 a b c d e f g 8} -body { - list [llength [ledit l 0x100000000 0x100000000 a b c d e f g]] [llength $l] [lrange $l 0x100000000 end] -} -setup { +bigtest ledit-bigdata-2 "ledit - large result" {4294967304 4294967304 {a b c d e f g 7}} -body { + # Do NOT initialize l in a -setup block. That requires more memory and fails. set l [bigList 0x100000002] + list [llength [ledit l 0x100000000 0x100000000 a b c d e f g]] [llength $l] [lrange $l 0x100000000 end] } -cleanup { bigClean -} -constraints bug-outofmemorypanic +} bigtest ledit-bigdata-3 "ledit - small -> large result" {2147483651 2147483651} -body { set l2 {a b c x y z} @@ -967,12 +966,12 @@ bigtest lseq-bigdata-2 "lseq" {9223372036854775807 9223372036854775799} -body { # # lset bigtest lset-bigdata-1 "lset" {4294967297 4294967297 {1 2 3 4 5 X}} -body { - list [llength [lset l 0x100000000 X]] [llength $l] [lrange $l end-5 end] -} -setup { + # Do NOT initialize l in a -setup block. That requires more memory and fails. set l [bigList 0x100000001] + list [llength [lset l 0x100000000 X]] [llength $l] [lrange $l end-5 end] } -cleanup { bigClean -} -constraints bug-outofmemorypanic +} # # lsort -- cgit v0.12 From e8326222de6ca4ce5eaadd888e9b8b515f6b165a Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sat, 15 Apr 2023 02:10:23 +0000 Subject: Add missing constraint to string-equal/compare test --- tests/bigdata.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bigdata.test b/tests/bigdata.test index 3d4f9bf..5729ef8 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -160,7 +160,7 @@ bigtestRO string-equal/compare-bigdata-2 "string compare/equal -length unequal s set s2 [bigString $len $len]; # Differs in last char } -cleanup { bigClean -} +} -constraints bug-a814ee5bbd # # string first -- cgit v0.12 From 713ccc8bb633b7d9df7587490e52352beca7d2c1 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sun, 16 Apr 2023 05:44:19 +0000 Subject: Fix VC++ unused variable warning, lappend and join. --- generic/tclTestObj.c | 1 - tests/bigdata.test | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index eb64717..7767601 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -1563,7 +1563,6 @@ TestbigdataCmd ( Tcl_Obj *objPtr; #define PATTERN_LEN 10 Tcl_Obj *patternObjs[PATTERN_LEN]; - Tcl_Obj *keyObjs[PATTERN_LEN]; if (objc < 2 || objc > 4) { Tcl_WrongNumArgs(interp, 1, objv, "command ?len? ?split?"); diff --git a/tests/bigdata.test b/tests/bigdata.test index 5729ef8..5519ded 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -741,7 +741,7 @@ bigtestRO foreach-bigdata-1 "foreach" 1 -body { # # lappend -bigtest lappend-bigdata-1 "lappend" {4294967300 4294967300 {0 1 2 3 4 a b c d}} -body { +bigtest lappend-bigdata-1 "lappend" {4294967300 4294967300 {1 2 3 4 5 a b c d}} -body { # Do NOT initialize l in a -setup block. That requires more memory and fails. # Do not have enough memory for a full compare. # Just check end @@ -990,13 +990,14 @@ bigtestRO lsort-bigdata-1 "lsort" [list 4294967296 [lrepeat 10 0] [lrepeat 10 9] # # join bigtestRO join-bigdata-1 "join" 1 -body { - string equal [join $l ""] $s + puts len:[string length [join $l ""]] + #string equal [join $l ""] $s } -setup { set l [bigList 0x100000000] set s [bigString 0x100000000] } -cleanup { bigClean -} +} -constraints bug-3c04fcdd1a bigtest split-bigdata-1 "split" {4294967296 {0 1 2 3 4} {1 2 3 4 5}} -body { # Fill list compare needs too much memory -- cgit v0.12