Skip to content

Commit 93714f0

Browse files
cassavaclsim
andcommitted
gndtruth_extractor: Add smoketests with output comparison
Co-authored-by: Martin Henselmeyer <[email protected]>
1 parent 0821655 commit 93714f0

5 files changed

+755
-1
lines changed

plugins/gndtruth_extractor/tests/conanfile_default.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class CloeTest(ConanFile):
6-
python_requires = "cloe-launch-profile/[~=0.19.0]@cloe/develop"
6+
python_requires = "cloe-launch-profile/[~=0.20.0]@cloe/develop"
77
python_requires_extend = "cloe-launch-profile.Base"
88

99
default_options = {

plugins/gndtruth_extractor/tests/test_gndtruth.bats

+67
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,73 @@ export CLOE_ROOT="${BATS_TEST_DIRNAME}/../../.."
55
load "${CLOE_ROOT}/tests/setup_bats.bash"
66
load "${CLOE_ROOT}/tests/setup_testname.bash"
77

8+
# Usage: FILENAME=$(mktemp_gndtruth_out SUFFIX)
9+
#
10+
# Prints a new temporary filename with the given suffix.
11+
# This allows different tests be run in parallel.
12+
mktemp_gndtruth_out() {
13+
local suffix=${1}
14+
mktemp -u --suffix=.${suffix} /tmp/cloe-gndtruth-XXXXX
15+
}
16+
17+
# Usage: fn_test_gndtruth SUFFIX DECOMPRESS
18+
#
19+
# Parameters:
20+
# SUFFIX One of "json", "json.gz", "json.bz2", "msgpack", "msgpack.gz", "msgpack.bz2"
21+
# DECOMPRESS One of "cat", "gunzip", "bunzip2"
22+
fn_test_gndtruth() {
23+
local suffix="$1"
24+
local decompress="$2"
25+
26+
# This neat little trick will give us "json" or "msgpack"
27+
local base_suffix="${suffix/.*/}"
28+
local CLOE_GNDTRUTH_REF="test_gndtruth_smoketest_output.${base_suffix}"
29+
30+
export CLOE_GNDTRUTH_OTYPE="$suffix"
31+
export CLOE_GNDTRUTH_ONAME="$(mktemp_gndtruth_out $suffix)"
32+
33+
# Clean any pre-existing file.
34+
if [ -f "$CLOE_GNDTRUTH_ONAME" ]; then
35+
rm "$CLOE_GNDTRUTH_ONAME"
36+
fi
37+
38+
cloe-engine run test_gndtruth_smoketest.json
39+
assert_exit_success $?
40+
41+
# Expect configured output file to exist.
42+
test -f "$CLOE_GNDTRUTH_ONAME"
43+
44+
# Expect reference file to equal the "decompressed" output file
45+
diff "$CLOE_GNDTRUTH_REF" <($decompress - < "$CLOE_GNDTRUTH_ONAME")
46+
47+
# Remove temporary file.
48+
rm "$CLOE_GNDTRUTH_ONAME"
49+
}
50+
51+
@test "$(testname 'Expect json' 'test_gndtruth_smoketest.json' 'd5f58690-e7bc-4170-ab7e-9b785a5866c3')" {
52+
fn_test_gndtruth "json" "cat"
53+
}
54+
55+
@test "$(testname 'Expect json.gz' 'test_gndtruth_smoketest.json' 'b3a11bb5-6fd1-401e-b9fb-db76b4c338e5')" {
56+
fn_test_gndtruth "json.gz" "gunzip"
57+
}
58+
59+
@test "$(testname 'Expect json.bz2' 'test_gndtruth_smoketest.json' '69eeb436-4b5e-4a31-9097-01f03cb0f71d')" {
60+
fn_test_gndtruth "json.bz2" "bunzip2"
61+
}
62+
63+
@test "$(testname 'Expect msgpack' 'test_gndtruth_smoketest.json' '40757b44-3aa0-4a46-8597-ebf2b8acfbab')" {
64+
fn_test_gndtruth "msgpack" "cat"
65+
}
66+
67+
@test "$(testname 'Expect msgpack.gz' 'test_gndtruth_smoketest.json' 'bf77683f-7c1a-4d70-b713-e26f440e71f7')" {
68+
fn_test_gndtruth "msgpack.gz" "gunzip"
69+
}
70+
71+
@test "$(testname 'Expect msgpack.bz2' 'test_gndtruth_smoketest.json' 'c50350d5-9b63-43bb-9e00-d31646e50b0a')" {
72+
fn_test_gndtruth "msgpack.bz2" "bunzip2"
73+
}
74+
875
@test "$(testname 'Expect run failure' 'test_gndtruth_invalid_file.json' '29e8ff3b-86f3-4320-ba69-05600df1f836')" {
976
cloe-engine check test_gndtruth_invalid_file.json
1077
run cloe-engine run test_gndtruth_invalid_file.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": "4",
3+
"include": [
4+
"config_minimator_smoketest.json"
5+
],
6+
"controllers": [
7+
{
8+
"binding": "gndtruth_extractor",
9+
"vehicle": "default",
10+
"args": {
11+
// This file is parameterized with these two fields that can
12+
// be supplied by the environment.
13+
//
14+
// This is done in test_gndtruth.bats
15+
"output_file": "${CLOE_GNDTRUTH_ONAME-/tmp/cloe_gndtruth.json}",
16+
"output_type": "${CLOE_GNDTRUTH_OTYPE-json}",
17+
"components": [
18+
"cloe::gndtruth_lane_sensor",
19+
"cloe::default_world_sensor"
20+
]
21+
}
22+
}
23+
],
24+
"triggers": [
25+
{ "event": "start", "action": "log=info: Running gndtruth/smoketest." },
26+
{ "event": "start", "action": "realtime_factor=-1" },
27+
28+
// This is earlier than the time configured in the included file.
29+
// It should result in 4 cycles for the gndtruth_extractor plugin.
30+
{ "event": "time=0.1", "action": "succeed" }
31+
]
32+
}

0 commit comments

Comments
 (0)