diff --git a/Makefile b/Makefile index 0344ae26438..bd2d866e3be 100644 --- a/Makefile +++ b/Makefile @@ -294,7 +294,6 @@ coverage-report-js: ## Report JavaScript coverage results. cctest: all ## Run the C++ tests using the built `cctest` executable. @out/$(BUILDTYPE)/$@ --gtest_filter=$(GTEST_FILTER) $(NODE) ./test/embedding/test-embedding.js - $(NODE) ./test/sqlite/test-sqlite-extensions.mjs .PHONY: list-gtests list-gtests: ## List all available C++ gtests. @@ -312,7 +311,7 @@ v8: ## Build deps/v8. tools/make-v8.sh $(V8_ARCH).$(BUILDTYPE_LOWER) $(V8_BUILD_OPTIONS) .PHONY: jstest -jstest: build-addons build-js-native-api-tests build-node-api-tests ## Run addon tests and JS tests. +jstest: build-addons build-js-native-api-tests build-node-api-tests build-sqlite-tests ## Run addon tests and JS tests. $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \ $(TEST_CI_ARGS) \ --skip-tests=$(CI_SKIP_TESTS) \ @@ -338,6 +337,7 @@ test: all ## Run default tests, linters, and build docs. $(MAKE) -s build-addons $(MAKE) -s build-js-native-api-tests $(MAKE) -s build-node-api-tests + $(MAKE) -s build-sqlite-tests $(MAKE) -s cctest $(MAKE) -s jstest @@ -346,6 +346,7 @@ test-only: all ## Run default tests, without linters or building the docs. $(MAKE) build-addons $(MAKE) build-js-native-api-tests $(MAKE) build-node-api-tests + $(MAKE) build-sqlite-tests $(MAKE) cctest $(MAKE) jstest $(MAKE) tooltest @@ -356,6 +357,7 @@ test-cov: all ## Run coverage tests. $(MAKE) build-addons $(MAKE) build-js-native-api-tests $(MAKE) build-node-api-tests + $(MAKE) build-sqlite-tests $(MAKE) cctest CI_SKIP_TESTS=$(COV_SKIP_TESTS) $(MAKE) jstest @@ -501,6 +503,23 @@ benchmark/napi/.buildstamp: $(ADDONS_PREREQS) \ $(BENCHMARK_NAPI_BINDING_GYPS) $(BENCHMARK_NAPI_BINDING_SOURCES) @$(call run_build_addons,"$$PWD/benchmark/napi",$@) +SQLITE_BINDING_GYPS := $(wildcard test/sqlite/*/binding.gyp) + +SQLITE_BINDING_SOURCES := \ + $(wildcard test/sqlite/*/*.c) + +# Implicitly depends on $(NODE_EXE), see the build-sqlite-tests rule for rationale. +test/sqlite/.buildstamp: $(ADDONS_PREREQS) \ + $(SQLITE_BINDING_GYPS) $(SQLITE_BINDING_SOURCES) + @$(call run_build_addons,"$$PWD/test/sqlite",$@) + +.PHONY: build-sqlite-tests +# .buildstamp needs $(NODE_EXE) but cannot depend on it +# directly because it calls make recursively. The parent make cannot know +# if the subprocess touched anything so it pessimistically assumes that +# .buildstamp is out of date and need a rebuild. +build-sqlite-tests: | $(NODE_EXE) test/sqlite/.buildstamp ## Build SQLite tests. + .PHONY: clear-stalled clear-stalled: ## Clear any stalled processes. $(info Clean up any leftover processes but don't error if found.) @@ -511,7 +530,7 @@ clear-stalled: ## Clear any stalled processes. fi .PHONY: test-build -test-build: | all build-addons build-js-native-api-tests build-node-api-tests ## Build all tests. +test-build: | all build-addons build-js-native-api-tests build-node-api-tests build-sqlite-tests ## Build all tests. .PHONY: test-build-js-native-api test-build-js-native-api: all build-js-native-api-tests ## Build JS Native-API tests. @@ -519,6 +538,10 @@ test-build-js-native-api: all build-js-native-api-tests ## Build JS Native-API t .PHONY: test-build-node-api test-build-node-api: all build-node-api-tests ## Build Node-API tests. +.PHONY: test-build-sqlite +test-build-sqlite: all build-sqlite-tests ## Build SQLite tests. + + .PHONY: test-all test-all: test-build ## Run default tests with both Debug and Release builds. $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug,release @@ -546,7 +569,7 @@ endif # Related CI job: node-test-commit-arm-fanned test-ci-native: LOGLEVEL := info ## Build and test addons without building anything else. -test-ci-native: | benchmark/napi/.buildstamp test/addons/.buildstamp test/js-native-api/.buildstamp test/node-api/.buildstamp +test-ci-native: | benchmark/napi/.buildstamp test/addons/.buildstamp test/js-native-api/.buildstamp test/node-api/.buildstamp test/sqlite/.buildstamp $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ $(TEST_CI_ARGS) $(CI_NATIVE_SUITES) @@ -569,13 +592,12 @@ test-ci-js: | clear-stalled ## Build and test JavaScript with building anything .PHONY: test-ci # Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned test-ci: LOGLEVEL := info ## Build and test everything (CI). -test-ci: | clear-stalled bench-addons-build build-addons build-js-native-api-tests build-node-api-tests doc-only +test-ci: | clear-stalled bench-addons-build build-addons build-js-native-api-tests build-node-api-tests build-sqlite-tests doc-only out/Release/cctest --gtest_output=xml:out/junit/cctest.xml $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ $(TEST_CI_ARGS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) $(CI_DOC) $(NODE) ./test/embedding/test-embedding.js - $(NODE) ./test/sqlite/test-sqlite-extensions.mjs $(info Clean up any leftover processes, error if found.) ps awwx | grep Release/node | grep -v grep | cat @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \ @@ -681,6 +703,16 @@ test-node-api-clean: ## Remove Node-API testing artifacts. $(RM) -r test/node-api/*/build $(RM) test/node-api/.buildstamp +.PHONY: test-sqlite +test-sqlite: test-build-sqlite ## Run SQLite tests. + $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) sqlite + +.PHONY: test-sqlite-clean +.NOTPARALLEL: test-sqlite-clean +test-sqlite-clean: ## Remove SQLite testing artifacts. + $(RM) -r test/sqlite/*/build + $(RM) test/sqlite/.buildstamp + .PHONY: test-addons test-addons: test-build test-js-native-api test-node-api ## Run addon tests. $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) addons @@ -1446,7 +1478,7 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \ test/cctest/*.h \ test/embedding/*.cc \ test/embedding/*.h \ - test/sqlite/*.c \ + test/sqlite/*/*.c \ test/fixtures/*.c \ test/js-native-api/*/*.cc \ test/node-api/*/*.cc \ @@ -1470,6 +1502,7 @@ FORMAT_CPP_FILES += $(wildcard \ test/js-native-api/*/*.h \ test/node-api/*/*.c \ test/node-api/*/*.h \ + test/sqlite/*/*.c \ ) # Code blocks don't have newline at the end, diff --git a/node.gyp b/node.gyp index a3688b8e6df..1633ed2d832 100644 --- a/node.gyp +++ b/node.gyp @@ -1296,26 +1296,6 @@ ], }, # embedtest - { - 'target_name': 'sqlite_extension', - 'type': 'shared_library', - 'sources': [ - 'test/sqlite/extension.c' - ], - - 'include_dirs': [ - 'test/sqlite', - 'deps/sqlite', - ], - - 'cflags': [ - '-fPIC', - '-Wall', - '-Wextra', - '-O3', - ], - }, # sqlitetest - { 'target_name': 'overlapped-checker', 'type': 'executable', diff --git a/test/sqlite/.gitignore b/test/sqlite/.gitignore new file mode 100644 index 00000000000..378eac25d31 --- /dev/null +++ b/test/sqlite/.gitignore @@ -0,0 +1 @@ +build diff --git a/test/sqlite/sqlite.status b/test/sqlite/sqlite.status new file mode 100644 index 00000000000..dae653683a3 --- /dev/null +++ b/test/sqlite/sqlite.status @@ -0,0 +1,7 @@ +prefix sqlite + +# To mark a test as flaky, list the test name in the appropriate section +# below, without ".js", followed by ": PASS,FLAKY". Example: +# sample-test : PASS,FLAKY + +[true] # This section applies to all platforms diff --git a/test/sqlite/test_sqlite_extensions/binding.gyp b/test/sqlite/test_sqlite_extensions/binding.gyp new file mode 100644 index 00000000000..aa4de6b8c08 --- /dev/null +++ b/test/sqlite/test_sqlite_extensions/binding.gyp @@ -0,0 +1,10 @@ +{ + "targets": [ + { + "target_name": "sqlite_extension", + "type": "shared_library", + "sources": [ "extension.c" ], + "include_dirs": [ "../../../deps/sqlite" ] + } + ] +} diff --git a/test/sqlite/extension.c b/test/sqlite/test_sqlite_extensions/extension.c similarity index 100% rename from test/sqlite/extension.c rename to test/sqlite/test_sqlite_extensions/extension.c diff --git a/test/sqlite/test-sqlite-extensions.mjs b/test/sqlite/test_sqlite_extensions/test.js similarity index 83% rename from test/sqlite/test-sqlite-extensions.mjs rename to test/sqlite/test_sqlite_extensions/test.js index 141f9c96270..ece230399c7 100644 --- a/test/sqlite/test-sqlite-extensions.mjs +++ b/test/sqlite/test_sqlite_extensions/test.js @@ -1,23 +1,25 @@ -import * as common from '../common/index.mjs'; - -import assert from 'node:assert'; -import path from 'node:path'; -import sqlite from 'node:sqlite'; -import test from 'node:test'; -import fs from 'node:fs'; -import childProcess from 'child_process'; +'use strict'; +const common = require('../../common'); +const assert = require('node:assert'); +const path = require('node:path'); +const sqlite = require('node:sqlite'); +const test = require('node:test'); +const fs = require('node:fs'); +const childProcess = require('node:child_process'); if (process.config.variables.node_shared_sqlite) { common.skip('Missing libsqlite_extension binary'); } // Lib extension binary is named differently on different platforms -function resolveBuiltBinary(binary) { - const targetFile = fs.readdirSync(path.dirname(process.execPath)).find((file) => file.startsWith(binary)); - return path.join(path.dirname(process.execPath), targetFile); +function resolveBuiltBinary() { + const buildDir = `${__dirname}/build/${common.buildType}`; + const lib = 'sqlite_extension'; + const targetFile = fs.readdirSync(buildDir).find((file) => file.startsWith(lib)); + return path.join(buildDir, targetFile); } -const binary = resolveBuiltBinary('libsqlite_extension'); +const binary = resolveBuiltBinary(); test('should load extension successfully', () => { const db = new sqlite.DatabaseSync(':memory:', { diff --git a/test/sqlite/testcfg.py b/test/sqlite/testcfg.py index 3d43abbe894..e66cfa69ff8 100644 --- a/test/sqlite/testcfg.py +++ b/test/sqlite/testcfg.py @@ -3,4 +3,4 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) import testpy def GetConfiguration(context, root): - return testpy.SimpleTestConfiguration(context, root, 'sqlite') + return testpy.AddonTestConfiguration(context, root, 'sqlite')