From db10c916283c7a33b01cf304871e59c3e62f4709 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 14 Aug 2015 19:45:39 -0500 Subject: [PATCH 01/15] Experiment with travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000000..362ed9726b328 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: c +compiler: +- clang +- gcc From c31ef1d145d2efa1d9554810581518c3d90fd2ad Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 14 Aug 2015 19:51:31 -0500 Subject: [PATCH 02/15] New build steps --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 362ed9726b328..54fdfb65a267c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,7 @@ language: c compiler: - clang - gcc +script: + - configure + - make -j2 + - make check-world From b7e3bb53892684366368e0a613de6cc239768d4d Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 14 Aug 2015 20:11:54 -0500 Subject: [PATCH 03/15] Add a bunch of variations --- .travis.yml | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 54fdfb65a267c..3de25638e0916 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,51 @@ language: c compiler: - clang - gcc +env: + global: + - CONFIG='--enable-debug --enable-cassert' + matrix: + - TAP='' BLKSZ=4 WALBLK=4 + - TAP='' BLKSZ=4 WALBLK=8 + - TAP='' BLKSZ=4 WALBLK=16 + - TAP='' BLKSZ=4 WALBLK=32 + + - TAP='' BLKSZ=8 WALBLK=4 + - TAP='' BLKSZ=8 WALBLK=8 + - TAP='' BLKSZ=8 WALBLK=16 + - TAP='' BLKSZ=8 WALBLK=32 + + - TAP='' BLKSZ=16 WALBLK=4 + - TAP='' BLKSZ=16 WALBLK=8 + - TAP='' BLKSZ=16 WALBLK=16 + - TAP='' BLKSZ=16 WALBLK=32 + + - TAP='' BLKSZ=32 WALBLK=4 + - TAP='' BLKSZ=32 WALBLK=8 + - TAP='' BLKSZ=32 WALBLK=16 + - TAP='' BLKSZ=32 WALBLK=32 + + - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=4 + - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=8 + - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=16 + - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=32 + + - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=4 + - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=8 + - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=16 + - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=32 + + - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=4 + - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=8 + - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=16 + - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=32 + + - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=4 + - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=8 + - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=16 + - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=32 + script: - - configure + - ./configure $CONFIG $TAP --with-blocksize=$BLKSZ --with-wal-blocksize=$WALBLK - make -j2 - make check-world From 866b8f2249af5ff9d02d3063c5641a4f61fcc238 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 14 Aug 2015 20:21:24 -0500 Subject: [PATCH 04/15] Spit out regression output on failure --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3de25638e0916..223ec28d25195 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,3 +50,6 @@ script: - ./configure $CONFIG $TAP --with-blocksize=$BLKSZ --with-wal-blocksize=$WALBLK - make -j2 - make check-world + - echo $TRAVIS_BUILD_DIR + - [ -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out ] && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out + - [ -e $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs ] && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs From 6fb6eeec73abb568f340502966b132e511c68217 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 14 Aug 2015 20:33:24 -0500 Subject: [PATCH 05/15] Trigger build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 223ec28d25195..cd64d0c6f3a29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: c compiler: - clang - gcc + env: global: - CONFIG='--enable-debug --enable-cassert' From b36d7d1c50759ba2ee72f6dc710833057bea7a6c Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 14 Aug 2015 20:34:52 -0500 Subject: [PATCH 06/15] Fix yaml syntax --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cd64d0c6f3a29..4088f8dc75fd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,5 +52,5 @@ script: - make -j2 - make check-world - echo $TRAVIS_BUILD_DIR - - [ -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out ] && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out - - [ -e $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs ] && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs + - test -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out + - test -e $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs From 0b0acddb077dd6176fbd6cf6b80f81d2560e984a Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Sun, 16 Aug 2015 17:44:27 -0500 Subject: [PATCH 07/15] Check regression dir --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4088f8dc75fd3..16ed3cbf43071 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,5 +52,7 @@ script: - make -j2 - make check-world - echo $TRAVIS_BUILD_DIR + - test -e $TRAVIS_BUILD_DIR && echo true + - test -e $TRAVIS_BUILD_DIR/src/test/regress && echo true - test -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out - test -e $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs From 85c6ae98618d9d2132b0791a3aad72aa782a555d Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Wed, 19 Aug 2015 11:01:21 -0500 Subject: [PATCH 08/15] Fix build script --- .travis.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 16ed3cbf43071..18d79d45aea01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,8 +51,5 @@ script: - ./configure $CONFIG $TAP --with-blocksize=$BLKSZ --with-wal-blocksize=$WALBLK - make -j2 - make check-world - - echo $TRAVIS_BUILD_DIR - - test -e $TRAVIS_BUILD_DIR && echo true - - test -e $TRAVIS_BUILD_DIR/src/test/regress && echo true - - test -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out - - test -e $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs && cat $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs + - test ! -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out || cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out + - test ! -e $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs || cat $TRAVIS_BUILD_DIR/src/test/regress/regression.diffs From af5e6bfd2371d9278b2e1712761ee4b93abd46ea Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Wed, 19 Aug 2015 18:03:15 -0500 Subject: [PATCH 09/15] Trim build config down --- .travis.yml | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18d79d45aea01..5b2125b0a3df3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,48 +7,12 @@ env: global: - CONFIG='--enable-debug --enable-cassert' matrix: - - TAP='' BLKSZ=4 WALBLK=4 - - TAP='' BLKSZ=4 WALBLK=8 - - TAP='' BLKSZ=4 WALBLK=16 - - TAP='' BLKSZ=4 WALBLK=32 - - - TAP='' BLKSZ=8 WALBLK=4 - - TAP='' BLKSZ=8 WALBLK=8 - - TAP='' BLKSZ=8 WALBLK=16 - - TAP='' BLKSZ=8 WALBLK=32 - - - TAP='' BLKSZ=16 WALBLK=4 - - TAP='' BLKSZ=16 WALBLK=8 - - TAP='' BLKSZ=16 WALBLK=16 - - TAP='' BLKSZ=16 WALBLK=32 - - - TAP='' BLKSZ=32 WALBLK=4 - - TAP='' BLKSZ=32 WALBLK=8 - - TAP='' BLKSZ=32 WALBLK=16 - TAP='' BLKSZ=32 WALBLK=32 - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=4 - - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=8 - - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=16 - - TAP='--enable-tap-tests' BLKSZ=4 WALBLK=32 - - - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=4 - - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=8 - - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=16 - - TAP='--enable-tap-tests' BLKSZ=8 WALBLK=32 - - - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=4 - - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=8 - - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=16 - - TAP='--enable-tap-tests' BLKSZ=16 WALBLK=32 - - - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=4 - - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=8 - - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=16 - - TAP='--enable-tap-tests' BLKSZ=32 WALBLK=32 script: - - ./configure $CONFIG $TAP --with-blocksize=$BLKSZ --with-wal-blocksize=$WALBLK + - ./configure $CONFIG $TAP - make -j2 - make check-world - test ! -e $TRAVIS_BUILD_DIR/src/test/regress/regression.out || cat $TRAVIS_BUILD_DIR/src/test/regress/regression.out From b115239541f4e8d522a484b46de29b2b01e2d5e7 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Fri, 21 Aug 2015 16:17:02 -0500 Subject: [PATCH 10/15] Add vim settings --- _vimrc_local.vim | 1 + 1 file changed, 1 insertion(+) create mode 100644 _vimrc_local.vim diff --git a/_vimrc_local.vim b/_vimrc_local.vim new file mode 100644 index 0000000000000..599a8c1553261 --- /dev/null +++ b/_vimrc_local.vim @@ -0,0 +1 @@ +set shiftwidth=4 tabstop=4 noexpandtab From fd4c444dfa058208d17163f92061451236e90069 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Tue, 11 Oct 2016 04:21:25 +0000 Subject: [PATCH 11/15] get trigger tests passing instead of crashing --- src/pl/tcl/pltcl.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 88d64297fc8fb..12fdeb2307792 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -1059,10 +1059,6 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) ************************************************************/ tcl_cmd = Tcl_NewObj(); Tcl_IncrRefCount(tcl_cmd); - tcl_trigtup = Tcl_NewObj(); - Tcl_IncrRefCount(tcl_trigtup); - tcl_newtup = Tcl_NewObj(); - Tcl_IncrRefCount(tcl_newtup); PG_TRY(); { /* The procedure name (note this is all ASCII, so no utf_e2u) */ @@ -1105,8 +1101,6 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) Tcl_NewStringObj(utf_e2u(NameStr(tupdesc->attrs[i]->attname)), -1)); } Tcl_ListObjAppendElement(NULL, tcl_cmd, tcl_trigtup); - Tcl_DecrRefCount(tcl_trigtup); - tcl_trigtup = Tcl_NewObj(); /* The when part of the event for TG_when */ if (TRIGGER_FIRED_BEFORE(trigdata->tg_event)) @@ -1208,8 +1202,6 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) PG_CATCH(); { Tcl_DecrRefCount(tcl_cmd); - Tcl_DecrRefCount(tcl_trigtup); - Tcl_DecrRefCount(tcl_newtup); PG_RE_THROW(); } PG_END_TRY(); @@ -1223,8 +1215,6 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) /* Release refcount to free tcl_cmd (and all subsidiary objects) */ Tcl_DecrRefCount(tcl_cmd); - Tcl_DecrRefCount(tcl_trigtup); - Tcl_DecrRefCount(tcl_newtup); /************************************************************ * Check for errors reported by Tcl. From 0aa8e5f0557e8d20e45dd24c5c51277dba2d74b0 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Tue, 11 Oct 2016 05:55:39 +0000 Subject: [PATCH 12/15] improve PL/Tcl test coverage --- src/pl/tcl/sql/pltcl_queries.sql | 48 ++++++++++++++++++++++++++++++++ src/pl/tcl/sql/pltcl_setup.sql | 21 ++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/pl/tcl/sql/pltcl_queries.sql b/src/pl/tcl/sql/pltcl_queries.sql index a0a9619a9bb21..b0f0762d53020 100644 --- a/src/pl/tcl/sql/pltcl_queries.sql +++ b/src/pl/tcl/sql/pltcl_queries.sql @@ -97,3 +97,51 @@ create temp table t1 (f1 int); select tcl_lastoid('t1'); create temp table t2 (f1 int) with oids; select tcl_lastoid('t2') > 0; + +-- Test quote +select * from tcl_eval('quote foo bar'); +select * from tcl_eval('quote [format %c 39]'); +select * from tcl_eval('quote [format %c 92]'); + +-- Test argisnull +select * from tcl_eval('argisnull'); +select * from tcl_eval('argisnull 14'); +select * from tcl_eval('argisnull abc'); + +-- Test return_null +select * from tcl_eval('return_null 14'); + +-- Test spi_exec +select * from tcl_eval('spi_exec'); +select * from tcl_eval('spi_exec -count'); +select * from tcl_eval('spi_exec -array'); +select * from tcl_eval('spi_exec -count abc'); +select * from tcl_eval('spi_exec query loop body toomuch'); + +-- Test spi_execp +select * from tcl_eval('spi_execp'); +select * from tcl_eval('spi_execp -count'); +select * from tcl_eval('spi_execp -array'); +select * from tcl_eval('spi_execp -count abc'); +select * from tcl_eval('spi_execp -nulls'); + +-- test spi_prepare +select * from tcl_eval('spi_prepare'); +select * from tcl_eval('spi_prepare a b'); +select * from tcl_eval('spi_prepare a "b {"'); + +-- test elog +select * from tcl_eval('elog'); +select * from tcl_eval('elog foo bar'); + +-- test compound return +select * from tcl_test_cube_squared(5); + +-- test multi-row returns +select * from tcl_test_cube_squared_rows(1,10); + +-- test setof returns +select * from tcl_test_sequence(1,10) as a; + +-- test forced error +select tcl_eval('error "forced error"'); diff --git a/src/pl/tcl/sql/pltcl_setup.sql b/src/pl/tcl/sql/pltcl_setup.sql index 8df65a5816550..e83604262d4ba 100644 --- a/src/pl/tcl/sql/pltcl_setup.sql +++ b/src/pl/tcl/sql/pltcl_setup.sql @@ -612,6 +612,27 @@ create function tcl_error_handling_test() returns text as $$ } $$ language pltcl; +CREATE OR REPLACE FUNCTION tcl_eval(in string varchar, out code int, out result varchar) AS $$ + set code [catch $1 catchResult] + return [list code $code result $catchResult] +$$ LANGUAGE 'pltcl'; + +CREATE OR REPLACE FUNCTION tcl_test_cube_squared(in int, out squared int, out cubed int) AS $$ + return [list squared [expr {$1 * $1}] cubed [expr {$1 * $1 * $1}]] +$$ LANGUAGE 'pltcl'; + +CREATE OR REPLACE FUNCTION tcl_test_cube_squared_rows(int,int) RETURNS TABLE (n int, squared int, cubed int) AS $$ + for {set i $1} {$i < $2} {incr i} { + return_next [list n $i squared [expr {$i * $i}] cubed [expr {$i * $i * $i}]] + } +$$ LANGUAGE 'pltcl'; + +CREATE OR REPLACE FUNCTION tcl_test_sequence(int,int) RETURNS SETOF int AS $$ + for {set i $1} {$i < $2} {incr i} { + return_next $i + } +$$ language 'pltcl'; + select tcl_error_handling_test(); create temp table foo(f1 int); From cb2eaf88881d1815406463dfa30743373cb957d2 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Tue, 11 Oct 2016 13:34:36 +0000 Subject: [PATCH 13/15] Don't have Tcl_GetIndexFromObj leave error message in spi_exec ...it isn't an error if it doesn't find an option and otherwise it leaves cruft in the Tcl result object. --- src/pl/tcl/pltcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 12fdeb2307792..4abe5d50b561f 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -2457,7 +2457,7 @@ pltcl_SPI_execute(ClientData cdata, Tcl_Interp *interp, i = 1; while (i < objc) { - if (Tcl_GetIndexFromObj(interp, objv[i], options, "option", + if (Tcl_GetIndexFromObj(NULL, objv[i], options, "option", TCL_EXACT, &optIndex) != TCL_OK) break; From d3d9845c812adf8d7ff9f7b94a7ac6ee2192a7ff Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Tue, 11 Oct 2016 13:39:32 +0000 Subject: [PATCH 14/15] Also don't leave Tcl_GetIndexFromObj error for spi_execp --- src/pl/tcl/pltcl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 4abe5d50b561f..bd2fde9788cef 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -2803,7 +2803,7 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp, i = 1; while (i < objc) { - if (Tcl_GetIndexFromObj(interp, objv[i], options, "option", + if (Tcl_GetIndexFromObj(NULL, objv[i], options, "option", TCL_EXACT, &optIndex) != TCL_OK) break; From 570e0c3c6849bc4acfd221cd0d6e48feaabb9139 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Tue, 11 Oct 2016 13:53:02 +0000 Subject: [PATCH 15/15] increase test coverage * test rollback from spi_exec and spi_execp * exercise the event loop using an "after" timer command and "vwait" Function coverage is now 87% and line coverage is 79% --- src/pl/tcl/sql/pltcl_queries.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pl/tcl/sql/pltcl_queries.sql b/src/pl/tcl/sql/pltcl_queries.sql index b0f0762d53020..a54763830edd9 100644 --- a/src/pl/tcl/sql/pltcl_queries.sql +++ b/src/pl/tcl/sql/pltcl_queries.sql @@ -117,6 +117,7 @@ select * from tcl_eval('spi_exec -count'); select * from tcl_eval('spi_exec -array'); select * from tcl_eval('spi_exec -count abc'); select * from tcl_eval('spi_exec query loop body toomuch'); +select * from tcl_eval('spi_exec "begin; rollback;"'); -- Test spi_execp select * from tcl_eval('spi_execp'); @@ -124,6 +125,7 @@ select * from tcl_eval('spi_execp -count'); select * from tcl_eval('spi_execp -array'); select * from tcl_eval('spi_execp -count abc'); select * from tcl_eval('spi_execp -nulls'); +select * from tcl_eval('set prep [spi_prepare "begin; rollback" ""]; spi_execp $prep'); -- test spi_prepare select * from tcl_eval('spi_prepare'); @@ -145,3 +147,5 @@ select * from tcl_test_sequence(1,10) as a; -- test forced error select tcl_eval('error "forced error"'); + +select * from tcl_eval('unset -nocomplain ::tcl_vwait; after 100 {set ::tcl_vwait 1}; vwait ::tcl_vwait; unset -nocomplain ::tcl_vwait');