Skip to content

Commit

Permalink
NodeJS Binding Tests
Browse files Browse the repository at this point in the history
Does not run the nodejs tests in sanitized builds. We'd have to

    export LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libasan.so.2'

the asan lib. But it seems like our Clang from mason does not like the
system's libasan. Also we'd need a suppression file for v8 and node.
  • Loading branch information
daniel-j-h authored and Patrick Niklaus committed Apr 4, 2017
1 parent e568b60 commit 70b3962
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 236 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ script:
- ./unit_tests/util-tests
- ./unit_tests/server-tests
- ./unit_tests/partition-tests
- |
if [ -n "${ENABLE_NODE_BINDINGS}" ] && [ -z "${ENABLE_SANITIZER}" ]; then
npm run nodejs-tests
fi
- popd
- yarn test

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ endif()
if (ENABLE_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(OSRM_CXXFLAGS "${OSRM_CXXFLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()

# Configuring compilers
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld",
"clean": "rm -rf test/cache",
"docs": "./scripts/build_api_docs.sh",
"install": "node-pre-gyp install --fallback-to-build=false"
"install": "node-pre-gyp install --fallback-to-build=false",
"nodejs-tests": "make -C test/data && ./lib/binding/osrm-datastore test/data/ch/monaco.osrm && node test/nodejs/index.js | faucet"
},
"repository": {
"type": "git",
Expand All @@ -44,6 +45,7 @@
"mkdirp": "^0.5.1",
"aws-sdk": "~2.0.31",
"tape": "^4.2.2",
"faucet": "^0.0.1",
"node-timeout": "0.0.4",
"polyline": "^0.2.0",
"request": "^2.69.0",
Expand Down
4 changes: 3 additions & 1 deletion src/nodejs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ message(STATUS "Building node-osrm")
set(BINDING_DIR "${PROJECT_SOURCE_DIR}/lib/binding")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/nodejs")
include(FindNodeJS)

set(NodeJS_CXX_STANDARD 14 CACHE INTERNAL "Use C++14" FORCE)
set(NodeJS_DOWNLOAD ON CACHE INTERNAL "Download node.js sources" FORCE)
set(NodeJS_USE_CLANG_STDLIB OFF CACHE BOOL "Don't use libc++ by default" FORCE)

# ^ Make sure to set NodeJs options before including and requiring the NodeJs module.
# Otherwise the module will use defaults (which - among many bad choices - means libc++).
include(FindNodeJS)
find_package(NodeJS REQUIRED)
add_nodejs_module(node-osrm node_osrm.cpp)
target_link_libraries(node-osrm osrm)
Expand Down
26 changes: 26 additions & 0 deletions test/nodejs/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var path = require('path');

// Constants and fixtures for nodejs tests on our Monaco dataset.

// Somewhere in Monaco
// http://www.openstreetmap.org/#map=18/43.73185/7.41772
exports.three_test_coordinates = [[7.41337, 43.72956],
[7.41546, 43.73077],
[7.41862, 43.73216]];

exports.two_test_coordinates = exports.three_test_coordinates.slice(0, 2)

exports.test_tile = {'at': [17059, 11948, 15], 'size': 114000};


// Test files generated by the routing engine; check test/data
if (process.env.OSRM_DATA_PATH !== undefined) {
exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/monaco.osrm");
exports.mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/monaco.osrm");
exports.corech_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "corech/monaco.osrm");
console.log('Setting custom data path to ' + exports.data_path);
} else {
exports.data_path = path.resolve(path.join(__dirname, "../data/ch/monaco.osrm"));
exports.mld_data_path = path.resolve(path.join(__dirname, "../data/mld/monaco.osrm"));
exports.corech_data_path = path.resolve(path.join(__dirname, "../data/corech/monaco.osrm"));
}
16 changes: 8 additions & 8 deletions test/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
var berlin_mld_path = require('./osrm-data-path').mld_data_path;
var berlin_corech_path = require('./osrm-data-path').corech_data_path;
var monaco_path = require('./constants').data_path;
var monaco_mld_path = require('./constants').mld_data_path;
var monaco_corech_path = require('./constants').corech_data_path;

test('constructor: throws if new keyword is not used', function(assert) {
assert.plan(1);
Expand Down Expand Up @@ -30,7 +30,7 @@ test('constructor: throws if necessary files do not exist', function(assert) {

test('constructor: takes a shared memory argument', function(assert) {
assert.plan(1);
var osrm = new OSRM({path: berlin_path, shared_memory: false});
var osrm = new OSRM({path: monaco_path, shared_memory: false});
assert.ok(osrm);
});

Expand All @@ -42,7 +42,7 @@ test('constructor: throws if shared_memory==false with no path defined', functio

test('constructor: throws if given a non-bool shared_memory option', function(assert) {
assert.plan(1);
assert.throws(function() { new OSRM({path: berlin_path, shared_memory: 'a'}); },
assert.throws(function() { new OSRM({path: monaco_path, shared_memory: 'a'}); },
/Shared_memory option must be a boolean/);
});

Expand All @@ -66,19 +66,19 @@ test('constructor: throws if given an invalid algorithm', function(assert) {

test('constructor: loads MLD if given as algorithm', function(assert) {
assert.plan(1);
var osrm = new OSRM({algorithm: 'MLD', path: berlin_mld_path});
var osrm = new OSRM({algorithm: 'MLD', path: monaco_mld_path});
assert.ok(osrm);
});

test('constructor: loads CH if given as algorithm', function(assert) {
assert.plan(1);
var osrm = new OSRM({algorithm: 'CH', path: berlin_path});
var osrm = new OSRM({algorithm: 'CH', path: monaco_path});
assert.ok(osrm);
});

test('constructor: loads CoreCH if given as algorithm', function(assert) {
assert.plan(1);
var osrm = new OSRM({algorithm: 'CoreCH', path: berlin_corech_path});
var osrm = new OSRM({algorithm: 'CoreCH', path: monaco_corech_path});
assert.ok(osrm);
});

Expand Down
63 changes: 33 additions & 30 deletions test/nodejs/match.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
var data_path = require('./constants').data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;

test('match: match in Berlin', function(assert) {
test('match: match in Monaco', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
coordinates: three_test_coordinates,
timestamps: [1424684612, 1424684616, 1424684620]
};
osrm.match(options, function(err, response) {
Expand All @@ -22,11 +24,11 @@ test('match: match in Berlin', function(assert) {
});
});

test('match: match in Berlin without timestamps', function(assert) {
test('match: match in Monaco without timestamps', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]]
coordinates: three_test_coordinates
};
osrm.match(options, function(err, response) {
assert.ifError(err);
Expand All @@ -35,11 +37,11 @@ test('match: match in Berlin without timestamps', function(assert) {
});
});

test('match: match in Berlin without geometry compression', function(assert) {
test('match: match in Monaco without geometry compression', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
coordinates: three_test_coordinates,
geometries: 'geojson'
};
osrm.match(options, function(err, response) {
Expand All @@ -50,11 +52,11 @@ test('match: match in Berlin without geometry compression', function(assert) {
});
});

test('match: match in Berlin with geometry compression', function(assert) {
test('match: match in Monaco with geometry compression', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]]
coordinates: three_test_coordinates,
};
osrm.match(options, function(err, response) {
assert.ifError(err);
Expand All @@ -63,11 +65,11 @@ test('match: match in Berlin with geometry compression', function(assert) {
});
});

test('match: match in Berlin with speed annotations options', function(assert) {
test('match: match in Monaco with speed annotations options', function(assert) {
assert.plan(12);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
coordinates: three_test_coordinates,
timestamps: [1424684612, 1424684616, 1424684620],
radiuses: [4.07, 4.07, 4.07],
steps: true,
Expand All @@ -92,11 +94,12 @@ test('match: match in Berlin with speed annotations options', function(assert) {
});


test('match: match in Berlin with several (duration, distance, nodes) annotations options', function(assert) {
test('match: match in Monaco with several (duration, distance, nodes) annotations options', function(assert) {
assert.plan(12);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
timestamps: [1424684612, 1424684616, 1424684620],
coordinates: three_test_coordinates,
timestamps: [1424684612, 1424684616, 1424684620],
radiuses: [4.07, 4.07, 4.07],
steps: true,
Expand All @@ -120,11 +123,11 @@ test('match: match in Berlin with several (duration, distance, nodes) annotation
});
});

test('match: match in Berlin with all options', function(assert) {
test('match: match in Monaco with all options', function(assert) {
assert.plan(8);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
coordinates: three_test_coordinates,
timestamps: [1424684612, 1424684616, 1424684620],
radiuses: [4.07, 4.07, 4.07],
steps: true,
Expand All @@ -146,42 +149,42 @@ test('match: match in Berlin with all options', function(assert) {

test('match: throws on missing arguments', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
assert.throws(function() { osrm.match({}) },
/Two arguments required/);
});

test('match: throws on non-object arg', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
assert.throws(function() { osrm.match(null, function(err, response) {}) },
/First arg must be an object/);
});

test('match: throws on invalid coordinates param', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: ''
};
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252,52.542648]];
options.coordinates = [three_test_coordinates[0]];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/At least two coordinates must be provided/);
options.coordinates = [13.393252,52.542648];
options.coordinates = three_test_coordinates[0]
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252],[52.542648]];
options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
});

test('match: throws on invalid timestamps param', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
coordinates: three_test_coordinates,
timestamps: 'timestamps'
};
assert.throws(function() { osrm.match(options, function(err, response) {}) },
Expand Down
21 changes: 12 additions & 9 deletions test/nodejs/nearest.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
var data_path = require('./constants').data_path;
var three_test_coordinates = require('./constants').three_test_coordinates;
var two_test_coordinates = require('./constants').two_test_coordinates;


test('nearest', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
osrm.nearest({
coordinates: [[13.333086, 52.4224]]
coordinates: [three_test_coordinates[0]]
}, function(err, result) {
assert.ifError(err);
assert.equal(result.waypoints.length, 1);
Expand All @@ -17,9 +20,9 @@ test('nearest', function(assert) {

test('nearest: can ask for multiple nearest pts', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
osrm.nearest({
coordinates: [[13.333086, 52.4224]],
coordinates: [three_test_coordinates[0]],
number: 3
}, function(err, result) {
assert.ifError(err);
Expand All @@ -29,19 +32,19 @@ test('nearest: can ask for multiple nearest pts', function(assert) {

test('nearest: throws on invalid args', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
var osrm = new OSRM(data_path);
var options = {};
assert.throws(function() { osrm.nearest(options); },
/Two arguments required/);
assert.throws(function() { osrm.nearest(null, function(err, res) {}); },
/First arg must be an object/);
options.coordinates = [52.4224];
options.coordinates = [43.73072];
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Coordinates must be an array of /);
options.coordinates = [[13.333086, 52.4224],[13.333086, 52.5224]];
options.coordinates = [three_test_coordinates[0], three_test_coordinates[1]];
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Exactly one coordinate pair must be provided/);
options.coordinates = [[13.333086, 52.4224]];
options.coordinates = [three_test_coordinates[0]];
options.number = 3.14159;
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Number must be an integer greater than or equal to 1/);
Expand Down
12 changes: 0 additions & 12 deletions test/nodejs/osrm-data-path.js

This file was deleted.

Loading

0 comments on commit 70b3962

Please sign in to comment.