/ Check-in [53081e72]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance testing support for the Win32 VFS dynamic extension loading facilities.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:53081e7202fb55f792a78e73627466eb0200f11c
User & Date: mistachkin 2014-02-24 21:20:25
Context
2014-02-24
21:42
Fix several small style/consistency issues with the previous check-in. check-in: 2477b3a2 user: mistachkin tags: trunk
21:23
Merge updates from trunk. Closed-Leaf check-in: 854d410a user: mistachkin tags: cygDlOpen
21:20
Enhance testing support for the Win32 VFS dynamic extension loading facilities. check-in: 53081e72 user: mistachkin tags: trunk
19:49
Close some stray connections in walro.test. check-in: d6746cab user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.msc.

  1315   1315   
  1316   1316   testfixture.exe:	$(TESTFIXTURE_SRC) $(LIBRESOBJS) $(HDR)
  1317   1317   	$(LTLINK) -DSQLITE_NO_SYNC=1 $(TESTFIXTURE_FLAGS) \
  1318   1318   		-DBUILD_sqlite -I$(TCLINCDIR) \
  1319   1319   		$(TESTFIXTURE_SRC) \
  1320   1320   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1321   1321   
         1322  +extensiontest: testfixture.exe testloadext.dll
         1323  +	.\testfixture.exe $(TOP)\test\loadext.test
         1324  +	.\testfixture.exe $(TOP)\test\loadext2.test
         1325  +
  1322   1326   fulltest:	testfixture.exe sqlite3.exe
  1323   1327   	.\testfixture.exe $(TOP)\test\all.test
  1324   1328   
  1325   1329   soaktest:	testfixture.exe sqlite3.exe
  1326   1330   	.\testfixture.exe $(TOP)\test\all.test -soak=1
  1327   1331   
  1328   1332   fulltestonly:	testfixture.exe sqlite3.exe
................................................................................
  1341   1345   	$(NAWK) -f $(TOP)\tool\tostr.awk $(TOP)\tool\spaceanal.tcl >> $@
  1342   1346   	echo ; return zMainloop; } >> $@
  1343   1347   
  1344   1348   sqlite3_analyzer.exe:	sqlite3_analyzer.c $(LIBRESOBJS)
  1345   1349   	$(LTLINK) -DBUILD_sqlite -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \
  1346   1350   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1347   1351   
         1352  +testloadext.lo:	$(TOP)\src\test_loadext.c
         1353  +	$(LTCOMPILE) -c $(TOP)\src\test_loadext.c
         1354  +
         1355  +testloadext.dll: testloadext.lo
         1356  +	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ testloadext.lo
         1357  +
  1348   1358   showdb.exe:	$(TOP)\tool\showdb.c $(SQLITE3C)
  1349   1359   	$(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \
  1350   1360   		$(TOP)\tool\showdb.c $(SQLITE3C)
  1351   1361   
  1352   1362   wordcount.exe:	$(TOP)\test\wordcount.c $(SQLITE3C)
  1353   1363   	$(LTLINK) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION -Fe$@ \
  1354   1364   		$(TOP)\test\wordcount.c $(SQLITE3C)
................................................................................
  1367   1377   	-rmdir /Q/S .libs
  1368   1378   	-rmdir /Q/S quota2a
  1369   1379   	-rmdir /Q/S quota2b
  1370   1380   	-rmdir /Q/S quota2c
  1371   1381   	-rmdir /Q/S tsrc
  1372   1382   	del /Q .target_source
  1373   1383   	del /Q tclsqlite3.exe tclsqlite3.exp
         1384  +	del /Q testloadext.dll testloadext.exp
  1374   1385   	del /Q testfixture.exe testfixture.exp test.db
  1375   1386   	del /Q sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def
  1376   1387   	del /Q sqlite3.c sqlite3-*.c
  1377   1388   	del /Q sqlite3rc.h
  1378   1389   	del /Q shell.c sqlite3ext.h
  1379   1390   	del /Q sqlite3_analyzer.exe sqlite3_analyzer.exp sqlite3_analyzer.c
  1380   1391   	del /Q sqlite-*-output.vsix

Changes to src/os_win.c.

  5131   5131   }
  5132   5132   
  5133   5133   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  5134   5134   /*
  5135   5135   ** Interfaces for opening a shared library, finding entry points
  5136   5136   ** within the shared library, and closing the shared library.
  5137   5137   */
  5138         -/*
  5139         -** Interfaces for opening a shared library, finding entry points
  5140         -** within the shared library, and closing the shared library.
  5141         -*/
  5142   5138   static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
  5143   5139     HANDLE h;
  5144   5140     void *zConverted = winConvertFromUtf8Filename(zFilename);
  5145   5141     UNUSED_PARAMETER(pVfs);
  5146   5142     if( zConverted==0 ){
         5143  +    OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
  5147   5144       return 0;
  5148   5145     }
  5149   5146     if( osIsNT() ){
  5150   5147   #if SQLITE_OS_WINRT
  5151   5148       h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
  5152   5149   #else
  5153   5150       h = osLoadLibraryW((LPCWSTR)zConverted);
................................................................................
  5154   5151   #endif
  5155   5152     }
  5156   5153   #ifdef SQLITE_WIN32_HAS_ANSI
  5157   5154     else{
  5158   5155       h = osLoadLibraryA((char*)zConverted);
  5159   5156     }
  5160   5157   #endif
         5158  +  OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
  5161   5159     sqlite3_free(zConverted);
  5162   5160     return (void*)h;
  5163   5161   }
  5164   5162   static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
  5165   5163     UNUSED_PARAMETER(pVfs);
  5166   5164     winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
  5167   5165   }
  5168   5166   static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
         5167  +  FARPROC pProc;
  5169   5168     UNUSED_PARAMETER(pVfs);
  5170         -  return (void(*)(void))osGetProcAddressA((HANDLE)pH, zSym);
         5169  +  pProc = osGetProcAddressA((HANDLE)pH, zSym);
         5170  +  OSTRACE(("DLSYM handle=%p, symbol=%s, proc=%p\n",
         5171  +           (void*)pH, zSym, (void*)pProc));
         5172  +  return (void(*)(void))pProc;
  5171   5173   }
  5172   5174   static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
  5173   5175     UNUSED_PARAMETER(pVfs);
  5174   5176     osFreeLibrary((HANDLE)pHandle);
         5177  +  OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
  5175   5178   }
  5176   5179   #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
  5177   5180     #define winDlOpen  0
  5178   5181     #define winDlError 0
  5179   5182     #define winDlSym   0
  5180   5183     #define winDlClose 0
  5181   5184   #endif

Changes to src/test_loadext.c.

    87     87       sqlite3_result_int(context, cur);
    88     88     }
    89     89   }
    90     90   
    91     91   /*
    92     92   ** Extension load function.
    93     93   */
           94  +#ifdef _WIN32
           95  +__declspec(dllexport)
           96  +#endif
    94     97   int testloadext_init(
    95     98     sqlite3 *db, 
    96     99     char **pzErrMsg, 
    97    100     const sqlite3_api_routines *pApi
    98    101   ){
    99    102     int nErr = 0;
   100    103     SQLITE_EXTENSION_INIT2(pApi);
................................................................................
   105    108                             statusFunc, 0, 0);
   106    109     return nErr ? SQLITE_ERROR : SQLITE_OK;
   107    110   }
   108    111   
   109    112   /*
   110    113   ** Another extension entry point. This one always fails.
   111    114   */
          115  +#ifdef _WIN32
          116  +__declspec(dllexport)
          117  +#endif
   112    118   int testbrokenext_init(
   113    119     sqlite3 *db, 
   114    120     char **pzErrMsg, 
   115    121     const sqlite3_api_routines *pApi
   116    122   ){
   117    123     char *zErr;
   118    124     SQLITE_EXTENSION_INIT2(pApi);
   119    125     zErr = sqlite3_mprintf("broken!");
   120    126     *pzErrMsg = zErr;
   121    127     return 1;
   122    128   }

Changes to test/loadext.test.

    61     61   set dlerror_nosymbol   {%s: undefined symbol: %s}
    62     62   
    63     63   if {$::tcl_platform(os) eq "Darwin"} {
    64     64     set dlerror_nosuchfile {dlopen(%s, 10): image not found}
    65     65     set dlerror_notadll    {dlopen(%1$s, 10): no suitable image found.*}
    66     66     set dlerror_nosymbol   {dlsym(XXX, %2$s): symbol not found}
    67     67   }
           68  +
           69  +if {$::tcl_platform(platform) eq "windows"} {
           70  +  set dlerror_nosuchfile {The specified module could not be found.*}
           71  +  set dlerror_notadll    {%%1 is not a valid Win32 application.*}
           72  +  set dlerror_nosymbol   {The specified procedure could not be found.*}
           73  +}
    68     74   
    69     75   # Make sure the test extension actually exists.  If it does not
    70     76   # exist, try to create it.  If unable to create it, then skip this
    71     77   # test file.
    72     78   #
    73     79   if {![file exists $testextension]} {
    74     80     set srcdir [file dir $testdir]/src
................................................................................
   163    169     set rc [catch {
   164    170       sqlite3_load_extension db $testextension icecream
   165    171     } msg]
   166    172     if {$::tcl_platform(os) eq "Darwin"} {
   167    173       regsub {0x[1234567890abcdefABCDEF]*} $msg XXX msg
   168    174     }
   169    175     list $rc $msg
   170         -} [list 1 [format $dlerror_nosymbol $testextension icecream]]
          176  +} /[list 1 [format $dlerror_nosymbol $testextension icecream]]/
   171    177   
   172    178   # Try to load an extension for which the entry point fails (returns non-zero) 
   173    179   #
   174    180   do_test loadext-2.4 {
   175    181     set rc [catch {
   176    182       sqlite3_load_extension db $testextension testbrokenext_init
   177    183     } msg]
................................................................................
   263    269   # Malloc failure in sqlite3_auto_extension and sqlite3_load_extension
   264    270   #
   265    271   do_malloc_test loadext-5 -tclprep {
   266    272     sqlite3_reset_auto_extension
   267    273   } -tclbody {
   268    274     if {[autoinstall_test_functions]==7} {error "out of memory"}
   269    275   }
   270         -do_malloc_test loadext-6 -tclbody {
   271         -  db enable_load_extension 1
   272         -  sqlite3_load_extension db $::testextension testloadext_init
          276  +
          277  +# On Windows, this malloc test must be skipped because the winDlOpen
          278  +# function itself can fail due to "out of memory" conditions.
          279  +#
          280  +if {$::tcl_platform(platform) ne "windows"} {
          281  +  do_malloc_test loadext-6 -tclbody {
          282  +    db enable_load_extension 1
          283  +    sqlite3_load_extension db $::testextension testloadext_init
          284  +  }
   273    285   }
          286  +
   274    287   autoinstall_test_functions
   275    288   
   276    289   finish_test