Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly use defined source and build dirs for testing #4392

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

kevinkreiser
Copy link
Member

trivial one but in a lot of the tests we dont use directories in a CWD safe way which causes some tests to fail when you run them outside of their narrow working criteria. this pr simply fixes the tests that rely on paths to either source stuff or stuff we are building in the build directory

@nilsnolde
Copy link
Member

ah thanks for the chore! never had the motivation so far, but it's so annoying to get all the test maps dumped in the wrong directory and messing up git (plus the inability to run them in some ways..)

@kevinkreiser
Copy link
Member Author

yeah was working on #4390 and it was annoying me so last night i decided i was going to remedy it. i didnt check the gurka directory yet but i can get that in another pass

@nilsnolde
Copy link
Member

nilsnolde commented Nov 14, 2023

Should we just add the VALHALLA_BUILD_DIR to test::make_config and be done with it? That'd give us all gurka tests for free and it seems there's only very few tests calling make_config with the right path so far, should be way less changes?

@kevinkreiser
Copy link
Member Author

i had the same th ought yep

Comment on lines +29 to +31
target_compile_definitions(valhalla_test PRIVATE
VALHALLA_SOURCE_DIR="${VALHALLA_SOURCE_DIR}/"
VALHALLA_BUILD_DIR="${VALHALLA_BUILD_DIR}/")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all test targets get these two dirs defined so that..

Comment on lines -10 to -13
#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont have to have this random hack in there and we always get the right value (i have no idea why this kind of thing was hacked in here..)

using namespace valhalla::mjolnir;
using namespace valhalla::baldr;

namespace {

const std::string config_file = "test/test_config_country";
const std::string config_file = VALHALLA_BUILD_DIR "test/test_config_country";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in places where we dont use make_config we use the thing manually

@@ -151,16 +151,16 @@ const gurka::ways ways = {{"AB", {{"highway", "primary"}}}, {"BC", {{"highway",

boost::property_tree::ptree get_config() {

return test::make_config(VALHALLA_BUILD_DIR "test/data/transit_tests",
return test::make_config("test/data/transit_tests",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in places where we do use make_config we rely on it to do the work for us

@@ -334,7 +335,7 @@ TEST(MapMatchRoute, IgnoreRestrictions) {
},
{{"type", "restriction"}, {"restriction", "no_straight_on"}}}};
const gurka::map map =
gurka::buildtiles(layout, ways, {}, relations, "test/data/mapmatch_restrictions",
gurka::buildtiles(layout, ways, {}, relations, VALHALLA_BUILD_DIR "test/data/mapmatch_restrictions",
{{"mjolnir.timezone", VALHALLA_BUILD_DIR "test/data/tz.sqlite"}});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i felt it made sense to do it manually in these cases where we use the config option overrides because if we rely on make_config doing the right thing by prefixing directories with VALHALLA_BUILD_DIR, but then we add a config override for timezone and we ourselves dont prefix it, then we've defeated ourselves.

alternatively i could have written code to see if any override value begins with "test/data" and then prefixed that but it felt a little too much? i dont feel stronly about it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand this: on line 205 you're removing the prefix for tzdb, on line 337 you're adding it for the graph build (which should be covered already by make_config) and on line 339 you left it again for tzdb. probably an oversight?

IMO it'd be more consistent that noone ever has to specify VALHALLA_BUILD_DIR manually, but it's also a much rarer thing to do, so I'm ok with it too.

Comment on lines +388 to +395
// we should use absolute paths so the binaries work regardless of CWD
std::string absolute;
if (path_prefix.find("test/") == 0) {
absolute = VALHALLA_BUILD_DIR;
}

// force the paths to be different
boost::replace_all(defaults, "%%", path_prefix);
boost::replace_all(defaults, "%%", absolute + path_prefix);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the important part, we detect if your data prefix doesnt have the absolute path on and add it if not. this lets the binaries be run from any working directory (which can be useful)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also note that gurka::buildtiles calls into this function so its covered too

@kevinkreiser
Copy link
Member Author

this is ready for review

{"mjolnir.transit_pbf_limit",
"1"}, // so we create more than one file per tile
{"mjolnir.hierarchy", "1"},
{"mjolnir.timezone", VALHALLA_BUILD_DIR "test/data/tz.sqlite"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, do we really want to remove it here? or maybe it's added somewhere else I didn't yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is the primary open issue at this point. the signature for make_config takes first the directory argument and second a map of key values replacements, some of which might be things that are directories some not.

it was easy for me to patch the first arg when it didnt have the absolute path because i knew it was a directory but for the key values i dont know which ones are and arent directories. this means detecting and patching those is harder.

there are two options to do it automatically:

  1. something simple where i see the value begins with "test/data" this will not catch everythign but it should get most of everything
  2. figure out which ones should be directories by looking at the default config for the path value that got substituted in everywhere and then patching only those that were substituted paths

i think ill take a try at the 2nd one because then everything can be completely automatic and i can remove any of these that exist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that'd be much appreciated, albeit quite a sizable mechanical chore

@@ -67,7 +67,8 @@ class ProbableRestrictions : public testing::TestWithParam<int> {
{gurka::node_member, "I", "via"},
},
{{"type", "restriction"}, {"restriction:probable", "no_left_turn @ probability=0"}}}};
map = gurka::buildtiles(layout, ways, {}, relations, "test/data/gurka_time_probable_restrictions",
map = gurka::buildtiles(layout, ways, {}, relations,
VALHALLA_BUILD_DIR "test/data/gurka_time_probable_restrictions",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'm confused.. isn't this the graph directory? don't we set that now in make_config()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same in lots of other places in gurka

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do and I went through 2 rounds of this and missed this in the last round. it's surprisingly annoying to find all occurances at midnight after a long day at work hahaha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants