Skip to content

Commit

Permalink
test: update compiled sqlite tests to match other tests
Browse files Browse the repository at this point in the history
This commit updates the sqlite compiled tests to be structured
like other compiled tests.

Refs: #56347
PR-URL: #56446
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Stewart X Addison <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
  • Loading branch information
cjihrig authored Jan 5, 2025
1 parent f97a7b6 commit d0ff34f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 40 deletions.
47 changes: 40 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) \
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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.)
Expand All @@ -511,14 +530,18 @@ 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.

.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
Expand Down Expand Up @@ -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)
Expand All @@ -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}'`; \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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,
Expand Down
20 changes: 0 additions & 20 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions test/sqlite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
7 changes: 7 additions & 0 deletions test/sqlite/sqlite.status
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/sqlite/test_sqlite_extensions/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"targets": [
{
"target_name": "sqlite_extension",
"type": "shared_library",
"sources": [ "extension.c" ],
"include_dirs": [ "../../../deps/sqlite" ]
}
]
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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:', {
Expand Down
2 changes: 1 addition & 1 deletion test/sqlite/testcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import testpy

def GetConfiguration(context, root):
return testpy.SimpleTestConfiguration(context, root, 'sqlite')
return testpy.AddonTestConfiguration(context, root, 'sqlite')

0 comments on commit d0ff34f

Please sign in to comment.