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

Add support for Jsonnet TLAs and clean up cfg tests. #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ clusters-*.json
*.zip
data
calgrind.*
callgrind.out*
9 changes: 8 additions & 1 deletion apps/inc/WireCellApps/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ namespace WireCell {
/// files (via std.extVar())
void add_code(const std::string& name, const std::string& value);

/// Bind a Top-Level argument variable to a string value.
void add_tlavar(const std::string& name, const std::string& value);

/// Bind a Top-Level argument variable to a code value.
void add_tlacode(const std::string& name, const std::string& value);


/// Add an element to the configuration path in which
/// configuration files may be found.
void add_path(const std::string& dirname);
Expand Down Expand Up @@ -86,7 +93,7 @@ namespace WireCell {
private:
ConfigManager m_cfgmgr;
std::vector<std::string> m_plugins, m_apps, m_cfgfiles, m_load_path;
Persist::externalvars_t m_extvars, m_extcode;
Persist::externalvars_t m_extvars, m_extcode, m_tlavars, m_tlacode;
Log::logptr_t l;

};
Expand Down
29 changes: 28 additions & 1 deletion apps/src/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int Main::cmdline(int argc, char* argv[])
// ("jsonpath,j", po::value< vector<string> >(),"specify a JSON path=value")
("ext-str,V", po::value< vector<string> >(),"specify a Jsonnet external variable=value")
("ext-code,C", po::value< vector<string> >(),"specify a Jsonnet external variable=code")
("tla-str", po::value< vector<string> >(),"specify a Jsonnet top level argument variable=value")
("tla-code", po::value< vector<string> >(),"specify a Jsonnet top level argument variable=code")
("path,P", po::value< vector<string> >(),"add to JSON/Jsonnet search path")
;

Expand Down Expand Up @@ -86,6 +88,21 @@ int Main::cmdline(int argc, char* argv[])
add_code(vv[0], vv[1]);
}
}
// Get any TLA variables
if (opts.count("tla-str")) {
for (auto vev : opts["tla-str"].as< vector<string> >()) {
auto vv = String::split(vev, "=");
add_tlavar(vv[0], vv[1]);
}
}
// And any TLA code
if (opts.count("tla-code")) {
for (auto vev : opts["tla-code"].as< vector<string> >()) {
auto vv = String::split(vev, "=");
add_tlacode(vv[0], vv[1]);
}
}

// fixme: these aren't yet supported.
// if (opts.count("jsonpath")) {
// jsonpath_vars = opts["jsonpath"].as< vector<string> >();
Expand Down Expand Up @@ -175,6 +192,16 @@ void Main::add_code(const std::string& name, const std::string& value)
m_extcode[name] = value;
}

void Main::add_tlavar(const std::string& name, const std::string& value)
{
m_tlavars[name] = value;
}

void Main::add_tlacode(const std::string& name, const std::string& value)
{
m_tlacode[name] = value;
}

void Main::add_path(const std::string& dirname)
{
m_load_path.push_back(dirname);
Expand All @@ -185,7 +212,7 @@ void Main::initialize()
{
for (auto filename : m_cfgfiles) {
l->info("loading config file {} ...", filename);
Persist::Parser p(m_load_path, m_extvars, m_extcode);
Persist::Parser p(m_load_path, m_extvars, m_extcode, m_tlavars, m_tlacode);
Json::Value one = p.load(filename); // throws
m_cfgmgr.extend(one);
l->info("...done");
Expand Down
25 changes: 2 additions & 23 deletions cfg/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,9 @@ dropped from the tip of the master branch.

* Tests

There may be other Jsonnet files found in the ~/test/~ sub-directories
of the various WCT packages.
As part of the normal build, various test Jsonnet compilations and
scripts run. Anything under ~test/test*.jsonnet~ should compile.

Running the configuration tests is done through the files under =test/=. They rely on a simple ad-hoc test harness. All tests can be run from the top-level =wire-cell= source directory after a build like:

#+BEGIN_EXAMPLE
./cfg/test/test_all.sh
#+END_EXAMPLE

A single test can be run like:

#+BEGIN_EXAMPLE
./cfg/test/test_one.sh <testname>
#+END_EXAMPLE

Each test has a =test_<testname>.jsonnet= file.

#+BEGIN_EXAMPLE
ls cfg/test/test_*.jsonnet
#+END_EXAMPLE

These main JSonnet files are typically composed of some chunks reused by the various different tests. The chunks are named like =cfg_*.jsonnet=. The body of each main =test_<testname>.jsonnet= largely consists of the data flow graph definition for the =TbbFlow= Wire Cell application object.

See also https://github.com/wirecell/wire-cell-tests.
* JQ tricks

The ~jq~ tool is like ~grep~ for JSON. Here are some useful tricks to operate on a mongo big JSON file.
Expand Down
4 changes: 4 additions & 0 deletions cfg/test/a-want.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "wire cell toolkit",
"port": 9999
}
4 changes: 4 additions & 0 deletions cfg/test/a.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function(name, port) {
name: name,
port: port
}
3 changes: 0 additions & 3 deletions cfg/test/tbbdfp_trackdepos.jsonnet

This file was deleted.

10 changes: 0 additions & 10 deletions cfg/test/test-pgrapher-common-funcs.jsonnet

This file was deleted.

7 changes: 7 additions & 0 deletions cfg/test/test-tla.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

mydir=$(dirname $(realpath $BASH_SOURCE))


jsonnet --tla-str name="wire cell toolkit" --tla-code port=9999 $mydir/a.jsonnet > a-got.json || exit -1
jsonnet -J $mydir -e 'local got=import "a-got.json"; local want=import "a-want.json"; assert (got == want); got' || exit -1
5 changes: 4 additions & 1 deletion cfg/test/test-all.sh → cfg/test/test-wct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ cfgdir=$(dirname $mydir)

for main in $(find $cfgdir/pgrapher -name '*wct-*.jsonnet') ; do
echo $main
jsonnet -J $cfgdir $main > /dev/null
jsonnet -J $cfgdir $main > /dev/null || exit -1
done



11 changes: 0 additions & 11 deletions cfg/test/test_all.sh

This file was deleted.

41 changes: 0 additions & 41 deletions cfg/test/test_diffuser.jsonnet

This file was deleted.

46 changes: 0 additions & 46 deletions cfg/test/test_drifter.jsonnet

This file was deleted.

13 changes: 0 additions & 13 deletions cfg/test/test_drifter.sh

This file was deleted.

105 changes: 0 additions & 105 deletions cfg/test/test_p2p.jsonnet

This file was deleted.

Loading