Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - neil456

#1
I found this function valuable in determining that the existing Postgres module test code did not cover very many of the functions.  It would be handy to have this someplace in the core.  It probably needs to be cleaned up.  But here it is, for you to use as you see fit.  Permission is given to use for any purpose, without restriction.

;;
;; @syntax (checkTestCoverage <function-testFunction> <context-testCode> <bool-showPassing>)
;; @param <function-testFunction> The function that tests the code.
;; @param <context-testCode> The context that contains the code to be tested.
;; @param <bool-showPassing> Flag to indicate printing of calls in the test function along with count of the number of times called.
;; @return 'float' as the percent of unique calls in the test function, given the functions defined in the context.
;; Functions in the context that are never called from the test function are always printed.
;; Functions in the context that are called from the test function may or may not be printed depending on the flag.
;;
;; This function assumes that the test function is in the 'MAIN' context and that each
;; relevant call in the test function is prefixed with the context name.
;;
;; To test the PgSQL module:
;; '  (println (format {Percent PgSQL Coverage: %3.1f} (checkTestCoverage 'test-pgsql PgSQL)))'
;;
;; Neil Tiffin, March 2015, newLisp 10.6.2

(define (checkTestCoverage testFunction testContext showTestCount)
  (let (
    (test-functions nil)
    (context-functions (sort  (filter (fn (s) (lambda? (eval s))) (symbols testContext)))))
    (dolist (ln (parse (source testFunction) "n"))
      (let (found-list (find-all (append (string testContext) {:[^"'():,s]+}) ln))
        (if (true? found-list)
          (dolist (found-function found-list)
              (if (nil? test-functions)
                (push (list found-function 1) test-functions)
                (if (nil? (assoc found-function test-functions))
                  (push (list found-function 1) test-functions)
                  (setf (assoc found-function test-functions) (list found-function (+ 1 (lookup found-function test-functions 1))))))))))

    (dolist (symb context-functions)
      (if (nil? (assoc (string symb) test-functions))
        (println "Function NOT Tested: " symb)))

    (if (true? showTestCount)
      (dolist (symb context-functions)
        (if (true? (assoc (string symb) test-functions))
          (println "Function     Tested: " (format {%3d  } (lookup (string symb) test-functions 1)) symb ))))

    ; return percent coverage  
    (mul (div (float (length test-functions)) (float (length context-functions))) 100.0)))
#2
Yeah, I was confused by this in the download section, but should have known better.
Quote
Win32 installer v.10.6.2 (also runs on Windows 7/8 64-bit)

The meaning of which is obvious now, but it would have been clearer with:
Quote
Win32 installer v.10.6.2 (also runs on Windows 7/8 64-bit, in 32-bit mode with only 32-bit libraries)

I took the original to mean that the Win32 installer now installed both 32 and 64 bit.  Again my Windows witchcraft failed me. Macs (my main dev platform) got over this sickness some time ago as I only have one install of PostgreSQL and it works fine with newLISP without any of this silliness.
#3
Thanks,

Neil
#4
OK, fixed.



I was using the 64-bit version of PostgreSQL, by uninstalling it and installing the 32-bit version everything seems to work.



Does anyone know of an easy way to detect 32-bit versus 64-bit libs on Windows?



Of course assuming that newLISP does not work with 64-bit libs?



Neil
#5
OK, lets start over and make it really simple.

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:Usersnt>pg_config --libdir
C:/PROGRA~1/POSTGR~1/9.4/lib

C:Usersnt>newLISP -n
newLISP v.10.6.2 32-bit on Win32 IPv4/6 libffi, options: newlisp -h

> (import {C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.dll} "PQcancel" "cdecl")

ERR: problem loading library in function import : "C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.dll"

>  (import {C:/Program Files/PostgreSQL/9.4/lib/libpq.dll} "PQcancel" "cdecl")

ERR: problem loading library in function import : "C:/Program Files/PostgreSQL/9.4/lib/libpq.dll"
>

Now we know libpq is present with the following:

C:Usersnt>dir "C:/PROGRA~1/POSTGR~1/9.4/lib"
 Volume in drive C has no label.
 Volume Serial Number is 8081-5731

 Directory of C:PROGRA~1POSTGR~19.4lib

02/12/2015  04:55 PM    <DIR>          .
02/12/2015  04:55 PM    <DIR>          ..
02/03/2015  03:19 AM            15,360 adminpack.dll
. . . .
02/03/2015  03:22 AM            70,656 libpgtypes.dll
02/03/2015  03:22 AM            12,150 libpgtypes.lib
02/03/2015  03:18 AM           178,688 libpq.dll
02/03/2015  03:18 AM            32,510 libpq.lib
02/03/2015  03:18 AM            16,384 libpqwalreceiver.dll
. . . .
05/08/2014  02:51 AM           277,806 zlib.lib
02/03/2015  03:20 AM            44,032 _int.dll
             113 File(s)     20,039,632 bytes
               2 Dir(s)  26,978,947,072 bytes free

C:Usersnt>

or the following:

C:Program FilesPostgreSQL9.4lib>dir libp*
 Volume in drive C has no label.
 Volume Serial Number is 8081-5731

 Directory of C:Program FilesPostgreSQL9.4lib

02/03/2015  03:18 AM           275,050 libpgcommon.lib
02/03/2015  03:18 AM         1,119,138 libpgport.lib
02/03/2015  03:22 AM            70,656 libpgtypes.dll
02/03/2015  03:22 AM            12,150 libpgtypes.lib
02/03/2015  03:18 AM           178,688 libpq.dll
02/03/2015  03:18 AM            32,510 libpq.lib
02/03/2015  03:18 AM            16,384 libpqwalreceiver.dll
               7 File(s)      1,704,576 bytes
               0 Dir(s)  27,102,736,384 bytes free
#6
This should be the complete test code for Windows to produce the error;



; get pg_config if available  
(set 'pg_lib_dir (exec "pg_config --libdir"))

(if pg_lib_dir
  (set 'files
    (list
      (append (first pg_lib_dir) "/libpq.dylib")  ; shared Mac OS X libs
      (append (first pg_lib_dir) "/libpq.so")   ; loadable elf libs Posix Unix Linux
      (append (first pg_lib_dir) "/libpq.dll")  ; Windows lib
  ))
  (set 'files '(
    "/usr/local/lib/libpq.so.5.1" ; OpenBSD 4.6
    "/usr/lib/libpq.so" ; CentOS or other Linux
    "/usr/lib64/libpq.so" ; Linux 64bit
    "/usr/lib/libpq.so.5.1" ; Debian
    "/usr/local/pgsql/lib/libpq.dylib" ; Mac OS X
    "c:/Program Files/PostgreSQL/8.3/bin/libpq.dll" ; Win32
  )))

; find the library file
(set 'library (files (or
  (find true (map file? files))
  (throw-error "Cannot find libpq library!"))))

; import functions and throw error if not found
(define (pg_import fun_name)
  (import library fun_name "cdecl"))

(map pg_import (list
"PQcancel"
"PQclear"
"PQcmdStatus"
"PQcmdTuples"
))
#7
The following code works fine. It correctly finds libpq.dll and sets its path:



(println files)
("C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.dylib" "C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.so"
 "C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.dll")

; find the library file
(set 'library (files (or
  (find true (map file? files))
  (throw-error "Cannot find libpq library!"))))


If I (println library) after the above code then the following is printed:

C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.dll



The actual code that is failing is the following when fun_name = "PQcancel":

(define (pg_import fun_name)
  (import library fun_name "cdecl"))


Also I checked permissions and my user is marked read and execute for libpq and read, execute and list dir for 9.4/lib directory.
#8
Unfortunately PostgreSQL Windows install reports file names in the short 8dot3 format.



C:Usersnt>pg_config --libdir
C:/PROGRA~1/POSTGR~1/9.4/lib


When I try to use this to create a path to the dll the following error occurs.



ERR: problem loading library in function import : "C:/PROGRA~1/POSTGR~1/9.4/lib/libpq.dll"


However if I do a directory listing, then the short name path seems to work fine.



C:Usersnt>dir  "C:/PROGRA~1/POSTGR~1/9.4/lib/"
 Volume in drive C has no label.
 Volume Serial Number is 8081-5731

 Directory of C:PROGRA~1POSTGR~19.4lib

02/12/2015  04:55 PM    <DIR>          .
02/12/2015  04:55 PM    <DIR>          ..
02/03/2015  03:19 AM            15,360 adminpack.dll
02/03/2015  03:23 AM             7,680 ascii_and_mic.dll
. . . . .
02/03/2015  03:22 AM            70,656 libpgtypes.dll
02/03/2015  03:22 AM            12,150 libpgtypes.lib
02/03/2015  03:18 AM           178,688 libpq.dll
02/03/2015  03:18 AM            32,510 libpq.lib
02/03/2015  03:18 AM            16,384 libpqwalreceiver.dll
05/08/2014  12:18 AM           368,982 libxml2.lib
. . . . .


Evidently one of two things are wrong; 1) I am not very good with Windows witchcraft, or 2) the import function in newLISP should somehow handle short file names.



I would be happy for some direction in solving this problem.



Thank you.

Neil
#9
In windows 8.1 the options to pin newLISP-GS to task bar never appears.  Windows will allow it pinning to the start view.  newLISP can pin to either the task bar or start view.  Anyway start view sucks and so I usually use the desktop which does have a shortcut, so all is not lost.



This is the current distribution of newLISP-GS v1.63 and newLISP 10.6.2 32-bit.



Just FYI.
#10
Still having a problem with this. Consider the following example:



(dolist (symb (symbols PgSQL))
(if (lambda? symb)
(println "found function: " symb)))


This does not work, so how do I get a list of symbols in a context that have lambda expressions assigned to them?
#11
Excellent, thanks

Neil
#12
What is the correct way to determine that a function is defined.  I am conditionally importing from a C lib and need to determine if the function was actually imported.



This is the import function.

(define (pg_import_warn fun_name)
  (if (not (catch (import library fun_name "cdecl") 'pg_load_error))
    (println "pg_import WARNING: " pg_load_error)))

Import is done like this

(pg_import_warn "PQescapeIdentifier")

Then sometime later i want to be able to do something like

(if (function? PQescapeIdentifier)  (PQescapeIdentifier text) (SomeOtherFuncton text))

to use the function or not as the case may be.